diff options
author | HampusM <hampus@hampusmat.com> | 2022-06-07 19:45:17 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:57:01 +0200 |
commit | 8805b1fe27344e8086cebabf869b7a02d2376f05 (patch) | |
tree | a90a2e2dda1bcb98fb4de5cd983138e5441c2222 /src/engine/engine.cpp | |
parent | f778317bae709f397345a2d5e04e23864c6391b3 (diff) |
refactor: decouple statusline from scene & cursor controller
Might be slightly slower than previously though...
Diffstat (limited to 'src/engine/engine.cpp')
-rw-r--r-- | src/engine/engine.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
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<IUserInputObserver> user_input_observer, std::shared_ptr<ICursorController> 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<IScene> 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(); } } |