mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-19 19:06:45 -05:00
Added start of scene management
This commit is contained in:
parent
56b2f146d3
commit
e68eafd5f6
@ -56,6 +56,10 @@ set( BGFX_CONFIG_DEBUG OFF )
|
|||||||
set( SDL_STATIC_PIC ON )
|
set( SDL_STATIC_PIC ON )
|
||||||
set( SDL_SHARED OFF )
|
set( SDL_SHARED OFF )
|
||||||
set( BUILD_SHARED_LIBS 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/spdlog spdlog)
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/cli11 cli11)
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/cli11 cli11)
|
||||||
|
@ -1,8 +1,19 @@
|
|||||||
add_executable(OpenDiablo2.Game
|
set (SOURCES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/D2Engine.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
|
target_include_directories(OpenDiablo2.SDL2
|
||||||
PUBLIC
|
PUBLIC
|
||||||
include
|
include
|
||||||
@ -17,8 +28,3 @@ target_link_libraries(OpenDiablo2.Game
|
|||||||
stdc++fs
|
stdc++fs
|
||||||
spdlog::spdlog
|
spdlog::spdlog
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
set(CXX_STANDARD 17)
|
|
||||||
|
|
||||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
||||||
|
@ -1,26 +1,41 @@
|
|||||||
#ifndef OPENDIABLO2_D2ENGINE_H
|
#ifndef OPENDIABLO2_D2ENGINE_H
|
||||||
#define OPENDIABLO2_D2ENGINE_H
|
#define OPENDIABLO2_D2ENGINE_H
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <memory>
|
||||||
#include <OpenDiablo2.System/D2Graphics.h>
|
#include <OpenDiablo2.System/D2Graphics.h>
|
||||||
#include <OpenDiablo2.System/D2Input.h>
|
#include <OpenDiablo2.System/D2Input.h>
|
||||||
|
#include <OpenDiablo2.Game/Scenes/D2Scene.h>
|
||||||
#include "D2EngineConfig.h"
|
#include "D2EngineConfig.h"
|
||||||
|
|
||||||
namespace OpenDiablo2 {
|
namespace OpenDiablo2::Game
|
||||||
namespace Game {
|
{
|
||||||
class D2Engine {
|
|
||||||
|
// The main OpenDiablo2 engine
|
||||||
|
class D2Engine : public std::enable_shared_from_this<D2Engine>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
D2Engine(const D2EngineConfig &config);
|
D2Engine(const D2EngineConfig &config);
|
||||||
|
|
||||||
|
// Runs the engine
|
||||||
void Run();
|
void Run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Represents the engine configuration
|
||||||
const D2EngineConfig config;
|
const D2EngineConfig config;
|
||||||
|
|
||||||
|
// The graphics subsystem
|
||||||
OpenDiablo2::System::D2Graphics::Ptr gfx;
|
OpenDiablo2::System::D2Graphics::Ptr gfx;
|
||||||
|
|
||||||
|
// The input subsystem
|
||||||
OpenDiablo2::System::D2Input::Ptr input;
|
OpenDiablo2::System::D2Input::Ptr input;
|
||||||
|
|
||||||
|
// Indicates the system should keep running (if set to true)
|
||||||
bool isRunning = true;
|
bool isRunning = true;
|
||||||
|
|
||||||
|
std::stack<std::shared_ptr<OpenDiablo2::Game::Scenes::D2Scene>> sceneStack;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif //OPENDIABLO2_D2ENGINE_H
|
#endif //OPENDIABLO2_D2ENGINE_H
|
||||||
|
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace OpenDiablo2 {
|
namespace OpenDiablo2::Game
|
||||||
namespace Game {
|
{
|
||||||
|
|
||||||
struct D2EngineConfig {
|
struct D2EngineConfig
|
||||||
|
{
|
||||||
std::string BasePath; // The base path where the MPQ files are located
|
std::string BasePath; // The base path where the MPQ files are located
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace OpenDiablo2::Game
|
||||||
}
|
|
||||||
|
|
||||||
#endif //OPENDIABLO2_D2ENGINECONFIG_H
|
#endif //OPENDIABLO2_D2ENGINECONFIG_H
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef OPENDIALOB2_SCENES_D2MAINMENU_H
|
||||||
|
#define OPENDIALOB2_SCENES_D2MAINMENU_H
|
||||||
|
|
||||||
|
#include <OpenDiablo2.Game/Scenes/D2Scene.h>
|
||||||
|
#include <OpenDiablo2.Game/D2Engine.h>
|
||||||
|
|
||||||
|
namespace OpenDiablo2::Game::Scenes {
|
||||||
|
|
||||||
|
class MainMenu : public D2Scene {
|
||||||
|
public:
|
||||||
|
MainMenu(std::shared_ptr<D2Engine> engine);
|
||||||
|
void Render();
|
||||||
|
void Update();
|
||||||
|
private:
|
||||||
|
std::shared_ptr<D2Engine> engine;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // OPENDIALOB2_SCENES_D2MAINMENU_H
|
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef OPENDIABLO2_D2SCENE_H
|
||||||
|
#define OPENDIABLO2_D2SCENE_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace OpenDiablo2::Game::Scenes
|
||||||
|
{
|
||||||
|
|
||||||
|
class D2Scene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Render() = 0;
|
||||||
|
virtual void Update() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,5 @@
|
|||||||
#include <OpenDiablo2.Game/D2Engine.h>
|
#include <OpenDiablo2.Game/D2Engine.h>
|
||||||
|
#include <OpenDiablo2.Game/Scenes/D2MainMenu.h>
|
||||||
|
|
||||||
|
|
||||||
OpenDiablo2::Game::D2Engine::D2Engine(const D2EngineConfig &config)
|
OpenDiablo2::Game::D2Engine::D2Engine(const D2EngineConfig &config)
|
||||||
@ -11,14 +12,17 @@ void
|
|||||||
OpenDiablo2::Game::D2Engine::Run() {
|
OpenDiablo2::Game::D2Engine::Run() {
|
||||||
gfx->InitializeWindow();
|
gfx->InitializeWindow();
|
||||||
|
|
||||||
|
sceneStack.emplace(std::make_shared<Scenes::MainMenu>(shared_from_this()));
|
||||||
|
|
||||||
while (isRunning) {
|
while (isRunning) {
|
||||||
input->ProcessEvents();
|
input->ProcessEvents();
|
||||||
|
sceneStack.top()->Update();
|
||||||
if (input->QuitIsRequested()) {
|
if (input->QuitIsRequested()) {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
gfx->Clear();
|
gfx->Clear();
|
||||||
|
sceneStack.top()->Render();
|
||||||
gfx->Present();
|
gfx->Present();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
src/OpenDiablo2.Game/src/Scenes/D2MainMenu.cpp
Normal file
14
src/OpenDiablo2.Game/src/Scenes/D2MainMenu.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <OpenDiablo2.Game/Scenes/D2MainMenu.h>
|
||||||
|
|
||||||
|
OpenDiablo2::Game::Scenes::MainMenu::MainMenu(std::shared_ptr<D2Engine> engine)
|
||||||
|
: engine(engine) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenDiablo2::Game::Scenes::MainMenu::Render() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenDiablo2::Game::Scenes::MainMenu::Update() {
|
||||||
|
|
||||||
|
}
|
@ -37,8 +37,8 @@ main(int argc,
|
|||||||
SFileCloseFile(mpq);
|
SFileCloseFile(mpq);
|
||||||
spdlog::info("Content files were located, starting engine.");
|
spdlog::info("Content files were located, starting engine.");
|
||||||
|
|
||||||
// Start up the engine
|
// Off to the races we go!
|
||||||
auto engine = std::make_unique<OpenDiablo2::Game::D2Engine>(engineConfig);
|
auto engine = std::make_shared<OpenDiablo2::Game::D2Engine>(engineConfig);
|
||||||
engine->Run();
|
engine->Run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
project(OpenDiablo2.SDL2 VERSION 0.1 LANGUAGES CXX)
|
project(OpenDiablo2.SDL2 VERSION 0.1 LANGUAGES CXX)
|
||||||
|
|
||||||
add_library(OpenDiablo2.SDL2 STATIC
|
set (SOURCES
|
||||||
src/D2Graphics.cpp
|
src/D2Graphics.cpp
|
||||||
src/D2Input.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
|
target_include_directories(OpenDiablo2.SDL2
|
||||||
PUBLIC
|
PUBLIC
|
||||||
include
|
include
|
||||||
@ -14,5 +21,5 @@ target_include_directories(OpenDiablo2.SDL2
|
|||||||
|
|
||||||
target_link_libraries(OpenDiablo2.SDL2
|
target_link_libraries(OpenDiablo2.SDL2
|
||||||
spdlog::spdlog
|
spdlog::spdlog
|
||||||
SDL2
|
SDL2-static
|
||||||
)
|
)
|
||||||
|
@ -5,16 +5,16 @@
|
|||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
namespace OpenDiablo2::System
|
||||||
namespace OpenDiablo2 {
|
{
|
||||||
namespace System {
|
|
||||||
|
|
||||||
struct SDLWindowDestroyer
|
struct SDLWindowDestroyer
|
||||||
{
|
{
|
||||||
void operator()(SDL_Window *w) const
|
void operator()(SDL_Window *w) const
|
||||||
{
|
{
|
||||||
spdlog::debug("Destroying SDL window");
|
spdlog::debug("Destroying SDL window");
|
||||||
if (w) SDL_DestroyWindow(w);
|
if (w)
|
||||||
|
SDL_DestroyWindow(w);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -23,23 +23,25 @@ namespace OpenDiablo2 {
|
|||||||
void operator()(SDL_Renderer *r) const
|
void operator()(SDL_Renderer *r) const
|
||||||
{
|
{
|
||||||
spdlog::debug("Destroying SDL renderer");
|
spdlog::debug("Destroying SDL renderer");
|
||||||
if (r) SDL_DestroyRenderer(r);
|
if (r)
|
||||||
|
SDL_DestroyRenderer(r);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class D2Graphics {
|
class D2Graphics
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::unique_ptr<D2Graphics> Ptr;
|
typedef std::unique_ptr<D2Graphics> Ptr;
|
||||||
D2Graphics();
|
D2Graphics();
|
||||||
void InitializeWindow();
|
void InitializeWindow();
|
||||||
void Clear();
|
void Clear();
|
||||||
void Present();
|
void Present();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<SDL_Window, SDLWindowDestroyer> window;
|
std::unique_ptr<SDL_Window, SDLWindowDestroyer> window;
|
||||||
std::unique_ptr<SDL_Renderer, SDLRendererDestroyer> renderer;
|
std::unique_ptr<SDL_Renderer, SDLRendererDestroyer> renderer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif //OPENDIABLO2_D2GRAPHICS_H
|
#endif //OPENDIABLO2_D2GRAPHICS_H
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace OpenDiablo2 {
|
namespace OpenDiablo2::System {
|
||||||
namespace System {
|
|
||||||
|
|
||||||
class D2Input {
|
class D2Input {
|
||||||
public:
|
public:
|
||||||
@ -16,8 +15,6 @@ namespace OpenDiablo2 {
|
|||||||
bool quitIsRequested = false;
|
bool quitIsRequested = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //OPENDIABLO2_D2INPUT_H
|
#endif //OPENDIABLO2_D2INPUT_H
|
||||||
|
@ -34,7 +34,7 @@ namespace OpenDiablo2 {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
spdlog::debug("Destroying SDL renderer");
|
spdlog::debug("Initializing SDL renderer");
|
||||||
renderer = std::unique_ptr<SDL_Renderer, SDLRendererDestroyer>(SDL_CreateRenderer(window.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC));
|
renderer = std::unique_ptr<SDL_Renderer, SDLRendererDestroyer>(SDL_CreateRenderer(window.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC));
|
||||||
if (renderer == nullptr){
|
if (renderer == nullptr){
|
||||||
spdlog::error("Could not create sdl2 window: " + std::string(SDL_GetError()));
|
spdlog::error("Could not create sdl2 window: " + std::string(SDL_GetError()));
|
||||||
|
Loading…
Reference in New Issue
Block a user