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/user/input.hpp | |
parent | b1183c712d94d38f75068bd62df006f73bd3550f (diff) |
refactor: improve input handling & remove commands
Diffstat (limited to 'src/engine/user/input.hpp')
-rw-r--r-- | src/engine/user/input.hpp | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp index f17472b..2fb97ac 100644 --- a/src/engine/user/input.hpp +++ b/src/engine/user/input.hpp @@ -5,40 +5,23 @@ #include <yacppdic/auto_wirable.hpp> -#include <array> -#include <climits> #include <memory> -#include <termios.h> -#include <vector> +#include <mutex> -class InputHandler : public IInputHandler, - public yacppdic::AutoWirable<IInputHandler, InputHandler> +class UserInputObserver + : public IUserInputObserver, + public yacppdic::AutoWirable<IUserInputObserver, UserInputObserver> { public: - InputHandler() noexcept = default; + UserInputObserver() noexcept = default; - void listen() const noexcept override; + void listen() noexcept override; - void subscribe( - const Event &event, - const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept override; + bool is_key_pressed(Key key) noexcept override; - void notify_subscribers(const Event &event, const Context &context) - const noexcept override; - - void enter_raw_mode() noexcept override; - - void leave_raw_mode() noexcept override; + void clear_currently_pressed() noexcept override; private: - std::array< - std::vector<std::shared_ptr<ISubscriber<Context>>>, - static_cast<std::size_t>(CHAR_MAX * 2U)> - _subscribers; - - std::shared_ptr<termios> _original_termios = nullptr; - - using SubscribersSizeType = decltype(_subscribers)::size_type; - - static auto _event_as_index(const Event &event) noexcept -> SubscribersSizeType; + Key _currently_pressed; + std::mutex _currently_pressed_mutex; }; |