From a9852bd2c5a601f9f9c58b1dff60e9130587657b Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 20 Mar 2022 14:09:48 +0100 Subject: refactor: move on start & on exit details to the game class --- src/engine/engine.cpp | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) (limited to 'src/engine') diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index b2add9c..db3ffb7 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1,10 +1,7 @@ #include "engine.hpp" -#include "strings.hpp" #include "util/function.hpp" -#include -#include #include CLIGameEngine::CLIGameEngine(IGameFactory game_factory, ISceneFactory scene_factory, @@ -13,9 +10,9 @@ CLIGameEngine::CLIGameEngine(IGameFactory game_factory, ISceneFactory scene_fact std::shared_ptr window) noexcept : _game_factory(game_factory), _scene_factory(scene_factory), - _input_handler(std::move(input_handler)), - _cursor_controller(std::move(cursor_controller)), - _window(std::move(window)) + _input_handler(std::move(std::move(input_handler))), + _cursor_controller(std::move(std::move(cursor_controller))), + _window(std::move(std::move(window))) { } @@ -26,44 +23,22 @@ void CLIGameEngine::start() noexcept scene->enter(); _input_handler->enter_raw_mode(); - const auto window_size = _window->size(); + auto game = _game_factory(_window, scene, _cursor_controller); - const auto center_position = - Vector2({.x = static_cast(window_size.get_width()) / 2, - .y = static_cast(window_size.get_height()) / 2}); - - _cursor_controller->move_to(center_position); - - scene->write_status(fmt::format(STATUS_BAR_COORDINATES, - fmt::arg("x", center_position.get_x()), - fmt::arg("y", center_position.get_y()))); + game->on_start(); std::atexit(normalize_lambda( - [this, scene]() + [this, scene, game]() { scene->leave(); _input_handler->leave_raw_mode(); - for (auto row : *scene->get_matrix()) - { - for (auto &col : row) - { - fmt::print("{}", col); - } - - fmt::print("\n"); - } - - std::cout.flush(); + game->on_exit(); })); - auto game = _game_factory(); - - _configure_input(game->get_input_config(_window, scene, _cursor_controller)); + _configure_input(game->get_input_config()); _input_handler->listen(); - - game->run(); } void CLIGameEngine::_configure_input( -- cgit v1.2.3-18-g5258