diff --git a/src/modes/classicmode/classicfactory.cpp b/src/modes/classicmode/classicfactory.cpp index 44af705..90a72bf 100644 --- a/src/modes/classicmode/classicfactory.cpp +++ b/src/modes/classicmode/classicfactory.cpp @@ -15,7 +15,6 @@ std::unique_ptr classic::getGame(const std::shared_ptr& core_factory) { - // read offset from beatmap metadata const kku::microsec visibility_offset = 1648648; const auto factory = std::make_shared(core_factory); @@ -30,7 +29,6 @@ std::unique_ptr classic::getGame(const std::shared_ptr classic::getEditor(const std::shared_ptr& core_factory) { - // read offset from beatmap metadata const kku::microsec visibility_offset = 1648648; const auto factory = std::make_shared(core_factory); diff --git a/src/modes/classicmode/editor/classiceditor.cpp b/src/modes/classicmode/editor/classiceditor.cpp index 7eed59b..ee0490d 100644 --- a/src/modes/classicmode/editor/classiceditor.cpp +++ b/src/modes/classicmode/editor/classiceditor.cpp @@ -53,6 +53,14 @@ ClassicEditor::ClassicEditor(const std::shared_ptr>& bool hold = false; + if (_note_id == 0) + { + element.keys = {kku::SystemEvent::Key::Code::S, + kku::SystemEvent::Key::Code::Down}; + + element.type = Type::DOWN; + } + if (counter == 0) { hold = true; @@ -163,8 +171,9 @@ void ClassicEditor::input(kku::GameEvent&& input) break; } - } + + _context->inputUI(std::move(input)); } void ClassicEditor::update(kku::UpdateData&& updatedata) diff --git a/src/modes/classicmode/editor/editorcontext.cpp b/src/modes/classicmode/editor/editorcontext.cpp index 75cc82b..b69ceb8 100644 --- a/src/modes/classicmode/editor/editorcontext.cpp +++ b/src/modes/classicmode/editor/editorcontext.cpp @@ -94,6 +94,12 @@ std::shared_ptr> EditorContext::getSelectionManage return _selection_manager; } +void EditorContext::inputUI(kku::GameEvent&& input) +{ + for (auto& manager : _graphics_managers) + manager->input(std::move(input)); +} + void EditorContext::updateGraphics(const kku::microsec& music_offset) { for (auto& manager : _graphics_managers) diff --git a/src/modes/classicmode/editor/editorcontext.h b/src/modes/classicmode/editor/editorcontext.h index 60c1361..a7813ab 100644 --- a/src/modes/classicmode/editor/editorcontext.h +++ b/src/modes/classicmode/editor/editorcontext.h @@ -17,6 +17,7 @@ public: virtual void input(ClassicArrowNote *note, kku::GameEvent&& input) const override; virtual void update(ClassicArrowNote *note, const kku::microsec &music_offset) const override; + void inputUI(kku::GameEvent&& input); void updateGraphics(const kku::microsec& music_offset); void displayGraphics() const; diff --git a/src/modes/classicmode/game/classicarrownote.cpp b/src/modes/classicmode/game/classicarrownote.cpp index 240f65c..38a51fa 100644 --- a/src/modes/classicmode/game/classicarrownote.cpp +++ b/src/modes/classicmode/game/classicarrownote.cpp @@ -36,7 +36,7 @@ void ClassicArrowNote::input(kku::GameEvent&& input) void ClassicArrowNote::draw(const std::shared_ptr& graphics_manager) const { - graphics_manager->draw(_elements); + graphics_manager->draw(this); } bool ClassicArrowNote::isHold() const @@ -49,6 +49,11 @@ std::vector& ClassicArrowNote::getElements() return _elements; } +const std::vector& ClassicArrowNote::getElements() const +{ + return _elements; +} + auto ClassicArrowNote::calculatePrecision(const kku::microsec& offset) const -> Grade { return _evaluator.calculatePrecision(offset); diff --git a/src/modes/classicmode/game/classicarrownote.h b/src/modes/classicmode/game/classicarrownote.h index acf598d..0b3c319 100644 --- a/src/modes/classicmode/game/classicarrownote.h +++ b/src/modes/classicmode/game/classicarrownote.h @@ -40,6 +40,7 @@ public: bool isHold() const; std::vector& getElements(); + const std::vector& getElements() const; Grade calculatePrecision(const kku::microsec& offset) const; bool isPressedAs(kku::SystemEvent::Key::Code key) const; diff --git a/src/modes/classicmode/graphics/classicgraphicsmanager.h b/src/modes/classicmode/graphics/classicgraphicsmanager.h index f042a77..69c2ab3 100644 --- a/src/modes/classicmode/graphics/classicgraphicsmanager.h +++ b/src/modes/classicmode/graphics/classicgraphicsmanager.h @@ -25,7 +25,7 @@ public: virtual void update(const kku::microsec& offset, ClassicArrowNote* note) = 0; // virtual void update(const kku::microsec& offset, ClassicSliderNote* note) = 0; - virtual void draw(const std::vector& elements) const = 0; + virtual void draw(const ClassicArrowNote * const note) const = 0; // virtual void draw(ClassicSliderNote* note) const = 0; protected: diff --git a/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp b/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp index b08261c..f89a93d 100644 --- a/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp +++ b/src/modes/classicmode/graphics/classicscenegraphicsmanager.cpp @@ -65,8 +65,9 @@ void ClassicSceneGraphicsManager::update(const kku::microsec& offset, ClassicArr } } -void ClassicSceneGraphicsManager::draw(const std::vector& elements) const +void ClassicSceneGraphicsManager::draw(const ClassicArrowNote * const note) const { + const auto elements = note->getElements(); for (std::size_t i = 0; i < elements.size(); ++i) { const auto& sprite = elements[i].sprite; diff --git a/src/modes/classicmode/graphics/classicscenegraphicsmanager.h b/src/modes/classicmode/graphics/classicscenegraphicsmanager.h index a18fd9e..552b129 100644 --- a/src/modes/classicmode/graphics/classicscenegraphicsmanager.h +++ b/src/modes/classicmode/graphics/classicscenegraphicsmanager.h @@ -23,7 +23,7 @@ public: virtual void update(const kku::microsec& offset) override; virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override; - virtual void draw(const std::vector& elements) const override; + virtual void draw(const ClassicArrowNote * const note) const override; void setGraphics(std::vector& elements, kku::TimeRange&& range); void removeGraphics(std::vector& elements); diff --git a/src/modes/classicmode/graphics/classictimelinegraphicsmanager.cpp b/src/modes/classicmode/graphics/classictimelinegraphicsmanager.cpp index f59e8dd..44a6f64 100644 --- a/src/modes/classicmode/graphics/classictimelinegraphicsmanager.cpp +++ b/src/modes/classicmode/graphics/classictimelinegraphicsmanager.cpp @@ -11,7 +11,9 @@ ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared Type::LEFT, Type::RIGHT}, factory), _factory(factory), - _timeline(timeline) + _timeline(timeline), + _back_visibility_offset(static_cast(visibility_offset) / 4.f), + _last_offset(0) { _timeline->expire(_first); _timeline->expire(_last); @@ -19,34 +21,49 @@ ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared void ClassicTimelineGraphicsManager::input(kku::GameEvent&& input) { - if (nothingToDraw()) - return; + switch (input.event.type) + { + default: + break; - for (auto it = _first; it != _last; ++it) + case kku::SystemEvent::Type::KeyPress: { - (*it)->input(std::move(input)); + const auto key_data = std::get(input.event.data); + if (key_data.view == kku::SystemEvent::Key::Code::Add) + { + _visibility_offset += 200000; + _back_visibility_offset = static_cast(_visibility_offset) / 4.f; + } + else if (key_data.view == kku::SystemEvent::Key::Code::Subtract) + { + _visibility_offset -= 200000; + _back_visibility_offset = static_cast(_visibility_offset) / 4.f; + } + break; + } } } void ClassicTimelineGraphicsManager::display() const { - if (nothingToDraw()) - return; + //if (nothingToDraw()) + //return; + std::cout << "displaying on tl: "; for (auto it = _first; it != _last; ++it) { - const auto note = *it; - if (note->getState() != ClassicNote::State::DEAD) - note->draw(shared_from_this()); + std::cout << (*it)->getId() << " "; + (*it)->draw(shared_from_this()); } + + std::cout << "\n" << std::flush; } void ClassicTimelineGraphicsManager::update(const kku::microsec &offset) { + _last_offset = offset; fetchLastNote(offset); fetchFirstNote(offset); - - updateVisibleNotes(offset); } void ClassicTimelineGraphicsManager::update(const kku::microsec& offset, ClassicArrowNote* note) @@ -63,21 +80,23 @@ void ClassicTimelineGraphicsManager::update(const kku::microsec& offset, Classic } } -void ClassicTimelineGraphicsManager::draw(const std::vector& elements) const +void ClassicTimelineGraphicsManager::draw(const ClassicArrowNote * const note) const { + const double d_visibility_offset = static_cast(_last_offset + _visibility_offset); + const double d_back_visibility_offset = static_cast(_last_offset - _back_visibility_offset); + + const double span = d_visibility_offset - d_back_visibility_offset; + const double note_span = static_cast(note->getPerfectOffset()) - d_visibility_offset; + + const double percent = note_span / (span / 100.f); + + const auto elements = note->getElements(); for (std::size_t i = 0; i < elements.size(); ++i) { - const auto& sprite = elements[i].sprite; + auto timeline_sprite = _factory->createSprite(elements[i].type); + timeline_sprite->setPosition(kku::Point{static_cast(850 + 1280.f / 100.f * percent), 700}); - if (i >= 1) - { - //const auto& neighbor_sprite = elements[i - 1].sprite; - //const auto c1 = neighbor_sprite->trailPosition(); - //const auto c2 = sprite->trailPosition(); - //_render_target->draw(makeLine(c1, c2)); - } - - sprite->display(); + timeline_sprite->display(); } } @@ -89,49 +108,24 @@ bool ClassicTimelineGraphicsManager::nothingToDraw() const noexcept bool ClassicTimelineGraphicsManager::isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept { - return (note->getPerfectOffset() - _visibility_offset) <= music_offset; + const auto& perfect_offset = note->getPerfectOffset(); + + return ((perfect_offset - _visibility_offset) <= music_offset) + || ((perfect_offset + (_visibility_offset / 4.)) >= music_offset); } void ClassicTimelineGraphicsManager::fetchFirstNote(const kku::microsec& offset) { - if (nothingToDraw()) - return; + //if (nothingToDraw()) + //return; - if (offset < (*_first)->getPerfectOffset()) + Iterator note_iterator = _first; + while (note_iterator != _timeline->begin() && isVisiblyClose(*note_iterator, offset)) { - Iterator note_iterator = _first; - while (note_iterator != _timeline->begin() && isVisiblyClose(*note_iterator, offset)) - { - --note_iterator; - } - - _first = note_iterator; - - auto note = *_first; - const auto state = note->getState(); - if (state != ClassicNote::State::FLYING - && state != ClassicNote::State::DYING - && state != ClassicNote::State::INITIAL - && offset <= note->getPerfectOffset()) - { - note->setState(ClassicNote::State::INITIAL); - } - } - else - { - Iterator note_iterator = _first; - while (note_iterator != _last) - { - auto note = *note_iterator; - if (note->getState() == ClassicNote::State::DEAD) - { - // note->removeGraphics(this); - ++_first; - } - - ++note_iterator; - } + --note_iterator; } + + _first = note_iterator; } void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& offset) @@ -142,24 +136,8 @@ void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& offset) if (nothingToDraw()) _first = note_iterator; - auto note = *note_iterator; - const auto state = note->getState(); - if (state != ClassicNote::State::FLYING - && state != ClassicNote::State::DYING - && state != ClassicNote::State::INITIAL - && offset <= note->getPerfectOffset()) - { - note->setState(ClassicNote::State::INITIAL); - } - ++note_iterator; } _last = note_iterator; } - -void ClassicTimelineGraphicsManager::updateVisibleNotes(const kku::microsec& offset) -{ - for (auto it = _first; it != _last; ++it) - (*it)->update(offset); -} diff --git a/src/modes/classicmode/graphics/classictimelinegraphicsmanager.h b/src/modes/classicmode/graphics/classictimelinegraphicsmanager.h index 5869b5c..b84bd8a 100644 --- a/src/modes/classicmode/graphics/classictimelinegraphicsmanager.h +++ b/src/modes/classicmode/graphics/classictimelinegraphicsmanager.h @@ -23,7 +23,7 @@ public: virtual void update(const kku::microsec& offset) override; virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override; - virtual void draw(const std::vector& elements) const override; + virtual void draw(const ClassicArrowNote * const note) const override; protected: kku::SpriteContainer _sprite_container; @@ -35,10 +35,11 @@ protected: Iterator _last; const std::shared_ptr> _timeline; + kku::microsec _back_visibility_offset; + kku::microsec _last_offset; inline bool nothingToDraw() const noexcept; inline bool isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept; void fetchFirstNote(const kku::microsec& offset); void fetchLastNote(const kku::microsec& offset); - void updateVisibleNotes(const kku::microsec& offset); };