Separate graphics from game and editor logic

This commit is contained in:
NaiJi ✨ 2021-11-18 01:14:52 +03:00
parent 7f7045c920
commit b3bec61542
22 changed files with 35 additions and 21 deletions

View File

@ -4,8 +4,8 @@
struct BPMSection struct BPMSection
{ {
int bpm = 0; int bpm = 120; // Hi, osu
int fraction = 1; int fraction = 2;
microsec offset_start = 0; microsec offset_start = 0;
}; };

View File

@ -23,12 +23,12 @@ public:
_bpm_sections = std::move(sections); _bpm_sections = std::move(sections);
} }
inline void insertBPMSection(const BPMSection& section) void insertBPMSection(const BPMSection& section)
{ {
_bpm_sections.insert(section); _bpm_sections.insert(section);
} }
inline void insertBPMSection(BPMSection&& section) void insertBPMSection(BPMSection&& section)
{ {
_bpm_sections.insert(std::move(section)); _bpm_sections.insert(std::move(section));
} }

View File

@ -6,7 +6,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include)
file(GLOB_RECURSE HEADERS "shared/*.h" ) 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}) add_library(classicmode STATIC ${SOURCES} ${HEADERS})
target_include_directories(classicmode PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(classicmode PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)

View File

@ -1,11 +1,18 @@
#include "shared/classicmode/classicfactory.h" #include "shared/classicmode/classicfactory.h"
#include "game/classicgame.h" #include "game/classicgame.h"
#include "game/classicgraphicsmanager.h" #include "graphics/classicgraphicsmanager.h"
#include "tools/music.h" #include "tools/music.h"
#include "editor/classiceditor.h"
#include <SFML/Graphics/RenderWindow.hpp> #include <SFML/Graphics/RenderWindow.hpp>
std::unique_ptr<Game> classic::init(sf::RenderWindow& game_window) std::unique_ptr<Game> classic::initGame(sf::RenderWindow& game_window)
{ {
return std::make_unique<ClassicGame>(std::make_unique<ClassicGraphicsManager>(game_window)); return std::make_unique<ClassicGame>(std::make_unique<ClassicGraphicsManager>(game_window));
} }
std::unique_ptr<Editor> classic::initEditor(sf::RenderWindow& game_window)
{
return std::make_unique<ClassicEditor>(std::make_unique<ClassicGraphicsManager>(game_window));
}

View File

@ -1,10 +1,10 @@
#include "classicarrownote.h" #include "classicarrownote.h"
#include "classicgraphicsmanager.h" #include "graphics/classicgraphicsmanager.h"
#include "holdmanager.h" #include "holdmanager.h"
// Replace with interface by dependency injection // Replace with interface by dependency injection
#include "classicflyinganimationscenario.h" #include "graphics/classicflyinganimationscenario.h"
#include "classicdyinganimationscenario.h" #include "graphics/classicdyinganimationscenario.h"
// //
ClassicArrowNote::ClassicArrowNote(ArrowNoteInitializer&& init) : ClassicArrowNote::ClassicArrowNote(ArrowNoteInitializer&& init) :

View File

@ -12,7 +12,8 @@
#include "context.h" #include "context.h"
#include "classicnote.h" #include "classicnote.h"
#include "classicactions.h"
#include "classicmode/classicactions.h"
class ClassicGraphicsManager; class ClassicGraphicsManager;
class HoldManager; class HoldManager;

View File

@ -2,8 +2,8 @@
#include "classicarrownote.h" #include "classicarrownote.h"
// Replace with interface by dependency injection // Replace with interface by dependency injection
#include "classicflyinganimationscenario.h" #include "graphics/classicflyinganimationscenario.h"
#include "classicdyinganimationscenario.h" #include "graphics/classicdyinganimationscenario.h"
// //
auto classic::createBeatmap(const std::string& filepath, const Context &context) -> Beatmap auto classic::createBeatmap(const std::string& filepath, const Context &context) -> Beatmap

View File

@ -1,10 +1,10 @@
#include "classicnote.h" #include "classicnote.h"
#include "classicsprite.h" #include "graphics/classicsprite.h"
#include "classicgraphicsmanager.h" #include "graphics/classicgraphicsmanager.h"
// Replace with interface by dependency injection // Replace with interface by dependency injection
#include "classicflyinganimationscenario.h" #include "graphics/classicflyinganimationscenario.h"
#include "classicdyinganimationscenario.h" #include "graphics/classicdyinganimationscenario.h"
// //
ClassicNote::ClassicNote(NoteInitializer &&init) : ClassicNote::ClassicNote(NoteInitializer &&init) :

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "elementinitializer.h" #include "elementinitializer.h"
#include "classicactions.h" #include "classicmode/classicactions.h"
struct ArrowElementInitializer struct ArrowElementInitializer
{ {

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "spritecontainer.h" #include "spritecontainer.h"
#include "classicactions.h" #include "classicmode/classicactions.h"
#include "classicspritefactory.h" #include "classicspritefactory.h"
#include <SFML/Graphics/RenderTarget.hpp> #include <SFML/Graphics/RenderTarget.hpp>

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include "classicactions.h" #include "classicmode/classicactions.h"
#include "classicsprite.h" #include "classicsprite.h"
class ClassicSpriteFactory class ClassicSpriteFactory

View File

@ -3,10 +3,13 @@
#include <memory> #include <memory>
class Game; class Game;
class Music;
class Editor;
namespace sf { class RenderWindow; } namespace sf { class RenderWindow; }
namespace classic namespace classic
{ {
std::unique_ptr<Game> init(sf::RenderWindow &game_window); std::unique_ptr<Game> initGame(sf::RenderWindow& game_window);
std::unique_ptr<Editor> initEditor(sf::RenderWindow& game_window);
} }

View File

@ -3,6 +3,7 @@
#include "widgets/group.h" #include "widgets/group.h"
#include "widgets/menubar.h" #include "widgets/menubar.h"
#include "widgets/window.h" #include "widgets/window.h"
#include "widgets/editorwidget.h"
#include "widgets/bpmcalculatorwidget.h" #include "widgets/bpmcalculatorwidget.h"
#include "tools/bpmcalculator.h" #include "tools/bpmcalculator.h"
@ -98,6 +99,8 @@ void EditorState::enter()
menu_bar->setVisibility(true); menu_bar->setVisibility(true);
auto editor_widget = std::make_unique<EditorWidget>(_edito)
_group = std::make_shared<Group>(); _group = std::make_shared<Group>();
_group->addChild(menu_bar); _group->addChild(menu_bar);
_group->addChild(bpm_widget); _group->addChild(bpm_widget);