diff options
Diffstat (limited to 'src/engine/engine.cpp')
-rw-r--r-- | src/engine/engine.cpp | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 774220a..c7605b5 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -9,11 +9,11 @@ CLIGameEngine::CLIGameEngine( IGameFactory game_factory, ISceneFactory scene_factory, - std::shared_ptr<IInputHandler> input_handler, + 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)), - _input_handler(std::move(input_handler)), + _user_input_observer(std::move(user_input_observer)), _cursor_controller(std::move(cursor_controller)) { } @@ -23,9 +23,8 @@ void CLIGameEngine::start() noexcept std::shared_ptr<IScene> scene = _scene_factory(_cursor_controller); scene->enter(); - _input_handler->enter_raw_mode(); - auto game = _game_factory(scene, _cursor_controller); + auto game = _game_factory(scene, _cursor_controller, _user_input_observer); game->on_start(); @@ -33,17 +32,14 @@ void CLIGameEngine::start() noexcept [this, scene, &game]() { scene->leave(); - _input_handler->leave_raw_mode(); game->on_exit(); })); - _configure_input(game->get_input_config()); - auto listen_input_thread = std::thread(normalize_lambda( [this]() { - _input_handler->listen(); + _user_input_observer->listen(); })); auto last_update_time = std::chrono::system_clock::now(); @@ -68,17 +64,7 @@ void CLIGameEngine::start() noexcept game->on_update(); last_update_time = std::chrono::system_clock::now(); - } -} - -void CLIGameEngine::_configure_input( - const std::unordered_map<char, std::shared_ptr<ICommand>> &input_config) noexcept -{ - for (const auto &config_pair : input_config) - { - auto key = config_pair.first; - auto command = config_pair.second; - _input_handler->subscribe(key, command); + _user_input_observer->clear_currently_pressed(); } } |