From b3bec61542b707f9e6e236e9bcea4dc568595366 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Thu, 18 Nov 2021 01:14:52 +0300 Subject: [PATCH] Separate graphics from game and editor logic --- core/shared/core/bpmsection.h | 4 ++-- core/shared/core/editor.h | 4 ++-- modes/classicmode/CMakeLists.txt | 2 +- modes/classicmode/classicfactory.cpp | 11 +++++++++-- modes/classicmode/game/classicarrownote.cpp | 6 +++--- modes/classicmode/game/classicgame.h | 3 ++- modes/classicmode/game/classicmapcreator.cpp | 4 ++-- modes/classicmode/game/classicnote.cpp | 8 ++++---- .../game/initializers/arrowelementinitializer.h | 2 +- .../{game => graphics}/classicanimationscenario.h | 0 .../classicdyinganimationscenario.cpp | 0 .../classicdyinganimationscenario.h | 0 .../classicflyinganimationscenario.cpp | 0 .../classicflyinganimationscenario.h | 0 .../{game => graphics}/classicgraphicsmanager.cpp | 0 .../{game => graphics}/classicgraphicsmanager.h | 2 +- .../classicmode/{game => graphics}/classicsprite.cpp | 0 modes/classicmode/{game => graphics}/classicsprite.h | 0 .../{game => graphics}/classicspritefactory.h | 2 +- .../{game => include/classicmode}/classicactions.h | 0 modes/classicmode/shared/classicmode/classicfactory.h | 5 ++++- src/application/editorstate.cpp | 3 +++ 22 files changed, 35 insertions(+), 21 deletions(-) rename modes/classicmode/{game => graphics}/classicanimationscenario.h (100%) rename modes/classicmode/{game => graphics}/classicdyinganimationscenario.cpp (100%) rename modes/classicmode/{game => graphics}/classicdyinganimationscenario.h (100%) rename modes/classicmode/{game => graphics}/classicflyinganimationscenario.cpp (100%) rename modes/classicmode/{game => graphics}/classicflyinganimationscenario.h (100%) rename modes/classicmode/{game => graphics}/classicgraphicsmanager.cpp (100%) rename modes/classicmode/{game => graphics}/classicgraphicsmanager.h (93%) rename modes/classicmode/{game => graphics}/classicsprite.cpp (100%) rename modes/classicmode/{game => graphics}/classicsprite.h (100%) rename modes/classicmode/{game => graphics}/classicspritefactory.h (95%) rename modes/classicmode/{game => include/classicmode}/classicactions.h (100%) diff --git a/core/shared/core/bpmsection.h b/core/shared/core/bpmsection.h index 1342841..dd622f8 100644 --- a/core/shared/core/bpmsection.h +++ b/core/shared/core/bpmsection.h @@ -4,8 +4,8 @@ struct BPMSection { - int bpm = 0; - int fraction = 1; + int bpm = 120; // Hi, osu + int fraction = 2; microsec offset_start = 0; }; diff --git a/core/shared/core/editor.h b/core/shared/core/editor.h index e669b64..4b97629 100644 --- a/core/shared/core/editor.h +++ b/core/shared/core/editor.h @@ -23,12 +23,12 @@ public: _bpm_sections = std::move(sections); } - inline void insertBPMSection(const BPMSection& section) + void insertBPMSection(const BPMSection& section) { _bpm_sections.insert(section); } - inline void insertBPMSection(BPMSection&& section) + void insertBPMSection(BPMSection&& section) { _bpm_sections.insert(std::move(section)); } diff --git a/modes/classicmode/CMakeLists.txt b/modes/classicmode/CMakeLists.txt index 0fea7ef..0f9e700 100644 --- a/modes/classicmode/CMakeLists.txt +++ b/modes/classicmode/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) include_directories(${CMAKE_SOURCE_DIR}/include) file(GLOB_RECURSE HEADERS "shared/*.h" ) -file(GLOB_RECURSE SOURCES "editor/*.h" "editor/*.cpp" "game/*.h" "game/*.cpp" "./classicfactory.cpp") +file(GLOB_RECURSE SOURCES "editor/*.h" "editor/*.cpp" "graphics/*.h" "graphics/*.cpp" "game/*.h" "game/*.cpp" "./classicfactory.cpp") add_library(classicmode STATIC ${SOURCES} ${HEADERS}) target_include_directories(classicmode PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/modes/classicmode/classicfactory.cpp b/modes/classicmode/classicfactory.cpp index c97d557..b4d0f8c 100644 --- a/modes/classicmode/classicfactory.cpp +++ b/modes/classicmode/classicfactory.cpp @@ -1,11 +1,18 @@ #include "shared/classicmode/classicfactory.h" #include "game/classicgame.h" -#include "game/classicgraphicsmanager.h" +#include "graphics/classicgraphicsmanager.h" #include "tools/music.h" +#include "editor/classiceditor.h" + #include -std::unique_ptr classic::init(sf::RenderWindow& game_window) +std::unique_ptr classic::initGame(sf::RenderWindow& game_window) { return std::make_unique(std::make_unique(game_window)); } + +std::unique_ptr classic::initEditor(sf::RenderWindow& game_window) +{ + return std::make_unique(std::make_unique(game_window)); +} diff --git a/modes/classicmode/game/classicarrownote.cpp b/modes/classicmode/game/classicarrownote.cpp index 1efc94b..d6b06b4 100644 --- a/modes/classicmode/game/classicarrownote.cpp +++ b/modes/classicmode/game/classicarrownote.cpp @@ -1,10 +1,10 @@ #include "classicarrownote.h" -#include "classicgraphicsmanager.h" +#include "graphics/classicgraphicsmanager.h" #include "holdmanager.h" // Replace with interface by dependency injection -#include "classicflyinganimationscenario.h" -#include "classicdyinganimationscenario.h" +#include "graphics/classicflyinganimationscenario.h" +#include "graphics/classicdyinganimationscenario.h" // ClassicArrowNote::ClassicArrowNote(ArrowNoteInitializer&& init) : diff --git a/modes/classicmode/game/classicgame.h b/modes/classicmode/game/classicgame.h index 114fd70..afeee7a 100644 --- a/modes/classicmode/game/classicgame.h +++ b/modes/classicmode/game/classicgame.h @@ -12,7 +12,8 @@ #include "context.h" #include "classicnote.h" -#include "classicactions.h" + +#include "classicmode/classicactions.h" class ClassicGraphicsManager; class HoldManager; diff --git a/modes/classicmode/game/classicmapcreator.cpp b/modes/classicmode/game/classicmapcreator.cpp index 0ed3653..ea85ec6 100644 --- a/modes/classicmode/game/classicmapcreator.cpp +++ b/modes/classicmode/game/classicmapcreator.cpp @@ -2,8 +2,8 @@ #include "classicarrownote.h" // Replace with interface by dependency injection -#include "classicflyinganimationscenario.h" -#include "classicdyinganimationscenario.h" +#include "graphics/classicflyinganimationscenario.h" +#include "graphics/classicdyinganimationscenario.h" // auto classic::createBeatmap(const std::string& filepath, const Context &context) -> Beatmap diff --git a/modes/classicmode/game/classicnote.cpp b/modes/classicmode/game/classicnote.cpp index 4ce39c0..fb9d903 100644 --- a/modes/classicmode/game/classicnote.cpp +++ b/modes/classicmode/game/classicnote.cpp @@ -1,10 +1,10 @@ #include "classicnote.h" -#include "classicsprite.h" -#include "classicgraphicsmanager.h" +#include "graphics/classicsprite.h" +#include "graphics/classicgraphicsmanager.h" // Replace with interface by dependency injection -#include "classicflyinganimationscenario.h" -#include "classicdyinganimationscenario.h" +#include "graphics/classicflyinganimationscenario.h" +#include "graphics/classicdyinganimationscenario.h" // ClassicNote::ClassicNote(NoteInitializer &&init) : diff --git a/modes/classicmode/game/initializers/arrowelementinitializer.h b/modes/classicmode/game/initializers/arrowelementinitializer.h index c8236dc..8c82ad4 100644 --- a/modes/classicmode/game/initializers/arrowelementinitializer.h +++ b/modes/classicmode/game/initializers/arrowelementinitializer.h @@ -1,7 +1,7 @@ #pragma once #include "elementinitializer.h" -#include "classicactions.h" +#include "classicmode/classicactions.h" struct ArrowElementInitializer { diff --git a/modes/classicmode/game/classicanimationscenario.h b/modes/classicmode/graphics/classicanimationscenario.h similarity index 100% rename from modes/classicmode/game/classicanimationscenario.h rename to modes/classicmode/graphics/classicanimationscenario.h diff --git a/modes/classicmode/game/classicdyinganimationscenario.cpp b/modes/classicmode/graphics/classicdyinganimationscenario.cpp similarity index 100% rename from modes/classicmode/game/classicdyinganimationscenario.cpp rename to modes/classicmode/graphics/classicdyinganimationscenario.cpp diff --git a/modes/classicmode/game/classicdyinganimationscenario.h b/modes/classicmode/graphics/classicdyinganimationscenario.h similarity index 100% rename from modes/classicmode/game/classicdyinganimationscenario.h rename to modes/classicmode/graphics/classicdyinganimationscenario.h diff --git a/modes/classicmode/game/classicflyinganimationscenario.cpp b/modes/classicmode/graphics/classicflyinganimationscenario.cpp similarity index 100% rename from modes/classicmode/game/classicflyinganimationscenario.cpp rename to modes/classicmode/graphics/classicflyinganimationscenario.cpp diff --git a/modes/classicmode/game/classicflyinganimationscenario.h b/modes/classicmode/graphics/classicflyinganimationscenario.h similarity index 100% rename from modes/classicmode/game/classicflyinganimationscenario.h rename to modes/classicmode/graphics/classicflyinganimationscenario.h diff --git a/modes/classicmode/game/classicgraphicsmanager.cpp b/modes/classicmode/graphics/classicgraphicsmanager.cpp similarity index 100% rename from modes/classicmode/game/classicgraphicsmanager.cpp rename to modes/classicmode/graphics/classicgraphicsmanager.cpp diff --git a/modes/classicmode/game/classicgraphicsmanager.h b/modes/classicmode/graphics/classicgraphicsmanager.h similarity index 93% rename from modes/classicmode/game/classicgraphicsmanager.h rename to modes/classicmode/graphics/classicgraphicsmanager.h index 181032d..26b626a 100644 --- a/modes/classicmode/game/classicgraphicsmanager.h +++ b/modes/classicmode/graphics/classicgraphicsmanager.h @@ -1,7 +1,7 @@ #pragma once #include "spritecontainer.h" -#include "classicactions.h" +#include "classicmode/classicactions.h" #include "classicspritefactory.h" #include diff --git a/modes/classicmode/game/classicsprite.cpp b/modes/classicmode/graphics/classicsprite.cpp similarity index 100% rename from modes/classicmode/game/classicsprite.cpp rename to modes/classicmode/graphics/classicsprite.cpp diff --git a/modes/classicmode/game/classicsprite.h b/modes/classicmode/graphics/classicsprite.h similarity index 100% rename from modes/classicmode/game/classicsprite.h rename to modes/classicmode/graphics/classicsprite.h diff --git a/modes/classicmode/game/classicspritefactory.h b/modes/classicmode/graphics/classicspritefactory.h similarity index 95% rename from modes/classicmode/game/classicspritefactory.h rename to modes/classicmode/graphics/classicspritefactory.h index 78819e5..c54a05d 100644 --- a/modes/classicmode/game/classicspritefactory.h +++ b/modes/classicmode/graphics/classicspritefactory.h @@ -1,7 +1,7 @@ #pragma once #include -#include "classicactions.h" +#include "classicmode/classicactions.h" #include "classicsprite.h" class ClassicSpriteFactory diff --git a/modes/classicmode/game/classicactions.h b/modes/classicmode/include/classicmode/classicactions.h similarity index 100% rename from modes/classicmode/game/classicactions.h rename to modes/classicmode/include/classicmode/classicactions.h diff --git a/modes/classicmode/shared/classicmode/classicfactory.h b/modes/classicmode/shared/classicmode/classicfactory.h index 29b4a9f..150250f 100644 --- a/modes/classicmode/shared/classicmode/classicfactory.h +++ b/modes/classicmode/shared/classicmode/classicfactory.h @@ -3,10 +3,13 @@ #include class Game; +class Music; +class Editor; namespace sf { class RenderWindow; } namespace classic { - std::unique_ptr init(sf::RenderWindow &game_window); + std::unique_ptr initGame(sf::RenderWindow& game_window); + std::unique_ptr initEditor(sf::RenderWindow& game_window); } diff --git a/src/application/editorstate.cpp b/src/application/editorstate.cpp index 744a461..984c8c7 100644 --- a/src/application/editorstate.cpp +++ b/src/application/editorstate.cpp @@ -3,6 +3,7 @@ #include "widgets/group.h" #include "widgets/menubar.h" #include "widgets/window.h" +#include "widgets/editorwidget.h" #include "widgets/bpmcalculatorwidget.h" #include "tools/bpmcalculator.h" @@ -98,6 +99,8 @@ void EditorState::enter() menu_bar->setVisibility(true); + auto editor_widget = std::make_unique(_edito) + _group = std::make_shared(); _group->addChild(menu_bar); _group->addChild(bpm_widget);