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/game/game.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/game/game.cpp') diff --git a/src/game/game.cpp b/src/game/game.cpp index f788d15..6632c08 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -3,22 +3,31 @@ #include "commands/insert_cell.hpp" #include "commands/move_cursor.hpp" #include "commands/quit.hpp" -#include "game/cursor_listener.hpp" +#include "commands/toggle_pause.hpp" #include #include +#include -Game::Game(const std::shared_ptr &window, const std::shared_ptr &scene, - const std::shared_ptr &cursor_controller) noexcept - : _window(window), _scene(scene), _cursor_controller(cursor_controller) +Game::Game(std::shared_ptr window, std::shared_ptr scene, + std::shared_ptr cursor_controller, + std::shared_ptr statusline, + std::shared_ptr generation_tracker, + std::shared_ptr status_updater) noexcept + : _window(std::move(window)), + _scene(std::move(scene)), + _cursor_controller(std::move(cursor_controller)), + _statusline(std::move(statusline)), + _generation_tracker(std::move(generation_tracker)), + _status_updater(std::move(status_updater)) { } void Game::on_start() noexcept { - auto cursor_listener = std::make_shared(_scene); + _statusline->initialize_background(); - _cursor_controller->subscribe(CursorEvent::POSITION_CHANGE, cursor_listener); + _cursor_controller->subscribe(CursorEvent::POSITION_CHANGE, _status_updater); const auto window_size = _window->size(); @@ -28,9 +37,11 @@ void Game::on_start() noexcept _cursor_controller->move_to(center_position); - cursor_listener->update(center_position); + _status_updater->update(center_position); } +void Game::on_update() noexcept {} + void Game::on_exit() const noexcept { for (auto row : *_scene->get_matrix()) @@ -51,6 +62,7 @@ Game::get_input_config() const noexcept { return {{'q', std::make_shared()}, {'i', std::make_shared(_cursor_controller, _scene)}, + {'p', std::make_shared(_generation_tracker, _statusline)}, {'k', std::make_shared(Vector2::up(), _cursor_controller, _window)}, {'j', std::make_shared(Vector2::down(), _cursor_controller, -- cgit v1.2.3-18-g5258