diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a82f233..ab87c4da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,6 +56,10 @@ set( BGFX_CONFIG_DEBUG OFF ) set( SDL_STATIC_PIC ON ) set( SDL_SHARED OFF ) set( BUILD_SHARED_LIBS OFF ) +set( CMAKE_CXX_STANDARD 17 ) +set( CXX_STANDARD 17 ) + +set_property(GLOBAL PROPERTY USE_FOLDERS ON) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/spdlog spdlog) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/cli11 cli11) diff --git a/src/OpenDiablo2.Game/CMakeLists.txt b/src/OpenDiablo2.Game/CMakeLists.txt index 56927efb..f6717bb7 100644 --- a/src/OpenDiablo2.Game/CMakeLists.txt +++ b/src/OpenDiablo2.Game/CMakeLists.txt @@ -1,24 +1,30 @@ -add_executable(OpenDiablo2.Game - src/main.cpp - src/D2Engine.cpp +set (SOURCES + src/main.cpp + src/D2Engine.cpp + src/Scenes/D2MainMenu.cpp ) +set (HEADERS + include/OpenDiablo2.Game/D2Engine.h + include/OpenDiablo2.Game/D2EngineConfig.h + include/OpenDiablo2.Game/Scenes/D2Scene.h + include/OpenDiablo2.Game/Scenes/D2MainMenu.h +) + + +add_executable(OpenDiablo2.Game ${SOURCES} ${HEADERS}) + target_include_directories(OpenDiablo2.SDL2 - PUBLIC - include - PRIVATE - include - ) - -target_link_libraries(OpenDiablo2.Game - OpenDiablo2.SDL2 - storm - CLI11::CLI11 - stdc++fs - spdlog::spdlog + PUBLIC + include + PRIVATE + include ) -set(CMAKE_CXX_STANDARD 17) -set(CXX_STANDARD 17) - -set_property(GLOBAL PROPERTY USE_FOLDERS ON) +target_link_libraries(OpenDiablo2.Game + OpenDiablo2.SDL2 + storm + CLI11::CLI11 + stdc++fs + spdlog::spdlog +) diff --git a/src/OpenDiablo2.Game/include/OpenDiablo2.Game/D2Engine.h b/src/OpenDiablo2.Game/include/OpenDiablo2.Game/D2Engine.h index aa35726f..25ca6ce8 100644 --- a/src/OpenDiablo2.Game/include/OpenDiablo2.Game/D2Engine.h +++ b/src/OpenDiablo2.Game/include/OpenDiablo2.Game/D2Engine.h @@ -1,26 +1,41 @@ #ifndef OPENDIABLO2_D2ENGINE_H #define OPENDIABLO2_D2ENGINE_H +#include +#include #include #include +#include #include "D2EngineConfig.h" -namespace OpenDiablo2 { - namespace Game { - class D2Engine { - public: - D2Engine(const D2EngineConfig& config); - void Run(); - private: - const D2EngineConfig config; - OpenDiablo2::System::D2Graphics::Ptr gfx; - OpenDiablo2::System::D2Input::Ptr input; - bool isRunning = true; +namespace OpenDiablo2::Game +{ + +// The main OpenDiablo2 engine +class D2Engine : public std::enable_shared_from_this +{ +public: + D2Engine(const D2EngineConfig &config); + + // Runs the engine + void Run(); + +private: + // Represents the engine configuration + const D2EngineConfig config; + + // The graphics subsystem + OpenDiablo2::System::D2Graphics::Ptr gfx; + + // The input subsystem + OpenDiablo2::System::D2Input::Ptr input; + + // Indicates the system should keep running (if set to true) + bool isRunning = true; + + std::stack> sceneStack; +}; - }; - } } - #endif //OPENDIABLO2_D2ENGINE_H - diff --git a/src/OpenDiablo2.Game/include/OpenDiablo2.Game/D2EngineConfig.h b/src/OpenDiablo2.Game/include/OpenDiablo2.Game/D2EngineConfig.h index a5d611e1..ac8753b5 100644 --- a/src/OpenDiablo2.Game/include/OpenDiablo2.Game/D2EngineConfig.h +++ b/src/OpenDiablo2.Game/include/OpenDiablo2.Game/D2EngineConfig.h @@ -3,14 +3,14 @@ #include -namespace OpenDiablo2 { - namespace Game { +namespace OpenDiablo2::Game +{ - struct D2EngineConfig { - std::string BasePath; // The base path where the MPQ files are located - }; +struct D2EngineConfig +{ + std::string BasePath; // The base path where the MPQ files are located +}; - } -} +} // namespace OpenDiablo2::Game #endif //OPENDIABLO2_D2ENGINECONFIG_H diff --git a/src/OpenDiablo2.Game/include/OpenDiablo2.Game/Scenes/D2MainMenu.h b/src/OpenDiablo2.Game/include/OpenDiablo2.Game/Scenes/D2MainMenu.h new file mode 100644 index 00000000..b48b30b5 --- /dev/null +++ b/src/OpenDiablo2.Game/include/OpenDiablo2.Game/Scenes/D2MainMenu.h @@ -0,0 +1,19 @@ +#ifndef OPENDIALOB2_SCENES_D2MAINMENU_H +#define OPENDIALOB2_SCENES_D2MAINMENU_H + +#include +#include + +namespace OpenDiablo2::Game::Scenes { + +class MainMenu : public D2Scene { +public: + MainMenu(std::shared_ptr engine); + void Render(); + void Update(); +private: + std::shared_ptr engine; +}; + +} +#endif // OPENDIALOB2_SCENES_D2MAINMENU_H diff --git a/src/OpenDiablo2.Game/include/OpenDiablo2.Game/Scenes/D2Scene.h b/src/OpenDiablo2.Game/include/OpenDiablo2.Game/Scenes/D2Scene.h new file mode 100644 index 00000000..20f32bd6 --- /dev/null +++ b/src/OpenDiablo2.Game/include/OpenDiablo2.Game/Scenes/D2Scene.h @@ -0,0 +1,18 @@ +#ifndef OPENDIABLO2_D2SCENE_H +#define OPENDIABLO2_D2SCENE_H + +#include + +namespace OpenDiablo2::Game::Scenes +{ + +class D2Scene +{ +public: + virtual void Render() = 0; + virtual void Update() = 0; +}; + +} + +#endif diff --git a/src/OpenDiablo2.Game/src/D2Engine.cpp b/src/OpenDiablo2.Game/src/D2Engine.cpp index 5bdadf81..5e14e841 100644 --- a/src/OpenDiablo2.Game/src/D2Engine.cpp +++ b/src/OpenDiablo2.Game/src/D2Engine.cpp @@ -1,4 +1,5 @@ #include +#include OpenDiablo2::Game::D2Engine::D2Engine(const D2EngineConfig &config) @@ -11,14 +12,17 @@ void OpenDiablo2::Game::D2Engine::Run() { gfx->InitializeWindow(); + sceneStack.emplace(std::make_shared(shared_from_this())); + while (isRunning) { input->ProcessEvents(); + sceneStack.top()->Update(); if (input->QuitIsRequested()) { isRunning = false; break; } gfx->Clear(); - + sceneStack.top()->Render(); gfx->Present(); } } diff --git a/src/OpenDiablo2.Game/src/Scenes/D2MainMenu.cpp b/src/OpenDiablo2.Game/src/Scenes/D2MainMenu.cpp new file mode 100644 index 00000000..94410a51 --- /dev/null +++ b/src/OpenDiablo2.Game/src/Scenes/D2MainMenu.cpp @@ -0,0 +1,14 @@ +#include + +OpenDiablo2::Game::Scenes::MainMenu::MainMenu(std::shared_ptr engine) +: engine(engine) { + +} + +void OpenDiablo2::Game::Scenes::MainMenu::Render() { + +} + +void OpenDiablo2::Game::Scenes::MainMenu::Update() { + +} diff --git a/src/OpenDiablo2.Game/src/main.cpp b/src/OpenDiablo2.Game/src/main.cpp index d99f6313..bddb66f8 100644 --- a/src/OpenDiablo2.Game/src/main.cpp +++ b/src/OpenDiablo2.Game/src/main.cpp @@ -37,8 +37,8 @@ main(int argc, SFileCloseFile(mpq); spdlog::info("Content files were located, starting engine."); - // Start up the engine - auto engine = std::make_unique(engineConfig); + // Off to the races we go! + auto engine = std::make_shared(engineConfig); engine->Run(); return 0; diff --git a/src/OpenDiablo2.SDL2/CMakeLists.txt b/src/OpenDiablo2.SDL2/CMakeLists.txt index c233ded9..9ab60fe2 100644 --- a/src/OpenDiablo2.SDL2/CMakeLists.txt +++ b/src/OpenDiablo2.SDL2/CMakeLists.txt @@ -1,10 +1,17 @@ project(OpenDiablo2.SDL2 VERSION 0.1 LANGUAGES CXX) -add_library(OpenDiablo2.SDL2 STATIC +set (SOURCES src/D2Graphics.cpp src/D2Input.cpp ) +set (HEADERS + include/OpenDiablo2.System/D2Graphics.h + include/OpenDiablo2.System/D2Input.h +) + +add_library(OpenDiablo2.SDL2 SHARED ${SOURCES} ${HEADERS}) + target_include_directories(OpenDiablo2.SDL2 PUBLIC include @@ -14,5 +21,5 @@ target_include_directories(OpenDiablo2.SDL2 target_link_libraries(OpenDiablo2.SDL2 spdlog::spdlog - SDL2 + SDL2-static ) diff --git a/src/OpenDiablo2.SDL2/include/OpenDiablo2.System/D2Graphics.h b/src/OpenDiablo2.SDL2/include/OpenDiablo2.System/D2Graphics.h index 2f939c6f..8dedc05d 100644 --- a/src/OpenDiablo2.SDL2/include/OpenDiablo2.System/D2Graphics.h +++ b/src/OpenDiablo2.SDL2/include/OpenDiablo2.System/D2Graphics.h @@ -5,41 +5,43 @@ #include #include +namespace OpenDiablo2::System +{ -namespace OpenDiablo2 { - namespace System { - - struct SDLWindowDestroyer - { - void operator()(SDL_Window* w) const - { - spdlog::debug("Destroying SDL window"); - if (w) SDL_DestroyWindow(w); - } - }; - - struct SDLRendererDestroyer - { - void operator()(SDL_Renderer* r) const - { - spdlog::debug("Destroying SDL renderer"); - if (r) SDL_DestroyRenderer(r); - } - }; - - class D2Graphics { - public: - typedef std::unique_ptr Ptr; - D2Graphics(); - void InitializeWindow(); - void Clear(); - void Present(); - private: - std::unique_ptr window; - std::unique_ptr renderer; - }; - +struct SDLWindowDestroyer +{ + void operator()(SDL_Window *w) const + { + spdlog::debug("Destroying SDL window"); + if (w) + SDL_DestroyWindow(w); } +}; + +struct SDLRendererDestroyer +{ + void operator()(SDL_Renderer *r) const + { + spdlog::debug("Destroying SDL renderer"); + if (r) + SDL_DestroyRenderer(r); + } +}; + +class D2Graphics +{ +public: + typedef std::unique_ptr Ptr; + D2Graphics(); + void InitializeWindow(); + void Clear(); + void Present(); + +private: + std::unique_ptr window; + std::unique_ptr renderer; +}; + } #endif //OPENDIABLO2_D2GRAPHICS_H diff --git a/src/OpenDiablo2.SDL2/include/OpenDiablo2.System/D2Input.h b/src/OpenDiablo2.SDL2/include/OpenDiablo2.System/D2Input.h index ea4ffa42..2ea3ebd0 100644 --- a/src/OpenDiablo2.SDL2/include/OpenDiablo2.System/D2Input.h +++ b/src/OpenDiablo2.SDL2/include/OpenDiablo2.System/D2Input.h @@ -3,21 +3,18 @@ #include -namespace OpenDiablo2 { - namespace System { +namespace OpenDiablo2::System { - class D2Input { - public: - typedef std::unique_ptr Ptr; - D2Input(); - void ProcessEvents(); - bool QuitIsRequested(); - private: - bool quitIsRequested = false; - }; +class D2Input { +public: + typedef std::unique_ptr Ptr; + D2Input(); + void ProcessEvents(); + bool QuitIsRequested(); +private: + bool quitIsRequested = false; +}; - - } } #endif //OPENDIABLO2_D2INPUT_H diff --git a/src/OpenDiablo2.SDL2/src/D2Graphics.cpp b/src/OpenDiablo2.SDL2/src/D2Graphics.cpp index e3c5cd9b..7781fbd6 100644 --- a/src/OpenDiablo2.SDL2/src/D2Graphics.cpp +++ b/src/OpenDiablo2.SDL2/src/D2Graphics.cpp @@ -34,7 +34,7 @@ namespace OpenDiablo2 { exit(1); } - spdlog::debug("Destroying SDL renderer"); + spdlog::debug("Initializing SDL renderer"); renderer = std::unique_ptr(SDL_CreateRenderer(window.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)); if (renderer == nullptr){ spdlog::error("Could not create sdl2 window: " + std::string(SDL_GetError()));