From 8805b1fe27344e8086cebabf869b7a02d2376f05 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 7 Jun 2022 19:45:17 +0200 Subject: refactor: decouple statusline from scene & cursor controller Might be slightly slower than previously though... --- src/CMakeLists.txt | 3 +- src/bootstrap.cpp | 24 +++++-- src/engine/components/statusline.cpp | 99 +++++++++++++++++++++++++ src/engine/components/statusline.hpp | 45 ++++++++++++ src/engine/engine.cpp | 15 +++- src/engine/engine.hpp | 4 ++ src/engine/graphics/component_renderer.cpp | 55 ++++++++++++++ src/engine/graphics/component_renderer.hpp | 23 ++++++ src/engine/graphics/scene.cpp | 15 +++- src/engine/graphics/scene.hpp | 14 ++++ src/engine/graphics/statusline.cpp | 112 ----------------------------- src/engine/graphics/statusline.hpp | 48 ------------- src/game/game.cpp | 2 + src/game/status_manager.cpp | 27 +++---- src/game/status_manager.hpp | 4 +- src/interfaces/component.hpp | 25 +++++++ src/interfaces/component_renderer.hpp | 24 +++++++ src/interfaces/matrix.hpp | 4 +- src/interfaces/scene.hpp | 11 +++ src/interfaces/status_manager.hpp | 3 + src/interfaces/statusline.hpp | 23 +++--- 21 files changed, 383 insertions(+), 197 deletions(-) create mode 100644 src/engine/components/statusline.cpp create mode 100644 src/engine/components/statusline.hpp create mode 100644 src/engine/graphics/component_renderer.cpp create mode 100644 src/engine/graphics/component_renderer.hpp delete mode 100644 src/engine/graphics/statusline.cpp delete mode 100644 src/engine/graphics/statusline.hpp create mode 100644 src/interfaces/component.hpp create mode 100644 src/interfaces/component_renderer.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 85ef2b9..4b470a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,8 @@ file(GLOB SOURCES engine/data/bounds.cpp engine/graphics/scene.cpp engine/graphics/string_matrix.cpp - engine/graphics/statusline.cpp + engine/graphics/component_renderer.cpp + engine/components/statusline.cpp engine/user/input.cpp engine/user/cursor.cpp) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 1effa96..44ef211 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -2,6 +2,8 @@ // Interfaces #include "interfaces/cell_helper.hpp" +#include "interfaces/component.hpp" +#include "interfaces/component_renderer.hpp" #include "interfaces/cursor.hpp" #include "interfaces/engine.hpp" #include "interfaces/game.hpp" @@ -13,12 +15,13 @@ #include "interfaces/statusline.hpp" // Implementations +#include "engine/components/statusline.hpp" #include "engine/data/bounds.hpp" #include "engine/data/vector2.hpp" #include "engine/engine.hpp" +#include "engine/graphics/component_renderer.hpp" #include "engine/graphics/matrix.hpp" #include "engine/graphics/scene.hpp" -#include "engine/graphics/statusline.hpp" #include "engine/user/cursor.hpp" #include "engine/user/input.hpp" #include "game/cell_helper.hpp" @@ -29,7 +32,6 @@ #include #include -#include #include #include #include @@ -48,8 +50,8 @@ auto bootstrap() noexcept -> yacppdic::Container const std::shared_ptr &cursor_controller, const std::shared_ptr &user_input_observer) { - std::shared_ptr statusline = - container.get()(cursor_controller, scene); + std::shared_ptr statusline = container.get()( + Bounds({.width = scene->size().get_width(), .height = 1})); std::shared_ptr status_manager = container.get()(statusline); @@ -83,10 +85,12 @@ auto bootstrap() noexcept -> yacppdic::Container }); container.bind().to_factory( - [](const std::shared_ptr &cursor_controller, - const std::shared_ptr &scene) + [&container](const Bounds &size) { - return std::make_unique(cursor_controller, scene); + const auto matrix_factory = + container.get>(); + + return std::make_unique(matrix_factory(size)); }); container.bind().to_factory( @@ -107,5 +111,11 @@ auto bootstrap() noexcept -> yacppdic::Container return std::make_unique>(matrix); }); + container.bind().to_factory( + [](const std::shared_ptr &cursor_controller) + { + return std::make_unique(cursor_controller); + }); + return container; } diff --git a/src/engine/components/statusline.cpp b/src/engine/components/statusline.cpp new file mode 100644 index 0000000..ae0f3fa --- /dev/null +++ b/src/engine/components/statusline.cpp @@ -0,0 +1,99 @@ +#include "statusline.hpp" + +#include "engine/data/vector2.hpp" +#include "util/color.hpp" + +#include + +#include + +StatusLine::StatusLine(std::shared_ptr component_matrix) noexcept + : _component_matrix(std::move(component_matrix)), _need_render(false) +{ + _component_matrix->fill(' '); +} + +auto StatusLine::get() const noexcept -> const std::shared_ptr & +{ + return _component_matrix; +} + +auto StatusLine::get_need_render() const noexcept -> bool +{ + return _need_render; +} + +void StatusLine::set_need_render(bool need_render) noexcept +{ + _need_render = need_render; +} + +auto StatusLine::get_foreground_color() const noexcept -> uint32_t +{ + return static_cast(fmt::color::white); +} + +auto StatusLine::get_background_color() const noexcept -> uint32_t +{ + return STATUSLINE_COLOR; +} + +void StatusLine::set_status( + StatusLineSection section, + const std::string_view &status, + int32_t start) noexcept +{ + _clear_section(section, start); + + auto section_start = _get_section_start_x(section); + + auto pos = Vector2({.x = section_start + start, .y = 0}); + + for (const auto &character : status) + { + _component_matrix->set(pos, character); + + pos += Vector2::right(); + } + + set_need_render(true); +} + +void StatusLine::set_section_length(StatusLineSection section, int32_t length) noexcept +{ + _section_lengths[section] = length; +} + +auto StatusLine::_get_section_start_x(StatusLineSection section) const noexcept -> int32_t +{ + int32_t section_start = 0; + + auto section_index = static_cast(section); + + while (section_index > 0) + { + const auto prev_section = static_cast(section_index - 1); + + section_start += static_cast(_section_lengths.at(prev_section)); + + section_index--; + } + + return section_start; +} + +void StatusLine::_clear_section(StatusLineSection section, int32_t start) noexcept +{ + auto section_start = _get_section_start_x(section); + + auto pos = Vector2({.x = section_start + start, .y = 0}); + + auto section_length = _section_lengths[section]; + + for (auto index = 0; index < section_length - start; index++) + { + _component_matrix->set(pos, ' '); + + pos += Vector2::right(); + } +} diff --git a/src/engine/components/statusline.hpp b/src/engine/components/statusline.hpp new file mode 100644 index 0000000..3fdb8d3 --- /dev/null +++ b/src/engine/components/statusline.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "interfaces/matrix.hpp" +#include "interfaces/statusline.hpp" + +#include "engine/data/vector2.hpp" + +#include +#include +#include + +constexpr uint32_t STATUSLINE_COLOR = 0x1A1A1AU; + +class StatusLine : public IStatusLine +{ +public: + explicit StatusLine(std::shared_ptr component_matrix) noexcept; + + auto get() const noexcept -> const std::shared_ptr & override; + + [[nodiscard]] auto get_need_render() const noexcept -> bool override; + + void set_need_render(bool need_render) noexcept override; + + auto get_foreground_color() const noexcept -> uint32_t override; + + auto get_background_color() const noexcept -> uint32_t override; + + void set_status( + StatusLineSection section, + const std::string_view &status, + int32_t start) noexcept override; + + void set_section_length(StatusLineSection section, int32_t length) noexcept override; + +private: + std::shared_ptr _component_matrix; + std::unordered_map _section_lengths; + bool _need_render; + + [[nodiscard]] auto _get_section_start_x(StatusLineSection section) const noexcept + -> int32_t; + + void _clear_section(StatusLineSection section, int32_t start) noexcept; +}; diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 4775fe4..f947a45 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -9,10 +9,12 @@ CLIGameEngine::CLIGameEngine( IGameFactory game_factory, ISceneFactory scene_factory, + IComponentRendererFactory component_renderer_factory, std::shared_ptr user_input_observer, std::shared_ptr cursor_controller) 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)) { @@ -22,6 +24,8 @@ void CLIGameEngine::start() noexcept { std::shared_ptr scene = _scene_factory(_cursor_controller); + auto component_renderer = _component_renderer_factory(_cursor_controller); + scene->enter(); _cursor_controller->set_bounds(scene->size()); @@ -65,8 +69,17 @@ void CLIGameEngine::start() noexcept game->on_update(); - last_update_time = std::chrono::system_clock::now(); + for (auto [component, position] : scene->get_components()) + { + if (component->get_need_render()) + { + component_renderer->render(component, position); + component->set_need_render(false); + } + } _user_input_observer->clear_currently_pressed(); + + last_update_time = std::chrono::system_clock::now(); } } diff --git a/src/engine/engine.hpp b/src/engine/engine.hpp index 1562bbb..a274ed4 100644 --- a/src/engine/engine.hpp +++ b/src/engine/engine.hpp @@ -1,5 +1,6 @@ #pragma once +#include "interfaces/component_renderer.hpp" #include "interfaces/cursor.hpp" #include "interfaces/engine.hpp" #include "interfaces/game.hpp" @@ -19,6 +20,7 @@ class CLIGameEngine : public ICLIGameEngine, CLIGameEngine, IGameFactory, ISceneFactory, + IComponentRendererFactory, IUserInputObserver, ICursorController> { @@ -26,6 +28,7 @@ public: CLIGameEngine( IGameFactory game_factory, ISceneFactory scene_factory, + IComponentRendererFactory component_renderer_factory, std::shared_ptr user_input_observer, std::shared_ptr cursor_controller) noexcept; @@ -34,6 +37,7 @@ public: private: IGameFactory _game_factory; ISceneFactory _scene_factory; + IComponentRendererFactory _component_renderer_factory; std::shared_ptr _user_input_observer; std::shared_ptr _cursor_controller; diff --git a/src/engine/graphics/component_renderer.cpp b/src/engine/graphics/component_renderer.cpp new file mode 100644 index 0000000..1ab4c08 --- /dev/null +++ b/src/engine/graphics/component_renderer.cpp @@ -0,0 +1,55 @@ +#include "component_renderer.hpp" + +#include "engine/escape.hpp" +#include "util/color.hpp" + +#include + +#include +#include + +ComponentRenderer::ComponentRenderer( + std::shared_ptr cursor_controller) noexcept + : _cursor_controller(std::move(cursor_controller)) +{ +} + +void ComponentRenderer::render( + const std::shared_ptr &component, + const Vector2 &position) noexcept +{ + const auto previous_pos = _cursor_controller->where(); + + _cursor_controller->hide(); + _cursor_controller->move_to(position); + + const auto component_matrix = component->get(); + + const auto foreground_color = component->get_foreground_color(); + const auto background_color = component->get_background_color(); + + fmt::print( + "{}{}", + get_background_esc_seq(background_color), + get_foreground_esc_seq(foreground_color)); + + for (const auto &row : *component_matrix) + { + for (const auto &col : row) + { + std::cout.put(col); + } + + const auto current_pos = _cursor_controller->where(); + + _cursor_controller->move_to( + Vector2({.x = previous_pos.get_x(), .y = current_pos.get_y() - 1})); + } + + fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); + + std::cout.flush(); + + _cursor_controller->move_to(previous_pos); + _cursor_controller->show(); +} diff --git a/src/engine/graphics/component_renderer.hpp b/src/engine/graphics/component_renderer.hpp new file mode 100644 index 0000000..4f53e07 --- /dev/null +++ b/src/engine/graphics/component_renderer.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "interfaces/component.hpp" +#include "interfaces/component_renderer.hpp" +#include "interfaces/cursor.hpp" + +#include "engine/data/vector2.hpp" + +#include + +class ComponentRenderer : public IComponentRenderer +{ +public: + explicit ComponentRenderer( + std::shared_ptr cursor_controller) noexcept; + + void render( + const std::shared_ptr &component, + const Vector2 &position) noexcept override; + +private: + std::shared_ptr _cursor_controller; +}; diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index 9f561f0..e0f4da6 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -8,7 +8,6 @@ #include #include -#include Scene::Scene( IMatrixFactory matrix_factory, @@ -84,3 +83,17 @@ auto Scene::get_matrix() const noexcept -> const std::shared_ptr &component, + const Vector2 &position) noexcept +{ + _components.emplace_back(std::make_pair(component, position)); +} + +auto Scene::get_components() const noexcept + -> std::vector, Vector2>> +{ + return _components; +} + diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index 60b541a..c2b11e8 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -1,14 +1,19 @@ #pragma once +#include "interfaces/component.hpp" #include "interfaces/cursor.hpp" #include "interfaces/matrix.hpp" #include "interfaces/scene.hpp" +#include "engine/data/vector2.hpp" + #include #include #include #include +#include +#include constexpr fmt::string_view ENABLE_ALT_BUFFER = "{esc}[?1049h"; constexpr fmt::string_view DISABLE_ALT_BUFFER = "{esc}[?1049l"; @@ -29,10 +34,19 @@ public: [[nodiscard]] auto get_matrix() const noexcept -> const std::shared_ptr> & override; + void register_component( + const std::shared_ptr &component, + const Vector2 &position) noexcept override; + + [[nodiscard]] auto get_components() const noexcept + -> std::vector, Vector2>> override; + private: std::shared_ptr> _matrix; std::shared_ptr _cursor_controller; bool _is_shown; std::shared_ptr _original_termios = nullptr; + + std::vector, Vector2>> _components; }; diff --git a/src/engine/graphics/statusline.cpp b/src/engine/graphics/statusline.cpp deleted file mode 100644 index bc83993..0000000 --- a/src/engine/graphics/statusline.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "statusline.hpp" - -#include "engine/escape.hpp" -#include "util/color.hpp" - -#include -#include - -StatusLine::StatusLine( - std::shared_ptr cursor_controller, - std::shared_ptr scene) noexcept - : _cursor_controller(std::move(cursor_controller)), _scene(std::move(scene)) -{ -} - -void StatusLine::initialize_background() noexcept -{ - const auto previous_position = _move_to_statusline(0); - - auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - - fmt::print("{}{}", background_color, std::string(_scene->size().get_width(), ' ')); - fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); - - _move_back(previous_position); -} - -void StatusLine::set_status( - const StatusLineSection §ion, - const std::string_view &status, - std::size_t start) noexcept -{ - _clear_section(section, start); - - auto section_start = _get_section_start_x(section); - - const auto previous_position = - _move_to_statusline(section_start + static_cast(start)); - - auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - - auto section_length = _sections_lengths[section]; - - fmt::print("{}{}", background_color, status); - fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); - - _move_back(previous_position); -} - -void StatusLine::set_section_length( - const StatusLineSection §ion, - uint32_t length) noexcept -{ - _sections_lengths[section] = length; -} - -auto StatusLine::_move_to_statusline(int32_t x) noexcept -> Vector2 -{ - const auto previous_position = _cursor_controller->where(); - - _cursor_controller->hide(); - - _cursor_controller->move_to(Vector2({.x = x, .y = 0})); - - return previous_position; -} - -void StatusLine::_move_back(Vector2 previous_position) noexcept -{ - _cursor_controller->move_to(previous_position); - _cursor_controller->show(); -} - -auto StatusLine::_get_section_start_x(const StatusLineSection §ion) const noexcept - -> int32_t -{ - int32_t section_start = 0; - - auto section_index = static_cast(section); - - while (section_index > 0) - { - section_start += static_cast( - _sections_lengths.at(StatusLineSection(section_index - 1))); - - section_index--; - } - - return section_start; -} - -void StatusLine::_clear_section( - const StatusLineSection §ion, - std::size_t start) noexcept -{ - auto section_start = _get_section_start_x(section); - - auto start_int32 = static_cast(start); - - const auto previous_position = _move_to_statusline(section_start + start_int32); - - auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - - auto section_length = _sections_lengths[section]; - - auto start_uint32 = static_cast(start); - - fmt::print("{}{}", background_color, std::string(section_length - start_uint32, ' ')); - fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); - - _move_back(previous_position); -} diff --git a/src/engine/graphics/statusline.hpp b/src/engine/graphics/statusline.hpp deleted file mode 100644 index 6f0a4c2..0000000 --- a/src/engine/graphics/statusline.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "interfaces/cursor.hpp" -#include "interfaces/scene.hpp" -#include "interfaces/statusline.hpp" - -#include "engine/data/vector2.hpp" - -#include - -#include -#include -#include - -constexpr uint32_t STATUSBAR_COLOR = 0x1A1A1AU; - -class StatusLine : public IStatusLine -{ -public: - StatusLine( - std::shared_ptr cursor_controller, - std::shared_ptr scene) noexcept; - - void initialize_background() noexcept override; - - void set_status( - const StatusLineSection §ion, - const std::string_view &status, - std::size_t start) noexcept override; - - void set_section_length(const StatusLineSection §ion, uint32_t length) noexcept - override; - -private: - std::unordered_map _sections_lengths; - - std::shared_ptr _cursor_controller; - std::shared_ptr _scene; - - auto _move_to_statusline(int32_t x) noexcept -> Vector2; - - void _move_back(Vector2 previous_position) noexcept; - - [[nodiscard]] auto - _get_section_start_x(const StatusLineSection §ion) const noexcept -> int32_t; - - void _clear_section(const StatusLineSection §ion, std::size_t start) noexcept; -}; diff --git a/src/game/game.cpp b/src/game/game.cpp index 064b643..8d72324 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -27,6 +27,8 @@ Game::Game( void Game::on_start() noexcept { + _scene->register_component(_status_manager->get_statusline(), Vector2({0, 0})); + _status_manager->initialize(); _status_manager->set_section_title(StatusLineSection::A, ""); diff --git a/src/game/status_manager.cpp b/src/game/status_manager.cpp index 3f2df01..c7d80e9 100644 --- a/src/game/status_manager.cpp +++ b/src/game/status_manager.cpp @@ -12,23 +12,21 @@ StatusManager::StatusManager(std::shared_ptr statusline) noexcept void StatusManager::initialize() noexcept { - _statusline->set_section_length(StatusLineSection::A, 5U); - _statusline->set_section_length(StatusLineSection::B, 15U); - _statusline->set_section_length(StatusLineSection::C, 15U); - _statusline->set_section_length(StatusLineSection::D, 20U); - _statusline->set_section_length(StatusLineSection::E, 25U); - _statusline->set_section_length(StatusLineSection::F, 60U); - _statusline->set_section_length(StatusLineSection::G, 30U); - _statusline->set_section_length(StatusLineSection::H, 30U); - - _statusline->initialize_background(); + _statusline->set_section_length(StatusLineSection::A, 5); + _statusline->set_section_length(StatusLineSection::B, 15); + _statusline->set_section_length(StatusLineSection::C, 15); + _statusline->set_section_length(StatusLineSection::D, 20); + _statusline->set_section_length(StatusLineSection::E, 25); + _statusline->set_section_length(StatusLineSection::F, 60); + _statusline->set_section_length(StatusLineSection::G, 30); + _statusline->set_section_length(StatusLineSection::H, 30); } void StatusManager::set_section_title( const StatusLineSection §ion, const std::string_view &title) noexcept { - if (_title_lengths.count(section) != 0) + if (_title_lengths.contains(section)) { fmt::print(stderr, "Error: can't set statusbar section title more than once"); return; @@ -36,7 +34,7 @@ void StatusManager::set_section_title( _statusline->set_status(section, title); - _title_lengths[section] = title.length(); + _title_lengths[section] = static_cast(title.length()); } void StatusManager::set_section_body( @@ -47,3 +45,8 @@ void StatusManager::set_section_body( _statusline->set_status(section, body, section_title_length + 1); } + +auto StatusManager::get_statusline() const noexcept -> std::shared_ptr +{ + return _statusline; +} diff --git a/src/game/status_manager.hpp b/src/game/status_manager.hpp index 7bb4f2f..245e888 100644 --- a/src/game/status_manager.hpp +++ b/src/game/status_manager.hpp @@ -24,8 +24,10 @@ public: const StatusLineSection §ion, const std::string_view &body) noexcept override; + auto get_statusline() const noexcept -> std::shared_ptr override; + private: std::shared_ptr _statusline; - std::unordered_map _title_lengths; + std::unordered_map _title_lengths; }; diff --git a/src/interfaces/component.hpp b/src/interfaces/component.hpp new file mode 100644 index 0000000..7e1b132 --- /dev/null +++ b/src/interfaces/component.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "interfaces/matrix.hpp" + +#include + +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) +class IComponent +{ +public: + using ComponentMatrix = IMatrix; + + virtual ~IComponent() = default; + + [[nodiscard]] virtual auto get() const noexcept + -> const std::shared_ptr & = 0; + + [[nodiscard]] virtual auto get_need_render() const noexcept -> bool = 0; + + virtual void set_need_render(bool need_render) noexcept = 0; + + [[nodiscard]] virtual auto get_foreground_color() const noexcept -> uint32_t = 0; + + [[nodiscard]] virtual auto get_background_color() const noexcept -> uint32_t = 0; +}; diff --git a/src/interfaces/component_renderer.hpp b/src/interfaces/component_renderer.hpp new file mode 100644 index 0000000..fa8bc18 --- /dev/null +++ b/src/interfaces/component_renderer.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "interfaces/component.hpp" +#include "interfaces/cursor.hpp" + +#include "engine/data/vector2.hpp" + +#include + +#include + +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) +class IComponentRenderer +{ +public: + virtual ~IComponentRenderer() = default; + + virtual void render( + const std::shared_ptr &component, + const Vector2 &position) noexcept = 0; +}; + +using IComponentRendererFactory = yacppdic::Factory( + const std::shared_ptr &)>; diff --git a/src/interfaces/matrix.hpp b/src/interfaces/matrix.hpp index 010138f..3ab102c 100644 --- a/src/interfaces/matrix.hpp +++ b/src/interfaces/matrix.hpp @@ -8,11 +8,13 @@ #include -template +template // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class IMatrix { public: + using Element = ElementType; + virtual ~IMatrix() noexcept = default; virtual void fill(Element element) noexcept = 0; diff --git a/src/interfaces/scene.hpp b/src/interfaces/scene.hpp index 903a299..daabb10 100644 --- a/src/interfaces/scene.hpp +++ b/src/interfaces/scene.hpp @@ -1,14 +1,18 @@ #pragma once +#include "interfaces/component.hpp" #include "interfaces/cursor.hpp" #include "interfaces/matrix.hpp" #include "engine/data/bounds.hpp" +#include "engine/data/vector2.hpp" #include #include #include +#include +#include // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class IScene @@ -26,6 +30,13 @@ public: [[nodiscard]] virtual auto get_matrix() const noexcept -> const std::shared_ptr> & = 0; + + virtual void register_component( + const std::shared_ptr &component, + const Vector2 &position) noexcept = 0; + + [[nodiscard]] virtual auto get_components() const noexcept + -> std::vector, Vector2>> = 0; }; using ISceneFactory = yacppdic::Factory( diff --git a/src/interfaces/status_manager.hpp b/src/interfaces/status_manager.hpp index 18d6928..9c7234e 100644 --- a/src/interfaces/status_manager.hpp +++ b/src/interfaces/status_manager.hpp @@ -22,6 +22,9 @@ public: virtual void set_section_body( const StatusLineSection §ion, const std::string_view &body) noexcept = 0; + + [[nodiscard]] virtual auto get_statusline() const noexcept + -> std::shared_ptr = 0; }; using IStatusManagerFactory = yacppdic::Factory( diff --git a/src/interfaces/statusline.hpp b/src/interfaces/statusline.hpp index a71699e..ae25fd9 100644 --- a/src/interfaces/statusline.hpp +++ b/src/interfaces/statusline.hpp @@ -1,7 +1,8 @@ #pragma once -#include "interfaces/cursor.hpp" -#include "interfaces/scene.hpp" +#include "interfaces/component.hpp" + +#include "engine/data/bounds.hpp" #include @@ -20,22 +21,18 @@ enum StatusLineSection }; // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) -class IStatusLine +class IStatusLine : public IComponent { public: - virtual ~IStatusLine() noexcept = default; - - virtual void initialize_background() noexcept = 0; - + // NOLINTNEXTLINE(google-default-arguments) virtual void set_status( - const StatusLineSection §ion, + StatusLineSection section, const std::string_view &status, - std::size_t start = 1UL) noexcept = 0; + int32_t start = 1) noexcept = 0; virtual void - set_section_length(const StatusLineSection §ion, uint32_t length) noexcept = 0; + set_section_length(StatusLineSection section, int32_t length) noexcept = 0; }; -using IStatusLineFactory = yacppdic::Factory( - const std::shared_ptr &cursor_controller, - const std::shared_ptr &scene)>; +using IStatusLineFactory = + yacppdic::Factory(const Bounds &size)>; -- cgit v1.2.3-18-g5258