Implement Editor command system
This commit is contained in:
parent
98273d3a39
commit
124417d778
|
@ -17,7 +17,7 @@ set(CMAKE_THREAD_LIBS_INIT "-lpthread")
|
|||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
file(GLOB_RECURSE SOURCES "src/main.cpp")
|
||||
file(GLOB_RECURSE SOURCES "src/main.cpp" "include/*.h")
|
||||
add_executable(project-kyoku ${SOURCES})
|
||||
|
||||
SET(CMAKE_INSTALL_PREFIX /)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/systemevent.h"
|
||||
#include <string>
|
||||
|
||||
namespace kku
|
||||
{
|
||||
|
||||
class EditorCallback
|
||||
{
|
||||
public:
|
||||
virtual ~EditorCallback() = default;
|
||||
|
||||
struct Metadata
|
||||
{
|
||||
const std::string group_title;
|
||||
const std::string title;
|
||||
};
|
||||
|
||||
virtual bool isEnabled() const = 0;
|
||||
virtual void run() const = 0;
|
||||
|
||||
virtual Metadata getMetadata() const = 0;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace kku
|
||||
{
|
||||
|
||||
using lambda = std::function<void(void)>;
|
||||
using predicate = std::function<bool(void)>;
|
||||
|
||||
}
|
|
@ -140,6 +140,11 @@ public:
|
|||
return _timeline.begin();
|
||||
}
|
||||
|
||||
inline Iterator end() const noexcept
|
||||
{
|
||||
return _timeline.end();
|
||||
}
|
||||
|
||||
private:
|
||||
std::set<TNote*, NotePtrComparator> _timeline;
|
||||
microsec _current_offset;
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
#include "application/state.h"
|
||||
#include "core/corefactory.h"
|
||||
#include "core/music.h"
|
||||
#include "core/functional.h"
|
||||
|
||||
class BPMCalculator;
|
||||
class Group;
|
||||
|
||||
namespace kku
|
||||
{
|
||||
class Editor;
|
||||
}
|
||||
namespace kku { class Editor; }
|
||||
|
||||
class EditorState : public GUIState
|
||||
{
|
||||
|
@ -18,7 +16,7 @@ public:
|
|||
|
||||
struct Callbacks
|
||||
{
|
||||
std::function<void(void)> onLeaveEditorState;
|
||||
kku::lambda onLeaveEditorState;
|
||||
};
|
||||
|
||||
explicit EditorState(const std::shared_ptr<kku::CoreFactory>& core_factory, std::unique_ptr<kku::Editor>&& editor, Callbacks&& callbacks);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "core/music.h"
|
||||
#include "core/game.h"
|
||||
#include "core/corefactory.h"
|
||||
#include "core/functional.h"
|
||||
|
||||
class Group;
|
||||
|
||||
|
@ -13,7 +14,7 @@ public:
|
|||
|
||||
struct Callbacks
|
||||
{
|
||||
std::function<void(void)> onLeaveGame;
|
||||
kku::lambda onLeaveGame;
|
||||
};
|
||||
|
||||
|
||||
|
@ -31,7 +32,7 @@ private:
|
|||
std::shared_ptr<kku::Music> _music;
|
||||
std::shared_ptr<kku::Game> _game;
|
||||
|
||||
std::function<void(void)> _onEnterGameCallback;
|
||||
std::function<void(void)> _onLeaveGameCallback;
|
||||
kku::lambda _onEnterGameCallback;
|
||||
kku::lambda _onLeaveGameCallback;
|
||||
};
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "application/state.h"
|
||||
#include "core/corefactory.h"
|
||||
#include "core/functional.h"
|
||||
|
||||
class Group;
|
||||
|
||||
|
@ -11,8 +12,8 @@ public:
|
|||
|
||||
struct Callbacks
|
||||
{
|
||||
std::function<void(void)> onAppendGameState;
|
||||
std::function<void(void)> onAppendEditorState;
|
||||
kku::lambda onAppendGameState;
|
||||
kku::lambda onAppendEditorState;
|
||||
};
|
||||
|
||||
explicit MainMenu(const std::shared_ptr<kku::CoreFactory>& factory, Callbacks&& callbacks);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
#include "core/systemevent.h"
|
||||
#include "core/vector.h"
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#include "widget.h"
|
||||
#include "core/corefactory.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
class Button : public Widget
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -43,7 +43,7 @@ void PushButton::input(const kku::SystemEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void PushButton::setCallback(std::function<void(void)> callback)
|
||||
void PushButton::setCallback(kku::lambda callback)
|
||||
{
|
||||
_on_click_callback = callback;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "button.h"
|
||||
#include "core/functional.h"
|
||||
|
||||
class PushButton : public Button
|
||||
{
|
||||
|
@ -8,7 +9,7 @@ public:
|
|||
explicit PushButton(const std::string& text, const std::shared_ptr<kku::CoreFactory>& factory, unsigned int font_size = 12);
|
||||
virtual void input(const kku::SystemEvent& event) override final;
|
||||
|
||||
void setCallback(std::function<void(void)> callback);
|
||||
void setCallback(kku::lambda callback);
|
||||
void setColors(kku::Color&& idle_color, kku::Color&& pressed_color);
|
||||
|
||||
private:
|
||||
|
@ -16,6 +17,6 @@ private:
|
|||
kku::Color _color_pressed;
|
||||
|
||||
bool _pressed;
|
||||
std::function<void(void)> _on_click_callback;
|
||||
kku::lambda _on_click_callback;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "window.h"
|
||||
#include "pushbutton.h"
|
||||
|
||||
Window::Window(const std::shared_ptr<kku::CoreFactory>& factory, const std::string& title) :
|
||||
_core_factory(factory),
|
||||
|
@ -109,7 +108,7 @@ bool Window::isUnderMouse(const kku::Point& position) const
|
|||
return _is_visible && _window_content->contains(position);
|
||||
}
|
||||
|
||||
void Window::addBarButton(const std::string &text, std::function<void(void)> callback)
|
||||
void Window::addBarButton(const std::string &text, kku::lambda callback)
|
||||
{
|
||||
const auto area = _window_content->getRect();
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "widget.h"
|
||||
#include "pushbutton.h"
|
||||
#include "core/corefactory.h"
|
||||
#include "core/rectangle.h"
|
||||
#include "core/vector.h"
|
||||
#include "core/text.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
class Window : public Widget
|
||||
{
|
||||
public:
|
||||
|
@ -25,7 +24,7 @@ public:
|
|||
virtual void setPosition(const kku::Point& position) override;
|
||||
virtual kku::Point getPosition() const override;
|
||||
|
||||
void addBarButton(const std::string& text, std::function<void(void)> callback);
|
||||
void addBarButton(const std::string& text, kku::lambda callback);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<kku::Rectangle> _bar;
|
||||
|
|
|
@ -17,7 +17,7 @@ std::unique_ptr<kku::Game> classic::getGame(const std::shared_ptr<kku::CoreFacto
|
|||
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
|
||||
const auto timeline = std::make_shared<kku::Timeline<ClassicNote>>();
|
||||
const auto selection_manager = std::make_shared<SelectionManager>();
|
||||
const auto graphics_manager = std::make_shared<ClassicSceneGraphicsManager>(timeline, factory, visibility_offset);
|
||||
const auto graphics_manager = std::make_shared<ClassicSceneGraphicsManager<ClassicNote>>(timeline, factory, visibility_offset);
|
||||
|
||||
return std::make_unique<ClassicGame>(timeline, graphics_manager);
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ std::unique_ptr<kku::Editor> classic::getEditor(const std::shared_ptr<kku::CoreF
|
|||
const kku::microsec visibility_offset = 1648648;
|
||||
|
||||
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
|
||||
const auto timeline = std::make_shared<kku::Timeline<ClassicNote>>();
|
||||
const auto timeline = std::make_shared<kku::Timeline<ClassicMockNote>>();
|
||||
const auto selection_manager = std::make_shared<SelectionManager>();
|
||||
const auto graphics_manager = std::make_shared<ClassicSceneGraphicsManager>(timeline, factory, visibility_offset);
|
||||
const auto graphics_manager = std::make_shared<ClassicSceneGraphicsManager<ClassicMockNote>>(timeline, factory, visibility_offset);
|
||||
|
||||
return std::make_unique<ClassicEditor>(timeline, graphics_manager, selection_manager);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#include "callbacksimple.h"
|
||||
|
||||
CallbackSimple::CallbackSimple(Init&& init, Metadata&& metadata) :
|
||||
_run(std::move(init.run)),
|
||||
_is_enabled(std::move(init.is_enabled)),
|
||||
_metadata(std::move(metadata))
|
||||
{}
|
||||
|
||||
bool CallbackSimple::isEnabled() const
|
||||
{
|
||||
return _is_enabled();
|
||||
}
|
||||
|
||||
void CallbackSimple::run() const
|
||||
{
|
||||
_run();
|
||||
}
|
||||
|
||||
auto CallbackSimple::getMetadata() const -> EditorCallback::Metadata
|
||||
{
|
||||
return _metadata;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/editorcallback.h"
|
||||
#include "core/functional.h"
|
||||
|
||||
class CallbackSimple : public kku::EditorCallback
|
||||
{
|
||||
public:
|
||||
|
||||
struct Init
|
||||
{
|
||||
kku::lambda run;
|
||||
kku::predicate is_enabled;
|
||||
};
|
||||
|
||||
explicit CallbackSimple(Init&& init, Metadata&& metadata);
|
||||
|
||||
virtual bool isEnabled() const override;
|
||||
virtual void run() const override;
|
||||
|
||||
virtual Metadata getMetadata() const override;
|
||||
|
||||
private:
|
||||
const kku::lambda _run;
|
||||
const kku::predicate _is_enabled;
|
||||
const Metadata _metadata;
|
||||
};
|
|
@ -9,7 +9,9 @@
|
|||
#include "graphics/animations/classicdyinganimationscenario.h"
|
||||
//
|
||||
|
||||
ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
||||
#include "callbacks/callbacksimple.h"
|
||||
|
||||
ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicMockNote>>& timeline,
|
||||
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager,
|
||||
const std::shared_ptr<SelectionManager>& selection_manager) :
|
||||
_timeline(timeline),
|
||||
|
@ -29,7 +31,7 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
|
|||
kku::microsec bpm_end = starting_beat_offset + (interval * amount_of_beats);
|
||||
|
||||
std::vector<kku::microsec> input_intervals = {note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset};
|
||||
std::set<ClassicNote*, kku::NotePtrComparator> notes;
|
||||
std::set<ClassicMockNote*, kku::NotePtrComparator> notes;
|
||||
input_intervals.shrink_to_fit();
|
||||
|
||||
bpm_iterator += tempo_interval;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "core/editor.h"
|
||||
#include "core/timeline.h"
|
||||
|
||||
#include "classicmode/classicnote.h"
|
||||
#include "classicmocknote.h"
|
||||
#include "classicmode/classicactions.h"
|
||||
|
||||
class ClassicGraphicsManager;
|
||||
|
@ -14,7 +14,7 @@ class SelectionManager;
|
|||
class ClassicEditor : public kku::Editor
|
||||
{
|
||||
public:
|
||||
explicit ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
||||
explicit ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicMockNote>>& timeline,
|
||||
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager,
|
||||
const std::shared_ptr<SelectionManager>& selection_manager);
|
||||
|
||||
|
@ -28,7 +28,7 @@ public:
|
|||
private:
|
||||
inline kku::microsec adjustOffset(kku::microsec offset) const noexcept;
|
||||
|
||||
const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline;
|
||||
const std::shared_ptr<kku::Timeline<ClassicMockNote>> _timeline;
|
||||
const std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
|
||||
const std::shared_ptr<SelectionManager> _selection_manager;
|
||||
|
||||
|
|
|
@ -89,22 +89,6 @@ void ClassicMockNote::update(const kku::microsec& music_offset)
|
|||
element.animations[_state]->update(music_offset);
|
||||
}
|
||||
|
||||
void ClassicMockNote::display(const ClassicGraphicsManager * const manager) const
|
||||
{
|
||||
manager->display(_elements);
|
||||
}
|
||||
|
||||
void ClassicMockNote::setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range)
|
||||
{
|
||||
manager->setGraphics(_elements, std::move(range));
|
||||
}
|
||||
|
||||
void ClassicMockNote::removeGraphics(ClassicGraphicsManager * const manager)
|
||||
{
|
||||
manager->removeGraphics(_elements);
|
||||
}
|
||||
|
||||
|
||||
std::vector<MockElement>& ClassicMockNote::getElements()
|
||||
{
|
||||
return _elements;
|
||||
|
|
|
@ -17,10 +17,6 @@ public:
|
|||
virtual void update(const kku::microsec &music_offset) override;
|
||||
virtual void input(kku::GameEvent&& input) override;
|
||||
|
||||
virtual void display(const ClassicGraphicsManager * const manager) const override;
|
||||
virtual void setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) override;
|
||||
virtual void removeGraphics(ClassicGraphicsManager * const manager) override;
|
||||
|
||||
std::vector<MockElement>& getElements();
|
||||
|
||||
private:
|
||||
|
|
|
@ -94,21 +94,6 @@ void ClassicArrowNote::update(const kku::microsec& music_offset)
|
|||
element.animations[_state]->update(music_offset);
|
||||
}
|
||||
|
||||
void ClassicArrowNote::display(const ClassicGraphicsManager * const manager) const
|
||||
{
|
||||
manager->display(_elements);
|
||||
}
|
||||
|
||||
void ClassicArrowNote::setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range)
|
||||
{
|
||||
manager->setGraphics(_elements, std::move(range));
|
||||
}
|
||||
|
||||
void ClassicArrowNote::removeGraphics(ClassicGraphicsManager * const manager)
|
||||
{
|
||||
manager->removeGraphics(_elements);
|
||||
}
|
||||
|
||||
bool ClassicArrowNote::allElementsPressed() const
|
||||
{
|
||||
return std::all_of(_elements.begin(), _elements.end(),
|
||||
|
@ -131,3 +116,8 @@ bool ClassicArrowNote::isHold() const
|
|||
{
|
||||
return _is_hold;
|
||||
}
|
||||
|
||||
std::vector<ArrowElement>& ClassicArrowNote::getElements()
|
||||
{
|
||||
return _elements;
|
||||
}
|
||||
|
|
|
@ -24,14 +24,12 @@ public:
|
|||
virtual void update(const kku::microsec &music_offset) override;
|
||||
virtual void input(kku::GameEvent&& input) override;
|
||||
|
||||
virtual void display(const ClassicGraphicsManager * const manager) const override;
|
||||
virtual void setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) override;
|
||||
virtual void removeGraphics(ClassicGraphicsManager * const manager) override;
|
||||
|
||||
bool allElementsPressed() const;
|
||||
bool isPressedAs(kku::SystemEvent::Key::Code key) const;
|
||||
inline bool isHold() const;
|
||||
|
||||
std::vector<ArrowElement>& getElements();
|
||||
|
||||
private:
|
||||
const kku::PrecisionEvaluator<Grade> _evaluator;
|
||||
const std::shared_ptr<HoldManager> _hold_manager;
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/time.h"
|
||||
#include "classicmode/classicactions.h"
|
||||
#include "core/gameevent.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
struct ArrowElement;
|
||||
struct MockElement;
|
||||
|
||||
class ClassicGraphicsManager : public std::enable_shared_from_this<ClassicGraphicsManager>
|
||||
{
|
||||
|
@ -18,15 +14,6 @@ public:
|
|||
{}
|
||||
|
||||
virtual void input(kku::GameEvent&& input) = 0;
|
||||
|
||||
virtual void display(const std::vector<ArrowElement>& elements) const = 0;
|
||||
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range) = 0;
|
||||
virtual void removeGraphics(std::vector<ArrowElement>& elements) = 0;
|
||||
|
||||
virtual void display(const std::vector<MockElement>& elements) const = 0;
|
||||
virtual void setGraphics(std::vector<MockElement>& elements, kku::TimeRange&& range) = 0;
|
||||
virtual void removeGraphics(std::vector<MockElement>& elements) = 0;
|
||||
|
||||
virtual void display() const = 0;
|
||||
virtual void update(const kku::microsec& offset) = 0;
|
||||
|
||||
|
|
|
@ -1,248 +0,0 @@
|
|||
#include "classicscenegraphicsmanager.h"
|
||||
|
||||
#include "editor/mockelement.h"
|
||||
#include "game/arrowelement.h"
|
||||
|
||||
#include "graphics/animations/classicflyinganimationscenario.h"
|
||||
#include "graphics/animations/classicdyinganimationscenario.h"
|
||||
|
||||
ClassicSceneGraphicsManager::ClassicSceneGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
||||
const std::shared_ptr<ClassicGraphicsFactory>& factory,
|
||||
const kku::microsec& visibility_offset) :
|
||||
ClassicGraphicsManager(visibility_offset),
|
||||
_sprite_container({Type::UP, Type::DOWN,
|
||||
Type::LEFT, Type::RIGHT},
|
||||
factory),
|
||||
_factory(factory),
|
||||
_timeline(timeline)
|
||||
{
|
||||
_timeline->expire(_first);
|
||||
_timeline->expire(_last);
|
||||
}
|
||||
|
||||
void ClassicSceneGraphicsManager::input(kku::GameEvent&& input)
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
{
|
||||
(*it)->input(std::move(input));
|
||||
}
|
||||
}
|
||||
|
||||
void ClassicSceneGraphicsManager::display() const
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
{
|
||||
(*it)->display(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ClassicSceneGraphicsManager::update(const kku::microsec &offset)
|
||||
{
|
||||
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;
|
||||
|
||||
//const auto c1 = neighbor_sprite->trailPosition();
|
||||
//const auto c2 = sprite->trailPosition();
|
||||
|
||||
//_render_target->draw(makeLine(c1, c2));
|
||||
}
|
||||
|
||||
sprite->display();
|
||||
}
|
||||
}
|
||||
|
||||
void ClassicSceneGraphicsManager::setGraphics(std::vector<ArrowElement>& 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.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);
|
||||
}
|
||||
}
|
||||
|
||||
void ClassicSceneGraphicsManager::removeGraphics(std::vector<ArrowElement>& elements)
|
||||
{
|
||||
for (auto& element : elements)
|
||||
{
|
||||
_sprite_container.resetSprite(element.sprite, element.type);
|
||||
element.sprite = nullptr;
|
||||
|
||||
element.animations[ClassicNote::State::NONE] = nullptr;
|
||||
element.animations[ClassicNote::State::FLYING] = nullptr;
|
||||
element.animations[ClassicNote::State::DYING] = nullptr;
|
||||
element.animations[ClassicNote::State::DEAD] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void ClassicSceneGraphicsManager::removeGraphics(std::vector<MockElement>& elements)
|
||||
{
|
||||
for (auto& element : elements)
|
||||
{
|
||||
_sprite_container.resetSprite(element.sprite, element.type);
|
||||
element.sprite = nullptr;
|
||||
|
||||
element.animations[ClassicNote::State::NONE] = nullptr;
|
||||
element.animations[ClassicNote::State::FLYING] = nullptr;
|
||||
element.animations[ClassicNote::State::DYING] = nullptr;
|
||||
element.animations[ClassicNote::State::DEAD] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/*sf::VertexArray ClassicSceneGraphicsSFML::makeLine(const kku::Point& c1, const kku::Point& 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 ClassicSceneGraphicsManager::updateVisibleNotes(const kku::microsec &offset)
|
||||
{
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
(*it)->update(offset);
|
||||
}
|
||||
|
||||
void ClassicSceneGraphicsManager::fetchFirstNote(const kku::microsec& offset)
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
|
||||
if (offset < (*_first)->getPerfectOffset())
|
||||
{
|
||||
Iterator note_iterator = _first;
|
||||
while (note_iterator != _timeline->begin() && isVisiblyClose(note_iterator, offset))
|
||||
{
|
||||
--note_iterator;
|
||||
}
|
||||
|
||||
_first = note_iterator;
|
||||
|
||||
auto note = *_first;
|
||||
if (note->getState() != ClassicNote::State::FLYING
|
||||
&& note->getState() != ClassicNote::State::DYING
|
||||
&& offset <= note->getPerfectOffset())
|
||||
{
|
||||
note->setState(ClassicNote::State::FLYING);
|
||||
note->setGraphics(this, kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Iterator note_iterator = _first;
|
||||
while (note_iterator != _last)
|
||||
{
|
||||
auto note = *note_iterator;
|
||||
if (note->getState() == ClassicNote::State::DEAD)
|
||||
{
|
||||
// note->removeGraphics(this);
|
||||
++_first;
|
||||
}
|
||||
|
||||
++note_iterator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClassicSceneGraphicsManager::fetchLastNote(const kku::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->getState() != ClassicNote::State::FLYING
|
||||
&& note->getState() != ClassicNote::State::DYING
|
||||
&& offset <= note->getPerfectOffset())
|
||||
{
|
||||
note->setState(ClassicNote::State::FLYING);
|
||||
note->setGraphics(this, kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
|
||||
}
|
||||
|
||||
++note_iterator;
|
||||
}
|
||||
|
||||
_last = note_iterator;
|
||||
}
|
||||
|
||||
bool ClassicSceneGraphicsManager::nothingToDraw() const noexcept
|
||||
{
|
||||
return _timeline->isExpired(_first)
|
||||
|| _timeline->isExpired(_last);
|
||||
}
|
||||
|
||||
bool ClassicSceneGraphicsManager::isVisiblyClose(const Iterator& iterator, const kku::microsec& music_offset) const noexcept
|
||||
{
|
||||
return ((*iterator)->getPerfectOffset() - _visibility_offset) <= music_offset;
|
||||
}
|
|
@ -6,43 +6,254 @@
|
|||
#include "core/timeline.h"
|
||||
#include "core/spritecontainer.h"
|
||||
|
||||
class ClassicSprite;
|
||||
#include "editor/mockelement.h"
|
||||
#include "game/arrowelement.h"
|
||||
|
||||
#include "graphics/animations/classicflyinganimationscenario.h"
|
||||
#include "graphics/animations/classicdyinganimationscenario.h"
|
||||
|
||||
template <class TNote, class = std::enable_if_t<std::is_base_of<kku::Note, TNote>::value>>
|
||||
class ClassicSceneGraphicsManager : public ClassicGraphicsManager
|
||||
{
|
||||
public:
|
||||
explicit ClassicSceneGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
||||
explicit ClassicSceneGraphicsManager(const std::shared_ptr<kku::Timeline<TNote>>& timeline,
|
||||
const std::shared_ptr<ClassicGraphicsFactory>& factory,
|
||||
const kku::microsec& visibility_offset);
|
||||
const kku::microsec& visibility_offset) :
|
||||
ClassicGraphicsManager(visibility_offset),
|
||||
_sprite_container({Type::UP, Type::DOWN,
|
||||
Type::LEFT, Type::RIGHT},
|
||||
factory),
|
||||
_factory(factory),
|
||||
_timeline(timeline)
|
||||
{
|
||||
_timeline->expire(_first);
|
||||
_timeline->expire(_last);
|
||||
}
|
||||
|
||||
virtual void input(kku::GameEvent&& input) override;
|
||||
virtual void input(kku::GameEvent&& input) override
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
|
||||
virtual void display() const override;
|
||||
virtual void update(const kku::microsec& offset) override;
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
{
|
||||
(*it)->input(std::move(input));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void display(const std::vector<ArrowElement>& elements) const override;
|
||||
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range) override;
|
||||
virtual void removeGraphics(std::vector<ArrowElement>& elements) override;
|
||||
virtual void display() const override
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
|
||||
virtual void display(const std::vector<MockElement>& elements) const override;
|
||||
virtual void setGraphics(std::vector<MockElement>& elements, kku::TimeRange&& range) override;
|
||||
virtual void removeGraphics(std::vector<MockElement>& elements) override;
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
{
|
||||
display((*it)->getElements());
|
||||
}
|
||||
}
|
||||
|
||||
virtual void update(const kku::microsec& offset) override
|
||||
{
|
||||
fetchLastNote(offset);
|
||||
fetchFirstNote(offset);
|
||||
|
||||
updateVisibleNotes(offset);
|
||||
}
|
||||
|
||||
virtual void 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;
|
||||
|
||||
//const auto c1 = neighbor_sprite->trailPosition();
|
||||
//const auto c2 = sprite->trailPosition();
|
||||
|
||||
//_render_target->draw(makeLine(c1, c2));
|
||||
}
|
||||
|
||||
sprite->display();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void setGraphics(std::vector<ArrowElement>& 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.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);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void removeGraphics(std::vector<ArrowElement>& elements)
|
||||
{
|
||||
for (auto& element : elements)
|
||||
{
|
||||
_sprite_container.resetSprite(element.sprite, element.type);
|
||||
element.sprite = nullptr;
|
||||
|
||||
element.animations[ClassicNote::State::NONE] = nullptr;
|
||||
element.animations[ClassicNote::State::FLYING] = nullptr;
|
||||
element.animations[ClassicNote::State::DYING] = nullptr;
|
||||
element.animations[ClassicNote::State::DEAD] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void 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();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void 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);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void removeGraphics(std::vector<MockElement>& elements)
|
||||
{
|
||||
for (auto& element : elements)
|
||||
{
|
||||
_sprite_container.resetSprite(element.sprite, element.type);
|
||||
element.sprite = nullptr;
|
||||
|
||||
element.animations[ClassicNote::State::NONE] = nullptr;
|
||||
element.animations[ClassicNote::State::FLYING] = nullptr;
|
||||
element.animations[ClassicNote::State::DYING] = nullptr;
|
||||
element.animations[ClassicNote::State::DEAD] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicSprite> _sprite_container;
|
||||
const std::shared_ptr<const ClassicGraphicsFactory> _factory;
|
||||
using Iterator = kku::Timeline<ClassicNote>::Iterator;
|
||||
|
||||
typedef typename std::set<TNote*>::const_iterator Iterator;
|
||||
|
||||
Iterator _first;
|
||||
Iterator _last;
|
||||
|
||||
const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline;
|
||||
const std::shared_ptr<kku::Timeline<TNote>> _timeline;
|
||||
|
||||
inline bool nothingToDraw() const noexcept;
|
||||
inline bool isVisiblyClose(const Iterator& iterator, const kku::microsec& music_offset) const noexcept;
|
||||
//inline sf::VertexArray makeLine(const kku::Point& c1, const kku::Point& c2) const;
|
||||
inline bool nothingToDraw() const noexcept
|
||||
{
|
||||
return _timeline->isExpired(_first)
|
||||
|| _timeline->isExpired(_last);
|
||||
}
|
||||
|
||||
void fetchFirstNote(const kku::microsec& offset);
|
||||
void fetchLastNote(const kku::microsec& offset);
|
||||
void updateVisibleNotes(const kku::microsec& offset);
|
||||
inline bool isVisiblyClose(const Iterator& iterator, const kku::microsec& music_offset) const noexcept
|
||||
{
|
||||
return ((*iterator)->getPerfectOffset() - _visibility_offset) <= music_offset;
|
||||
}
|
||||
|
||||
void fetchFirstNote(const kku::microsec& offset)
|
||||
{
|
||||
if (nothingToDraw())
|
||||
return;
|
||||
|
||||
if (offset < (*_first)->getPerfectOffset())
|
||||
{
|
||||
Iterator note_iterator = _first;
|
||||
while (note_iterator != _timeline->begin() && isVisiblyClose(note_iterator, offset))
|
||||
{
|
||||
--note_iterator;
|
||||
}
|
||||
|
||||
_first = note_iterator;
|
||||
|
||||
auto note = *_first;
|
||||
if (note->getState() != ClassicNote::State::FLYING
|
||||
&& note->getState() != ClassicNote::State::DYING
|
||||
&& offset <= note->getPerfectOffset())
|
||||
{
|
||||
note->setState(ClassicNote::State::FLYING);
|
||||
setGraphics(note, kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Iterator note_iterator = _first;
|
||||
while (note_iterator != _last)
|
||||
{
|
||||
auto note = *note_iterator;
|
||||
if (note->getState() == ClassicNote::State::DEAD)
|
||||
{
|
||||
// note->removeGraphics(this);
|
||||
++_first;
|
||||
}
|
||||
|
||||
++note_iterator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fetchLastNote(const kku::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->getState() != ClassicNote::State::FLYING
|
||||
&& note->getState() != ClassicNote::State::DYING
|
||||
&& offset <= note->getPerfectOffset())
|
||||
{
|
||||
note->setState(ClassicNote::State::FLYING);
|
||||
note->setGraphics(this, kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
|
||||
}
|
||||
|
||||
++note_iterator;
|
||||
}
|
||||
|
||||
_last = note_iterator;
|
||||
}
|
||||
|
||||
void updateVisibleNotes(const kku::microsec& offset)
|
||||
{
|
||||
for (auto it = _first; it != _last; ++it)
|
||||
(*it)->update(offset);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -27,10 +27,6 @@ public:
|
|||
|
||||
virtual void input(kku::GameEvent&& input) override = 0;
|
||||
|
||||
virtual void display(const ClassicGraphicsManager * const manager) const = 0;
|
||||
virtual void setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) = 0;
|
||||
virtual void removeGraphics(ClassicGraphicsManager * const manager) = 0;
|
||||
|
||||
void setState(State state) noexcept;
|
||||
State getState() const noexcept;
|
||||
|
||||
|
|
Loading…
Reference in New Issue