From f3e1c990f6d9ea68c8d5d1e1abcaa8d2776e8005 Mon Sep 17 00:00:00 2001 From: Pierre Moreau Date: Tue, 31 Aug 2021 19:46:32 +0200 Subject: [PATCH] core: Small improvements to the InputHandler class --- src/core/InputHandler.cpp | 9 ++++----- src/core/InputHandler.h | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core/InputHandler.cpp b/src/core/InputHandler.cpp index 36fffdd3..907a07ed 100644 --- a/src/core/InputHandler.cpp +++ b/src/core/InputHandler.cpp @@ -1,5 +1,4 @@ #include "InputHandler.h" -#include "Log.h" /*----------------------------------------------------------------------------*/ @@ -16,7 +15,7 @@ void InputHandler::Advance() mTick++; } -void InputHandler::DownEvent(std::unordered_map &map, size_t loc) +void InputHandler::DownEvent(InputStateMap& map, size_t loc) { // If the key already exists, insert does not modify the associated value // and just returns an iterator to it. @@ -26,7 +25,7 @@ void InputHandler::DownEvent(std::unordered_map &map, size_t loc state.mDownTick = mTick; } -void InputHandler::UpEvent(std::unordered_map &map, size_t loc) +void InputHandler::UpEvent(InputStateMap& map, size_t loc) { // If the key already exists, insert does not modify the associated value // and just returns an iterator to it. @@ -55,7 +54,7 @@ void InputHandler::FeedKeyboard(int key, int scancode, int action) void InputHandler::FeedMouseMotion(glm::vec2 const& position) { - mMousePosition = position; + mMousePosition = position; } void InputHandler::FeedMouseButtons(int button, int action) @@ -74,7 +73,7 @@ void InputHandler::FeedMouseButtons(int button, int action) mMousePositionSwitched[button] = mMousePosition; } -std::uint32_t InputHandler::GetState(std::unordered_map &map, size_t loc) +std::uint32_t InputHandler::GetState(InputStateMap const& map, size_t loc) { auto const sc = map.find(loc); if (sc == map.end()) diff --git a/src/core/InputHandler.h b/src/core/InputHandler.h index b5c1f424..3d284c75 100644 --- a/src/core/InputHandler.h +++ b/src/core/InputHandler.h @@ -19,9 +19,9 @@ class InputHandler { public: struct IState { - std::uint64_t mDownTick{std::numeric_limits::max()}; - std::uint64_t mUpTick{std::numeric_limits::max()}; - bool mIsDown{false}; + std::uint64_t mDownTick{ std::numeric_limits::max() }; + std::uint64_t mUpTick{ std::numeric_limits::max() }; + bool mIsDown{ false }; }; public: @@ -42,14 +42,15 @@ class InputHandler void SetUICapture(bool mouseCapture, bool keyboardCapture); private: - void DownEvent(std::unordered_map &map, size_t loc); - void UpEvent(std::unordered_map &map, size_t loc); + using InputStateMap = std::unordered_map; - std::uint32_t GetState(std::unordered_map &map, size_t loc); + void DownEvent(InputStateMap& map, size_t loc); + void UpEvent(InputStateMap& map, size_t loc); + std::uint32_t GetState(InputStateMap const& map, size_t loc); - std::unordered_map mScancodeMap; - std::unordered_map mKeycodeMap; - std::unordered_map mMouseMap; + InputStateMap mScancodeMap; + InputStateMap mKeycodeMap; + InputStateMap mMouseMap; glm::vec2 mMousePosition{ -1.0f }; std::array mMousePositionSwitched;