forked from NaiJi/project-kyoku
Improve visible notes calculation for scrolling in editor
This commit is contained in:
parent
9216fc9f84
commit
ed3330cb97
|
@ -135,6 +135,11 @@ public:
|
||||||
return _top_note;
|
return _top_note;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Iterator begin() const noexcept
|
||||||
|
{
|
||||||
|
return _timeline.begin();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::set<TNote*, NotePtrComparator> _timeline;
|
std::set<TNote*, NotePtrComparator> _timeline;
|
||||||
microsec _current_offset;
|
microsec _current_offset;
|
||||||
|
|
|
@ -99,6 +99,12 @@ void ClassicMockNote::setGraphics(ClassicGraphicsManager * const manager, kku::T
|
||||||
manager->setGraphics(_elements, std::move(range));
|
manager->setGraphics(_elements, std::move(range));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClassicMockNote::removeGraphics(ClassicGraphicsManager * const manager)
|
||||||
|
{
|
||||||
|
manager->removeGraphics(_elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<MockElement>& ClassicMockNote::getElements()
|
std::vector<MockElement>& ClassicMockNote::getElements()
|
||||||
{
|
{
|
||||||
return _elements;
|
return _elements;
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
|
|
||||||
virtual void display(const ClassicGraphicsManager * const manager) const override;
|
virtual void display(const ClassicGraphicsManager * const manager) const override;
|
||||||
virtual void setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) override;
|
virtual void setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) override;
|
||||||
|
virtual void removeGraphics(ClassicGraphicsManager * const manager) override;
|
||||||
|
|
||||||
std::vector<MockElement>& getElements();
|
std::vector<MockElement>& getElements();
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,11 @@ void ClassicArrowNote::setGraphics(ClassicGraphicsManager * const manager, kku::
|
||||||
manager->setGraphics(_elements, std::move(range));
|
manager->setGraphics(_elements, std::move(range));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClassicArrowNote::removeGraphics(ClassicGraphicsManager * const manager)
|
||||||
|
{
|
||||||
|
manager->removeGraphics(_elements);
|
||||||
|
}
|
||||||
|
|
||||||
bool ClassicArrowNote::allElementsPressed() const
|
bool ClassicArrowNote::allElementsPressed() const
|
||||||
{
|
{
|
||||||
return std::all_of(_elements.begin(), _elements.end(),
|
return std::all_of(_elements.begin(), _elements.end(),
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
|
|
||||||
virtual void display(const ClassicGraphicsManager * const manager) const override;
|
virtual void display(const ClassicGraphicsManager * const manager) const override;
|
||||||
virtual void setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) override;
|
virtual void setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) override;
|
||||||
|
virtual void removeGraphics(ClassicGraphicsManager * const manager) override;
|
||||||
|
|
||||||
bool allElementsPressed() const;
|
bool allElementsPressed() const;
|
||||||
bool isPressedAs(kku::SystemEvent::Key::Code key) const;
|
bool isPressedAs(kku::SystemEvent::Key::Code key) const;
|
||||||
|
|
|
@ -21,9 +21,11 @@ public:
|
||||||
|
|
||||||
virtual void display(const std::vector<ArrowElement>& elements) const = 0;
|
virtual void display(const std::vector<ArrowElement>& elements) const = 0;
|
||||||
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range) = 0;
|
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range) = 0;
|
||||||
|
virtual void removeGraphics(std::vector<ArrowElement>& elements) = 0;
|
||||||
|
|
||||||
virtual void display(const std::vector<MockElement>& elements) const = 0;
|
virtual void display(const std::vector<MockElement>& elements) const = 0;
|
||||||
virtual void setGraphics(std::vector<MockElement>& elements, kku::TimeRange&& range) = 0;
|
virtual void setGraphics(std::vector<MockElement>& elements, kku::TimeRange&& range) = 0;
|
||||||
|
virtual void removeGraphics(std::vector<MockElement>& elements) = 0;
|
||||||
|
|
||||||
virtual void display() const = 0;
|
virtual void display() const = 0;
|
||||||
virtual void update(const kku::microsec& offset) = 0;
|
virtual void update(const kku::microsec& offset) = 0;
|
||||||
|
|
|
@ -87,6 +87,20 @@ void ClassicSceneGraphicsManager::setGraphics(std::vector<ArrowElement>& element
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClassicSceneGraphicsManager::removeGraphics(std::vector<ArrowElement>& 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ClassicSceneGraphicsManager::display(const std::vector<MockElement>& elements) const
|
void ClassicSceneGraphicsManager::display(const std::vector<MockElement>& elements) const
|
||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < elements.size(); ++i)
|
for (std::size_t i = 0; i < elements.size(); ++i)
|
||||||
|
@ -128,6 +142,20 @@ void ClassicSceneGraphicsManager::setGraphics(std::vector<MockElement>& elements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClassicSceneGraphicsManager::removeGraphics(std::vector<MockElement>& 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*sf::VertexArray ClassicSceneGraphicsSFML::makeLine(const kku::Point& c1, const kku::Point& c2) const
|
/*sf::VertexArray ClassicSceneGraphicsSFML::makeLine(const kku::Point& c1, const kku::Point& c2) const
|
||||||
{
|
{
|
||||||
sf::VertexArray line(sf::LinesStrip, 2);
|
sf::VertexArray line(sf::LinesStrip, 2);
|
||||||
|
@ -147,21 +175,44 @@ void ClassicSceneGraphicsManager::updateVisibleNotes(const kku::microsec &offset
|
||||||
|
|
||||||
void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset)
|
void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset)
|
||||||
{
|
{
|
||||||
(void)offset; // ????
|
|
||||||
|
|
||||||
if (nothingToDraw())
|
if (nothingToDraw())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (offset < (*_first)->getPerfectOffset())
|
||||||
|
{
|
||||||
|
Iterator note_iterator = _first;
|
||||||
|
while (note_iterator != _timeline->begin() && !isVisiblyClose(note_iterator, offset))
|
||||||
|
{
|
||||||
|
--note_iterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
_first = note_iterator;
|
||||||
|
|
||||||
|
auto note = *_first;
|
||||||
|
if (note->getState() != ClassicNote::State::FLYING
|
||||||
|
&& note->getState() != ClassicNote::State::DYING
|
||||||
|
&& offset <= note->getPerfectOffset())
|
||||||
|
{
|
||||||
|
note->setState(ClassicNote::State::FLYING);
|
||||||
|
note->setGraphics(this, kku::TimeRange{offset, note->getPerfectOffset()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Iterator note_iterator = _first;
|
Iterator note_iterator = _first;
|
||||||
while (note_iterator != _last)
|
while (note_iterator != _last)
|
||||||
{
|
{
|
||||||
auto note = *note_iterator;
|
auto note = *note_iterator;
|
||||||
if (note->getState() == ClassicNote::State::DEAD)
|
if (note->getState() == ClassicNote::State::DEAD)
|
||||||
|
{
|
||||||
|
// note->removeGraphics(this);
|
||||||
++_first;
|
++_first;
|
||||||
|
}
|
||||||
|
|
||||||
++note_iterator;
|
++note_iterator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ClassicSceneGraphicsManager::fetchLastNote(const kku::microsec& offset)
|
void ClassicSceneGraphicsManager::fetchLastNote(const kku::microsec& offset)
|
||||||
{
|
{
|
||||||
|
@ -174,7 +225,8 @@ void ClassicSceneGraphicsManager::fetchLastNote(const kku::microsec& offset)
|
||||||
auto note = *note_iterator;
|
auto note = *note_iterator;
|
||||||
|
|
||||||
if (note->getState() != ClassicNote::State::FLYING
|
if (note->getState() != ClassicNote::State::FLYING
|
||||||
&& note->getState() != ClassicNote::State::DYING)
|
&& note->getState() != ClassicNote::State::DYING
|
||||||
|
&& offset <= note->getPerfectOffset())
|
||||||
{
|
{
|
||||||
note->setState(ClassicNote::State::FLYING);
|
note->setState(ClassicNote::State::FLYING);
|
||||||
note->setGraphics(this, kku::TimeRange{offset, note->getPerfectOffset()});
|
note->setGraphics(this, kku::TimeRange{offset, note->getPerfectOffset()});
|
||||||
|
|
|
@ -22,9 +22,11 @@ public:
|
||||||
|
|
||||||
virtual void display(const std::vector<ArrowElement>& elements) const override;
|
virtual void display(const std::vector<ArrowElement>& elements) const override;
|
||||||
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range) override;
|
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range) override;
|
||||||
|
virtual void removeGraphics(std::vector<ArrowElement>& elements) override;
|
||||||
|
|
||||||
virtual void display(const std::vector<MockElement>& elements) const override;
|
virtual void display(const std::vector<MockElement>& elements) const override;
|
||||||
virtual void setGraphics(std::vector<MockElement>& elements, kku::TimeRange&& range) override;
|
virtual void setGraphics(std::vector<MockElement>& elements, kku::TimeRange&& range) override;
|
||||||
|
virtual void removeGraphics(std::vector<MockElement>& elements) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicSprite> _sprite_container;
|
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicSprite> _sprite_container;
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
|
|
||||||
virtual void display(const ClassicGraphicsManager * const manager) const = 0;
|
virtual void display(const ClassicGraphicsManager * const manager) const = 0;
|
||||||
virtual void setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) = 0;
|
virtual void setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) = 0;
|
||||||
|
virtual void removeGraphics(ClassicGraphicsManager * const manager) = 0;
|
||||||
|
|
||||||
void setState(State state) noexcept;
|
void setState(State state) noexcept;
|
||||||
State getState() const noexcept;
|
State getState() const noexcept;
|
||||||
|
|
Loading…
Reference in New Issue