forked from NaiJi/project-kyoku
Remove unneded calls from GraphicsManager interface
This commit is contained in:
parent
bf35501c21
commit
51d83f524a
|
@ -0,0 +1,137 @@
|
||||||
|
#include "classiceditorgraphicsmanager.h"
|
||||||
|
#include "graphics/classicsprite.h"
|
||||||
|
|
||||||
|
#include "graphics/classicflyinganimationscenario.h"
|
||||||
|
#include "graphics/classicdyinganimationscenario.h"
|
||||||
|
|
||||||
|
ClassicEditorGraphicsManager::ClassicEditorGraphicsManager(Timeline<MockClassicNote> &timeline, const microsec& visibility_offset) :
|
||||||
|
ClassicGraphicsManager(visibility_offset),
|
||||||
|
_timeline(&timeline)
|
||||||
|
{
|
||||||
|
_timeline->expire(_first);
|
||||||
|
_timeline->expire(_last);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicEditorGraphicsManager::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||||
|
{
|
||||||
|
if (nothingToDraw())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto it = _first; it != _last; ++it)
|
||||||
|
{
|
||||||
|
(*it)->draw(this, target, states);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicEditorGraphicsManager::draw(const std::vector<MockClassicNote::MockElement>& elements, sf::RenderTarget& target, sf::RenderStates states) 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->trailCoordinates();
|
||||||
|
const auto c2 = sprite->trailCoordinates();
|
||||||
|
|
||||||
|
target.draw(makeLine(c1, c2));
|
||||||
|
}
|
||||||
|
|
||||||
|
target.draw(*sprite, states);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::VertexArray ClassicEditorGraphicsManager::makeLine(const Coordinates& c1, const Coordinates& c2) const
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicEditorGraphicsManager::setGraphics(std::vector<MockClassicNote::MockElement>& elements, TimeRange &&range)
|
||||||
|
{
|
||||||
|
for (auto& element : elements)
|
||||||
|
{
|
||||||
|
element.sprite = _sprite_container.getSprite(element.type);
|
||||||
|
element.sprite->setCoordinates(element.coordinates);
|
||||||
|
element.sprite->setTrailCoordinates(Coordinates( 0.f, 9.f ));
|
||||||
|
|
||||||
|
element.animations[MockClassicNote::State::NONE] = nullptr;
|
||||||
|
element.animations[MockClassicNote::State::FLYING] = std::make_shared<ClassicFlyingAnimationScenario>();
|
||||||
|
element.animations[MockClassicNote::State::DYING] = std::make_shared<ClassicDyingAnimationScenario>();
|
||||||
|
element.animations[MockClassicNote::State::DEAD] = nullptr;
|
||||||
|
|
||||||
|
element.animations[MockClassicNote::State::FLYING]->launch(element.sprite, range.begin, range.end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicEditorGraphicsManager::update(const microsec &offset)
|
||||||
|
{
|
||||||
|
fetchLastNote(offset);
|
||||||
|
fetchFirstNote(offset);
|
||||||
|
|
||||||
|
updateVisibleNotes(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicEditorGraphicsManager::updateVisibleNotes(const microsec &offset)
|
||||||
|
{
|
||||||
|
for (auto it = _first; it != _last; ++it)
|
||||||
|
(*it)->update(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicEditorGraphicsManager::fetchFirstNote(const microsec& offset)
|
||||||
|
{
|
||||||
|
(void)offset; // ????
|
||||||
|
|
||||||
|
if (nothingToDraw())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Iterator note_iterator = _first;
|
||||||
|
while (note_iterator != _last)
|
||||||
|
{
|
||||||
|
auto note = *note_iterator;
|
||||||
|
if (note->shouldRemove())
|
||||||
|
++_first;
|
||||||
|
|
||||||
|
++note_iterator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicEditorGraphicsManager::fetchLastNote(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();
|
||||||
|
note->setGraphics(this, TimeRange{offset, note->offset()});
|
||||||
|
}
|
||||||
|
|
||||||
|
++note_iterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
_last = note_iterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ClassicEditorGraphicsManager::nothingToDraw() const noexcept
|
||||||
|
{
|
||||||
|
return _timeline->isExpired(_first)
|
||||||
|
|| _timeline->isExpired(_last);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ClassicEditorGraphicsManager::isVisiblyClose(const Iterator& iterator, const microsec& music_offset) const noexcept
|
||||||
|
{
|
||||||
|
return ((*iterator)->offset() - _visibility_offset) <= music_offset;
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mockclassicnote.h"
|
||||||
|
#include "graphics/classicgraphicsmanager.h"
|
||||||
|
#include "core/timeline.h"
|
||||||
|
|
||||||
|
#include <SFML/Graphics/RenderTarget.hpp>
|
||||||
|
|
||||||
|
class ClassicSprite;
|
||||||
|
|
||||||
|
class ClassicEditorGraphicsManager : public ClassicGraphicsManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ClassicEditorGraphicsManager(Timeline<MockClassicNote>& timeline, const microsec& visibility_offset);
|
||||||
|
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||||
|
|
||||||
|
void draw(const std::vector<MockClassicNote::MockElement>& elements, sf::RenderTarget& target, sf::RenderStates states) const;
|
||||||
|
void setGraphics(std::vector<MockClassicNote::MockElement> &elements, TimeRange&& range);
|
||||||
|
|
||||||
|
virtual void update(const microsec& offset) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
using Iterator = Timeline<MockClassicNote>::Iterator;
|
||||||
|
|
||||||
|
Iterator _first;
|
||||||
|
Iterator _last;
|
||||||
|
|
||||||
|
Timeline<MockClassicNote> * const _timeline;
|
||||||
|
|
||||||
|
inline bool nothingToDraw() const noexcept;
|
||||||
|
inline bool isVisiblyClose(const Iterator& iterator, const microsec& music_offset) const noexcept;
|
||||||
|
inline sf::VertexArray makeLine(const Coordinates& c1, const Coordinates& c2) const;
|
||||||
|
|
||||||
|
void fetchFirstNote(const microsec& offset);
|
||||||
|
void fetchLastNote(const microsec& offset);
|
||||||
|
void updateVisibleNotes(const microsec& offset);
|
||||||
|
};
|
|
@ -32,7 +32,6 @@ public:
|
||||||
virtual void putToGame() override final;
|
virtual void putToGame() override final;
|
||||||
virtual void update(const microsec &music_offset) override final;
|
virtual void update(const microsec &music_offset) override final;
|
||||||
|
|
||||||
private:
|
|
||||||
struct MockElement
|
struct MockElement
|
||||||
{
|
{
|
||||||
std::shared_ptr<ClassicSprite> sprite;
|
std::shared_ptr<ClassicSprite> sprite;
|
||||||
|
@ -43,6 +42,7 @@ private:
|
||||||
std::vector<Coordinates> falling_curve_interpolation;
|
std::vector<Coordinates> falling_curve_interpolation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
std::vector<MockElement> _elements;
|
std::vector<MockElement> _elements;
|
||||||
|
|
||||||
State _state;
|
State _state;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "classicarrownote.h"
|
#include "classicarrownote.h"
|
||||||
#include "graphics/classicgraphicsmanager.h"
|
#include "game/classicgamegraphicsmanager.h"
|
||||||
#include "graphics/classicanimationscenario.h"
|
#include "graphics/classicanimationscenario.h"
|
||||||
#include "holdmanager.h"
|
#include "holdmanager.h"
|
||||||
|
|
||||||
|
@ -89,12 +89,12 @@ void ClassicArrowNote::update(const microsec& music_offset)
|
||||||
element.animations[_state]->update(music_offset);
|
element.animations[_state]->update(music_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassicArrowNote::draw(const ClassicGraphicsManager * const manager, sf::RenderTarget& target, sf::RenderStates states) const
|
void ClassicArrowNote::draw(const ClassicGameGraphicsManager * const manager, sf::RenderTarget& target, sf::RenderStates states) const
|
||||||
{
|
{
|
||||||
manager->draw(_elements, target, states);
|
manager->draw(_elements, target, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassicArrowNote::setGraphics(ClassicGraphicsManager * const manager, TimeRange&& range)
|
void ClassicArrowNote::setGraphics(ClassicGameGraphicsManager * const manager, TimeRange&& range)
|
||||||
{
|
{
|
||||||
manager->setGraphics(_elements, std::move(range));
|
manager->setGraphics(_elements, std::move(range));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ public:
|
||||||
virtual void update(const microsec &music_offset) override;
|
virtual void update(const microsec &music_offset) override;
|
||||||
virtual void input(PlayerInput&& inputdata) override;
|
virtual void input(PlayerInput&& inputdata) override;
|
||||||
|
|
||||||
virtual void draw(const ClassicGraphicsManager * const manager, sf::RenderTarget& target, sf::RenderStates states) const override;
|
virtual void draw(const ClassicGameGraphicsManager * const manager, sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||||
virtual void setGraphics(ClassicGraphicsManager * const manager, TimeRange&& range) override;
|
virtual void setGraphics(ClassicGameGraphicsManager * const manager, TimeRange&& range) override;
|
||||||
|
|
||||||
bool allElementsPressed() const;
|
bool allElementsPressed() const;
|
||||||
bool isPressedAs(sf::Keyboard::Key key) const;
|
bool isPressedAs(sf::Keyboard::Key key) const;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "game/classicarrownote.h"
|
||||||
#include "graphics/classicgraphicsmanager.h"
|
#include "graphics/classicgraphicsmanager.h"
|
||||||
#include "core/timeline.h"
|
#include "core/timeline.h"
|
||||||
|
|
||||||
|
@ -13,8 +14,8 @@ public:
|
||||||
explicit ClassicGameGraphicsManager(Timeline<ClassicNote>& timeline, const microsec& visibility_offset);
|
explicit ClassicGameGraphicsManager(Timeline<ClassicNote>& timeline, const microsec& visibility_offset);
|
||||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||||
|
|
||||||
virtual void draw(const std::vector<ClassicArrowNote::ArrowElement>& elements, sf::RenderTarget& target, sf::RenderStates states) const override;
|
void draw(const std::vector<ClassicArrowNote::ArrowElement>& elements, sf::RenderTarget& target, sf::RenderStates states) const;
|
||||||
virtual void setGraphics(std::vector<ClassicArrowNote::ArrowElement> &elements, TimeRange&& range) override;
|
void setGraphics(std::vector<ClassicArrowNote::ArrowElement> &elements, TimeRange&& range);
|
||||||
|
|
||||||
virtual void update(const microsec& offset) override;
|
virtual void update(const microsec& offset) override;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
class ClassicSprite;
|
class ClassicSprite;
|
||||||
class ClassicAnimationScenario;
|
class ClassicAnimationScenario;
|
||||||
class ClassicGraphicsManager;
|
class ClassicGameGraphicsManager;
|
||||||
|
|
||||||
namespace sf { class RenderTarget; class RenderStates; }
|
namespace sf { class RenderTarget; class RenderStates; }
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ public:
|
||||||
virtual void input(PlayerInput&& inputdata) = 0;
|
virtual void input(PlayerInput&& inputdata) = 0;
|
||||||
|
|
||||||
// encapsulate
|
// encapsulate
|
||||||
virtual void draw(const ClassicGraphicsManager * const manager, sf::RenderTarget& target, sf::RenderStates states) const = 0;
|
virtual void draw(const ClassicGameGraphicsManager * const manager, sf::RenderTarget& target, sf::RenderStates states) const = 0;
|
||||||
virtual void setGraphics(ClassicGraphicsManager * const manager, TimeRange&& range) = 0;
|
virtual void setGraphics(ClassicGameGraphicsManager * const manager, TimeRange&& range) = 0;
|
||||||
//
|
//
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "game/classicarrownote.h"
|
|
||||||
#include "spritecontainer.h"
|
#include "spritecontainer.h"
|
||||||
#include "classicmode/classicactions.h"
|
#include "classicmode/classicactions.h"
|
||||||
#include "graphics/classicspritefactory.h"
|
#include "graphics/classicspritefactory.h"
|
||||||
|
@ -20,9 +19,6 @@ public:
|
||||||
_visibility_offset(visibility_offset)
|
_visibility_offset(visibility_offset)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual void draw(const std::vector<ClassicArrowNote::ArrowElement>& elements, sf::RenderTarget& target, sf::RenderStates states) const = 0;
|
|
||||||
virtual void setGraphics(std::vector<ClassicArrowNote::ArrowElement> &elements, TimeRange&& range) = 0;
|
|
||||||
|
|
||||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override = 0;
|
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override = 0;
|
||||||
virtual void update(const microsec& offset) = 0;
|
virtual void update(const microsec& offset) = 0;
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,8 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class Game;
|
class Game;
|
||||||
class Music;
|
|
||||||
class Editor;
|
class Editor;
|
||||||
|
|
||||||
namespace sf { class RenderWindow; }
|
|
||||||
|
|
||||||
namespace classic
|
namespace classic
|
||||||
{
|
{
|
||||||
std::unique_ptr<Game> initGame();
|
std::unique_ptr<Game> initGame();
|
||||||
|
|
Loading…
Reference in New Issue