diff options
author | HampusM <hampus@hampusmat.com> | 2022-06-08 16:21:40 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:57:01 +0200 |
commit | dcc6d3d5cafe47d53d1b321476bf73bb2d65ae9b (patch) | |
tree | 8fabd71b3f71d82a63694031dda1a89c49fb4f15 | |
parent | 3f9004b598fc8006576db9b8d2ae4e080101101b (diff) |
refactor: remove unused cursor controller dependency from scene
-rw-r--r-- | src/bootstrap.cpp | 9 | ||||
-rw-r--r-- | src/engine/engine.cpp | 22 | ||||
-rw-r--r-- | src/engine/engine.hpp | 10 | ||||
-rw-r--r-- | src/engine/graphics/scene.cpp | 8 | ||||
-rw-r--r-- | src/engine/graphics/scene.hpp | 11 | ||||
-rw-r--r-- | src/interfaces/scene.hpp | 4 |
6 files changed, 23 insertions, 41 deletions
diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index e651512..1231937 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -39,6 +39,7 @@ auto bootstrap() noexcept -> yacppdic::Container container.bind<ICursorController>().to<CursorController>(); container.bind<ICLIGameEngine>().to<CLIGameEngine>(); container.bind<IStatusManager>().to<StatusManager>(); + container.bind<IScene>().to<Scene>(); container.bind<IGameFactory>().to_factory( [&container]( @@ -72,14 +73,6 @@ auto bootstrap() noexcept -> yacppdic::Container return std::make_unique<Matrix<char>>(bounds); }); - container.bind<ISceneFactory>().to_factory( - [&container](const std::shared_ptr<ICursorController> &cursor_controller) - { - auto matrix_factory = container.get<IMatrixFactory<Scene::MatrixElement>>(); - - return std::make_unique<Scene>(matrix_factory, cursor_controller); - }); - container.bind<IStatusLineFactory>().to_factory( [&container](const Bounds &size) { diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index f947a45..c569c69 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -8,36 +8,34 @@ CLIGameEngine::CLIGameEngine( IGameFactory game_factory, - ISceneFactory scene_factory, IComponentRendererFactory component_renderer_factory, std::shared_ptr<IUserInputObserver> user_input_observer, - std::shared_ptr<ICursorController> cursor_controller) noexcept + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IScene> scene) noexcept : _game_factory(std::move(game_factory)), - _scene_factory(std::move(scene_factory)), _component_renderer_factory(std::move(component_renderer_factory)), _user_input_observer(std::move(user_input_observer)), - _cursor_controller(std::move(cursor_controller)) + _cursor_controller(std::move(cursor_controller)), + _scene(std::move(scene)) { } void CLIGameEngine::start() noexcept { - std::shared_ptr<IScene> scene = _scene_factory(_cursor_controller); - auto component_renderer = _component_renderer_factory(_cursor_controller); - scene->enter(); + _scene->enter(); - _cursor_controller->set_bounds(scene->size()); + _cursor_controller->set_bounds(_scene->size()); - auto game = _game_factory(scene, _cursor_controller, _user_input_observer); + auto game = _game_factory(_scene, _cursor_controller, _user_input_observer); game->on_start(); std::atexit(normalize_lambda( - [this, scene, &game]() + [this, &game]() { - scene->leave(); + _scene->leave(); game->on_exit(); })); @@ -69,7 +67,7 @@ void CLIGameEngine::start() noexcept game->on_update(); - for (auto [component, position] : scene->get_components()) + for (auto [component, position] : _scene->get_components()) { if (component->get_need_render()) { diff --git a/src/engine/engine.hpp b/src/engine/engine.hpp index a274ed4..28eb8fc 100644 --- a/src/engine/engine.hpp +++ b/src/engine/engine.hpp @@ -19,26 +19,26 @@ class CLIGameEngine : public ICLIGameEngine, ICLIGameEngine, CLIGameEngine, IGameFactory, - ISceneFactory, IComponentRendererFactory, IUserInputObserver, - ICursorController> + ICursorController, + IScene> { public: CLIGameEngine( IGameFactory game_factory, - ISceneFactory scene_factory, IComponentRendererFactory component_renderer_factory, std::shared_ptr<IUserInputObserver> user_input_observer, - std::shared_ptr<ICursorController> cursor_controller) noexcept; + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IScene> scene) noexcept; void start() noexcept override; private: IGameFactory _game_factory; - ISceneFactory _scene_factory; IComponentRendererFactory _component_renderer_factory; std::shared_ptr<IUserInputObserver> _user_input_observer; std::shared_ptr<ICursorController> _cursor_controller; + std::shared_ptr<IScene> _scene; }; diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index e0f4da6..e4bdb6e 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -9,12 +9,8 @@ #include <iostream> #include <sys/ioctl.h> -Scene::Scene( - IMatrixFactory<MatrixElement> matrix_factory, - std::shared_ptr<ICursorController> cursor_controller) noexcept - : _matrix(matrix_factory(size())), - _cursor_controller(std::move(cursor_controller)), - _is_shown(false) +Scene::Scene(const IMatrixFactory<MatrixElement> &matrix_factory) noexcept + : _matrix(matrix_factory(size())), _is_shown(false) { _matrix->fill(' '); } diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index c2b11e8..4df5f56 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -1,13 +1,13 @@ #pragma once #include "interfaces/component.hpp" -#include "interfaces/cursor.hpp" #include "interfaces/matrix.hpp" #include "interfaces/scene.hpp" #include "engine/data/vector2.hpp" #include <fmt/core.h> +#include <yacppdic/auto_wirable.hpp> #include <memory> #include <string_view> @@ -18,12 +18,12 @@ constexpr fmt::string_view ENABLE_ALT_BUFFER = "{esc}[?1049h"; constexpr fmt::string_view DISABLE_ALT_BUFFER = "{esc}[?1049l"; -class Scene : public IScene +class Scene + : public IScene, + public yacppdic::AutoWirable<IScene, Scene, IMatrixFactory<IScene::MatrixElement>> { public: - explicit Scene( - IMatrixFactory<MatrixElement> matrix_factory, - std::shared_ptr<ICursorController> cursor_controller) noexcept; + explicit Scene(const IMatrixFactory<MatrixElement> &matrix_factory) noexcept; void enter() noexcept override; @@ -43,7 +43,6 @@ public: private: std::shared_ptr<IMatrix<MatrixElement>> _matrix; - std::shared_ptr<ICursorController> _cursor_controller; bool _is_shown; std::shared_ptr<termios> _original_termios = nullptr; diff --git a/src/interfaces/scene.hpp b/src/interfaces/scene.hpp index daabb10..b7bb97d 100644 --- a/src/interfaces/scene.hpp +++ b/src/interfaces/scene.hpp @@ -7,8 +7,6 @@ #include "engine/data/bounds.hpp" #include "engine/data/vector2.hpp" -#include <yacppdic/factory.hpp> - #include <memory> #include <string_view> #include <utility> @@ -39,5 +37,3 @@ public: -> std::vector<std::pair<std::shared_ptr<IComponent>, Vector2>> = 0; }; -using ISceneFactory = yacppdic::Factory<std::unique_ptr<IScene>( - const std::shared_ptr<ICursorController> &cursor_controller)>; |