From 486ca3846b46dc229e5807968578809766ec1991 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 23 Mar 2022 19:41:31 +0100 Subject: feat: implement generations & multithreading --- src/engine/engine.cpp | 12 +++++++++++- src/engine/graphics/scene.cpp | 20 -------------------- src/engine/graphics/scene.hpp | 6 ------ src/engine/user/input.hpp | 4 +++- 4 files changed, 14 insertions(+), 28 deletions(-) (limited to 'src/engine') diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index e463f28..c988c33 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -2,6 +2,7 @@ #include "util/function.hpp" +#include #include CLIGameEngine::CLIGameEngine(IGameFactory game_factory, ISceneFactory scene_factory, @@ -38,7 +39,16 @@ void CLIGameEngine::start() noexcept _configure_input(game->get_input_config()); - _input_handler->listen(); + std::thread listen_input_thread(normalize_lambda( + [this]() + { + _input_handler->listen(); + })); + + while (true) + { + game->on_update(); + } } void CLIGameEngine::_configure_input( diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index 4e382fe..24c174f 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -45,26 +45,6 @@ void Scene::leave() noexcept _is_shown = false; } -void Scene::write_status(const std::string_view &str) noexcept -{ - const auto previous_position = _cursor_controller->where(); - - const auto window_size = _window->size(); - - _cursor_controller->move_to( - Vector2({.x = 2, .y = static_cast(window_size.get_height())}), - true); - - auto background_color = get_background_esc_seq(STATUSBAR_COLOR); - - fmt::print("{}", background_color); - fmt::print(ERASE_ENTIRE_LINE, fmt::arg("esc", ESC)); - fmt::print(fmt::runtime(str.data())); - fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); - - _cursor_controller->move_to(previous_position, true); -} - const std::shared_ptr> &Scene::get_matrix() const noexcept { return _matrix; diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index 1f1c51c..c4f6d67 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -12,10 +12,6 @@ constexpr fmt::string_view ENABLE_ALT_BUFFER = "{esc}[?1049h"; constexpr fmt::string_view DISABLE_ALT_BUFFER = "{esc}[?1049l"; -constexpr fmt::string_view ERASE_ENTIRE_LINE = "{esc}[2K"; - -constexpr uint32_t STATUSBAR_COLOR = 0x1A1A1AU; - class Scene : public IScene { public: @@ -27,8 +23,6 @@ public: void leave() noexcept override; - void write_status(const std::string_view &str) noexcept override; - [[nodiscard]] const std::shared_ptr> & get_matrix() const noexcept override; diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp index 6a9edfd..51f3fcb 100644 --- a/src/engine/user/input.hpp +++ b/src/engine/user/input.hpp @@ -29,7 +29,9 @@ public: void leave_raw_mode() noexcept override; private: - std::array>>, CHAR_MAX> _subscribers; + std::array>>, + static_cast(CHAR_MAX * 2U)> + _subscribers; std::shared_ptr _original_termios = nullptr; -- cgit v1.2.3-18-g5258