#include "classicgraphicsmanager.h" #include "graphics/classicsprite.h" ClassicGraphicsManager::ClassicGraphicsManager(Timeline &timeline, const microsec& visibility_offset) : _sprite_container({Type::UP, Type::DOWN, Type::LEFT, Type::RIGHT}, std::make_unique()), _timeline(&timeline), _visibility_offset(visibility_offset) { _timeline->expire(_first); _timeline->expire(_last); } void ClassicGraphicsManager::draw(sf::RenderTarget& target, sf::RenderStates states) const { if (nothingToDraw()) return; std::for_each(_first, _last, [&target, &states](const auto& note) { target.draw(*note->sprite(), states); }); } std::shared_ptr ClassicGraphicsManager::getSprite(Type type) { return _sprite_container.getSprite(type); } void ClassicGraphicsManager::update(const microsec &offset) { Iterator note_iterator = _timeline->getTopNote(); while (!_timeline->isExpired(note_iterator) && isVisiblyClose(note_iterator, offset)) { if (nothingToDraw()) _first = note_iterator; auto note = *note_iterator; if (!note->isInGame()) note->putToGame(offset); ++note_iterator; } _last = note_iterator; } bool ClassicGraphicsManager::nothingToDraw() const noexcept { return _timeline->isExpired(_first) || _timeline->isExpired(_last); } bool ClassicGraphicsManager::isVisiblyClose(const Iterator& iterator, const microsec& music_offset) const noexcept { return ((iterator)->offset() - _visibility_offset) <= music_offset; }