diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-22 17:05:00 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:59 +0200 |
commit | 7de921836587cdc359c2c4b84ed6446ada16c008 (patch) | |
tree | c4ec20b4769817c41ce7d939956da297bf787597 /src/engine | |
parent | 723ea6535b4c4e5605e5592137a898d6ffa458c1 (diff) |
refactor: remove window class
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/engine.cpp | 10 | ||||
-rw-r--r-- | src/engine/engine.hpp | 8 | ||||
-rw-r--r-- | src/engine/graphics/matrix.hpp | 1 | ||||
-rw-r--r-- | src/engine/graphics/scene.cpp | 20 | ||||
-rw-r--r-- | src/engine/graphics/scene.hpp | 8 | ||||
-rw-r--r-- | src/engine/graphics/statusline.cpp | 12 | ||||
-rw-r--r-- | src/engine/graphics/statusline.hpp | 6 | ||||
-rw-r--r-- | src/engine/graphics/window.cpp | 13 | ||||
-rw-r--r-- | src/engine/graphics/window.hpp | 15 |
9 files changed, 35 insertions, 58 deletions
diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 8b55d88..fda1fc2 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -9,24 +9,22 @@ CLIGameEngine::CLIGameEngine( IGameFactory game_factory, ISceneFactory scene_factory, std::shared_ptr<IInputHandler> input_handler, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept + std::shared_ptr<ICursorController> cursor_controller) noexcept : _game_factory(std::move(game_factory)), _scene_factory(std::move(scene_factory)), _input_handler(std::move(input_handler)), - _cursor_controller(std::move(cursor_controller)), - _window(std::move(window)) + _cursor_controller(std::move(cursor_controller)) { } void CLIGameEngine::start() noexcept { - std::shared_ptr<IScene> scene = _scene_factory(_cursor_controller, _window); + std::shared_ptr<IScene> scene = _scene_factory(_cursor_controller); scene->enter(); _input_handler->enter_raw_mode(); - auto game = _game_factory(_window, scene, _cursor_controller); + auto game = _game_factory(scene, _cursor_controller); game->on_start(); diff --git a/src/engine/engine.hpp b/src/engine/engine.hpp index 5073553..7b322b5 100644 --- a/src/engine/engine.hpp +++ b/src/engine/engine.hpp @@ -6,7 +6,6 @@ #include "interfaces/game.hpp" #include "interfaces/input.hpp" #include "interfaces/scene.hpp" -#include "interfaces/window.hpp" #include <yacppdic/auto_wirable.hpp> @@ -20,16 +19,14 @@ class CLIGameEngine : public ICLIGameEngine, IGameFactory, ISceneFactory, IInputHandler, - ICursorController, - IWindow> + ICursorController> { public: CLIGameEngine( IGameFactory game_factory, ISceneFactory scene_factory, std::shared_ptr<IInputHandler> input_handler, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept; + std::shared_ptr<ICursorController> cursor_controller) noexcept; void start() noexcept override; @@ -39,7 +36,6 @@ private: std::shared_ptr<IInputHandler> _input_handler; std::shared_ptr<ICursorController> _cursor_controller; - std::shared_ptr<IWindow> _window; void _configure_input( const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config) noexcept; diff --git a/src/engine/graphics/matrix.hpp b/src/engine/graphics/matrix.hpp index f71018b..5a7d893 100644 --- a/src/engine/graphics/matrix.hpp +++ b/src/engine/graphics/matrix.hpp @@ -7,6 +7,7 @@ #include "engine/matrix_iterator.hpp" #include <gsl/pointers> + #include <memory> template <typename Element> diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index 73c1292..52613d8 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -5,17 +5,17 @@ #include <fmt/color.h> #include <fmt/core.h> + #include <iostream> +#include <sys/ioctl.h> #include <utility> Scene::Scene( IMatrixFactory<std::string_view> matrix_factory, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept + std::shared_ptr<ICursorController> cursor_controller) noexcept : _is_shown(false), - _matrix(matrix_factory(window->size() - Bounds({.width = 0U, .height = 1U}))), - _cursor_controller(std::move(cursor_controller)), - _window(std::move(window)) + _matrix(matrix_factory(size() - Bounds({.width = 0U, .height = 1U}))), + _cursor_controller(std::move(cursor_controller)) { _matrix->fill(" "); } @@ -46,6 +46,16 @@ void Scene::leave() noexcept _is_shown = false; } +auto Scene::size() const noexcept -> Bounds +{ + winsize window_size = {}; + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + ioctl(0, TIOCGWINSZ, &window_size); + + return Bounds({window_size.ws_col, window_size.ws_row}); +} + auto Scene::get_matrix() const noexcept -> const std::shared_ptr<IMatrix<std::string_view>> & { diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index 5e74725..268f8dc 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -3,9 +3,9 @@ #include "interfaces/cursor.hpp" #include "interfaces/matrix.hpp" #include "interfaces/scene.hpp" -#include "interfaces/window.hpp" #include <fmt/core.h> + #include <memory> #include <string_view> @@ -17,13 +17,14 @@ class Scene : public IScene public: explicit Scene( IMatrixFactory<std::string_view> matrix_factory, - std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept; + std::shared_ptr<ICursorController> cursor_controller) noexcept; void enter() noexcept override; void leave() noexcept override; + [[nodiscard]] auto size() const noexcept -> Bounds override; + [[nodiscard]] auto get_matrix() const noexcept -> const std::shared_ptr<IMatrix<std::string_view>> & override; @@ -32,5 +33,4 @@ private: std::shared_ptr<IMatrix<std::string_view>> _matrix; std::shared_ptr<ICursorController> _cursor_controller; - std::shared_ptr<IWindow> _window; }; diff --git a/src/engine/graphics/statusline.cpp b/src/engine/graphics/statusline.cpp index 3968fae..52edd8f 100644 --- a/src/engine/graphics/statusline.cpp +++ b/src/engine/graphics/statusline.cpp @@ -8,8 +8,8 @@ StatusLine::StatusLine( std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept - : _cursor_controller(std::move(cursor_controller)), _window(std::move(window)) + std::shared_ptr<IScene> scene) noexcept + : _cursor_controller(std::move(cursor_controller)), _scene(std::move(scene)) { } @@ -19,7 +19,7 @@ void StatusLine::initialize_background() noexcept auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - fmt::print("{}{}", background_color, std::string(_window->size().get_width(), ' ')); + fmt::print("{}{}", background_color, std::string(_scene->size().get_width(), ' ')); fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); _move_back(previous_position); @@ -58,13 +58,13 @@ auto StatusLine::_move_to_statusline(int32_t x) noexcept -> Vector2 { const auto previous_position = _cursor_controller->where(); - const auto window_size = _window->size(); + const auto scene_size = _scene->size(); _cursor_controller->hide(); - auto window_height = static_cast<Vector2::Value>(window_size.get_height()); + auto scene_height = static_cast<Vector2::Value>(scene_size.get_height()); - _cursor_controller->move_to(Vector2({.x = x, .y = window_height}), true); + _cursor_controller->move_to(Vector2({.x = x, .y = scene_height}), true); return previous_position; } diff --git a/src/engine/graphics/statusline.hpp b/src/engine/graphics/statusline.hpp index add8e02..6f0a4c2 100644 --- a/src/engine/graphics/statusline.hpp +++ b/src/engine/graphics/statusline.hpp @@ -1,8 +1,8 @@ #pragma once #include "interfaces/cursor.hpp" +#include "interfaces/scene.hpp" #include "interfaces/statusline.hpp" -#include "interfaces/window.hpp" #include "engine/data/vector2.hpp" @@ -19,7 +19,7 @@ class StatusLine : public IStatusLine public: StatusLine( std::shared_ptr<ICursorController> cursor_controller, - std::shared_ptr<IWindow> window) noexcept; + std::shared_ptr<IScene> scene) noexcept; void initialize_background() noexcept override; @@ -35,7 +35,7 @@ private: std::unordered_map<StatusLineSection, uint32_t> _sections_lengths; std::shared_ptr<ICursorController> _cursor_controller; - std::shared_ptr<IWindow> _window; + std::shared_ptr<IScene> _scene; auto _move_to_statusline(int32_t x) noexcept -> Vector2; diff --git a/src/engine/graphics/window.cpp b/src/engine/graphics/window.cpp deleted file mode 100644 index bb33402..0000000 --- a/src/engine/graphics/window.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "window.hpp" - -#include <sys/ioctl.h> - -auto Window::size() const noexcept -> Bounds -{ - winsize window_size = {}; - - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - ioctl(0, TIOCGWINSZ, &window_size); - - return Bounds({window_size.ws_col, window_size.ws_row}); -} diff --git a/src/engine/graphics/window.hpp b/src/engine/graphics/window.hpp deleted file mode 100644 index 9284e5e..0000000 --- a/src/engine/graphics/window.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "interfaces/window.hpp" - -#include "engine/data/bounds.hpp" - -#include <yacppdic/auto_wirable.hpp> - -class Window : public IWindow, public yacppdic::AutoWirable<IWindow, Window> -{ -public: - Window() noexcept = default; - - [[nodiscard]] auto size() const noexcept -> Bounds override; -}; |