Separate sprite graphics from note logic
This commit is contained in:
parent
017f400ad9
commit
c576686752
|
@ -8,10 +8,9 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/shared)
|
||||||
|
|
||||||
# check SFML by some compilation flag or idk
|
# check SFML by some compilation flag or idk
|
||||||
file(GLOB_RECURSE SOURCES "sfml/*.cpp" "sfml/*.h")
|
file(GLOB_RECURSE SOURCES "sfml/*.cpp" "sfml/*.h")
|
||||||
find_package(SFML REQUIRED graphics window system)
|
find_package(SFML REQUIRED graphics window system audio)
|
||||||
include_directories(${SFML_INCL_DIR} ${CMAKE_SOURCE_DIR}/include)
|
include_directories(${SFML_INCL_DIR} ${CMAKE_SOURCE_DIR}/include)
|
||||||
target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network)
|
target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network)
|
||||||
include_directories(${SFML_INCL_DIR} ${CMAKE_SOURCE_DIR}/include)
|
|
||||||
######
|
######
|
||||||
|
|
||||||
add_library(impl STATIC ${SOURCES})
|
add_library(impl STATIC ${SOURCES})
|
||||||
|
|
|
@ -22,6 +22,6 @@ public:
|
||||||
virtual void display() override;
|
virtual void display() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<sf::RenderTarget> _render_target;
|
sf::RenderTarget * const _render_target;
|
||||||
sf::Text _text;
|
sf::Text _text;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/spritecontainer.h"
|
#include "core/time.h"
|
||||||
#include "classicmode/classicactions.h"
|
#include "classicmode/classicactions.h"
|
||||||
#include "graphics/classicspritefactory.h"
|
|
||||||
|
|
||||||
class ClassicSprite;
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct ArrowElement;
|
struct ArrowElement;
|
||||||
|
|
||||||
class ClassicGraphicsManager : public std::enable_shared_from_this<ClassicGraphicsManager>
|
class ClassicGraphicsManager : public std::enable_shared_from_this<ClassicGraphicsManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~ClassicGraphicsManager() = default;
|
virtual ~ClassicGraphicsManager() = default;
|
||||||
explicit ClassicGraphicsManager(const std::shared_ptr<ClassicSpriteFactory>& factory, const kku::microsec& visibility_offset) :
|
explicit ClassicGraphicsManager(const kku::microsec& visibility_offset) :
|
||||||
_sprite_container({Type::UP, Type::DOWN,
|
|
||||||
Type::LEFT, Type::RIGHT},
|
|
||||||
factory),
|
|
||||||
_visibility_offset(visibility_offset)
|
_visibility_offset(visibility_offset)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -25,6 +23,5 @@ public:
|
||||||
virtual void update(const kku::microsec& offset) = 0;
|
virtual void update(const kku::microsec& offset) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
kku::SpriteContainer<Type, ClassicSpriteFactory, ClassicSprite> _sprite_container;
|
|
||||||
kku::microsec _visibility_offset;
|
kku::microsec _visibility_offset;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,10 @@
|
||||||
ClassicSceneGraphicsManager::ClassicSceneGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
ClassicSceneGraphicsManager::ClassicSceneGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
||||||
const std::shared_ptr<ClassicSpriteFactory>& factory,
|
const std::shared_ptr<ClassicSpriteFactory>& factory,
|
||||||
const kku::microsec& visibility_offset) :
|
const kku::microsec& visibility_offset) :
|
||||||
ClassicGraphicsManager(factory, visibility_offset),
|
ClassicGraphicsManager(visibility_offset),
|
||||||
|
_sprite_container({Type::UP, Type::DOWN,
|
||||||
|
Type::LEFT, Type::RIGHT},
|
||||||
|
factory),
|
||||||
_timeline(timeline)
|
_timeline(timeline)
|
||||||
{
|
{
|
||||||
_timeline->expire(_first);
|
_timeline->expire(_first);
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
#include "game/classicnote.h"
|
#include "game/classicnote.h"
|
||||||
#include "graphics/classicgraphicsmanager.h"
|
#include "graphics/classicgraphicsmanager.h"
|
||||||
|
#include "graphics/classicspritefactory.h"
|
||||||
#include "core/timeline.h"
|
#include "core/timeline.h"
|
||||||
|
#include "core/spritecontainer.h"
|
||||||
|
|
||||||
class ClassicSprite;
|
class ClassicSprite;
|
||||||
|
|
||||||
|
@ -20,6 +22,7 @@ public:
|
||||||
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range) override;
|
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
kku::SpriteContainer<Type, ClassicSpriteFactory, ClassicSprite> _sprite_container;
|
||||||
using Iterator = kku::Timeline<ClassicNote>::Iterator;
|
using Iterator = kku::Timeline<ClassicNote>::Iterator;
|
||||||
|
|
||||||
Iterator _first;
|
Iterator _first;
|
||||||
|
|
|
@ -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);
|
||||||
|
};
|
|
@ -25,5 +25,7 @@ enum class Type
|
||||||
LEFT,
|
LEFT,
|
||||||
|
|
||||||
SLIDER_RIGHT,
|
SLIDER_RIGHT,
|
||||||
SLIDER_LEFT
|
SLIDER_LEFT,
|
||||||
|
|
||||||
|
COUNT
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue