diff --git a/core/shared/core/bpmsection.h b/core/shared/core/bpmsection.h index 195edd3..1342841 100644 --- a/core/shared/core/bpmsection.h +++ b/core/shared/core/bpmsection.h @@ -7,9 +7,12 @@ struct BPMSection int bpm = 0; int fraction = 1; 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; } }; diff --git a/core/shared/core/editor.h b/core/shared/core/editor.h index 5a58c23..e669b64 100644 --- a/core/shared/core/editor.h +++ b/core/shared/core/editor.h @@ -10,15 +10,15 @@ public: virtual ~Editor() = default; virtual void input(PlayerInput&& inputdata) = 0; - virtual void update() = 0; + virtual void update(const sf::Time& dt) = 0; virtual void draw() const = 0; - inline void setBPMSections(const std::set& sections) + inline void setBPMSections(const std::set& sections) noexcept { _bpm_sections = sections; } - inline void setBPMSections(std::set&& sections) + inline void setBPMSections(std::set&& sections) noexcept { _bpm_sections = std::move(sections); } @@ -33,7 +33,7 @@ public: _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(), [offset](const auto& section) @@ -43,13 +43,13 @@ public: if (section_it != _bpm_sections.rend()) _bpm_sections.erase((section_it + 1).base()); - } + }*/ - inline void clearBPMSections() + inline void clearBPMSections() noexcept { _bpm_sections.clear(); } protected: - std::set _bpm_sections; + std::set _bpm_sections; }; diff --git a/core/shared/core/note.h b/core/shared/core/note.h index 19bf997..6bf3e88 100644 --- a/core/shared/core/note.h +++ b/core/shared/core/note.h @@ -44,8 +44,8 @@ protected: struct NotePtrCompt { - bool operator()(const Note* lhs, const Note* rhs) const - { - return lhs->offset() < rhs->offset(); - } + bool operator()(const Note* lhs, const Note* rhs) const noexcept + { + return lhs->offset() < rhs->offset(); + } }; diff --git a/modes/classicmode/classicfactory.cpp b/modes/classicmode/classicfactory.cpp index 6d60773..c97d557 100644 --- a/modes/classicmode/classicfactory.cpp +++ b/modes/classicmode/classicfactory.cpp @@ -7,5 +7,5 @@ std::unique_ptr classic::init(sf::RenderWindow& game_window) { - return std::make_unique(std::make_unique(game_window), std::make_unique()); + return std::make_unique(std::make_unique(game_window)); } diff --git a/modes/classicmode/editor/classiceditor.cpp.autosave b/modes/classicmode/editor/classiceditor.cpp.autosave deleted file mode 100644 index 45665fd..0000000 --- a/modes/classicmode/editor/classiceditor.cpp.autosave +++ /dev/null @@ -1,6 +0,0 @@ -#include "classiceditor.h" - -ClassicEditor::ClassicEditor(std::shared_ptr&& manager) -{ - -} diff --git a/modes/classicmode/editor/classiceditor.h b/modes/classicmode/editor/classiceditor.h index ce65d04..a9f7659 100644 --- a/modes/classicmode/editor/classiceditor.h +++ b/modes/classicmode/editor/classiceditor.h @@ -8,6 +8,6 @@ public: explicit ClassicEditor(); virtual void input(PlayerInput&& inputdata) = 0; - virtual void update() = 0; + virtual void update(const sf::Time& dt) = 0; virtual void draw() const = 0; }; diff --git a/modes/classicmode/game/classicgame.cpp b/modes/classicmode/game/classicgame.cpp index bf50681..469c5eb 100644 --- a/modes/classicmode/game/classicgame.cpp +++ b/modes/classicmode/game/classicgame.cpp @@ -2,14 +2,10 @@ #include "classicnote.h" #include "classicmapcreator.h" #include "holdmanager.h" -#include "context.h" -#include "tools/music.h" -ClassicGame::ClassicGame(std::shared_ptr&& manager, std::unique_ptr&& music) : +ClassicGame::ClassicGame(std::shared_ptr&& manager) : _graphics_manager(std::move(manager)), - _hold_manager(std::make_shared(_graphics_manager)), - _music(std::move(music)), - _is_paused(false) + _hold_manager(std::make_unique(_graphics_manager)) { _slap_buffer.loadFromFile("Tick.ogg"); _slap.setBuffer(_slap_buffer); @@ -59,19 +55,19 @@ ClassicGame::~ClassicGame() void ClassicGame::run() { - const auto context = std::make_shared(Context{_graphics_manager, _hold_manager}); + _context.hold_manager = _hold_manager; + _context.graphics_manager = _graphics_manager; - ClassicMapCreator creator(context); - auto beatmap = creator.createBeatmap("aa"); - _music->openFromFile("METEOR.flac"); - _music->setVolume(10); - _music->play(); + auto beatmap = classic::createBeatmap("aa", _context); + _music.openFromFile("METEOR.flac"); + _music.setVolume(10); + _music.play(); _timeline.setNotes(beatmap.notes, beatmap.visibility_offset); } void ClassicGame::input(PlayerInput&& inputdata) { - inputdata.timestamp = _music->fetchOffset(); + inputdata.timestamp = _music.fetchOffset(); switch (inputdata.event.type) { @@ -83,16 +79,14 @@ void ClassicGame::input(PlayerInput&& inputdata) { if (inputdata.event.key.code == sf::Keyboard::Space) { - if (!_is_paused) + if (_music.isPaused()) { - _is_paused = true; - _music->pause(); + _music.play(); return; } else { - _is_paused = false; - _music->play(); + _music.pause(); return; } } @@ -119,7 +113,7 @@ void ClassicGame::input(PlayerInput&& inputdata) void ClassicGame::update() { - _timeline.update(_music->fetchOffset()); + _timeline.update(_music.fetchOffset()); _timeline.fetchVisibleNotes(); } diff --git a/modes/classicmode/game/classicgame.h b/modes/classicmode/game/classicgame.h index 81297d2..114fd70 100644 --- a/modes/classicmode/game/classicgame.h +++ b/modes/classicmode/game/classicgame.h @@ -8,18 +8,19 @@ #include "core/game.h" #include "core/timeline.h" +#include "tools/music.h" +#include "context.h" #include "classicnote.h" #include "classicactions.h" -class Music; class ClassicGraphicsManager; class HoldManager; class ClassicGame final : public Game { public: - explicit ClassicGame(std::shared_ptr&& manager, std::unique_ptr&& music); + explicit ClassicGame(std::shared_ptr&& manager); virtual ~ClassicGame() override; virtual void run() override; @@ -40,7 +41,6 @@ private: sf::SoundBuffer _slap_buffer; sf::Sound _slap; - std::unique_ptr _music; - - bool _is_paused; + Music _music; + Context _context; }; diff --git a/modes/classicmode/game/classicmapcreator.cpp b/modes/classicmode/game/classicmapcreator.cpp index a2027b2..0ed3653 100644 --- a/modes/classicmode/game/classicmapcreator.cpp +++ b/modes/classicmode/game/classicmapcreator.cpp @@ -6,11 +6,7 @@ #include "classicdyinganimationscenario.h" // -ClassicMapCreator::ClassicMapCreator(const std::shared_ptr &context) : - _context(context) -{} - -Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const +auto classic::createBeatmap(const std::string& filepath, const Context &context) -> Beatmap { (void) filepath; @@ -40,7 +36,7 @@ Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const init.initializer.intervals = input_intervals; init.initializer.perfect_offset = bpm_iterator; init.hold = false; - init.initializer.context = _context; + init.initializer.context = &context; element.element.coordinates = {x, 390.}; element.element.falling_curve_interpolation = {}; diff --git a/modes/classicmode/game/classicmapcreator.h b/modes/classicmode/game/classicmapcreator.h index 7ede8bb..87a2e11 100644 --- a/modes/classicmode/game/classicmapcreator.h +++ b/modes/classicmode/game/classicmapcreator.h @@ -5,7 +5,8 @@ #include "tools/mathutils.h" #include "classicnote.h" -struct Context; +namespace classic +{ struct Beatmap { @@ -13,13 +14,7 @@ struct Beatmap microsec visibility_offset; }; -class ClassicMapCreator -{ -public: - explicit ClassicMapCreator(const std::shared_ptr& context); +Beatmap createBeatmap(const std::string& filepath, const Context& context); - Beatmap createBeatmap(const std::string& filepath) const; +} -private: - const std::shared_ptr _context; -}; diff --git a/modes/classicmode/game/classicnote.h b/modes/classicmode/game/classicnote.h index 38482da..eb20c19 100644 --- a/modes/classicmode/game/classicnote.h +++ b/modes/classicmode/game/classicnote.h @@ -45,5 +45,5 @@ protected: const PrecisionEvaluator _evaluator; State _state; - std::shared_ptr _context; + const Context *_context; }; diff --git a/modes/classicmode/game/initializers/noteinitializer.h b/modes/classicmode/game/initializers/noteinitializer.h index cd5108d..6a98596 100644 --- a/modes/classicmode/game/initializers/noteinitializer.h +++ b/modes/classicmode/game/initializers/noteinitializer.h @@ -8,7 +8,7 @@ struct NoteInitializer { - std::shared_ptr context; + const Context *context; std::vector intervals; microsec perfect_offset = 0; }; diff --git a/src/application/application.cpp b/src/application/application.cpp index 3e575ec..4bbb681 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -17,8 +17,6 @@ Application::Application() : { _font_holder.load(Fonts::Id::GUI, "SourceCodePro-Regular.ttf"); - _game = classic::init(_game_window); - _game_window.setFramerateLimit(60); _game_window.setKeyRepeatEnabled(false); _game_window.setMouseCursorGrabbed(false); @@ -33,7 +31,7 @@ Application::Application() : EditorState::Callbacks editor_callbacks = {[&](){ popState(); }}; const auto main_menu = std::make_shared(_game_window, std::move(callbacks), _font_holder); - const auto game_state = std::make_shared(_game_window, _game, GameState::Callbacks()); + const auto game_state = std::make_shared(_game_window, classic::init(_game_window), GameState::Callbacks()); const auto editor = std::make_shared(_game_window, std::move(editor_callbacks), std::make_unique(), _font_holder); _states[GUIState::Tag::MAIN_MENU] = main_menu; diff --git a/src/application/application.h b/src/application/application.h index e474dff..d762c6b 100644 --- a/src/application/application.h +++ b/src/application/application.h @@ -1,5 +1,4 @@ -#ifndef APPLICATION_H -#define APPLICATION_H +#pragma once #include #include @@ -14,12 +13,13 @@ #include "core/game.h" #include "state.h" +#include "tools/music.h" #include "tools/resourceholder.h" class Application { public: - Application(); + explicit Application(); void run(); void input(); void update(const sf::Time& dt); @@ -30,7 +30,7 @@ private: std::vector> _state_stack; sf::RenderWindow _game_window; - std::shared_ptr _game; + Music _music; void exec(); void pushState(GUIState::Tag new_state); @@ -38,5 +38,3 @@ private: FontHolder _font_holder; }; - -#endif // APPLICATION_H diff --git a/src/application/widgets/editorwidget.cpp b/src/application/widgets/editorwidget.cpp index 4914201..5d7e060 100644 --- a/src/application/widgets/editorwidget.cpp +++ b/src/application/widgets/editorwidget.cpp @@ -1,4 +1,5 @@ #include "editorwidget.h" +#include "core/editor.h" EditorWidget::EditorWidget(const std::shared_ptr& editor) : _editor(editor) @@ -6,45 +7,49 @@ EditorWidget::EditorWidget(const std::shared_ptr& editor) : void EditorWidget::input(const sf::Event& event) { - + _editor->input(PlayerInput{0, event}); } void EditorWidget::update(const sf::Time& dt) { - + _editor->update(dt); } void EditorWidget::draw(sf::RenderTarget& target, sf::RenderStates states) const { - + // !!!!!!!!!!!!!!!!! + (void)target; (void)states; + _editor->draw(); } void EditorWidget::move(const sf::Vector2f& delta) { - + (void)delta; + // delegate to children } 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)rect; + // basically useless beacuse editor widget fills the entire screen } sf::FloatRect EditorWidget::rect() const { - + return {}; } void EditorWidget::setPosition(const sf::Vector2f& position) { - + (void)position; } sf::Vector2f EditorWidget::position() const { - + return {}; } diff --git a/tools/shared/tools/music.h b/tools/shared/tools/music.h index 49e5bba..2d597ab 100644 --- a/tools/shared/tools/music.h +++ b/tools/shared/tools/music.h @@ -16,6 +16,8 @@ public: void pause(); void stop(); + bool isPaused() const; + void setVolume(int volume); void setOffset(const microsec& offset); diff --git a/tools/src/music.cpp b/tools/src/music.cpp index 9041369..833f16c 100644 --- a/tools/src/music.cpp +++ b/tools/src/music.cpp @@ -27,6 +27,11 @@ void Music::stop() _music.stop(); } +bool Music::isPaused() const +{ + return (_music.getStatus() == sf::Music::Paused); +} + void Music::setVolume(int volume) { _music.setVolume(volume);