diff --git a/include/core/spritecontainer.h b/include/core/spritecontainer.h index 139a3e8..51b7489 100644 --- a/include/core/spritecontainer.h +++ b/include/core/spritecontainer.h @@ -35,6 +35,7 @@ public: inline void resetSprite(const std::shared_ptr &sprite, Type action) noexcept { + sprite->reset(); _sprite_dispatcher[action].push(sprite); } diff --git a/src/main.cpp b/src/main.cpp index 0a505b6..c295739 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,7 @@ int main() { - sf::RenderWindow window(sf::VideoMode{1280, 720}, "Project Kyoku", sf::Style::Fullscreen); + sf::RenderWindow window(sf::VideoMode{1280, 720}, "Project Kyoku", sf::Style::Default); ApplicationSFML app(&window); if (app.init()) app.run(); diff --git a/src/modes/classicmode/classicnote.cpp b/src/modes/classicmode/classicnote.cpp index aa6c843..76d4aea 100644 --- a/src/modes/classicmode/classicnote.cpp +++ b/src/modes/classicmode/classicnote.cpp @@ -1,8 +1,9 @@ #include "classicmode/classicnote.h" -ClassicNote::ClassicNote(const kku::microsec& perfect_offset) : +ClassicNote::ClassicNote(const kku::microsec& perfect_offset, int id) : Note(perfect_offset), - _state(State::NONE) + _state(State::NONE), + _id(id) {} void ClassicNote::setState(ClassicNote::State state) noexcept @@ -14,3 +15,8 @@ auto ClassicNote::getState() const noexcept -> State { return _state; } + +int ClassicNote::getId() const noexcept +{ + return _id; +} diff --git a/src/modes/classicmode/editor/classiceditor.cpp b/src/modes/classicmode/editor/classiceditor.cpp index d23a645..7eed59b 100644 --- a/src/modes/classicmode/editor/classiceditor.cpp +++ b/src/modes/classicmode/editor/classiceditor.cpp @@ -18,7 +18,8 @@ ClassicEditor::ClassicEditor(const std::shared_ptr>& _context(context), _selected_type(Type::UP), _current_time(0), - _scroll_step(500000) + _scroll_step(500000), + _note_id(0) { kku::microsec starting_beat_offset = 402162; int amount_of_beats = 209; @@ -38,7 +39,6 @@ ClassicEditor::ClassicEditor(const std::shared_ptr>& float x = 90.; int counter = 3; - while (bpm_iterator < bpm_end) { ArrowElement element; @@ -69,6 +69,7 @@ ClassicEditor::ClassicEditor(const std::shared_ptr>& ClassicArrowNote::Init init { + _note_id++, context, bpm_iterator, input_intervals, @@ -144,6 +145,7 @@ void ClassicEditor::input(kku::GameEvent&& input) ClassicArrowNote::Init init { + _note_id++, _context, _current_time, {}, diff --git a/src/modes/classicmode/editor/classiceditor.h b/src/modes/classicmode/editor/classiceditor.h index 2c90754..90c244d 100644 --- a/src/modes/classicmode/editor/classiceditor.h +++ b/src/modes/classicmode/editor/classiceditor.h @@ -34,4 +34,5 @@ private: Type _selected_type; kku::microsec _current_time; kku::microsec _scroll_step; + int _note_id; }; diff --git a/src/modes/classicmode/editor/editorcontext.cpp b/src/modes/classicmode/editor/editorcontext.cpp index a0beab6..75cc82b 100644 --- a/src/modes/classicmode/editor/editorcontext.cpp +++ b/src/modes/classicmode/editor/editorcontext.cpp @@ -76,7 +76,11 @@ void EditorContext::update(ClassicArrowNote *note, const kku::microsec& music_of case ClassicArrowNote::State::DYING: if (elements[0].animations[note->getState()]->isDone()) + { note->setState(ClassicArrowNote::State::DEAD); + for (auto& manager : _graphics_managers) + manager->update(music_offset, note); + } break; } diff --git a/src/modes/classicmode/game/classicarrownote.cpp b/src/modes/classicmode/game/classicarrownote.cpp index 7e3549f..240f65c 100644 --- a/src/modes/classicmode/game/classicarrownote.cpp +++ b/src/modes/classicmode/game/classicarrownote.cpp @@ -3,7 +3,7 @@ #include "graphics/classicgraphicsmanager.h" ClassicArrowNote::ClassicArrowNote(Init&& init) : - ClassicNote(init.perfect_offset), + ClassicNote(init.perfect_offset, init.id), _evaluator(init.intervals, init.perfect_offset), _context(init.context), _is_holding(init.is_holding) diff --git a/src/modes/classicmode/game/classicarrownote.h b/src/modes/classicmode/game/classicarrownote.h index 7b22954..acf598d 100644 --- a/src/modes/classicmode/game/classicarrownote.h +++ b/src/modes/classicmode/game/classicarrownote.h @@ -14,6 +14,7 @@ public: struct Init { + const int id = 0; const std::shared_ptr context; const kku::microsec perfect_offset = 0; diff --git a/src/modes/classicmode/game/classicmapcreator.cpp b/src/modes/classicmode/game/classicmapcreator.cpp index 568e781..eff0974 100644 --- a/src/modes/classicmode/game/classicmapcreator.cpp +++ b/src/modes/classicmode/game/classicmapcreator.cpp @@ -30,6 +30,7 @@ auto classic::createBeatmap(const std::string& filepath, const std::shared_ptrsetTrailPosition(kku::Point(getPoint( kku::Point{xa, xb}, i ), getPoint( kku::Point{ya, yb}, i ))); - - bool pastPerfectScore = (i >= 1); - - if (pastPerfectScore) - fadeTrailSprite(); } bool ClassicFlyingAnimationScenario::isDone() const @@ -39,15 +36,7 @@ bool ClassicFlyingAnimationScenario::isDone() const return false; } -void ClassicFlyingAnimationScenario::fadeTrailSprite() const +void ClassicFlyingAnimationScenario::refillColor() const { - auto fill_color = _sprite->getTrailColor(); - - if (fill_color.alpha == 0) - return; - - auto new_alpha = (int(fill_color.alpha) - 15) < 0 ? 0 : int(fill_color.alpha) - 15; - fill_color.alpha = new_alpha; - - _sprite->setTrailColor(fill_color); + _sprite->setTrailColor(_sprite->getColor()); } diff --git a/src/modes/classicmode/graphics/animations/classicflyinganimationscenario.h b/src/modes/classicmode/graphics/animations/classicflyinganimationscenario.h index fda6911..7ebdb2a 100644 --- a/src/modes/classicmode/graphics/animations/classicflyinganimationscenario.h +++ b/src/modes/classicmode/graphics/animations/classicflyinganimationscenario.h @@ -12,7 +12,7 @@ public: private: float getPoint(const kku::Point& position, float perc) const; - void fadeTrailSprite() const; + void refillColor() const; float _percentage; }; diff --git a/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp b/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp index de13146..b08261c 100644 --- a/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp +++ b/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp @@ -1,6 +1,8 @@ #include "classicscenegraphicsmanager.h" #include "game/classicarrownote.h" +#include + ClassicSceneGraphicsManager::ClassicSceneGraphicsManager(const std::shared_ptr>& timeline, const std::shared_ptr& factory, const kku::microsec& visibility_offset) : @@ -33,7 +35,9 @@ void ClassicSceneGraphicsManager::display() const for (auto it = _first; it != _last; ++it) { - (*it)->draw(shared_from_this()); + const auto note = *it; + if (note->getState() != ClassicNote::State::DEAD) + note->draw(shared_from_this()); } } @@ -48,8 +52,17 @@ void ClassicSceneGraphicsManager::update(const kku::microsec &offset) void ClassicSceneGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note) { bool hasGraphics = (note->getElements()[0].sprite != nullptr); - if (isVisiblyClose(note, offset) && (!hasGraphics)) + + if (isVisiblyClose(note, offset) && !hasGraphics) + { + std::cout << note->getId() << ": set graphics!\n" << std::flush; setGraphics(note->getElements(), kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()}); + } + else + { + std::cout << note->getId() << ": remove graphics!\n" << std::flush; + removeGraphics(note->getElements()); + } } void ClassicSceneGraphicsManager::draw(const std::vector& elements) const @@ -87,6 +100,20 @@ void ClassicSceneGraphicsManager::setGraphics(std::vector& element } } +void ClassicSceneGraphicsManager::removeGraphics(std::vector& elements) +{ + for (auto& element : elements) + { + _sprite_container.resetSprite(element.sprite, element.type); + element.sprite = nullptr; + + element.animations[ClassicNote::State::NONE] = nullptr; + element.animations[ClassicNote::State::FLYING] = nullptr; + element.animations[ClassicNote::State::DYING] = nullptr; + element.animations[ClassicNote::State::DEAD] = nullptr; + } +} + bool ClassicSceneGraphicsManager::nothingToDraw() const noexcept { return _timeline->isExpired(_first) diff --git a/src/modes/classicmode/graphics/classicscenegraphicsmanager.h b/src/modes/classicmode/graphics/classicscenegraphicsmanager.h index 35e2e7d..a18fd9e 100644 --- a/src/modes/classicmode/graphics/classicscenegraphicsmanager.h +++ b/src/modes/classicmode/graphics/classicscenegraphicsmanager.h @@ -24,7 +24,10 @@ public: virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override; virtual void draw(const std::vector& elements) const override; - virtual void setGraphics(std::vector& elements, kku::TimeRange&& range); + + void setGraphics(std::vector& elements, kku::TimeRange&& range); + void removeGraphics(std::vector& elements); + protected: kku::SpriteContainer _sprite_container; diff --git a/src/modes/classicmode/include/classicmode/classicnote.h b/src/modes/classicmode/include/classicmode/classicnote.h index 33a1011..04efc9c 100644 --- a/src/modes/classicmode/include/classicmode/classicnote.h +++ b/src/modes/classicmode/include/classicmode/classicnote.h @@ -19,7 +19,7 @@ public: DEAD = 4 }; - explicit ClassicNote(const kku::microsec& perfect_offset); + explicit ClassicNote(const kku::microsec& perfect_offset, int id); virtual ~ClassicNote() override = default; virtual bool isActive(const kku::microsec& offset) const override = 0; @@ -29,7 +29,9 @@ public: void setState(State state) noexcept; State getState() const noexcept; + int getId() const noexcept; protected: State _state; + int _id; };