forked from NaiJi/project-kyoku
Separate sprite graphics from note logic
parent
017f400ad9
commit
c576686752
@ -0,0 +1,112 @@
|
||||
#include "classictimelinegraphicsmanager.h"
|
||||
#include "graphics/classicsprite.h"
|
||||
|
||||
#include "game/arrowelement.h"
|
||||
|
||||
#include "graphics/animations/classicflyinganimationscenario.h"
|
||||
#include "graphics/animations/classicdyinganimationscenario.h"
|
||||
|
||||
ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
||||
const std::shared_ptr<ClassicSpriteFactory>& factory,
|
||||
const kku::microsec& visibility_offset) :
|
||||
ClassicGraphicsManager(factory, visibility_offset),
|
||||
_timeline(timeline),
|
||||
_display_offset(0)
|
||||
{
|
||||
_timeline->expire(_first);
|
||||
_timeline->expire(_last);
|
||||
|
||||
_sprites[Type::NONE] = nullptr;
|
||||
_sprites[Type::UP] = factory->getSprite(Type::UP);
|
||||
_sprites[Type::RIGHT] = factory->getSprite(Type::RIGHT);
|
||||
_sprites[Type::DOWN] = factory->getSprite(Type::DOWN);
|
||||
_sprites[Type::LEFT] = factory->getSprite(Type::LEFT);
|
||||
//_sprites[Type::SLIDER_RIGHT] = factory->getSprite(Type::SLIDER_RIGHT);
|
||||
//_sprites[Type::SLIDER_LEFT] = factory->getSprite(Type::SLIDER_LEFT);
|
||||
}
|
||||
|
||||
void ClassicTimelineGraphicsManager::display() const
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
{
|
||||
const auto& note = (*it);
|
||||
note->display(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ClassicTimelineGraphicsManager::update(const kku::microsec &offset)
|
||||
{
|
||||
_timeline->expire(_first);
|
||||
_timeline->expire(_last);
|
||||
|
||||
fetchLastNote(offset);
|
||||
fetchFirstNote(offset);
|
||||
|
||||
_display_offset = offset;
|
||||
}
|
||||
|
||||
void ClassicTimelineGraphicsManager::display(const std::vector<ArrowElement>& elements) const
|
||||
{
|
||||
for (std::size_t i = 0; i < elements.size(); ++i)
|
||||
{
|
||||
auto sprite = *_sprites.at(elements.at(i).type)
|
||||
|
||||
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->setPosition(kku::Position{});
|
||||
sprite->display();
|
||||
}
|
||||
}
|
||||
|
||||
void ClassicTimelineGraphicsManager::fetchFirstNote(const kku::microsec& offset)
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
|
||||
Iterator note_iterator = _first;
|
||||
while (!_timeline->isExpired(note_iterator) && isVisiblyClose(note_iterator, offset))
|
||||
{
|
||||
--note_iterator;
|
||||
}
|
||||
|
||||
_first = note_iterator;
|
||||
}
|
||||
|
||||
void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& offset)
|
||||
{
|
||||
Iterator note_iterator = _timeline->getTopNote();
|
||||
while (!_timeline->isExpired(note_iterator) && isVisiblyClose(note_iterator, offset))
|
||||
{
|
||||
if (nothingToDraw())
|
||||
_first = note_iterator;
|
||||
|
||||
++note_iterator;
|
||||
}
|
||||
|
||||
_last = note_iterator;
|
||||
}
|
||||
|
||||
bool ClassicTimelineGraphicsManager::nothingToDraw() const noexcept
|
||||
{
|
||||
return _timeline->isExpired(_first)
|
||||
|| _timeline->isExpired(_last);
|
||||
}
|
||||
|
||||
bool ClassicTimelineGraphicsManager::isVisiblyClose(const Iterator& iterator, const kku::microsec& music_offset) const noexcept
|
||||
{
|
||||
const auto& perfect_offset = (*iterator)->getPerfectOffset();
|
||||
|
||||
return ((perfect_offset - _visibility_offset) <= music_offset)
|
||||
|| ((perfect_offset + (_visibility_offset / 4.)) >= music_offset);
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "game/classicnote.h"
|
||||
#include "graphics/classicgraphicsmanager.h"
|
||||
#include "core/timeline.h"
|
||||
|
||||
class ClassicSprite;
|
||||
|
||||
class ClassicTimelineGraphicsManager : public ClassicGraphicsManager
|
||||
{
|
||||
public:
|
||||
explicit ClassicTimelineGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
||||
const std::shared_ptr<ClassicSpriteFactory>& factory,
|
||||
const kku::microsec& visibility_offset);
|
||||
|
||||
virtual void display() const override;
|
||||
virtual void update(const kku::microsec& offset) override;
|
||||
|
||||
virtual void display(const std::vector<ArrowElement>& elements) const override;
|
||||
|
||||
protected:
|
||||
using Iterator = kku::Timeline<ClassicNote>::Iterator;
|
||||
|
||||
Iterator _first;
|
||||
Iterator _last;
|
||||
|
||||
const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline;
|
||||
kku::microsec _display_offset;
|
||||
|
||||
mutable std::map<std::shared_ptr<ClassicSprite>, Type::COUNT> _sprites;
|
||||
|
||||
inline bool nothingToDraw() const noexcept;
|
||||
inline bool isVisiblyClose(const Iterator& iterator, const kku::microsec& music_offset) const noexcept;
|
||||
|
||||
void fetchFirstNote(const kku::microsec& offset);
|
||||
void fetchLastNote(const kku::microsec& offset);
|
||||
};
|
Loading…
Reference in New Issue