diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-22 23:13:29 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:59 +0200 |
commit | b74611d2b20fc071b8a699f2ce25e61f60118d6e (patch) | |
tree | 55d4dbf727724f7f527f2acebea83abd34317329 /src/engine/engine.cpp | |
parent | b1183c712d94d38f75068bd62df006f73bd3550f (diff) |
refactor: improve input handling & remove commands
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(); } } |