aboutsummaryrefslogtreecommitdiff
path: root/src/engine/engine.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-20 14:09:48 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:56 +0200
commita9852bd2c5a601f9f9c58b1dff60e9130587657b (patch)
tree87830594a20614aa7f73f8dc15b86900e805dd4a /src/engine/engine.cpp
parent78f5d8cf644383adf20933ad64c160c07c2c54fb (diff)
refactor: move on start & on exit details to the game class
Diffstat (limited to 'src/engine/engine.cpp')
-rw-r--r--src/engine/engine.cpp41
1 files changed, 8 insertions, 33 deletions
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 <fmt/core.h>
-#include <iostream>
#include <utility>
CLIGameEngine::CLIGameEngine(IGameFactory game_factory, ISceneFactory scene_factory,
@@ -13,9 +10,9 @@ CLIGameEngine::CLIGameEngine(IGameFactory game_factory, ISceneFactory scene_fact
std::shared_ptr<IWindow> 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<Vector2::Value>(window_size.get_width()) / 2,
- .y = static_cast<Vector2::Value>(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(