diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-03 20:40:29 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:54 +0200 |
commit | d27f1a89266e141a944f88e9080bdeca95c49da3 (patch) | |
tree | be78081c7b71f335b59057d25bc817bcb1306d36 /src/engine | |
parent | b8e33c5aa3417bdf7989bef55cc449f75f806b76 (diff) |
refactor: add game initializer
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/game_initializer.cpp | 21 | ||||
-rw-r--r-- | src/engine/game_initializer.hpp | 26 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/engine/game_initializer.cpp b/src/engine/game_initializer.cpp new file mode 100644 index 0000000..9430999 --- /dev/null +++ b/src/engine/game_initializer.cpp @@ -0,0 +1,21 @@ +#include "game_initializer.hpp" + +#include <utility> + +GameInitializer::GameInitializer(std::shared_ptr<IScene> scene, + std::shared_ptr<IInputHandler> input_handler, + std::shared_ptr<IGame> game) + : _scene(std::move(scene)), + _input_handler(std::move(input_handler)), + _game(std::move(game)) +{ +} + +void GameInitializer::initialize() +{ + _scene->enter(); + + _input_handler->enter_raw_mode(); + + _game->run(*_scene, *_input_handler); +} diff --git a/src/engine/game_initializer.hpp b/src/engine/game_initializer.hpp new file mode 100644 index 0000000..12b42de --- /dev/null +++ b/src/engine/game_initializer.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "DI/auto_wirable.hpp" +#include "interfaces/game.hpp" +#include "interfaces/game_initializer.hpp" +#include "interfaces/input.hpp" +#include "interfaces/scene.hpp" + +#include <memory> + +class GameInitializer + : public IGameInitializer, + public AutoWirable<IGameInitializer, GameInitializer, IScene, IInputHandler, IGame> +{ +public: + GameInitializer(std::shared_ptr<IScene> scene, + std::shared_ptr<IInputHandler> input_handler, + std::shared_ptr<IGame> game); + + void initialize() override; + +private: + std::shared_ptr<IScene> _scene; + std::shared_ptr<IInputHandler> _input_handler; + std::shared_ptr<IGame> _game; +}; |