2021-12-28 19:04:50 +01:00
|
|
|
#include "classicscenegraphicsmanager.h"
|
|
|
|
|
2022-02-10 00:30:49 +01:00
|
|
|
#include "editor/mockelement.h"
|
2021-12-28 19:04:50 +01:00
|
|
|
#include "game/arrowelement.h"
|
|
|
|
|
|
|
|
#include "graphics/animations/classicflyinganimationscenario.h"
|
|
|
|
#include "graphics/animations/classicdyinganimationscenario.h"
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
ClassicSceneGraphicsManager::ClassicSceneGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
2022-02-06 02:33:09 +01:00
|
|
|
const std::shared_ptr<ClassicGraphicsFactory>& factory,
|
2021-12-29 15:59:18 +01:00
|
|
|
const kku::microsec& visibility_offset) :
|
2022-01-18 04:15:59 +01:00
|
|
|
ClassicGraphicsManager(visibility_offset),
|
|
|
|
_sprite_container({Type::UP, Type::DOWN,
|
|
|
|
Type::LEFT, Type::RIGHT},
|
|
|
|
factory),
|
2022-02-06 02:33:09 +01:00
|
|
|
_factory(factory),
|
2021-12-28 19:04:50 +01:00
|
|
|
_timeline(timeline)
|
|
|
|
{
|
|
|
|
_timeline->expire(_first);
|
|
|
|
_timeline->expire(_last);
|
|
|
|
}
|
|
|
|
|
2022-02-06 02:33:09 +01:00
|
|
|
void ClassicSceneGraphicsManager::input(kku::GameEvent&& input)
|
|
|
|
{
|
|
|
|
if (nothingToDraw())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (auto it = _first; it != _last; ++it)
|
|
|
|
{
|
|
|
|
(*it)->input(std::move(input));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-28 19:04:50 +01:00
|
|
|
void ClassicSceneGraphicsManager::display() const
|
|
|
|
{
|
|
|
|
if (nothingToDraw())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (auto it = _first; it != _last; ++it)
|
|
|
|
{
|
|
|
|
(*it)->display(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicSceneGraphicsManager::update(const kku::microsec &offset)
|
2021-12-28 19:04:50 +01:00
|
|
|
{
|
|
|
|
fetchLastNote(offset);
|
|
|
|
fetchFirstNote(offset);
|
|
|
|
|
|
|
|
updateVisibleNotes(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicSceneGraphicsManager::display(const std::vector<ArrowElement>& elements) const
|
|
|
|
{
|
|
|
|
for (std::size_t i = 0; i < elements.size(); ++i)
|
|
|
|
{
|
|
|
|
const auto& sprite = elements[i].sprite;
|
|
|
|
|
|
|
|
if (i >= 1)
|
|
|
|
{
|
|
|
|
//const auto& neighbor_sprite = elements[i - 1].sprite;
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
//const auto c1 = neighbor_sprite->trailPosition();
|
|
|
|
//const auto c2 = sprite->trailPosition();
|
2021-12-28 19:04:50 +01:00
|
|
|
|
|
|
|
//_render_target->draw(makeLine(c1, c2));
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite->display();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicSceneGraphicsManager::setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange &&range)
|
2021-12-28 19:04:50 +01:00
|
|
|
{
|
|
|
|
for (auto& element : elements)
|
|
|
|
{
|
|
|
|
element.sprite = _sprite_container.getSprite(element.type);
|
2021-12-29 15:59:18 +01:00
|
|
|
element.sprite->setPosition(element.position);
|
|
|
|
element.sprite->setTrailPosition(kku::Point( 0.f, 9.f ));
|
2021-12-28 19:04:50 +01:00
|
|
|
|
|
|
|
element.animations[ClassicNote::State::NONE] = nullptr;
|
|
|
|
element.animations[ClassicNote::State::FLYING] = std::make_shared<ClassicFlyingAnimationScenario>();
|
|
|
|
element.animations[ClassicNote::State::DYING] = std::make_shared<ClassicDyingAnimationScenario>();
|
|
|
|
element.animations[ClassicNote::State::DEAD] = nullptr;
|
|
|
|
|
|
|
|
element.animations[ClassicNote::State::FLYING]->launch(element.sprite, range.begin, range.end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-06 02:33:09 +01:00
|
|
|
void ClassicSceneGraphicsManager::display(const std::vector<MockElement>& elements) const
|
|
|
|
{
|
|
|
|
for (std::size_t i = 0; i < elements.size(); ++i)
|
|
|
|
{
|
|
|
|
const auto& sprite = elements[i].sprite;
|
|
|
|
|
|
|
|
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();
|
2022-02-10 00:30:49 +01:00
|
|
|
if (elements[i].selected)
|
|
|
|
elements[i].selection->display();
|
2022-02-06 02:33:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicSceneGraphicsManager::setGraphics(std::vector<MockElement>& elements, kku::TimeRange &&range)
|
|
|
|
{
|
|
|
|
for (auto& element : elements)
|
|
|
|
{
|
|
|
|
element.sprite = _sprite_container.getSprite(element.type);
|
|
|
|
element.sprite->setPosition(element.position);
|
|
|
|
element.sprite->setTrailPosition(kku::Point( 0.f, 9.f ));
|
|
|
|
|
|
|
|
element.selection = _factory->createSelection();
|
|
|
|
element.selection->adjustTo(element.sprite);
|
|
|
|
|
|
|
|
element.animations[ClassicNote::State::NONE] = nullptr;
|
|
|
|
element.animations[ClassicNote::State::FLYING] = std::make_shared<ClassicFlyingAnimationScenario>();
|
|
|
|
element.animations[ClassicNote::State::DYING] = std::make_shared<ClassicDyingAnimationScenario>();
|
|
|
|
element.animations[ClassicNote::State::DEAD] = nullptr;
|
|
|
|
element.animations[ClassicNote::State::FLYING]->launch(element.sprite, range.begin, range.end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
/*sf::VertexArray ClassicSceneGraphicsSFML::makeLine(const kku::Point& c1, const kku::Point& c2) const
|
2021-12-28 19:04:50 +01:00
|
|
|
{
|
|
|
|
sf::VertexArray line(sf::LinesStrip, 2);
|
|
|
|
line[0].color = sf::Color::Yellow;
|
|
|
|
line[0].position = {c1.x + 10, c1.y};
|
|
|
|
line[1].color = sf::Color::Blue;
|
|
|
|
line[1].position = {c2.x + 10, c2.y};
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}*/
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicSceneGraphicsManager::updateVisibleNotes(const kku::microsec &offset)
|
2021-12-28 19:04:50 +01:00
|
|
|
{
|
|
|
|
for (auto it = _first; it != _last; ++it)
|
|
|
|
(*it)->update(offset);
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset)
|
2021-12-28 19:04:50 +01:00
|
|
|
{
|
|
|
|
(void)offset; // ????
|
|
|
|
|
|
|
|
if (nothingToDraw())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Iterator note_iterator = _first;
|
|
|
|
while (note_iterator != _last)
|
|
|
|
{
|
|
|
|
auto note = *note_iterator;
|
2022-02-06 02:33:09 +01:00
|
|
|
if (note->getState() == ClassicNote::State::DEAD)
|
2021-12-28 19:04:50 +01:00
|
|
|
++_first;
|
|
|
|
|
|
|
|
++note_iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicSceneGraphicsManager::fetchLastNote(const kku::microsec& offset)
|
2021-12-28 19:04:50 +01:00
|
|
|
{
|
|
|
|
Iterator note_iterator = _timeline->getTopNote();
|
|
|
|
while (!_timeline->isExpired(note_iterator) && isVisiblyClose(note_iterator, offset))
|
|
|
|
{
|
|
|
|
if (nothingToDraw())
|
|
|
|
_first = note_iterator;
|
|
|
|
|
|
|
|
auto note = *note_iterator;
|
|
|
|
|
2022-02-06 02:33:09 +01:00
|
|
|
if (note->getState() != ClassicNote::State::FLYING
|
|
|
|
&& note->getState() != ClassicNote::State::DYING)
|
2021-12-28 19:04:50 +01:00
|
|
|
{
|
2022-02-06 02:33:09 +01:00
|
|
|
note->setState(ClassicNote::State::FLYING);
|
2021-12-29 15:59:18 +01:00
|
|
|
note->setGraphics(this, kku::TimeRange{offset, note->getPerfectOffset()});
|
2021-12-28 19:04:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
++note_iterator;
|
|
|
|
}
|
|
|
|
|
|
|
|
_last = note_iterator;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClassicSceneGraphicsManager::nothingToDraw() const noexcept
|
|
|
|
{
|
|
|
|
return _timeline->isExpired(_first)
|
|
|
|
|| _timeline->isExpired(_last);
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
bool ClassicSceneGraphicsManager::isVisiblyClose(const Iterator& iterator, const kku::microsec& music_offset) const noexcept
|
2021-12-28 19:04:50 +01:00
|
|
|
{
|
2021-12-29 15:59:18 +01:00
|
|
|
return ((*iterator)->getPerfectOffset() - _visibility_offset) <= music_offset;
|
2021-12-28 19:04:50 +01:00
|
|
|
}
|