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/engine/engine.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/engine/engine.cpp') 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(); } } -- cgit v1.2.3-18-g5258