diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-23 19:41:31 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:57 +0200 |
commit | 486ca3846b46dc229e5807968578809766ec1991 (patch) | |
tree | 65a4b7a746d6305666af06f8a1975c76244085a7 /src/game/game.cpp | |
parent | b8e86ce397dc07320c02f6a5f592c7c6a4421c86 (diff) |
feat: implement generations & multithreading
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r-- | src/game/game.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
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 <fmt/core.h> #include <iostream> +#include <utility> -Game::Game(const std::shared_ptr<IWindow> &window, const std::shared_ptr<IScene> &scene, - const std::shared_ptr<ICursorController> &cursor_controller) noexcept - : _window(window), _scene(scene), _cursor_controller(cursor_controller) +Game::Game(std::shared_ptr<IWindow> window, std::shared_ptr<IScene> scene, + std::shared_ptr<ICursorController> cursor_controller, + std::shared_ptr<IStatusLine> statusline, + std::shared_ptr<IGenerationTracker> generation_tracker, + std::shared_ptr<IStatusUpdater> 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<CursorListener>(_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<QuitCommand>()}, {'i', std::make_shared<InsertCellCommand>(_cursor_controller, _scene)}, + {'p', std::make_shared<TogglePauseCommand>(_generation_tracker, _statusline)}, {'k', std::make_shared<MoveCursorCommand>(Vector2::up(), _cursor_controller, _window)}, {'j', std::make_shared<MoveCursorCommand>(Vector2::down(), _cursor_controller, |