forked from NaiJi/project-kyoku
Fix Editor interface, replace some Game pointers with stack objects
This commit is contained in:
parent
c097ac0da5
commit
cfc8706c23
|
@ -7,9 +7,12 @@ struct BPMSection
|
||||||
int bpm = 0;
|
int bpm = 0;
|
||||||
int fraction = 1;
|
int fraction = 1;
|
||||||
microsec offset_start = 0;
|
microsec offset_start = 0;
|
||||||
|
};
|
||||||
|
|
||||||
inline bool operator<(const BPMSection& right)
|
struct BPMSectionCompt
|
||||||
|
{
|
||||||
|
bool operator()(const BPMSection& lhs, const BPMSection& rhs) const noexcept
|
||||||
{
|
{
|
||||||
return offset_start < right.offset_start;
|
return lhs.offset_start < rhs.offset_start;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,15 +10,15 @@ public:
|
||||||
virtual ~Editor() = default;
|
virtual ~Editor() = default;
|
||||||
|
|
||||||
virtual void input(PlayerInput&& inputdata) = 0;
|
virtual void input(PlayerInput&& inputdata) = 0;
|
||||||
virtual void update() = 0;
|
virtual void update(const sf::Time& dt) = 0;
|
||||||
virtual void draw() const = 0;
|
virtual void draw() const = 0;
|
||||||
|
|
||||||
inline void setBPMSections(const std::set<BPMSection>& sections)
|
inline void setBPMSections(const std::set<BPMSection, BPMSectionCompt>& sections) noexcept
|
||||||
{
|
{
|
||||||
_bpm_sections = sections;
|
_bpm_sections = sections;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setBPMSections(std::set<BPMSection>&& sections)
|
inline void setBPMSections(std::set<BPMSection, BPMSectionCompt>&& sections) noexcept
|
||||||
{
|
{
|
||||||
_bpm_sections = std::move(sections);
|
_bpm_sections = std::move(sections);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public:
|
||||||
_bpm_sections.insert(std::move(section));
|
_bpm_sections.insert(std::move(section));
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeBPMSectionAt(const microsec& offset)
|
/*void removeBPMSectionAt(const microsec& offset)
|
||||||
{
|
{
|
||||||
const auto section_it = std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(),
|
const auto section_it = std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(),
|
||||||
[offset](const auto& section)
|
[offset](const auto& section)
|
||||||
|
@ -43,13 +43,13 @@ public:
|
||||||
|
|
||||||
if (section_it != _bpm_sections.rend())
|
if (section_it != _bpm_sections.rend())
|
||||||
_bpm_sections.erase((section_it + 1).base());
|
_bpm_sections.erase((section_it + 1).base());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
inline void clearBPMSections()
|
inline void clearBPMSections() noexcept
|
||||||
{
|
{
|
||||||
_bpm_sections.clear();
|
_bpm_sections.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::set<BPMSection> _bpm_sections;
|
std::set<BPMSection, BPMSectionCompt> _bpm_sections;
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,7 +44,7 @@ protected:
|
||||||
|
|
||||||
struct NotePtrCompt
|
struct NotePtrCompt
|
||||||
{
|
{
|
||||||
bool operator()(const Note* lhs, const Note* rhs) const
|
bool operator()(const Note* lhs, const Note* rhs) const noexcept
|
||||||
{
|
{
|
||||||
return lhs->offset() < rhs->offset();
|
return lhs->offset() < rhs->offset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,5 @@
|
||||||
|
|
||||||
std::unique_ptr<Game> classic::init(sf::RenderWindow& game_window)
|
std::unique_ptr<Game> classic::init(sf::RenderWindow& game_window)
|
||||||
{
|
{
|
||||||
return std::make_unique<ClassicGame>(std::make_unique<ClassicGraphicsManager>(game_window), std::make_unique<Music>());
|
return std::make_unique<ClassicGame>(std::make_unique<ClassicGraphicsManager>(game_window));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#include "classiceditor.h"
|
|
||||||
|
|
||||||
ClassicEditor::ClassicEditor(std::shared_ptr<ClassicGraphicsManager>&& manager)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -8,6 +8,6 @@ public:
|
||||||
explicit ClassicEditor();
|
explicit ClassicEditor();
|
||||||
|
|
||||||
virtual void input(PlayerInput&& inputdata) = 0;
|
virtual void input(PlayerInput&& inputdata) = 0;
|
||||||
virtual void update() = 0;
|
virtual void update(const sf::Time& dt) = 0;
|
||||||
virtual void draw() const = 0;
|
virtual void draw() const = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,14 +2,10 @@
|
||||||
#include "classicnote.h"
|
#include "classicnote.h"
|
||||||
#include "classicmapcreator.h"
|
#include "classicmapcreator.h"
|
||||||
#include "holdmanager.h"
|
#include "holdmanager.h"
|
||||||
#include "context.h"
|
|
||||||
#include "tools/music.h"
|
|
||||||
|
|
||||||
ClassicGame::ClassicGame(std::shared_ptr<ClassicGraphicsManager>&& manager, std::unique_ptr<Music>&& music) :
|
ClassicGame::ClassicGame(std::shared_ptr<ClassicGraphicsManager>&& manager) :
|
||||||
_graphics_manager(std::move(manager)),
|
_graphics_manager(std::move(manager)),
|
||||||
_hold_manager(std::make_shared<HoldManager>(_graphics_manager)),
|
_hold_manager(std::make_unique<HoldManager>(_graphics_manager))
|
||||||
_music(std::move(music)),
|
|
||||||
_is_paused(false)
|
|
||||||
{
|
{
|
||||||
_slap_buffer.loadFromFile("Tick.ogg");
|
_slap_buffer.loadFromFile("Tick.ogg");
|
||||||
_slap.setBuffer(_slap_buffer);
|
_slap.setBuffer(_slap_buffer);
|
||||||
|
@ -59,19 +55,19 @@ ClassicGame::~ClassicGame()
|
||||||
|
|
||||||
void ClassicGame::run()
|
void ClassicGame::run()
|
||||||
{
|
{
|
||||||
const auto context = std::make_shared<Context>(Context{_graphics_manager, _hold_manager});
|
_context.hold_manager = _hold_manager;
|
||||||
|
_context.graphics_manager = _graphics_manager;
|
||||||
|
|
||||||
ClassicMapCreator creator(context);
|
auto beatmap = classic::createBeatmap("aa", _context);
|
||||||
auto beatmap = creator.createBeatmap("aa");
|
_music.openFromFile("METEOR.flac");
|
||||||
_music->openFromFile("METEOR.flac");
|
_music.setVolume(10);
|
||||||
_music->setVolume(10);
|
_music.play();
|
||||||
_music->play();
|
|
||||||
_timeline.setNotes(beatmap.notes, beatmap.visibility_offset);
|
_timeline.setNotes(beatmap.notes, beatmap.visibility_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassicGame::input(PlayerInput&& inputdata)
|
void ClassicGame::input(PlayerInput&& inputdata)
|
||||||
{
|
{
|
||||||
inputdata.timestamp = _music->fetchOffset();
|
inputdata.timestamp = _music.fetchOffset();
|
||||||
|
|
||||||
switch (inputdata.event.type)
|
switch (inputdata.event.type)
|
||||||
{
|
{
|
||||||
|
@ -83,16 +79,14 @@ void ClassicGame::input(PlayerInput&& inputdata)
|
||||||
{
|
{
|
||||||
if (inputdata.event.key.code == sf::Keyboard::Space)
|
if (inputdata.event.key.code == sf::Keyboard::Space)
|
||||||
{
|
{
|
||||||
if (!_is_paused)
|
if (_music.isPaused())
|
||||||
{
|
{
|
||||||
_is_paused = true;
|
_music.play();
|
||||||
_music->pause();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_is_paused = false;
|
_music.pause();
|
||||||
_music->play();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +113,7 @@ void ClassicGame::input(PlayerInput&& inputdata)
|
||||||
|
|
||||||
void ClassicGame::update()
|
void ClassicGame::update()
|
||||||
{
|
{
|
||||||
_timeline.update(_music->fetchOffset());
|
_timeline.update(_music.fetchOffset());
|
||||||
_timeline.fetchVisibleNotes();
|
_timeline.fetchVisibleNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,18 +8,19 @@
|
||||||
|
|
||||||
#include "core/game.h"
|
#include "core/game.h"
|
||||||
#include "core/timeline.h"
|
#include "core/timeline.h"
|
||||||
|
#include "tools/music.h"
|
||||||
|
|
||||||
|
#include "context.h"
|
||||||
#include "classicnote.h"
|
#include "classicnote.h"
|
||||||
#include "classicactions.h"
|
#include "classicactions.h"
|
||||||
|
|
||||||
class Music;
|
|
||||||
class ClassicGraphicsManager;
|
class ClassicGraphicsManager;
|
||||||
class HoldManager;
|
class HoldManager;
|
||||||
|
|
||||||
class ClassicGame final : public Game
|
class ClassicGame final : public Game
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ClassicGame(std::shared_ptr<ClassicGraphicsManager>&& manager, std::unique_ptr<Music>&& music);
|
explicit ClassicGame(std::shared_ptr<ClassicGraphicsManager>&& manager);
|
||||||
virtual ~ClassicGame() override;
|
virtual ~ClassicGame() override;
|
||||||
|
|
||||||
virtual void run() override;
|
virtual void run() override;
|
||||||
|
@ -40,7 +41,6 @@ private:
|
||||||
sf::SoundBuffer _slap_buffer;
|
sf::SoundBuffer _slap_buffer;
|
||||||
sf::Sound _slap;
|
sf::Sound _slap;
|
||||||
|
|
||||||
std::unique_ptr<Music> _music;
|
Music _music;
|
||||||
|
Context _context;
|
||||||
bool _is_paused;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,11 +6,7 @@
|
||||||
#include "classicdyinganimationscenario.h"
|
#include "classicdyinganimationscenario.h"
|
||||||
//
|
//
|
||||||
|
|
||||||
ClassicMapCreator::ClassicMapCreator(const std::shared_ptr<Context> &context) :
|
auto classic::createBeatmap(const std::string& filepath, const Context &context) -> Beatmap
|
||||||
_context(context)
|
|
||||||
{}
|
|
||||||
|
|
||||||
Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
|
|
||||||
{
|
{
|
||||||
(void) filepath;
|
(void) filepath;
|
||||||
|
|
||||||
|
@ -40,7 +36,7 @@ Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
|
||||||
init.initializer.intervals = input_intervals;
|
init.initializer.intervals = input_intervals;
|
||||||
init.initializer.perfect_offset = bpm_iterator;
|
init.initializer.perfect_offset = bpm_iterator;
|
||||||
init.hold = false;
|
init.hold = false;
|
||||||
init.initializer.context = _context;
|
init.initializer.context = &context;
|
||||||
|
|
||||||
element.element.coordinates = {x, 390.};
|
element.element.coordinates = {x, 390.};
|
||||||
element.element.falling_curve_interpolation = {};
|
element.element.falling_curve_interpolation = {};
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
#include "tools/mathutils.h"
|
#include "tools/mathutils.h"
|
||||||
#include "classicnote.h"
|
#include "classicnote.h"
|
||||||
|
|
||||||
struct Context;
|
namespace classic
|
||||||
|
{
|
||||||
|
|
||||||
struct Beatmap
|
struct Beatmap
|
||||||
{
|
{
|
||||||
|
@ -13,13 +14,7 @@ struct Beatmap
|
||||||
microsec visibility_offset;
|
microsec visibility_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClassicMapCreator
|
Beatmap createBeatmap(const std::string& filepath, const Context& context);
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit ClassicMapCreator(const std::shared_ptr<Context>& context);
|
|
||||||
|
|
||||||
Beatmap createBeatmap(const std::string& filepath) const;
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
const std::shared_ptr<Context> _context;
|
|
||||||
};
|
|
||||||
|
|
|
@ -45,5 +45,5 @@ protected:
|
||||||
const PrecisionEvaluator<Grade> _evaluator;
|
const PrecisionEvaluator<Grade> _evaluator;
|
||||||
|
|
||||||
State _state;
|
State _state;
|
||||||
std::shared_ptr<Context> _context;
|
const Context *_context;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
struct NoteInitializer
|
struct NoteInitializer
|
||||||
{
|
{
|
||||||
std::shared_ptr<Context> context;
|
const Context *context;
|
||||||
std::vector<microsec> intervals;
|
std::vector<microsec> intervals;
|
||||||
microsec perfect_offset = 0;
|
microsec perfect_offset = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,8 +17,6 @@ Application::Application() :
|
||||||
{
|
{
|
||||||
_font_holder.load(Fonts::Id::GUI, "SourceCodePro-Regular.ttf");
|
_font_holder.load(Fonts::Id::GUI, "SourceCodePro-Regular.ttf");
|
||||||
|
|
||||||
_game = classic::init(_game_window);
|
|
||||||
|
|
||||||
_game_window.setFramerateLimit(60);
|
_game_window.setFramerateLimit(60);
|
||||||
_game_window.setKeyRepeatEnabled(false);
|
_game_window.setKeyRepeatEnabled(false);
|
||||||
_game_window.setMouseCursorGrabbed(false);
|
_game_window.setMouseCursorGrabbed(false);
|
||||||
|
@ -33,7 +31,7 @@ Application::Application() :
|
||||||
EditorState::Callbacks editor_callbacks = {[&](){ popState(); }};
|
EditorState::Callbacks editor_callbacks = {[&](){ popState(); }};
|
||||||
|
|
||||||
const auto main_menu = std::make_shared<MainMenu>(_game_window, std::move(callbacks), _font_holder);
|
const auto main_menu = std::make_shared<MainMenu>(_game_window, std::move(callbacks), _font_holder);
|
||||||
const auto game_state = std::make_shared<GameState>(_game_window, _game, GameState::Callbacks());
|
const auto game_state = std::make_shared<GameState>(_game_window, classic::init(_game_window), GameState::Callbacks());
|
||||||
const auto editor = std::make_shared<EditorState>(_game_window, std::move(editor_callbacks), std::make_unique<Music>(), _font_holder);
|
const auto editor = std::make_shared<EditorState>(_game_window, std::move(editor_callbacks), std::make_unique<Music>(), _font_holder);
|
||||||
|
|
||||||
_states[GUIState::Tag::MAIN_MENU] = main_menu;
|
_states[GUIState::Tag::MAIN_MENU] = main_menu;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#ifndef APPLICATION_H
|
#pragma once
|
||||||
#define APPLICATION_H
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -14,12 +13,13 @@
|
||||||
#include "core/game.h"
|
#include "core/game.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
|
|
||||||
|
#include "tools/music.h"
|
||||||
#include "tools/resourceholder.h"
|
#include "tools/resourceholder.h"
|
||||||
|
|
||||||
class Application
|
class Application
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Application();
|
explicit Application();
|
||||||
void run();
|
void run();
|
||||||
void input();
|
void input();
|
||||||
void update(const sf::Time& dt);
|
void update(const sf::Time& dt);
|
||||||
|
@ -30,7 +30,7 @@ private:
|
||||||
std::vector<std::shared_ptr<GUIState>> _state_stack;
|
std::vector<std::shared_ptr<GUIState>> _state_stack;
|
||||||
|
|
||||||
sf::RenderWindow _game_window;
|
sf::RenderWindow _game_window;
|
||||||
std::shared_ptr<Game> _game;
|
Music _music;
|
||||||
|
|
||||||
void exec();
|
void exec();
|
||||||
void pushState(GUIState::Tag new_state);
|
void pushState(GUIState::Tag new_state);
|
||||||
|
@ -38,5 +38,3 @@ private:
|
||||||
|
|
||||||
FontHolder _font_holder;
|
FontHolder _font_holder;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPLICATION_H
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "editorwidget.h"
|
#include "editorwidget.h"
|
||||||
|
#include "core/editor.h"
|
||||||
|
|
||||||
EditorWidget::EditorWidget(const std::shared_ptr<Editor>& editor) :
|
EditorWidget::EditorWidget(const std::shared_ptr<Editor>& editor) :
|
||||||
_editor(editor)
|
_editor(editor)
|
||||||
|
@ -6,45 +7,49 @@ EditorWidget::EditorWidget(const std::shared_ptr<Editor>& editor) :
|
||||||
|
|
||||||
void EditorWidget::input(const sf::Event& event)
|
void EditorWidget::input(const sf::Event& event)
|
||||||
{
|
{
|
||||||
|
_editor->input(PlayerInput{0, event});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWidget::update(const sf::Time& dt)
|
void EditorWidget::update(const sf::Time& dt)
|
||||||
{
|
{
|
||||||
|
_editor->update(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWidget::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
void EditorWidget::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||||
{
|
{
|
||||||
|
// !!!!!!!!!!!!!!!!!
|
||||||
|
(void)target; (void)states;
|
||||||
|
_editor->draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWidget::move(const sf::Vector2f& delta)
|
void EditorWidget::move(const sf::Vector2f& delta)
|
||||||
{
|
{
|
||||||
|
(void)delta;
|
||||||
|
// delegate to children
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorWidget::isUnderMouse(int mouse_x, int mouse_y) const
|
bool EditorWidget::isUnderMouse(int mouse_x, int mouse_y) const
|
||||||
{
|
{
|
||||||
|
return _parent->isUnderMouse(mouse_x, mouse_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWidget::setRect(const sf::FloatRect& rect)
|
void EditorWidget::setRect(const sf::FloatRect& rect)
|
||||||
{
|
{
|
||||||
|
(void)rect;
|
||||||
|
// basically useless beacuse editor widget fills the entire screen
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::FloatRect EditorWidget::rect() const
|
sf::FloatRect EditorWidget::rect() const
|
||||||
{
|
{
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWidget::setPosition(const sf::Vector2f& position)
|
void EditorWidget::setPosition(const sf::Vector2f& position)
|
||||||
{
|
{
|
||||||
|
(void)position;
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Vector2f EditorWidget::position() const
|
sf::Vector2f EditorWidget::position() const
|
||||||
{
|
{
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ public:
|
||||||
void pause();
|
void pause();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
bool isPaused() const;
|
||||||
|
|
||||||
void setVolume(int volume);
|
void setVolume(int volume);
|
||||||
|
|
||||||
void setOffset(const microsec& offset);
|
void setOffset(const microsec& offset);
|
||||||
|
|
|
@ -27,6 +27,11 @@ void Music::stop()
|
||||||
_music.stop();
|
_music.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Music::isPaused() const
|
||||||
|
{
|
||||||
|
return (_music.getStatus() == sf::Music::Paused);
|
||||||
|
}
|
||||||
|
|
||||||
void Music::setVolume(int volume)
|
void Music::setVolume(int volume)
|
||||||
{
|
{
|
||||||
_music.setVolume(volume);
|
_music.setVolume(volume);
|
||||||
|
|
Loading…
Reference in New Issue