From cbf136d127b4548d0d7eb55f18c70b5f3de96862 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Fri, 29 Sep 2023 18:14:13 -0400 Subject: [PATCH 01/18] Rework input to use events and callbacks from GLFW --- include/NovelRT/Input/Glfw/GlfwInputDevice.h | 9 +- include/NovelRT/Input/Glfw/Input.Glfw.h | 1 + include/NovelRT/Input/IInputDevice.h | 5 +- include/NovelRT/Input/Input.h | 6 +- include/NovelRT/Input/InputAction.h | 12 + include/NovelRT/Input/KeyState.h | 8 +- .../NovelRT/Input/KeyStateFrameChangeLog.h | 53 +++ include/NovelRT/Input/NovelKey.h | 16 +- .../Windowing/Glfw/GlfwWindowingDevice.h | 17 + src/NovelRT/Ecs/Input/InputSystem.cpp | 2 +- src/NovelRT/Input/Glfw/GlfwInputDevice.cpp | 335 ++++++++++++++---- .../Windowing/Glfw/GlfwWindowingDevice.cpp | 13 + 12 files changed, 392 insertions(+), 85 deletions(-) create mode 100644 include/NovelRT/Input/KeyStateFrameChangeLog.h diff --git a/include/NovelRT/Input/Glfw/GlfwInputDevice.h b/include/NovelRT/Input/Glfw/GlfwInputDevice.h index 0d1f6ac28..d7ac52968 100644 --- a/include/NovelRT/Input/Glfw/GlfwInputDevice.h +++ b/include/NovelRT/Input/Glfw/GlfwInputDevice.h @@ -13,15 +13,22 @@ namespace NovelRT::Input::Glfw class GlfwInputDevice final : public Input::IInputDevice { private: + uint32_t _previousBufferIndex; + uint32_t _currentBufferIndex; bool _isInitialised; GLFWwindow* _window; std::vector _previousStates; NovelRT::Maths::GeoVector2F _mousePos; + NovelRT::Maths::GeoVector2F _windowDimensions; + + void ProcessKeyInput(int32_t key, int32_t action); + void ProcessMouseInput(int32_t key, int32_t action, NovelRT::Maths::GeoVector2F pos); + void ProcessKeyState(int32_t action, KeyState state); public: GlfwInputDevice() noexcept; - void Initialise(void* window) final; + void Initialise(NovelRT::Windowing::IWindowingDevice* device, uint32_t inputBufferCount) final; void Update(Timing::Timestamp delta) final; [[nodiscard]] bool IsKeyPressed(const std::string& input) noexcept final; [[nodiscard]] bool IsKeyHeld(const std::string& input) noexcept final; diff --git a/include/NovelRT/Input/Glfw/Input.Glfw.h b/include/NovelRT/Input/Glfw/Input.Glfw.h index 0826e3072..0c2fcabbf 100644 --- a/include/NovelRT/Input/Glfw/Input.Glfw.h +++ b/include/NovelRT/Input/Glfw/Input.Glfw.h @@ -16,6 +16,7 @@ namespace NovelRT::Input::Glfw #define GLFW_INCLUDE_NONE #include "NovelRT/Input/Input.h" #include "NovelRT/PluginManagement/PluginManagement.h" +#include "NovelRT/Windowing/Glfw/Windowing.Glfw.h" #include #include diff --git a/include/NovelRT/Input/IInputDevice.h b/include/NovelRT/Input/IInputDevice.h index fdf66f138..8dd1af90b 100644 --- a/include/NovelRT/Input/IInputDevice.h +++ b/include/NovelRT/Input/IInputDevice.h @@ -13,12 +13,15 @@ namespace NovelRT::Input class IInputDevice : public std::enable_shared_from_this { protected: + static inline const uint32_t DEFAULT_INPUT_BUFFER_COUNT = 2; LoggingService _logger; std::vector _mappedActions; std::map _availableKeys; + std::vector> _keyStates; + uint32_t _inputBufferCount; public: - virtual void Initialise(void* window) = 0; + virtual void Initialise(NovelRT::Windowing::IWindowingDevice* device, uint32_t inputBufferCount = DEFAULT_INPUT_BUFFER_COUNT) = 0; virtual void Update(Timing::Timestamp delta) = 0; [[nodiscard]] virtual bool IsKeyPressed(const std::string& key) = 0; [[nodiscard]] virtual bool IsKeyHeld(const std::string& key) = 0; diff --git a/include/NovelRT/Input/Input.h b/include/NovelRT/Input/Input.h index ff7bcd03d..eda788124 100644 --- a/include/NovelRT/Input/Input.h +++ b/include/NovelRT/Input/Input.h @@ -9,8 +9,10 @@ #include "NovelRT/Maths/Maths.h" #include "NovelRT/Timing/Timestamp.h" #include "NovelRT/Utilities/Misc.h" +#include "NovelRT/Windowing/Windowing.h" #include #include +#include /** * @brief The input plugin API. @@ -18,6 +20,7 @@ namespace NovelRT::Input { enum class KeyState; + class KeyStateFrameChangeLog; class IInputDevice; class NovelKey; struct InputAction; @@ -25,10 +28,11 @@ namespace NovelRT::Input // clang-format off // Input Types -#include "IInputDevice.h" #include "KeyState.h" +#include "KeyStateFrameChangeLog.h" #include "NovelKey.h" #include "InputAction.h" +#include "IInputDevice.h" // clang-format on #endif // NOVELRT_INPUT_H diff --git a/include/NovelRT/Input/InputAction.h b/include/NovelRT/Input/InputAction.h index 511122052..f19f177cf 100644 --- a/include/NovelRT/Input/InputAction.h +++ b/include/NovelRT/Input/InputAction.h @@ -16,6 +16,18 @@ namespace NovelRT::Input NovelKey pairedKey; KeyState state = KeyState::Idle; }; + + inline bool operator==(InputAction const& lhs, InputAction const& rhs) noexcept + { + return lhs.state == rhs.state && (lhs.pairedKey == rhs.pairedKey) && lhs.actionName == rhs.actionName; + } + + inline bool operator!=(const InputAction& lhs, const InputAction& rhs) noexcept + { + return (lhs.state != rhs.state) || (lhs.pairedKey != rhs.pairedKey) || (lhs.actionName != rhs.actionName); + } + + } #endif // NOVELRT_INPUT_INPUTACTION_H diff --git a/include/NovelRT/Input/KeyState.h b/include/NovelRT/Input/KeyState.h index 14b33754e..26a3702df 100644 --- a/include/NovelRT/Input/KeyState.h +++ b/include/NovelRT/Input/KeyState.h @@ -15,10 +15,10 @@ namespace NovelRT::Input */ enum class KeyState : int32_t { - Idle = 0, - KeyUp = 1, - KeyDown = 2, - KeyDownHeld = 3 + Idle = -1, + KeyUp = 0, + KeyDown = 1, + KeyDownHeld = 2 }; } diff --git a/include/NovelRT/Input/KeyStateFrameChangeLog.h b/include/NovelRT/Input/KeyStateFrameChangeLog.h new file mode 100644 index 000000000..0d49f532e --- /dev/null +++ b/include/NovelRT/Input/KeyStateFrameChangeLog.h @@ -0,0 +1,53 @@ +// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root +// for more information. + +#ifndef NOVELRT_INPUT_KEYSTATEFRAMECHANGELOG_H +#define NOVELRT_INPUT_KEYSTATEFRAMECHANGELOG_H + +#ifndef NOVELRT_INPUT_H +#error NovelRT does not support including types explicitly by default. Please include Input.h instead for the Input namespace subset. +#endif + +namespace NovelRT::Input +{ + class KeyStateFrameChangeLog + { + + private: + KeyState _currentState = KeyState::Idle; + uint32_t _changeCount = 0; + + public: + inline void PushNewState(KeyState newState) noexcept + { + if (_currentState == newState) + { + return; + } + + _currentState = newState; + _changeCount++; + } + + inline KeyState GetCurrentState() const noexcept + { + return _currentState; + } + + inline uint32_t GetChangeCount() const noexcept + { + return _changeCount; + } + }; + + inline bool operator==(const KeyStateFrameChangeLog& lhs, const KeyState& rhs) noexcept + { + return lhs.GetCurrentState() == rhs; + } + + inline bool operator==(const KeyState& lhs, const KeyStateFrameChangeLog& rhs) noexcept + { + return rhs == lhs; + } +} +#endif //! NOVELRT_INPUT_KEYSTATEFRAMECHANGELOG_H diff --git a/include/NovelRT/Input/NovelKey.h b/include/NovelRT/Input/NovelKey.h index 14d682498..6044d49cc 100644 --- a/include/NovelRT/Input/NovelKey.h +++ b/include/NovelRT/Input/NovelKey.h @@ -12,12 +12,10 @@ namespace NovelRT::Input { class NovelKey { - private: + public: int32_t _pairedKey; std::string _keyName; int32_t _modifier; - - public: NovelKey(std::string keyName = "", int32_t pairedKeyCode = -1, int32_t modifier = 0) noexcept; void PairKey(int32_t externalKeyCode) noexcept; void UnpairKey() noexcept; @@ -27,9 +25,19 @@ namespace NovelRT::Input [[nodiscard]] inline bool operator==(NovelKey& other) noexcept { - return (_keyName == other.GetKeyName()) || (_pairedKey == other.GetExternalKeyCode()); + return (_keyName == other.GetKeyName()) && (_pairedKey == other.GetExternalKeyCode()); }; }; + + inline bool operator==(NovelKey const& lhs, NovelKey const& rhs) noexcept + { + return lhs._pairedKey == rhs._pairedKey && (lhs._modifier == rhs._modifier) && lhs._keyName == rhs._keyName; + } + + inline bool operator!=(NovelKey const& lhs, NovelKey const& rhs) noexcept + { + return lhs._pairedKey != rhs._pairedKey || (lhs._modifier == rhs._modifier) || lhs._keyName == rhs._keyName; + } } #endif // NOVELRT_INPUT_NOVELKEY_H diff --git a/include/NovelRT/Windowing/Glfw/GlfwWindowingDevice.h b/include/NovelRT/Windowing/Glfw/GlfwWindowingDevice.h index 49fa3951a..c1d9675e1 100644 --- a/include/NovelRT/Windowing/Glfw/GlfwWindowingDevice.h +++ b/include/NovelRT/Windowing/Glfw/GlfwWindowingDevice.h @@ -12,6 +12,23 @@ namespace NovelRT::Windowing::Glfw { class GlfwWindowingDevice final : public IWindowingDevice { + public: + struct MouseClickEventArgs + { + int32_t button = 0; + int32_t action = 0; + Maths::GeoVector2F mousePosition = Maths::GeoVector2F::Zero(); + }; + + struct KeyboardButtonChangeEventArgs + { + int32_t key = 0; + int32_t action = 0; + }; + + Utilities::Event MouseButtonClicked; + Utilities::Event KeyboardButtonChanged; + private: std::unique_ptr _window; std::string _currentTitle; diff --git a/src/NovelRT/Ecs/Input/InputSystem.cpp b/src/NovelRT/Ecs/Input/InputSystem.cpp index 0bb3f83d1..74110636f 100644 --- a/src/NovelRT/Ecs/Input/InputSystem.cpp +++ b/src/NovelRT/Ecs/Input/InputSystem.cpp @@ -10,7 +10,7 @@ namespace NovelRT::Ecs::Input { _inputMap = std::map(); _device = inputProvider->GetInputService(); - _device->Initialise(windowingProvider->GetWindowingDevice()->GetHandle()); + _device->Initialise(windowingProvider->GetWindowingDevice().get()); } void InputSystem::Update(Timing::Timestamp delta, Ecs::Catalogue catalogue) diff --git a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp b/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp index c0e885376..57b104954 100644 --- a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp +++ b/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp @@ -12,7 +12,7 @@ namespace NovelRT::Input::Glfw { } - void GlfwInputDevice::Initialise(void* window) + void GlfwInputDevice::Initialise(NovelRT::Windowing::IWindowingDevice* device, uint32_t inputBufferCount = DEFAULT_INPUT_BUFFER_COUNT) { if (!glfwInit()) { @@ -21,17 +21,37 @@ namespace NovelRT::Input::Glfw throw Exceptions::InitialisationFailureException("GLFW3 failed to initialise.", std::string(output)); } - if (window == nullptr) + if (device == nullptr) { throw Exceptions::NullPointerException( - "Could not initialise GLFW input service - null pointer was provided for window."); + "Could not initialise GLFW input service - null pointer was provided for windowing device."); } _logger.logInfoLine("Initialising GLFW input service."); _availableKeys = std::map(); _mappedActions = std::vector(); - _window = reinterpret_cast(window); + _keyStates = std::vector>(inputBufferCount); + _previousBufferIndex = 0; + _currentBufferIndex = 1; + if(inputBufferCount < DEFAULT_INPUT_BUFFER_COUNT) + { + _inputBufferCount = DEFAULT_INPUT_BUFFER_COUNT; + } + else + { + _inputBufferCount = inputBufferCount; + } + + auto properDevice = reinterpret_cast(device); + _window = properDevice->GetRawGLFWwindowHandle(); + properDevice->KeyboardButtonChanged += [this](auto eventArgs) + { ProcessKeyInput(eventArgs.key, eventArgs.action); }; + properDevice->MouseButtonClicked += [this](auto eventArgs) + { ProcessMouseInput(eventArgs.button, eventArgs.action, eventArgs.mousePosition); }; + + +#pragma region KeyMapping // Map GLFW keys to NovelKeys _availableKeys.emplace("LeftMouseButton", NovelKey("LeftMouseButton", GLFW_MOUSE_BUTTON_LEFT)); _availableKeys.emplace("RightMouseButton", NovelKey("RightMouseButton", GLFW_MOUSE_BUTTON_RIGHT)); @@ -161,99 +181,143 @@ namespace NovelRT::Input::Glfw _availableKeys.emplace("Quote", NovelKey("Quote", GLFW_KEY_APOSTROPHE, GLFW_MOD_SHIFT)); _availableKeys.emplace("Underscore", NovelKey("Underscore", GLFW_KEY_MINUS, GLFW_MOD_SHIFT)); _availableKeys.emplace("Tilde", NovelKey("Tilde", GLFW_KEY_GRAVE_ACCENT, GLFW_MOD_SHIFT)); +#pragma endregion KeyMapping _isInitialised = true; - int width = 0; - int height = 0; + int32_t width = 0; + int32_t height = 0; glfwGetWindowSize(_window, &width, &height); + _windowDimensions = NovelRT::Maths::GeoVector2F(width, height); + _logger.logInfo("GLFW input system initialised: window at {} x {}", width, height); } void GlfwInputDevice::Update(Timing::Timestamp /*delta*/) { - double x = 0; - double y = 0; - int width = 0; - int height = 0; - glfwGetCursorPos(_window, &x, &y); - glfwGetWindowSize(_window, &width, &height); - _mousePos.x = static_cast(x - (width / 2)); - _mousePos.y = static_cast(-y + (height / 2)); - - _previousStates = _mappedActions; - - size_t count = _mappedActions.size(); - auto mapIterator = std::next(_mappedActions.begin(), 0); - auto stateIterator = std::next(_previousStates.begin(), 0); - - for (size_t c = 0; c < count; c++) + // double x = 0; + // double y = 0; + int32_t width = 0; + int32_t height = 0; + // glfwGetCursorPos(_window, &x, &y); + glfwGetWindowSize(_window, &width, &height); + _windowDimensions.x = width; + _windowDimensions.y = height; + // _mousePos.x = static_cast(x - (width / 2)); + // _mousePos.y = static_cast(-y + (height / 2)); + + // _currentBufferIndex++; + // _previousBufferIndex++; + // if(_currentBufferIndex >= _inputBufferCount) + // { + // _currentBufferIndex = 0; + // } + // if(_previousBufferIndex >= _inputBufferCount) + // { + // _previousBufferIndex = 0; + // } + + //auto& currentBuffer = ; + + for (const auto& [action, log] : _keyStates.at(_previousBufferIndex)) { - mapIterator = std::next(_mappedActions.begin(), c); - stateIterator = std::next(_previousStates.begin(), c); - - if (mapIterator->actionName == stateIterator->actionName) + for(const auto& [currentAction, currentLog] : _keyStates.at(_currentBufferIndex)) { - bool press = false; - bool release = false; - - if ((mapIterator->pairedKey.GetKeyName() == "LeftMouseButton") || - (mapIterator->pairedKey.GetKeyName() == "RightMouseButton") || - (mapIterator->pairedKey.GetKeyName() == "MiddleMouseButton")) - { - press = glfwGetMouseButton(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_PRESS; - release = glfwGetMouseButton(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_RELEASE; - } - else - { - press = glfwGetKey(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_PRESS; - release = glfwGetKey(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_RELEASE; - } + if(currentAction != action) + continue; - if (press && - (stateIterator->state == KeyState::KeyDown || stateIterator->state == KeyState::KeyDownHeld)) - { - mapIterator->state = KeyState::KeyDownHeld; - } - else if (press && stateIterator->state == KeyState::Idle) - { - mapIterator->state = KeyState::KeyDown; - } - else if (release && - (stateIterator->state == KeyState::KeyDown || stateIterator->state == KeyState::KeyDownHeld)) - { - mapIterator->state = KeyState::KeyUp; - } - else - { - mapIterator->state = KeyState::Idle; - } + ProcessKeyState(currentAction, currentLog.GetCurrentState()); } + ProcessKeyState(action, log.GetCurrentState()); } + // _previousStates = _mappedActions; + + // size_t count = _mappedActions.size(); + // auto mapIterator = std::next(_mappedActions.begin(), 0); + // auto stateIterator = std::next(_previousStates.begin(), 0); + + // for (size_t c = 0; c < count; c++) + // { + // mapIterator = std::next(_mappedActions.begin(), c); + // stateIterator = std::next(_previousStates.begin(), c); + + // if (mapIterator->actionName == stateIterator->actionName) + // { + // bool press = false; + // bool release = false; + + // if ((mapIterator->pairedKey.GetKeyName() == "LeftMouseButton") || + // (mapIterator->pairedKey.GetKeyName() == "RightMouseButton") || + // (mapIterator->pairedKey.GetKeyName() == "MiddleMouseButton")) + // { + // press = glfwGetMouseButton(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_PRESS; + // release = glfwGetMouseButton(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_RELEASE; + // } + // else + // { + // press = glfwGetKey(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_PRESS; + // release = glfwGetKey(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_RELEASE; + // } + + // if (press && + // (stateIterator->state == KeyState::KeyDown || stateIterator->state == KeyState::KeyDownHeld)) + // { + // mapIterator->state = KeyState::KeyDownHeld; + // } + // else if (press && stateIterator->state == KeyState::Idle) + // { + // mapIterator->state = KeyState::KeyDown; + // } + // else if (release && + // (stateIterator->state == KeyState::KeyDown || stateIterator->state == KeyState::KeyDownHeld)) + // { + // mapIterator->state = KeyState::KeyUp; + // } + // else + // { + // mapIterator->state = KeyState::Idle; + // } + // } + // } } KeyState GlfwInputDevice::GetKeyState(const std::string& key) noexcept { - size_t count = _mappedActions.size(); - for (size_t c = 0; c < count; c++) + for(auto& action : _mappedActions) { - if (_mappedActions[c].actionName == key) + if(action.actionName != key) + continue; + + auto key = action.pairedKey.GetExternalKeyCode(); + + auto& currentBuffer = _keyStates.at(_currentBufferIndex); + for(const auto& [currentKey, currentLog] : currentBuffer) { - return _mappedActions[c].state; + if (currentKey == key) + { + return currentLog.GetCurrentState(); + } } } - _logger.logWarning("Requested action is not mapped: {}", key); return KeyState::Idle; } bool GlfwInputDevice::IsKeyPressed(const std::string& input) noexcept { - for (auto action : _mappedActions) + for(auto& action : _mappedActions) { - if (action.actionName == input) + if(action.actionName != input) + continue; + + auto key = action.pairedKey.GetExternalKeyCode(); + auto& currentBuffer = _keyStates.at(_currentBufferIndex); + for(auto& [currentKey, currentLog] : currentBuffer) { - return action.state == KeyState::KeyDown; + if(currentKey != key) + continue; + + return currentLog.GetCurrentState() == KeyState::KeyDown; } } @@ -263,11 +327,19 @@ namespace NovelRT::Input::Glfw bool GlfwInputDevice::IsKeyHeld(const std::string& input) noexcept { - for (auto action : _mappedActions) + for(auto& action : _mappedActions) { - if (action.actionName == input) + if(action.actionName != input) + continue; + + auto key = action.pairedKey.GetExternalKeyCode(); + auto& currentBuffer = _keyStates.at(_currentBufferIndex); + for(auto& [currentKey, currentLog] : currentBuffer) { - return action.state == KeyState::KeyDownHeld; + if(currentKey != key) + continue; + + return currentLog.GetCurrentState() == KeyState::KeyDownHeld; } } @@ -277,11 +349,19 @@ namespace NovelRT::Input::Glfw bool GlfwInputDevice::IsKeyReleased(const std::string& input) noexcept { - for (auto action : _mappedActions) + for(auto& action : _mappedActions) { - if (action.actionName == input) + if(action.actionName != input) + continue; + + auto key = action.pairedKey.GetExternalKeyCode(); + auto& currentBuffer = _keyStates.at(_currentBufferIndex); + for(auto& [currentKey, currentLog] : currentBuffer) { - return action.state == KeyState::KeyUp; + if(currentKey != key) + continue; + + return currentLog.GetCurrentState() == KeyState::KeyUp; } } @@ -351,6 +431,115 @@ namespace NovelRT::Input::Glfw return _mousePos; } + void GlfwInputDevice::ProcessKeyInput(int32_t key, int32_t state) + { + //auto keyState = static_cast(action); + auto& map = _keyStates.at(_currentBufferIndex); + + for(auto& mapped : _mappedActions) + { + if(mapped.pairedKey.GetExternalKeyCode() != key) + continue; + + KeyStateFrameChangeLog log{}; + for(auto& [currentKey, currentLog] : map) + { + if(currentKey != mapped.pairedKey.GetExternalKeyCode()) + continue; + + log = currentLog; + break; + } + + log.PushNewState(static_cast(state)); + map.insert_or_assign(key, log); + //map.insert_or_assign(action, log); + } + } + + void GlfwInputDevice::ProcessMouseInput(int32_t key, int32_t state, NovelRT::Maths::GeoVector2F pos) + { + //auto keyState = static_cast(action); + auto& map = _keyStates.at(_currentBufferIndex); + for(auto& action : _mappedActions) + { + if(action.pairedKey.GetExternalKeyCode() != key) + continue; + + auto vec4 = NovelRT::Maths::GeoVector4F(pos); + auto val = reinterpret_cast(vec4); + + auto value = val * + glm::scale(glm::vec3(1920.0f / _windowDimensions.x, 1080.0f / _windowDimensions.y, 0.0f)); + + _mousePos.x = value.x; + _mousePos.y = value.y; + KeyStateFrameChangeLog log{}; + for(auto& [currentKey, currentLog] : map) + { + if(currentKey != key) + continue; + + log = currentLog; + break; + } + + log.PushNewState(static_cast(state)); + map.insert_or_assign(key, log); + } + } + + void GlfwInputDevice::ProcessKeyState(int32_t key, KeyState state) + { + auto& previousBuffer = _keyStates.at(_previousBufferIndex); + auto& currentBuffer = _keyStates.at(_currentBufferIndex); + + KeyState previousStateResult = KeyState::Idle; + + for(auto& [previousKey, previousLog] : previousBuffer) + { + if(previousKey == key) + { + previousStateResult = previousLog.GetCurrentState(); + break; + } + } + + KeyStateFrameChangeLog changeLogObject = KeyStateFrameChangeLog(); + + for(auto& [currentKey, currentLog] : currentBuffer) + { + if(currentKey == key) + { + changeLogObject = currentLog; + break; + } + } + + switch (state) + { + case KeyState::KeyDown: + if (previousStateResult == KeyState::KeyDown) + { + changeLogObject.PushNewState(KeyState::KeyDownHeld); + } + else if (previousStateResult != KeyState::KeyDownHeld) + { + changeLogObject.PushNewState(KeyState::KeyDown); + } + break; + case KeyState::KeyDownHeld: + case KeyState::KeyUp: + changeLogObject.PushNewState((previousStateResult == KeyState::KeyUp) ? KeyState::Idle : state); + break; + case KeyState::Idle: + default: + break; + } + + currentBuffer.insert_or_assign(key, changeLogObject); + } + GlfwInputDevice::~GlfwInputDevice() { } diff --git a/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp b/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp index 6f97d29aa..b0b30699b 100644 --- a/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp +++ b/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp @@ -63,6 +63,19 @@ namespace NovelRT::Windowing::Glfw thisDevice->SizeChanged(Maths::GeoVector2F(static_cast(width), static_cast(height))); }); + glfwSetKeyCallback(window, [](auto window, auto key, auto /*scancode*/, auto action, auto /*mods*/) { + auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); + thisPtr->KeyboardButtonChanged(KeyboardButtonChangeEventArgs{key, action}); + }); + + glfwSetMouseButtonCallback(window, [](auto window, auto mouseButton, auto action, auto /*mods*/) { + auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); + double x = 0, y = 0; + glfwGetCursorPos(window, &x, &y); + thisPtr->MouseButtonClicked( + MouseClickEventArgs{mouseButton, action, Maths::GeoVector2F((float)x, (float)y)}); + }); + _window = std::unique_ptr(window, glfwDestroyWindow); if (glfwVulkanSupported() == GLFW_FALSE) From 84807b1a7e202bb9ccc560c9eda638bd26157504 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sat, 30 Sep 2023 15:20:15 -0400 Subject: [PATCH 02/18] [NOT WORKING] Key input fixed to hard 2 buffers. Mouse input is currently bugged. --- include/NovelRT/Input/Glfw/GlfwInputDevice.h | 6 +- include/NovelRT/Input/IInputDevice.h | 7 +- src/NovelRT/Input/Glfw/GlfwInputDevice.cpp | 156 +++++++------------ 3 files changed, 69 insertions(+), 100 deletions(-) diff --git a/include/NovelRT/Input/Glfw/GlfwInputDevice.h b/include/NovelRT/Input/Glfw/GlfwInputDevice.h index d7ac52968..b8c1af2c2 100644 --- a/include/NovelRT/Input/Glfw/GlfwInputDevice.h +++ b/include/NovelRT/Input/Glfw/GlfwInputDevice.h @@ -24,11 +24,12 @@ namespace NovelRT::Input::Glfw void ProcessKeyInput(int32_t key, int32_t action); void ProcessMouseInput(int32_t key, int32_t action, NovelRT::Maths::GeoVector2F pos); void ProcessKeyState(int32_t action, KeyState state); + NovelRT::Maths::GeoVector2F DetermineMouseScreenPosition(NovelRT::Maths::GeoVector2F& pos); public: GlfwInputDevice() noexcept; - void Initialise(NovelRT::Windowing::IWindowingDevice* device, uint32_t inputBufferCount) final; + void Initialise(NovelRT::Windowing::IWindowingDevice* device) final; void Update(Timing::Timestamp delta) final; [[nodiscard]] bool IsKeyPressed(const std::string& input) noexcept final; [[nodiscard]] bool IsKeyHeld(const std::string& input) noexcept final; @@ -39,6 +40,9 @@ namespace NovelRT::Input::Glfw [[nodiscard]] NovelKey& GetAvailableKey(const std::string& keyRequested) final; [[nodiscard]] NovelRT::Maths::GeoVector2F GetMousePosition() noexcept final; [[nodiscard]] NovelRT::Utilities::Misc::Span GetAllMappings() noexcept final; + [[nodiscard]] KeyStateFrameChangeLog GetCurrentChangeLog(const std::string& key) final; + [[nodiscard]] KeyStateFrameChangeLog GetPreviousChangeLog(const std::string& key) final; + [[nodiscard]] std::vector> GetAllChangeLogs() final; ~GlfwInputDevice() final; }; diff --git a/include/NovelRT/Input/IInputDevice.h b/include/NovelRT/Input/IInputDevice.h index 8dd1af90b..e4d9f30e2 100644 --- a/include/NovelRT/Input/IInputDevice.h +++ b/include/NovelRT/Input/IInputDevice.h @@ -13,7 +13,7 @@ namespace NovelRT::Input class IInputDevice : public std::enable_shared_from_this { protected: - static inline const uint32_t DEFAULT_INPUT_BUFFER_COUNT = 2; + static inline const uint32_t DEFAULT_INPUT_BUFFER_COUNT = 6; LoggingService _logger; std::vector _mappedActions; std::map _availableKeys; @@ -21,7 +21,7 @@ namespace NovelRT::Input uint32_t _inputBufferCount; public: - virtual void Initialise(NovelRT::Windowing::IWindowingDevice* device, uint32_t inputBufferCount = DEFAULT_INPUT_BUFFER_COUNT) = 0; + virtual void Initialise(NovelRT::Windowing::IWindowingDevice* device) = 0; virtual void Update(Timing::Timestamp delta) = 0; [[nodiscard]] virtual bool IsKeyPressed(const std::string& key) = 0; [[nodiscard]] virtual bool IsKeyHeld(const std::string& key) = 0; @@ -32,6 +32,9 @@ namespace NovelRT::Input [[nodiscard]] virtual NovelKey& GetAvailableKey(const std::string& keyRequested) = 0; [[nodiscard]] virtual NovelRT::Maths::GeoVector2F GetMousePosition() = 0; [[nodiscard]] virtual NovelRT::Utilities::Misc::Span GetAllMappings() = 0; + [[nodiscard]] virtual KeyStateFrameChangeLog GetCurrentChangeLog(const std::string& key) = 0; + [[nodiscard]] virtual KeyStateFrameChangeLog GetPreviousChangeLog(const std::string& key) = 0; + [[nodiscard]] virtual std::vector> GetAllChangeLogs() = 0; virtual ~IInputDevice() = default; }; diff --git a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp b/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp index 57b104954..84a5a25cf 100644 --- a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp +++ b/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp @@ -12,7 +12,7 @@ namespace NovelRT::Input::Glfw { } - void GlfwInputDevice::Initialise(NovelRT::Windowing::IWindowingDevice* device, uint32_t inputBufferCount = DEFAULT_INPUT_BUFFER_COUNT) + void GlfwInputDevice::Initialise(NovelRT::Windowing::IWindowingDevice* device) { if (!glfwInit()) { @@ -30,17 +30,11 @@ namespace NovelRT::Input::Glfw _logger.logInfoLine("Initialising GLFW input service."); _availableKeys = std::map(); _mappedActions = std::vector(); - _keyStates = std::vector>(inputBufferCount); + _inputBufferCount = DEFAULT_INPUT_BUFFER_COUNT; + _keyStates = std::vector>(_inputBufferCount); _previousBufferIndex = 0; _currentBufferIndex = 1; - if(inputBufferCount < DEFAULT_INPUT_BUFFER_COUNT) - { - _inputBufferCount = DEFAULT_INPUT_BUFFER_COUNT; - } - else - { - _inputBufferCount = inputBufferCount; - } + auto properDevice = reinterpret_cast(device); _window = properDevice->GetRawGLFWwindowHandle(); @@ -195,90 +189,30 @@ namespace NovelRT::Input::Glfw void GlfwInputDevice::Update(Timing::Timestamp /*delta*/) { - // double x = 0; - // double y = 0; + double x = 0; + double y = 0; int32_t width = 0; int32_t height = 0; - // glfwGetCursorPos(_window, &x, &y); - glfwGetWindowSize(_window, &width, &height); + glfwGetWindowSize(_window, &width, &height); + glfwGetCursorPos(_window, &x, &y); _windowDimensions.x = width; _windowDimensions.y = height; - // _mousePos.x = static_cast(x - (width / 2)); - // _mousePos.y = static_cast(-y + (height / 2)); - - // _currentBufferIndex++; - // _previousBufferIndex++; - // if(_currentBufferIndex >= _inputBufferCount) - // { - // _currentBufferIndex = 0; - // } - // if(_previousBufferIndex >= _inputBufferCount) - // { - // _previousBufferIndex = 0; - // } - - //auto& currentBuffer = ; - - for (const auto& [action, log] : _keyStates.at(_previousBufferIndex)) + //_mousePos = DetermineMouseScreenPosition(NovelRT::Maths::GeoVector2F(x, y)); + + auto& currentBuffer = _keyStates.at(_currentBufferIndex); + + for (const auto& [key, log] : _keyStates.at(_previousBufferIndex)) { - for(const auto& [currentAction, currentLog] : _keyStates.at(_currentBufferIndex)) + auto findResultForCurrent = currentBuffer.find(key); + if (findResultForCurrent != currentBuffer.end()) { - if(currentAction != action) - continue; - - ProcessKeyState(currentAction, currentLog.GetCurrentState()); + ProcessKeyState(findResultForCurrent->first, findResultForCurrent->second.GetCurrentState()); + } + else + { + ProcessKeyState(key, log.GetCurrentState()); } - ProcessKeyState(action, log.GetCurrentState()); } - // _previousStates = _mappedActions; - - // size_t count = _mappedActions.size(); - // auto mapIterator = std::next(_mappedActions.begin(), 0); - // auto stateIterator = std::next(_previousStates.begin(), 0); - - // for (size_t c = 0; c < count; c++) - // { - // mapIterator = std::next(_mappedActions.begin(), c); - // stateIterator = std::next(_previousStates.begin(), c); - - // if (mapIterator->actionName == stateIterator->actionName) - // { - // bool press = false; - // bool release = false; - - // if ((mapIterator->pairedKey.GetKeyName() == "LeftMouseButton") || - // (mapIterator->pairedKey.GetKeyName() == "RightMouseButton") || - // (mapIterator->pairedKey.GetKeyName() == "MiddleMouseButton")) - // { - // press = glfwGetMouseButton(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_PRESS; - // release = glfwGetMouseButton(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_RELEASE; - // } - // else - // { - // press = glfwGetKey(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_PRESS; - // release = glfwGetKey(_window, mapIterator->pairedKey.GetExternalKeyCode()) == GLFW_RELEASE; - // } - - // if (press && - // (stateIterator->state == KeyState::KeyDown || stateIterator->state == KeyState::KeyDownHeld)) - // { - // mapIterator->state = KeyState::KeyDownHeld; - // } - // else if (press && stateIterator->state == KeyState::Idle) - // { - // mapIterator->state = KeyState::KeyDown; - // } - // else if (release && - // (stateIterator->state == KeyState::KeyDown || stateIterator->state == KeyState::KeyDownHeld)) - // { - // mapIterator->state = KeyState::KeyUp; - // } - // else - // { - // mapIterator->state = KeyState::Idle; - // } - // } - // } } KeyState GlfwInputDevice::GetKeyState(const std::string& key) noexcept @@ -433,7 +367,6 @@ namespace NovelRT::Input::Glfw void GlfwInputDevice::ProcessKeyInput(int32_t key, int32_t state) { - //auto keyState = static_cast(action); auto& map = _keyStates.at(_currentBufferIndex); for(auto& mapped : _mappedActions) @@ -453,27 +386,18 @@ namespace NovelRT::Input::Glfw log.PushNewState(static_cast(state)); map.insert_or_assign(key, log); - //map.insert_or_assign(action, log); } } void GlfwInputDevice::ProcessMouseInput(int32_t key, int32_t state, NovelRT::Maths::GeoVector2F pos) { - //auto keyState = static_cast(action); auto& map = _keyStates.at(_currentBufferIndex); for(auto& action : _mappedActions) { if(action.pairedKey.GetExternalKeyCode() != key) continue; - auto vec4 = NovelRT::Maths::GeoVector4F(pos); - auto val = reinterpret_cast(vec4); - - auto value = val * - glm::scale(glm::vec3(1920.0f / _windowDimensions.x, 1080.0f / _windowDimensions.y, 0.0f)); - - _mousePos.x = value.x; - _mousePos.y = value.y; + _mousePos = DetermineMouseScreenPosition(pos); KeyStateFrameChangeLog log{}; for(auto& [currentKey, currentLog] : map) { @@ -540,6 +464,44 @@ namespace NovelRT::Input::Glfw currentBuffer.insert_or_assign(key, changeLogObject); } + NovelRT::Maths::GeoVector2F GlfwInputDevice::DetermineMouseScreenPosition(NovelRT::Maths::GeoVector2F& pos) + { + return NovelRT::Maths::GeoVector2F(static_cast(pos.x - (_windowDimensions.x / 2)), + static_cast(-pos.y + (_windowDimensions.y / 2))); + } + + KeyStateFrameChangeLog GlfwInputDevice::GetCurrentChangeLog(const std::string& key) + { + for(auto& action : _mappedActions) + { + if(action.actionName != key) + continue; + + return _keyStates.at(_currentBufferIndex).at(action.pairedKey.GetExternalKeyCode()); + } + + return KeyStateFrameChangeLog(); + } + + KeyStateFrameChangeLog GlfwInputDevice::GetPreviousChangeLog(const std::string& key) + { + for(auto& action : _mappedActions) + { + if(action.actionName != key) + continue; + + return _keyStates.at(_previousBufferIndex).at(action.pairedKey.GetExternalKeyCode()); + } + + return KeyStateFrameChangeLog(); + } + + std::vector> GlfwInputDevice::GetAllChangeLogs() + { + return _keyStates; + } + + GlfwInputDevice::~GlfwInputDevice() { } From d6c38ebf17e517d7a8e736353146aaa838d01bfd Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Mon, 2 Oct 2023 06:47:25 -0400 Subject: [PATCH 03/18] Updated mouse input to respect holding down mouse click --- .../OpenGLLinkageFailureException.h | 3 +- include/NovelRT/Input/Glfw/GlfwInputDevice.h | 2 +- include/NovelRT/Utilities/Misc.h | 1 + .../Windowing/Glfw/GlfwWindowingDevice.h | 14 +++--- samples/InputEcsSample/main.cpp | 3 +- src/NovelRT/Ecs/Input/InputSystem.cpp | 9 ++-- src/NovelRT/Input/Glfw/GlfwInputDevice.cpp | 47 ++++++++++--------- .../Windowing/Glfw/GlfwWindowingDevice.cpp | 11 +++-- 8 files changed, 49 insertions(+), 41 deletions(-) diff --git a/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h b/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h index b5c4fd017..a6d6258f8 100644 --- a/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h +++ b/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h @@ -6,6 +6,7 @@ #include #include +#include namespace NovelRT::Exceptions { @@ -20,4 +21,4 @@ namespace NovelRT::Exceptions }; } -#endif //! NOVELRT_EXCEPTIONS_OPENGLLINKAGEFAILUREEXCEPTION_H \ No newline at end of file +#endif //! NOVELRT_EXCEPTIONS_OPENGLLINKAGEFAILUREEXCEPTION_H diff --git a/include/NovelRT/Input/Glfw/GlfwInputDevice.h b/include/NovelRT/Input/Glfw/GlfwInputDevice.h index b8c1af2c2..a6635de6b 100644 --- a/include/NovelRT/Input/Glfw/GlfwInputDevice.h +++ b/include/NovelRT/Input/Glfw/GlfwInputDevice.h @@ -22,7 +22,7 @@ namespace NovelRT::Input::Glfw NovelRT::Maths::GeoVector2F _windowDimensions; void ProcessKeyInput(int32_t key, int32_t action); - void ProcessMouseInput(int32_t key, int32_t action, NovelRT::Maths::GeoVector2F pos); + void ProcessCursorMovement(NovelRT::Maths::GeoVector2F& pos); void ProcessKeyState(int32_t action, KeyState state); NovelRT::Maths::GeoVector2F DetermineMouseScreenPosition(NovelRT::Maths::GeoVector2F& pos); diff --git a/include/NovelRT/Utilities/Misc.h b/include/NovelRT/Utilities/Misc.h index ce4b25d64..267078dfd 100644 --- a/include/NovelRT/Utilities/Misc.h +++ b/include/NovelRT/Utilities/Misc.h @@ -43,6 +43,7 @@ namespace NovelRT::Utilities static inline const char* CONSOLE_LOG_AUDIO = "Audio"; static inline const char* CONSOLE_LOG_INPUT = "Input"; static inline const char* CONSOLE_LOG_WINDOWING = "WindowManager"; + static inline const char* CONSOLE_LOG_ECS_INPUT = "EcsInputSystem"; template #ifdef NOVELRT_USE_STD_SPAN diff --git a/include/NovelRT/Windowing/Glfw/GlfwWindowingDevice.h b/include/NovelRT/Windowing/Glfw/GlfwWindowingDevice.h index c1d9675e1..f50039a71 100644 --- a/include/NovelRT/Windowing/Glfw/GlfwWindowingDevice.h +++ b/include/NovelRT/Windowing/Glfw/GlfwWindowingDevice.h @@ -13,21 +13,21 @@ namespace NovelRT::Windowing::Glfw class GlfwWindowingDevice final : public IWindowingDevice { public: - struct MouseClickEventArgs + struct CursorPositionEventArgs { - int32_t button = 0; - int32_t action = 0; - Maths::GeoVector2F mousePosition = Maths::GeoVector2F::Zero(); + double x = 0; + double y = 0; }; - struct KeyboardButtonChangeEventArgs + struct ButtonChangeEventArgs { int32_t key = 0; int32_t action = 0; }; - Utilities::Event MouseButtonClicked; - Utilities::Event KeyboardButtonChanged; + Utilities::Event CursorMoved; + Utilities::Event MouseButtonClicked; + Utilities::Event KeyboardButtonChanged; private: std::unique_ptr _window; diff --git a/samples/InputEcsSample/main.cpp b/samples/InputEcsSample/main.cpp index 4db4deca6..1497cbd77 100644 --- a/samples/InputEcsSample/main.cpp +++ b/samples/InputEcsSample/main.cpp @@ -131,8 +131,7 @@ int main() scale += NovelRT::Maths::GeoVector2F{-0.2f, -0.2f}; } - if (events.TryGetComponent(mouseClick, input) && - (input.state == KeyState::KeyDown || input.state == KeyState::KeyDownHeld)) + if (events.TryGetComponent(mouseClick, input) && input.state == KeyState::KeyDown) { logger.logInfo("Clicked at {}, {}", input.mousePositionX, input.mousePositionY); } diff --git a/src/NovelRT/Ecs/Input/InputSystem.cpp b/src/NovelRT/Ecs/Input/InputSystem.cpp index 74110636f..dfc4d0e8c 100644 --- a/src/NovelRT/Ecs/Input/InputSystem.cpp +++ b/src/NovelRT/Ecs/Input/InputSystem.cpp @@ -6,7 +6,8 @@ namespace NovelRT::Ecs::Input { InputSystem::InputSystem(std::shared_ptr windowingProvider, - std::shared_ptr inputProvider) + std::shared_ptr inputProvider) : + _logger(Utilities::Misc::CONSOLE_LOG_ECS_INPUT) { _inputMap = std::map(); _device = inputProvider->GetInputService(); @@ -18,7 +19,7 @@ namespace NovelRT::Ecs::Input _device->Update(delta); auto inputs = catalogue.GetComponentView(); - + auto mouse = _device->GetMousePosition(); for (auto&& input : _inputMap) { InputEventComponent in; @@ -32,7 +33,8 @@ namespace NovelRT::Ecs::Input case NovelRT::Input::KeyState::KeyDown: case NovelRT::Input::KeyState::KeyDownHeld: { - auto event = InputEventComponent{in.actionId, state, in.mousePositionX, in.mousePositionY}; + + auto event = InputEventComponent{in.actionId, state, mouse.x, mouse.y}; inputs.PushComponentUpdateInstruction(in.actionId, event); break; } @@ -48,7 +50,6 @@ namespace NovelRT::Ecs::Input { if (state != NovelRT::Input::KeyState::Idle) { - auto mouse = _device->GetMousePosition(); in = InputEventComponent{input.second, state, mouse.x, mouse.y}; inputs.AddComponent(input.second, in); } diff --git a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp b/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp index 84a5a25cf..727811491 100644 --- a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp +++ b/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp @@ -10,6 +10,7 @@ namespace NovelRT::Input::Glfw _previousStates(std::vector()), _mousePos(NovelRT::Maths::GeoVector2F::Zero()) { + _logger = NovelRT::LoggingService(NovelRT::Utilities::Misc::CONSOLE_LOG_INPUT); } void GlfwInputDevice::Initialise(NovelRT::Windowing::IWindowingDevice* device) @@ -41,7 +42,11 @@ namespace NovelRT::Input::Glfw properDevice->KeyboardButtonChanged += [this](auto eventArgs) { ProcessKeyInput(eventArgs.key, eventArgs.action); }; properDevice->MouseButtonClicked += [this](auto eventArgs) - { ProcessMouseInput(eventArgs.button, eventArgs.action, eventArgs.mousePosition); }; + { ProcessKeyInput(eventArgs.key, eventArgs.action); }; + properDevice->CursorMoved += [this](auto eventArgs) + { + NovelRT::Maths::GeoVector2F nativePos = NovelRT::Maths::GeoVector2F(eventArgs.x, eventArgs.y); + ProcessCursorMovement(nativePos);}; @@ -375,37 +380,30 @@ namespace NovelRT::Input::Glfw continue; KeyStateFrameChangeLog log{}; + bool mouseMod = false; for(auto& [currentKey, currentLog] : map) { if(currentKey != mapped.pairedKey.GetExternalKeyCode()) continue; log = currentLog; + if(currentKey == GLFW_MOUSE_BUTTON_LEFT || + currentKey == GLFW_MOUSE_BUTTON_MIDDLE || + currentKey == GLFW_MOUSE_BUTTON_RIGHT) + { + mouseMod = true; + } break; } - log.PushNewState(static_cast(state)); - map.insert_or_assign(key, log); - } - } - - void GlfwInputDevice::ProcessMouseInput(int32_t key, int32_t state, NovelRT::Maths::GeoVector2F pos) - { - auto& map = _keyStates.at(_currentBufferIndex); - for(auto& action : _mappedActions) - { - if(action.pairedKey.GetExternalKeyCode() != key) - continue; - - _mousePos = DetermineMouseScreenPosition(pos); - KeyStateFrameChangeLog log{}; - for(auto& [currentKey, currentLog] : map) + if(mouseMod) { - if(currentKey != key) - continue; - - log = currentLog; - break; + auto currentState = log.GetCurrentState(); + if(state == (int32_t)KeyState::KeyDown && (currentState == KeyState::KeyDown || + currentState == KeyState::KeyDownHeld)) + { + state = (int32_t)KeyState::KeyDownHeld; + } } log.PushNewState(static_cast(state)); @@ -413,6 +411,11 @@ namespace NovelRT::Input::Glfw } } + void GlfwInputDevice::ProcessCursorMovement(NovelRT::Maths::GeoVector2F& pos) + { + _mousePos = DetermineMouseScreenPosition(pos); + } + void GlfwInputDevice::ProcessKeyState(int32_t key, KeyState state) { auto& previousBuffer = _keyStates.at(_previousBufferIndex); diff --git a/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp b/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp index b0b30699b..5c6f272c1 100644 --- a/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp +++ b/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp @@ -65,15 +65,18 @@ namespace NovelRT::Windowing::Glfw glfwSetKeyCallback(window, [](auto window, auto key, auto /*scancode*/, auto action, auto /*mods*/) { auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); - thisPtr->KeyboardButtonChanged(KeyboardButtonChangeEventArgs{key, action}); + thisPtr->KeyboardButtonChanged(ButtonChangeEventArgs{key, action}); }); glfwSetMouseButtonCallback(window, [](auto window, auto mouseButton, auto action, auto /*mods*/) { auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); - double x = 0, y = 0; - glfwGetCursorPos(window, &x, &y); thisPtr->MouseButtonClicked( - MouseClickEventArgs{mouseButton, action, Maths::GeoVector2F((float)x, (float)y)}); + ButtonChangeEventArgs{mouseButton, action}); + }); + + glfwSetCursorPosCallback(window, [](auto window, double x, double y) { + auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); + thisPtr->CursorMoved(CursorPositionEventArgs{x, y}); }); _window = std::unique_ptr(window, glfwDestroyWindow); From 6062d383b3e60f342d27bd918dd837b14d065250 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Mon, 2 Oct 2023 09:12:53 -0400 Subject: [PATCH 04/18] Clang-format --- .../OpenGLLinkageFailureException.h | 2 +- include/NovelRT/Input/Input.h | 2 +- include/NovelRT/Input/InputAction.h | 1 - src/NovelRT/Ecs/Input/InputSystem.cpp | 4 +- src/NovelRT/Input/Glfw/GlfwInputDevice.cpp | 87 +++++++++---------- .../Windowing/Glfw/GlfwWindowingDevice.cpp | 11 ++- 6 files changed, 50 insertions(+), 57 deletions(-) diff --git a/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h b/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h index a6d6258f8..4a4701400 100644 --- a/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h +++ b/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h @@ -4,9 +4,9 @@ #ifndef NOVELRT_EXCEPTIONS_OPENGLLINKAGEFAILUREEXCEPTION_H #define NOVELRT_EXCEPTIONS_OPENGLLINKAGEFAILUREEXCEPTION_H +#include #include #include -#include namespace NovelRT::Exceptions { diff --git a/include/NovelRT/Input/Input.h b/include/NovelRT/Input/Input.h index eda788124..45bf08eb6 100644 --- a/include/NovelRT/Input/Input.h +++ b/include/NovelRT/Input/Input.h @@ -10,9 +10,9 @@ #include "NovelRT/Timing/Timestamp.h" #include "NovelRT/Utilities/Misc.h" #include "NovelRT/Windowing/Windowing.h" +#include #include #include -#include /** * @brief The input plugin API. diff --git a/include/NovelRT/Input/InputAction.h b/include/NovelRT/Input/InputAction.h index f19f177cf..6d967f484 100644 --- a/include/NovelRT/Input/InputAction.h +++ b/include/NovelRT/Input/InputAction.h @@ -27,7 +27,6 @@ namespace NovelRT::Input return (lhs.state != rhs.state) || (lhs.pairedKey != rhs.pairedKey) || (lhs.actionName != rhs.actionName); } - } #endif // NOVELRT_INPUT_INPUTACTION_H diff --git a/src/NovelRT/Ecs/Input/InputSystem.cpp b/src/NovelRT/Ecs/Input/InputSystem.cpp index dfc4d0e8c..d34cc6b10 100644 --- a/src/NovelRT/Ecs/Input/InputSystem.cpp +++ b/src/NovelRT/Ecs/Input/InputSystem.cpp @@ -6,8 +6,8 @@ namespace NovelRT::Ecs::Input { InputSystem::InputSystem(std::shared_ptr windowingProvider, - std::shared_ptr inputProvider) : - _logger(Utilities::Misc::CONSOLE_LOG_ECS_INPUT) + std::shared_ptr inputProvider) + : _logger(Utilities::Misc::CONSOLE_LOG_ECS_INPUT) { _inputMap = std::map(); _device = inputProvider->GetInputService(); diff --git a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp b/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp index 727811491..f72a76d84 100644 --- a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp +++ b/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp @@ -36,19 +36,16 @@ namespace NovelRT::Input::Glfw _previousBufferIndex = 0; _currentBufferIndex = 1; - auto properDevice = reinterpret_cast(device); _window = properDevice->GetRawGLFWwindowHandle(); - properDevice->KeyboardButtonChanged += [this](auto eventArgs) - { ProcessKeyInput(eventArgs.key, eventArgs.action); }; - properDevice->MouseButtonClicked += [this](auto eventArgs) - { ProcessKeyInput(eventArgs.key, eventArgs.action); }; - properDevice->CursorMoved += [this](auto eventArgs) - { - NovelRT::Maths::GeoVector2F nativePos = NovelRT::Maths::GeoVector2F(eventArgs.x, eventArgs.y); - ProcessCursorMovement(nativePos);}; - - + properDevice->KeyboardButtonChanged += + [this](auto eventArgs) { ProcessKeyInput(eventArgs.key, eventArgs.action); }; + properDevice->MouseButtonClicked += + [this](auto eventArgs) { ProcessKeyInput(eventArgs.key, eventArgs.action); }; + properDevice->CursorMoved += [this](auto eventArgs) { + NovelRT::Maths::GeoVector2F nativePos = NovelRT::Maths::GeoVector2F(eventArgs.x, eventArgs.y); + ProcessCursorMovement(nativePos); + }; #pragma region KeyMapping // Map GLFW keys to NovelKeys @@ -222,15 +219,15 @@ namespace NovelRT::Input::Glfw KeyState GlfwInputDevice::GetKeyState(const std::string& key) noexcept { - for(auto& action : _mappedActions) + for (auto& action : _mappedActions) { - if(action.actionName != key) + if (action.actionName != key) continue; auto key = action.pairedKey.GetExternalKeyCode(); auto& currentBuffer = _keyStates.at(_currentBufferIndex); - for(const auto& [currentKey, currentLog] : currentBuffer) + for (const auto& [currentKey, currentLog] : currentBuffer) { if (currentKey == key) { @@ -244,16 +241,16 @@ namespace NovelRT::Input::Glfw bool GlfwInputDevice::IsKeyPressed(const std::string& input) noexcept { - for(auto& action : _mappedActions) + for (auto& action : _mappedActions) { - if(action.actionName != input) + if (action.actionName != input) continue; auto key = action.pairedKey.GetExternalKeyCode(); auto& currentBuffer = _keyStates.at(_currentBufferIndex); - for(auto& [currentKey, currentLog] : currentBuffer) + for (auto& [currentKey, currentLog] : currentBuffer) { - if(currentKey != key) + if (currentKey != key) continue; return currentLog.GetCurrentState() == KeyState::KeyDown; @@ -266,16 +263,16 @@ namespace NovelRT::Input::Glfw bool GlfwInputDevice::IsKeyHeld(const std::string& input) noexcept { - for(auto& action : _mappedActions) + for (auto& action : _mappedActions) { - if(action.actionName != input) + if (action.actionName != input) continue; auto key = action.pairedKey.GetExternalKeyCode(); auto& currentBuffer = _keyStates.at(_currentBufferIndex); - for(auto& [currentKey, currentLog] : currentBuffer) + for (auto& [currentKey, currentLog] : currentBuffer) { - if(currentKey != key) + if (currentKey != key) continue; return currentLog.GetCurrentState() == KeyState::KeyDownHeld; @@ -288,16 +285,16 @@ namespace NovelRT::Input::Glfw bool GlfwInputDevice::IsKeyReleased(const std::string& input) noexcept { - for(auto& action : _mappedActions) + for (auto& action : _mappedActions) { - if(action.actionName != input) + if (action.actionName != input) continue; auto key = action.pairedKey.GetExternalKeyCode(); auto& currentBuffer = _keyStates.at(_currentBufferIndex); - for(auto& [currentKey, currentLog] : currentBuffer) + for (auto& [currentKey, currentLog] : currentBuffer) { - if(currentKey != key) + if (currentKey != key) continue; return currentLog.GetCurrentState() == KeyState::KeyUp; @@ -374,33 +371,32 @@ namespace NovelRT::Input::Glfw { auto& map = _keyStates.at(_currentBufferIndex); - for(auto& mapped : _mappedActions) + for (auto& mapped : _mappedActions) { - if(mapped.pairedKey.GetExternalKeyCode() != key) + if (mapped.pairedKey.GetExternalKeyCode() != key) continue; KeyStateFrameChangeLog log{}; bool mouseMod = false; - for(auto& [currentKey, currentLog] : map) + for (auto& [currentKey, currentLog] : map) { - if(currentKey != mapped.pairedKey.GetExternalKeyCode()) + if (currentKey != mapped.pairedKey.GetExternalKeyCode()) continue; log = currentLog; - if(currentKey == GLFW_MOUSE_BUTTON_LEFT || - currentKey == GLFW_MOUSE_BUTTON_MIDDLE || - currentKey == GLFW_MOUSE_BUTTON_RIGHT) + if (currentKey == GLFW_MOUSE_BUTTON_LEFT || currentKey == GLFW_MOUSE_BUTTON_MIDDLE || + currentKey == GLFW_MOUSE_BUTTON_RIGHT) { mouseMod = true; } break; } - if(mouseMod) + if (mouseMod) { auto currentState = log.GetCurrentState(); - if(state == (int32_t)KeyState::KeyDown && (currentState == KeyState::KeyDown || - currentState == KeyState::KeyDownHeld)) + if (state == (int32_t)KeyState::KeyDown && + (currentState == KeyState::KeyDown || currentState == KeyState::KeyDownHeld)) { state = (int32_t)KeyState::KeyDownHeld; } @@ -423,9 +419,9 @@ namespace NovelRT::Input::Glfw KeyState previousStateResult = KeyState::Idle; - for(auto& [previousKey, previousLog] : previousBuffer) + for (auto& [previousKey, previousLog] : previousBuffer) { - if(previousKey == key) + if (previousKey == key) { previousStateResult = previousLog.GetCurrentState(); break; @@ -434,9 +430,9 @@ namespace NovelRT::Input::Glfw KeyStateFrameChangeLog changeLogObject = KeyStateFrameChangeLog(); - for(auto& [currentKey, currentLog] : currentBuffer) + for (auto& [currentKey, currentLog] : currentBuffer) { - if(currentKey == key) + if (currentKey == key) { changeLogObject = currentLog; break; @@ -470,14 +466,14 @@ namespace NovelRT::Input::Glfw NovelRT::Maths::GeoVector2F GlfwInputDevice::DetermineMouseScreenPosition(NovelRT::Maths::GeoVector2F& pos) { return NovelRT::Maths::GeoVector2F(static_cast(pos.x - (_windowDimensions.x / 2)), - static_cast(-pos.y + (_windowDimensions.y / 2))); + static_cast(-pos.y + (_windowDimensions.y / 2))); } KeyStateFrameChangeLog GlfwInputDevice::GetCurrentChangeLog(const std::string& key) { - for(auto& action : _mappedActions) + for (auto& action : _mappedActions) { - if(action.actionName != key) + if (action.actionName != key) continue; return _keyStates.at(_currentBufferIndex).at(action.pairedKey.GetExternalKeyCode()); @@ -488,9 +484,9 @@ namespace NovelRT::Input::Glfw KeyStateFrameChangeLog GlfwInputDevice::GetPreviousChangeLog(const std::string& key) { - for(auto& action : _mappedActions) + for (auto& action : _mappedActions) { - if(action.actionName != key) + if (action.actionName != key) continue; return _keyStates.at(_previousBufferIndex).at(action.pairedKey.GetExternalKeyCode()); @@ -504,7 +500,6 @@ namespace NovelRT::Input::Glfw return _keyStates; } - GlfwInputDevice::~GlfwInputDevice() { } diff --git a/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp b/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp index 5c6f272c1..491532464 100644 --- a/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp +++ b/src/NovelRT/Windowing/Glfw/GlfwWindowingDevice.cpp @@ -64,19 +64,18 @@ namespace NovelRT::Windowing::Glfw }); glfwSetKeyCallback(window, [](auto window, auto key, auto /*scancode*/, auto action, auto /*mods*/) { - auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); - thisPtr->KeyboardButtonChanged(ButtonChangeEventArgs{key, action}); + auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); + thisPtr->KeyboardButtonChanged(ButtonChangeEventArgs{key, action}); }); glfwSetMouseButtonCallback(window, [](auto window, auto mouseButton, auto action, auto /*mods*/) { auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); - thisPtr->MouseButtonClicked( - ButtonChangeEventArgs{mouseButton, action}); + thisPtr->MouseButtonClicked(ButtonChangeEventArgs{mouseButton, action}); }); glfwSetCursorPosCallback(window, [](auto window, double x, double y) { - auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); - thisPtr->CursorMoved(CursorPositionEventArgs{x, y}); + auto thisPtr = reinterpret_cast(glfwGetWindowUserPointer(window)); + thisPtr->CursorMoved(CursorPositionEventArgs{x, y}); }); _window = std::unique_ptr(window, glfwDestroyWindow); From dc1c6b783fa0d2d31c449de1d444f3e547e775c2 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Mon, 2 Oct 2023 22:50:19 -0400 Subject: [PATCH 05/18] Refactor to new layout --- CMakeLists.txt | 1 + include/NovelRT/Ecs/Input/Ecs.Input.h | 2 +- include/NovelRT/NovelRT.h | 4 +- .../PluginManagement/PluginManagement.h | 2 +- input/CMakeLists.txt | 67 +++++++++++++++++++ .../Input => input}/Glfw/GlfwInputDevice.cpp | 2 +- .../Glfw/GlfwInputPluginProvider.cpp | 2 +- {src/NovelRT/Input => input}/NovelKey.cpp | 2 +- .../NovelRT/Input/Glfw/GlfwInputDevice.hpp | 0 .../Input/Glfw/GlfwInputPluginProvider.hpp | 0 .../include/NovelRT/Input/Glfw/Input.Glfw.hpp | 6 +- .../include/NovelRT/Input/IInputDevice.hpp | 0 .../include/NovelRT/Input/Input.hpp | 10 +-- .../include/NovelRT/Input/InputAction.hpp | 0 .../include/NovelRT/Input/KeyState.hpp | 0 .../NovelRT/Input/KeyStateFrameChangeLog.hpp | 0 .../include/NovelRT/Input/NovelKey.hpp | 0 src/NovelRT/CMakeLists.txt | 7 +- .../PluginManagement/TemporaryFnPtrs.cpp | 2 +- 19 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 input/CMakeLists.txt rename {src/NovelRT/Input => input}/Glfw/GlfwInputDevice.cpp (99%) rename {src/NovelRT/Input => input}/Glfw/GlfwInputPluginProvider.cpp (90%) rename {src/NovelRT/Input => input}/NovelKey.cpp (96%) rename include/NovelRT/Input/Glfw/GlfwInputDevice.h => input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp (100%) rename include/NovelRT/Input/Glfw/GlfwInputPluginProvider.h => input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp (100%) rename include/NovelRT/Input/Glfw/Input.Glfw.h => input/include/NovelRT/Input/Glfw/Input.Glfw.hpp (85%) rename include/NovelRT/Input/IInputDevice.h => input/include/NovelRT/Input/IInputDevice.hpp (100%) rename include/NovelRT/Input/Input.h => input/include/NovelRT/Input/Input.hpp (83%) rename include/NovelRT/Input/InputAction.h => input/include/NovelRT/Input/InputAction.hpp (100%) rename include/NovelRT/Input/KeyState.h => input/include/NovelRT/Input/KeyState.hpp (100%) rename include/NovelRT/Input/KeyStateFrameChangeLog.h => input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp (100%) rename include/NovelRT/Input/NovelKey.h => input/include/NovelRT/Input/NovelKey.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54e5b9fa2..80901d84e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,7 @@ add_subdirectory(thirdparty) add_subdirectory(resources) add_subdirectory(graphics) add_subdirectory(audio) +add_subdirectory(input) add_subdirectory(src) if(NOVELRT_BUILD_SAMPLES) diff --git a/include/NovelRT/Ecs/Input/Ecs.Input.h b/include/NovelRT/Ecs/Input/Ecs.Input.h index 5c1311fb7..960321f30 100644 --- a/include/NovelRT/Ecs/Input/Ecs.Input.h +++ b/include/NovelRT/Ecs/Input/Ecs.Input.h @@ -8,7 +8,7 @@ #error NovelRT does not support including types explicitly by default. Please include Ecs.h instead for the Ecs namespace subset. #endif -#include "../../Input/Input.h" +#include #include namespace NovelRT::Ecs::Input diff --git a/include/NovelRT/NovelRT.h b/include/NovelRT/NovelRT.h index e0f4156e3..cfdeafe86 100644 --- a/include/NovelRT/NovelRT.h +++ b/include/NovelRT/NovelRT.h @@ -114,8 +114,8 @@ #include #include #include - #include - #include + #include + #include // Plugin Management types #include diff --git a/include/NovelRT/PluginManagement/PluginManagement.h b/include/NovelRT/PluginManagement/PluginManagement.h index 1362b2839..d2923c446 100644 --- a/include/NovelRT/PluginManagement/PluginManagement.h +++ b/include/NovelRT/PluginManagement/PluginManagement.h @@ -5,7 +5,7 @@ #define NOVELRT_PLUGINMANAGEMENT_H // PluginManagement Dependencies -#include "../Input/Input.h" +#include #include "../ResourceManagement/ResourceManagement.h" #include "../Windowing/Windowing.h" #include diff --git a/input/CMakeLists.txt b/input/CMakeLists.txt new file mode 100644 index 000000000..8cacdd603 --- /dev/null +++ b/input/CMakeLists.txt @@ -0,0 +1,67 @@ +add_library(NovelRT-Input STATIC + NovelKey.cpp + Glfw/GlfwInputDevice.cpp + Glfw/GlfwInputPluginProvider.cpp +) + +target_sources(NovelRT-Input + PUBLIC + FILE_SET public_headers + TYPE HEADERS + BASE_DIRS include + FILES + include/NovelRT/Input/Input.hpp + include/NovelRT/Input/IInputDevice.hpp + include/NovelRT/Input/InputAction.hpp + include/NovelRT/Input/KeyState.hpp + include/NovelRT/Input/KeyStateFrameChangeLog.hpp + include/NovelRT/Input/NovelKey.hpp + include/NovelRT/Input/Glfw/Input.Glfw.hpp + include/NovelRT/Input/Glfw/GlfwInputDevice.hpp + include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp +) + +set_target_properties(NovelRT-Input + PROPERTIES + EXPORT_NAME Input + POSITION_INDEPENDENT_CODE ON +) + +target_compile_features(NovelRT-Input + PUBLIC + cxx_std_17 +) + +target_compile_options(NovelRT-Input + PRIVATE + $<$:-Wall> + $<$:-Wabi> + $<$:-Werror> + $<$:-Wextra> + $<$:-Wpedantic> + $<$:-pedantic-errors> + + $<$:-Wall> + $<$:-Werror> + $<$:-Wextra> + $<$:-Wpedantic> + $<$:-pedantic-errors> + + $<$:/W4> + $<$:/WX> + $<$:/permissive-> +) + +target_include_directories(NovelRT-Input PRIVATE "$") +target_link_libraries(NovelRT-Input + PUBLIC + spdlog + glfw +) + +install( + TARGETS NovelRT-Input + EXPORT NovelRTConfig + LIBRARY DESTINATION lib + FILE_SET public_headers DESTINATION include +) diff --git a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp similarity index 99% rename from src/NovelRT/Input/Glfw/GlfwInputDevice.cpp rename to input/Glfw/GlfwInputDevice.cpp index f72a76d84..6e4228b1f 100644 --- a/src/NovelRT/Input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -1,7 +1,7 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#include +#include namespace NovelRT::Input::Glfw { diff --git a/src/NovelRT/Input/Glfw/GlfwInputPluginProvider.cpp b/input/Glfw/GlfwInputPluginProvider.cpp similarity index 90% rename from src/NovelRT/Input/Glfw/GlfwInputPluginProvider.cpp rename to input/Glfw/GlfwInputPluginProvider.cpp index df64ddbcc..30563017e 100644 --- a/src/NovelRT/Input/Glfw/GlfwInputPluginProvider.cpp +++ b/input/Glfw/GlfwInputPluginProvider.cpp @@ -1,7 +1,7 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#include +#include namespace NovelRT::Input::Glfw { diff --git a/src/NovelRT/Input/NovelKey.cpp b/input/NovelKey.cpp similarity index 96% rename from src/NovelRT/Input/NovelKey.cpp rename to input/NovelKey.cpp index a589bda74..039ee4f54 100644 --- a/src/NovelRT/Input/NovelKey.cpp +++ b/input/NovelKey.cpp @@ -1,7 +1,7 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#include +#include #include namespace NovelRT::Input diff --git a/include/NovelRT/Input/Glfw/GlfwInputDevice.h b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp similarity index 100% rename from include/NovelRT/Input/Glfw/GlfwInputDevice.h rename to input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp diff --git a/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.h b/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp similarity index 100% rename from include/NovelRT/Input/Glfw/GlfwInputPluginProvider.h rename to input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp diff --git a/include/NovelRT/Input/Glfw/Input.Glfw.h b/input/include/NovelRT/Input/Glfw/Input.Glfw.hpp similarity index 85% rename from include/NovelRT/Input/Glfw/Input.Glfw.h rename to input/include/NovelRT/Input/Glfw/Input.Glfw.hpp index 0c2fcabbf..84cbbe0ce 100644 --- a/include/NovelRT/Input/Glfw/Input.Glfw.h +++ b/input/include/NovelRT/Input/Glfw/Input.Glfw.hpp @@ -14,14 +14,14 @@ namespace NovelRT::Input::Glfw // Input.Glfw dependencies #define GLFW_INCLUDE_NONE -#include "NovelRT/Input/Input.h" +#include #include "NovelRT/PluginManagement/PluginManagement.h" #include "NovelRT/Windowing/Glfw/Windowing.Glfw.h" #include #include // Input.Glfw types -#include "GlfwInputDevice.h" -#include "GlfwInputPluginProvider.h" +#include "GlfwInputDevice.hpp" +#include "GlfwInputPluginProvider.hpp" #endif // NOVELRT_INPUT_GLFW_H diff --git a/include/NovelRT/Input/IInputDevice.h b/input/include/NovelRT/Input/IInputDevice.hpp similarity index 100% rename from include/NovelRT/Input/IInputDevice.h rename to input/include/NovelRT/Input/IInputDevice.hpp diff --git a/include/NovelRT/Input/Input.h b/input/include/NovelRT/Input/Input.hpp similarity index 83% rename from include/NovelRT/Input/Input.h rename to input/include/NovelRT/Input/Input.hpp index 45bf08eb6..ddd57bd8f 100644 --- a/include/NovelRT/Input/Input.h +++ b/input/include/NovelRT/Input/Input.hpp @@ -28,11 +28,11 @@ namespace NovelRT::Input // clang-format off // Input Types -#include "KeyState.h" -#include "KeyStateFrameChangeLog.h" -#include "NovelKey.h" -#include "InputAction.h" -#include "IInputDevice.h" +#include "KeyState.hpp" +#include "KeyStateFrameChangeLog.hpp" +#include "NovelKey.hpp" +#include "InputAction.hpp" +#include "IInputDevice.hpp" // clang-format on #endif // NOVELRT_INPUT_H diff --git a/include/NovelRT/Input/InputAction.h b/input/include/NovelRT/Input/InputAction.hpp similarity index 100% rename from include/NovelRT/Input/InputAction.h rename to input/include/NovelRT/Input/InputAction.hpp diff --git a/include/NovelRT/Input/KeyState.h b/input/include/NovelRT/Input/KeyState.hpp similarity index 100% rename from include/NovelRT/Input/KeyState.h rename to input/include/NovelRT/Input/KeyState.hpp diff --git a/include/NovelRT/Input/KeyStateFrameChangeLog.h b/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp similarity index 100% rename from include/NovelRT/Input/KeyStateFrameChangeLog.h rename to input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp diff --git a/include/NovelRT/Input/NovelKey.h b/input/include/NovelRT/Input/NovelKey.hpp similarity index 100% rename from include/NovelRT/Input/NovelKey.h rename to input/include/NovelRT/Input/NovelKey.hpp diff --git a/src/NovelRT/CMakeLists.txt b/src/NovelRT/CMakeLists.txt index 5b1fd6d73..224808c21 100644 --- a/src/NovelRT/CMakeLists.txt +++ b/src/NovelRT/CMakeLists.txt @@ -19,9 +19,9 @@ set(CORE_SOURCES Ecs/Input/InputSystem.cpp Ecs/Narrative/NarrativePlayerSystem.cpp - Input/Glfw/GlfwInputDevice.cpp - Input/Glfw/GlfwInputPluginProvider.cpp - Input/NovelKey.cpp + #Input/Glfw/GlfwInputDevice.cpp + #Input/Glfw/GlfwInputPluginProvider.cpp + #Input/NovelKey.cpp Maths/GeoBounds.cpp Maths/QuadTree.cpp @@ -85,6 +85,7 @@ target_link_libraries(Engine ogg NovelRT-Graphics NovelRT-Audio + NovelRT-Input ) if(NOVELRT_INSTALL) diff --git a/src/NovelRT/PluginManagement/TemporaryFnPtrs.cpp b/src/NovelRT/PluginManagement/TemporaryFnPtrs.cpp index 64802f1ad..1fc675c1c 100644 --- a/src/NovelRT/PluginManagement/TemporaryFnPtrs.cpp +++ b/src/NovelRT/PluginManagement/TemporaryFnPtrs.cpp @@ -2,7 +2,7 @@ // for more information. #include -#include +#include #include #include #include From 89de6b7751ba946bd0094c1829bec822f1a28d46 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Tue, 3 Oct 2023 20:40:57 -0400 Subject: [PATCH 06/18] Changes based on GHA --- input/Glfw/GlfwInputDevice.cpp | 12 ++++++------ src/NovelRT.Interop/Input/NrtIInputDevice.cpp | 2 +- src/NovelRT.Interop/Input/NrtInputAction.cpp | 2 +- src/NovelRT.Interop/Input/NrtNovelKey.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index 6e4228b1f..82babcc9c 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -43,7 +43,7 @@ namespace NovelRT::Input::Glfw properDevice->MouseButtonClicked += [this](auto eventArgs) { ProcessKeyInput(eventArgs.key, eventArgs.action); }; properDevice->CursorMoved += [this](auto eventArgs) { - NovelRT::Maths::GeoVector2F nativePos = NovelRT::Maths::GeoVector2F(eventArgs.x, eventArgs.y); + NovelRT::Maths::GeoVector2F nativePos = NovelRT::Maths::GeoVector2F(static_cast(eventArgs.x), static_cast(eventArgs.y); ProcessCursorMovement(nativePos); }; @@ -184,7 +184,7 @@ namespace NovelRT::Input::Glfw int32_t width = 0; int32_t height = 0; glfwGetWindowSize(_window, &width, &height); - _windowDimensions = NovelRT::Maths::GeoVector2F(width, height); + _windowDimensions = NovelRT::Maths::GeoVector2F(static_cast(width), static_cast(height); _logger.logInfo("GLFW input system initialised: window at {} x {}", width, height); } @@ -197,8 +197,8 @@ namespace NovelRT::Input::Glfw int32_t height = 0; glfwGetWindowSize(_window, &width, &height); glfwGetCursorPos(_window, &x, &y); - _windowDimensions.x = width; - _windowDimensions.y = height; + _windowDimensions.x = static_cast(width); + _windowDimensions.y =static_cast(height); //_mousePos = DetermineMouseScreenPosition(NovelRT::Maths::GeoVector2F(x, y)); auto& currentBuffer = _keyStates.at(_currentBufferIndex); @@ -224,12 +224,12 @@ namespace NovelRT::Input::Glfw if (action.actionName != key) continue; - auto key = action.pairedKey.GetExternalKeyCode(); + auto externalKeyCode = action.pairedKey.GetExternalKeyCode(); auto& currentBuffer = _keyStates.at(_currentBufferIndex); for (const auto& [currentKey, currentLog] : currentBuffer) { - if (currentKey == key) + if (currentKey == externalKeyCode) { return currentLog.GetCurrentState(); } diff --git a/src/NovelRT.Interop/Input/NrtIInputDevice.cpp b/src/NovelRT.Interop/Input/NrtIInputDevice.cpp index 4d0c97d02..d29132323 100644 --- a/src/NovelRT.Interop/Input/NrtIInputDevice.cpp +++ b/src/NovelRT.Interop/Input/NrtIInputDevice.cpp @@ -4,7 +4,7 @@ #include "../LifetimeExtender.h" #include #include -#include +#include using namespace NovelRT::Input; using namespace NovelRT::Interop; diff --git a/src/NovelRT.Interop/Input/NrtInputAction.cpp b/src/NovelRT.Interop/Input/NrtInputAction.cpp index d6b9f86a8..1200fb88b 100644 --- a/src/NovelRT.Interop/Input/NrtInputAction.cpp +++ b/src/NovelRT.Interop/Input/NrtInputAction.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include using namespace NovelRT::Input; diff --git a/src/NovelRT.Interop/Input/NrtNovelKey.cpp b/src/NovelRT.Interop/Input/NrtNovelKey.cpp index 102880abb..e0efe6795 100644 --- a/src/NovelRT.Interop/Input/NrtNovelKey.cpp +++ b/src/NovelRT.Interop/Input/NrtNovelKey.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include using namespace NovelRT::Input; From 5e7b1a79bc1f87ec4eb47f2105351f63771560f0 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Tue, 3 Oct 2023 20:49:25 -0400 Subject: [PATCH 07/18] Fixed error with parentheses --- input/Glfw/GlfwInputDevice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index 82babcc9c..0b3a28c8e 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -43,7 +43,7 @@ namespace NovelRT::Input::Glfw properDevice->MouseButtonClicked += [this](auto eventArgs) { ProcessKeyInput(eventArgs.key, eventArgs.action); }; properDevice->CursorMoved += [this](auto eventArgs) { - NovelRT::Maths::GeoVector2F nativePos = NovelRT::Maths::GeoVector2F(static_cast(eventArgs.x), static_cast(eventArgs.y); + NovelRT::Maths::GeoVector2F nativePos = NovelRT::Maths::GeoVector2F(static_cast(eventArgs.x), static_cast(eventArgs.y)); ProcessCursorMovement(nativePos); }; @@ -184,7 +184,7 @@ namespace NovelRT::Input::Glfw int32_t width = 0; int32_t height = 0; glfwGetWindowSize(_window, &width, &height); - _windowDimensions = NovelRT::Maths::GeoVector2F(static_cast(width), static_cast(height); + _windowDimensions = NovelRT::Maths::GeoVector2F(static_cast(width), static_cast(height)); _logger.logInfo("GLFW input system initialised: window at {} x {}", width, height); } From 2f1607b732fc0ea56ac3274ecb3849e105ee1fb0 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Tue, 3 Oct 2023 20:57:36 -0400 Subject: [PATCH 08/18] Clang-format number 2 --- include/NovelRT/PluginManagement/PluginManagement.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/NovelRT/PluginManagement/PluginManagement.h b/include/NovelRT/PluginManagement/PluginManagement.h index d2923c446..560ebbc86 100644 --- a/include/NovelRT/PluginManagement/PluginManagement.h +++ b/include/NovelRT/PluginManagement/PluginManagement.h @@ -5,10 +5,10 @@ #define NOVELRT_PLUGINMANAGEMENT_H // PluginManagement Dependencies -#include #include "../ResourceManagement/ResourceManagement.h" #include "../Windowing/Windowing.h" #include +#include /** * @brief The NovelRT engine plugin system for loading modules such as Vulkan, GLFW3, OpenAL, and more. From a613d76c04ca395cb05e8d72a31a8c4af038fc0c Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sun, 15 Oct 2023 18:44:44 -0400 Subject: [PATCH 09/18] Addressed PR feedback and fixed build issues for Windows --- include/NovelRT/Exceptions/Exceptions.h | 6 ++--- .../OpenGLLinkageFailureException.h | 24 ------------------- input/CMakeLists.txt | 1 + input/Glfw/GlfwInputDevice.cpp | 4 ++-- .../NovelRT/Input/Glfw/GlfwInputDevice.hpp | 2 +- input/include/NovelRT/Input/IInputDevice.hpp | 2 +- src/NovelRT/CMakeLists.txt | 4 ---- src/NovelRT/Ecs/Input/InputSystem.cpp | 2 +- 8 files changed, 8 insertions(+), 37 deletions(-) delete mode 100644 include/NovelRT/Exceptions/OpenGLLinkageFailureException.h diff --git a/include/NovelRT/Exceptions/Exceptions.h b/include/NovelRT/Exceptions/Exceptions.h index 67c807834..c63b958b9 100644 --- a/include/NovelRT/Exceptions/Exceptions.h +++ b/include/NovelRT/Exceptions/Exceptions.h @@ -1,6 +1,5 @@ -// -// Created by Matt on 06/01/2021. -// +// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root +// for more information. #ifndef NOVELRT_EXCEPTIONS_H #define NOVELRT_EXCEPTIONS_H @@ -17,7 +16,6 @@ #include "NotInitialisedException.h" #include "NotSupportedException.h" #include "NullPointerException.h" -#include "OpenGLLinkageFailureException.h" #include "OutOfMemoryException.h" #include "RuntimeNotFoundException.h" #include "TimeoutException.h" diff --git a/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h b/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h deleted file mode 100644 index 4a4701400..000000000 --- a/include/NovelRT/Exceptions/OpenGLLinkageFailureException.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root -// for more information. - -#ifndef NOVELRT_EXCEPTIONS_OPENGLLINKAGEFAILUREEXCEPTION_H -#define NOVELRT_EXCEPTIONS_OPENGLLINKAGEFAILUREEXCEPTION_H - -#include -#include -#include - -namespace NovelRT::Exceptions -{ - class OpenGLLinkageFailureException final : public std::runtime_error - { - public: - OpenGLLinkageFailureException(uint32_t programId, const std::string& errorMessage) - : std::runtime_error(std::string("Program with ID \"") + std::to_string(programId) + - "\" has encountered an error. Error: " + errorMessage) - { - } - }; -} - -#endif //! NOVELRT_EXCEPTIONS_OPENGLLINKAGEFAILUREEXCEPTION_H diff --git a/input/CMakeLists.txt b/input/CMakeLists.txt index 8cacdd603..917ff2561 100644 --- a/input/CMakeLists.txt +++ b/input/CMakeLists.txt @@ -57,6 +57,7 @@ target_link_libraries(NovelRT-Input PUBLIC spdlog glfw + tbb ) install( diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index 0b3a28c8e..53fa5cc73 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -13,7 +13,7 @@ namespace NovelRT::Input::Glfw _logger = NovelRT::LoggingService(NovelRT::Utilities::Misc::CONSOLE_LOG_INPUT); } - void GlfwInputDevice::Initialise(NovelRT::Windowing::IWindowingDevice* device) + void GlfwInputDevice::Initialise(std::shared_ptr device) { if (!glfwInit()) { @@ -36,7 +36,7 @@ namespace NovelRT::Input::Glfw _previousBufferIndex = 0; _currentBufferIndex = 1; - auto properDevice = reinterpret_cast(device); + auto properDevice = reinterpret_cast(device.get()); _window = properDevice->GetRawGLFWwindowHandle(); properDevice->KeyboardButtonChanged += [this](auto eventArgs) { ProcessKeyInput(eventArgs.key, eventArgs.action); }; diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp index a6635de6b..966f6fec9 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp @@ -29,7 +29,7 @@ namespace NovelRT::Input::Glfw public: GlfwInputDevice() noexcept; - void Initialise(NovelRT::Windowing::IWindowingDevice* device) final; + void Initialise(std::shared_ptr device) final; void Update(Timing::Timestamp delta) final; [[nodiscard]] bool IsKeyPressed(const std::string& input) noexcept final; [[nodiscard]] bool IsKeyHeld(const std::string& input) noexcept final; diff --git a/input/include/NovelRT/Input/IInputDevice.hpp b/input/include/NovelRT/Input/IInputDevice.hpp index e4d9f30e2..7d40f3203 100644 --- a/input/include/NovelRT/Input/IInputDevice.hpp +++ b/input/include/NovelRT/Input/IInputDevice.hpp @@ -21,7 +21,7 @@ namespace NovelRT::Input uint32_t _inputBufferCount; public: - virtual void Initialise(NovelRT::Windowing::IWindowingDevice* device) = 0; + virtual void Initialise(std::shared_ptr device) = 0; virtual void Update(Timing::Timestamp delta) = 0; [[nodiscard]] virtual bool IsKeyPressed(const std::string& key) = 0; [[nodiscard]] virtual bool IsKeyHeld(const std::string& key) = 0; diff --git a/src/NovelRT/CMakeLists.txt b/src/NovelRT/CMakeLists.txt index 224808c21..bdeb384b9 100644 --- a/src/NovelRT/CMakeLists.txt +++ b/src/NovelRT/CMakeLists.txt @@ -19,10 +19,6 @@ set(CORE_SOURCES Ecs/Input/InputSystem.cpp Ecs/Narrative/NarrativePlayerSystem.cpp - #Input/Glfw/GlfwInputDevice.cpp - #Input/Glfw/GlfwInputPluginProvider.cpp - #Input/NovelKey.cpp - Maths/GeoBounds.cpp Maths/QuadTree.cpp diff --git a/src/NovelRT/Ecs/Input/InputSystem.cpp b/src/NovelRT/Ecs/Input/InputSystem.cpp index d34cc6b10..fad5cfe3e 100644 --- a/src/NovelRT/Ecs/Input/InputSystem.cpp +++ b/src/NovelRT/Ecs/Input/InputSystem.cpp @@ -11,7 +11,7 @@ namespace NovelRT::Ecs::Input { _inputMap = std::map(); _device = inputProvider->GetInputService(); - _device->Initialise(windowingProvider->GetWindowingDevice().get()); + _device->Initialise(windowingProvider->GetWindowingDevice()); } void InputSystem::Update(Timing::Timestamp delta, Ecs::Catalogue catalogue) From 9e544688b39053a9454f571c7570857f22e3dc1b Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sun, 29 Oct 2023 17:22:06 -0400 Subject: [PATCH 10/18] Removing dead code --- input/Glfw/GlfwInputDevice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index 53fa5cc73..de5c45622 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -199,7 +199,6 @@ namespace NovelRT::Input::Glfw glfwGetCursorPos(_window, &x, &y); _windowDimensions.x = static_cast(width); _windowDimensions.y =static_cast(height); - //_mousePos = DetermineMouseScreenPosition(NovelRT::Maths::GeoVector2F(x, y)); auto& currentBuffer = _keyStates.at(_currentBufferIndex); From ee28a2f1274e89a3452f2b1db165c1986a55fd1b Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sun, 29 Oct 2023 17:44:32 -0400 Subject: [PATCH 11/18] Changed return to Span --- input/Glfw/GlfwInputDevice.cpp | 2 +- input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp | 2 +- input/include/NovelRT/Input/IInputDevice.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index de5c45622..eda3035a5 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -494,7 +494,7 @@ namespace NovelRT::Input::Glfw return KeyStateFrameChangeLog(); } - std::vector> GlfwInputDevice::GetAllChangeLogs() + NovelRT::Utilities::Misc::Span> GlfwInputDevice::GetAllChangeLogs() { return _keyStates; } diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp index 966f6fec9..1644db9bf 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp @@ -42,7 +42,7 @@ namespace NovelRT::Input::Glfw [[nodiscard]] NovelRT::Utilities::Misc::Span GetAllMappings() noexcept final; [[nodiscard]] KeyStateFrameChangeLog GetCurrentChangeLog(const std::string& key) final; [[nodiscard]] KeyStateFrameChangeLog GetPreviousChangeLog(const std::string& key) final; - [[nodiscard]] std::vector> GetAllChangeLogs() final; + [[nodiscard]] NovelRT::Utilities::Misc::Span> GetAllChangeLogs() final; ~GlfwInputDevice() final; }; diff --git a/input/include/NovelRT/Input/IInputDevice.hpp b/input/include/NovelRT/Input/IInputDevice.hpp index 7d40f3203..8ac21cfa5 100644 --- a/input/include/NovelRT/Input/IInputDevice.hpp +++ b/input/include/NovelRT/Input/IInputDevice.hpp @@ -34,7 +34,7 @@ namespace NovelRT::Input [[nodiscard]] virtual NovelRT::Utilities::Misc::Span GetAllMappings() = 0; [[nodiscard]] virtual KeyStateFrameChangeLog GetCurrentChangeLog(const std::string& key) = 0; [[nodiscard]] virtual KeyStateFrameChangeLog GetPreviousChangeLog(const std::string& key) = 0; - [[nodiscard]] virtual std::vector> GetAllChangeLogs() = 0; + [[nodiscard]] virtual NovelRT::Utilities::Misc::Span> GetAllChangeLogs() = 0; virtual ~IInputDevice() = default; }; From c7a47b6c37c41f281e12c0f3e57fae0bd338452b Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sun, 29 Oct 2023 17:45:54 -0400 Subject: [PATCH 12/18] Removed constness --- input/Glfw/GlfwInputDevice.cpp | 4 ++-- input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp | 4 ++-- input/include/NovelRT/Input/IInputDevice.hpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index eda3035a5..dffc9edb2 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -468,7 +468,7 @@ namespace NovelRT::Input::Glfw static_cast(-pos.y + (_windowDimensions.y / 2))); } - KeyStateFrameChangeLog GlfwInputDevice::GetCurrentChangeLog(const std::string& key) + KeyStateFrameChangeLog GlfwInputDevice::GetCurrentChangeLog(std::string& key) { for (auto& action : _mappedActions) { @@ -481,7 +481,7 @@ namespace NovelRT::Input::Glfw return KeyStateFrameChangeLog(); } - KeyStateFrameChangeLog GlfwInputDevice::GetPreviousChangeLog(const std::string& key) + KeyStateFrameChangeLog GlfwInputDevice::GetPreviousChangeLog(std::string& key) { for (auto& action : _mappedActions) { diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp index 1644db9bf..62b65d606 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp @@ -40,8 +40,8 @@ namespace NovelRT::Input::Glfw [[nodiscard]] NovelKey& GetAvailableKey(const std::string& keyRequested) final; [[nodiscard]] NovelRT::Maths::GeoVector2F GetMousePosition() noexcept final; [[nodiscard]] NovelRT::Utilities::Misc::Span GetAllMappings() noexcept final; - [[nodiscard]] KeyStateFrameChangeLog GetCurrentChangeLog(const std::string& key) final; - [[nodiscard]] KeyStateFrameChangeLog GetPreviousChangeLog(const std::string& key) final; + [[nodiscard]] KeyStateFrameChangeLog GetCurrentChangeLog(std::string& key) final; + [[nodiscard]] KeyStateFrameChangeLog GetPreviousChangeLog(std::string& key) final; [[nodiscard]] NovelRT::Utilities::Misc::Span> GetAllChangeLogs() final; ~GlfwInputDevice() final; diff --git a/input/include/NovelRT/Input/IInputDevice.hpp b/input/include/NovelRT/Input/IInputDevice.hpp index 8ac21cfa5..b5a0fbafb 100644 --- a/input/include/NovelRT/Input/IInputDevice.hpp +++ b/input/include/NovelRT/Input/IInputDevice.hpp @@ -32,8 +32,8 @@ namespace NovelRT::Input [[nodiscard]] virtual NovelKey& GetAvailableKey(const std::string& keyRequested) = 0; [[nodiscard]] virtual NovelRT::Maths::GeoVector2F GetMousePosition() = 0; [[nodiscard]] virtual NovelRT::Utilities::Misc::Span GetAllMappings() = 0; - [[nodiscard]] virtual KeyStateFrameChangeLog GetCurrentChangeLog(const std::string& key) = 0; - [[nodiscard]] virtual KeyStateFrameChangeLog GetPreviousChangeLog(const std::string& key) = 0; + [[nodiscard]] virtual KeyStateFrameChangeLog GetCurrentChangeLog(std::string& key) = 0; + [[nodiscard]] virtual KeyStateFrameChangeLog GetPreviousChangeLog(std::string& key) = 0; [[nodiscard]] virtual NovelRT::Utilities::Misc::Span> GetAllChangeLogs() = 0; virtual ~IInputDevice() = default; From f4bf436768086eb69237a1cd15b2eeb61c28091e Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sun, 29 Oct 2023 17:57:35 -0400 Subject: [PATCH 13/18] Removed out-of-member functions --- input/Glfw/GlfwInputDevice.cpp | 2 +- input/include/NovelRT/Input/InputAction.hpp | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index dffc9edb2..185411ca5 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -36,7 +36,7 @@ namespace NovelRT::Input::Glfw _previousBufferIndex = 0; _currentBufferIndex = 1; - auto properDevice = reinterpret_cast(device.get()); + auto properDevice = std::reinterpret_pointer_cast(device); _window = properDevice->GetRawGLFWwindowHandle(); properDevice->KeyboardButtonChanged += [this](auto eventArgs) { ProcessKeyInput(eventArgs.key, eventArgs.action); }; diff --git a/input/include/NovelRT/Input/InputAction.hpp b/input/include/NovelRT/Input/InputAction.hpp index 6d967f484..511122052 100644 --- a/input/include/NovelRT/Input/InputAction.hpp +++ b/input/include/NovelRT/Input/InputAction.hpp @@ -16,17 +16,6 @@ namespace NovelRT::Input NovelKey pairedKey; KeyState state = KeyState::Idle; }; - - inline bool operator==(InputAction const& lhs, InputAction const& rhs) noexcept - { - return lhs.state == rhs.state && (lhs.pairedKey == rhs.pairedKey) && lhs.actionName == rhs.actionName; - } - - inline bool operator!=(const InputAction& lhs, const InputAction& rhs) noexcept - { - return (lhs.state != rhs.state) || (lhs.pairedKey != rhs.pairedKey) || (lhs.actionName != rhs.actionName); - } - } #endif // NOVELRT_INPUT_INPUTACTION_H From 8af81e5de07c38f224b67555c203e4308d7b9eb2 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sun, 29 Oct 2023 18:09:09 -0400 Subject: [PATCH 14/18] Refactor includes --- input/CMakeLists.txt | 1 + input/KeyStateFrameChangeLog.cpp | 28 ++++++++++++++ .../NovelRT/Input/Glfw/GlfwInputDevice.hpp | 4 -- .../Input/Glfw/GlfwInputPluginProvider.hpp | 4 -- input/include/NovelRT/Input/IInputDevice.hpp | 4 -- input/include/NovelRT/Input/InputAction.hpp | 4 -- input/include/NovelRT/Input/KeyState.hpp | 4 -- .../NovelRT/Input/KeyStateFrameChangeLog.hpp | 37 ++----------------- input/include/NovelRT/Input/NovelKey.hpp | 4 -- 9 files changed, 32 insertions(+), 58 deletions(-) create mode 100644 input/KeyStateFrameChangeLog.cpp diff --git a/input/CMakeLists.txt b/input/CMakeLists.txt index 917ff2561..bbad7162a 100644 --- a/input/CMakeLists.txt +++ b/input/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(NovelRT-Input STATIC + KeyStateFrameChangeLog.cpp NovelKey.cpp Glfw/GlfwInputDevice.cpp Glfw/GlfwInputPluginProvider.cpp diff --git a/input/KeyStateFrameChangeLog.cpp b/input/KeyStateFrameChangeLog.cpp new file mode 100644 index 000000000..72837e169 --- /dev/null +++ b/input/KeyStateFrameChangeLog.cpp @@ -0,0 +1,28 @@ +// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root +// for more information. + +#include + +namespace NovelRT::Input +{ + void KeyStateFrameChangeLog::PushNewState(KeyState newState) noexcept + { + if (_currentState == newState) + { + return; + } + + _currentState = newState; + _changeCount++; + } + + KeyState KeyStateFrameChangeLog::GetCurrentState() const noexcept + { + return _currentState; + } + + uint32_t KeyStateFrameChangeLog::GetChangeCount() const noexcept + { + return _changeCount; + } +} diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp index 62b65d606..2b408d1a6 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp @@ -4,10 +4,6 @@ #ifndef NOVELRT_INPUT_GLFW_GLFWINPUTDEVICE_H #define NOVELRT_INPUT_GLFW_GLFWINPUTDEVICE_H -#ifndef NOVELRT_INPUT_GLFW_H -#error NovelRT does not support including types explicitly by default. Please include Input.Glfw.h instead for the Input::Glfw namespace subset. -#endif - namespace NovelRT::Input::Glfw { class GlfwInputDevice final : public Input::IInputDevice diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp index af9a0184c..a490a7ac5 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp @@ -4,10 +4,6 @@ #ifndef NOVELRT_INPUT_GLFW_GLFWINPUTPLUGINPROVIDER_H #define NOVELRT_INPUT_GLFW_GLFWINPUTPLUGINPROVIDER_H -#ifndef NOVELRT_INPUT_GLFW_H -#error NovelRT does not support including types explicitly by default. Please include Input.Glfw.h instead for the Input::Glfw namespace subset. -#endif - namespace NovelRT::Input::Glfw { class GlfwInputPluginProvider final : public PluginManagement::IInputPluginProvider diff --git a/input/include/NovelRT/Input/IInputDevice.hpp b/input/include/NovelRT/Input/IInputDevice.hpp index b5a0fbafb..dc3d81589 100644 --- a/input/include/NovelRT/Input/IInputDevice.hpp +++ b/input/include/NovelRT/Input/IInputDevice.hpp @@ -4,10 +4,6 @@ #ifndef NOVELRT_INPUT_IINPUTSERVICE_H #define NOVELRT_INPUT_IINPUTSERVICE_H -#ifndef NOVELRT_INPUT_H -#error NovelRT does not support including types explicitly by default. Please include Input.h instead for the Input namespace subset. -#endif - namespace NovelRT::Input { class IInputDevice : public std::enable_shared_from_this diff --git a/input/include/NovelRT/Input/InputAction.hpp b/input/include/NovelRT/Input/InputAction.hpp index 511122052..2277442c1 100644 --- a/input/include/NovelRT/Input/InputAction.hpp +++ b/input/include/NovelRT/Input/InputAction.hpp @@ -4,10 +4,6 @@ #ifndef NOVELRT_INPUT_INPUTACTION_H #define NOVELRT_INPUT_INPUTACTION_H -#ifndef NOVELRT_INPUT_H -#error NovelRT does not support including types explicitly by default. Please include Input.h instead for the Input namespace subset. -#endif - namespace NovelRT::Input { struct InputAction diff --git a/input/include/NovelRT/Input/KeyState.hpp b/input/include/NovelRT/Input/KeyState.hpp index 26a3702df..5d12d7c78 100644 --- a/input/include/NovelRT/Input/KeyState.hpp +++ b/input/include/NovelRT/Input/KeyState.hpp @@ -4,10 +4,6 @@ #ifndef NOVELRT_INPUT_KEYSTATE_H #define NOVELRT_INPUT_KEYSTATE_H -#ifndef NOVELRT_INPUT_H -#error NovelRT does not support including types explicitly by default. Please include Input.h instead for the Input namespace subset. -#endif - namespace NovelRT::Input { /** diff --git a/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp b/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp index 0d49f532e..b7d9c7064 100644 --- a/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp +++ b/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp @@ -4,10 +4,6 @@ #ifndef NOVELRT_INPUT_KEYSTATEFRAMECHANGELOG_H #define NOVELRT_INPUT_KEYSTATEFRAMECHANGELOG_H -#ifndef NOVELRT_INPUT_H -#error NovelRT does not support including types explicitly by default. Please include Input.h instead for the Input namespace subset. -#endif - namespace NovelRT::Input { class KeyStateFrameChangeLog @@ -18,36 +14,9 @@ namespace NovelRT::Input uint32_t _changeCount = 0; public: - inline void PushNewState(KeyState newState) noexcept - { - if (_currentState == newState) - { - return; - } - - _currentState = newState; - _changeCount++; - } - - inline KeyState GetCurrentState() const noexcept - { - return _currentState; - } - - inline uint32_t GetChangeCount() const noexcept - { - return _changeCount; - } + void PushNewState(KeyState newState) noexcept; + KeyState GetCurrentState() const noexcept; + uint32_t GetChangeCount() const noexcept; }; - - inline bool operator==(const KeyStateFrameChangeLog& lhs, const KeyState& rhs) noexcept - { - return lhs.GetCurrentState() == rhs; - } - - inline bool operator==(const KeyState& lhs, const KeyStateFrameChangeLog& rhs) noexcept - { - return rhs == lhs; - } } #endif //! NOVELRT_INPUT_KEYSTATEFRAMECHANGELOG_H diff --git a/input/include/NovelRT/Input/NovelKey.hpp b/input/include/NovelRT/Input/NovelKey.hpp index 6044d49cc..176f309ff 100644 --- a/input/include/NovelRT/Input/NovelKey.hpp +++ b/input/include/NovelRT/Input/NovelKey.hpp @@ -4,10 +4,6 @@ #ifndef NOVELRT_INPUT_NOVELKEY_H #define NOVELRT_INPUT_NOVELKEY_H -#ifndef NOVELRT_INPUT_H -#error NovelRT does not support including types explicitly by default. Please include Input.h instead for the Input namespace subset. -#endif - namespace NovelRT::Input { class NovelKey From c3ce40da00d2aff63eeb333564f0eb5c51bd5dcf Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sun, 29 Oct 2023 18:42:55 -0400 Subject: [PATCH 15/18] Bringin' const back --- input/Glfw/GlfwInputDevice.cpp | 4 ++-- input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp | 4 ++-- input/include/NovelRT/Input/IInputDevice.hpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index 185411ca5..3d7fc70ed 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -468,7 +468,7 @@ namespace NovelRT::Input::Glfw static_cast(-pos.y + (_windowDimensions.y / 2))); } - KeyStateFrameChangeLog GlfwInputDevice::GetCurrentChangeLog(std::string& key) + KeyStateFrameChangeLog GlfwInputDevice::GetCurrentChangeLog(const std::string& key) { for (auto& action : _mappedActions) { @@ -481,7 +481,7 @@ namespace NovelRT::Input::Glfw return KeyStateFrameChangeLog(); } - KeyStateFrameChangeLog GlfwInputDevice::GetPreviousChangeLog(std::string& key) + KeyStateFrameChangeLog GlfwInputDevice::GetPreviousChangeLog(const std::string& key) { for (auto& action : _mappedActions) { diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp index 2b408d1a6..35b504d71 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp @@ -36,8 +36,8 @@ namespace NovelRT::Input::Glfw [[nodiscard]] NovelKey& GetAvailableKey(const std::string& keyRequested) final; [[nodiscard]] NovelRT::Maths::GeoVector2F GetMousePosition() noexcept final; [[nodiscard]] NovelRT::Utilities::Misc::Span GetAllMappings() noexcept final; - [[nodiscard]] KeyStateFrameChangeLog GetCurrentChangeLog(std::string& key) final; - [[nodiscard]] KeyStateFrameChangeLog GetPreviousChangeLog(std::string& key) final; + [[nodiscard]] KeyStateFrameChangeLog GetCurrentChangeLog(const std::string& key) final; + [[nodiscard]] KeyStateFrameChangeLog GetPreviousChangeLog(const std::string& key) final; [[nodiscard]] NovelRT::Utilities::Misc::Span> GetAllChangeLogs() final; ~GlfwInputDevice() final; diff --git a/input/include/NovelRT/Input/IInputDevice.hpp b/input/include/NovelRT/Input/IInputDevice.hpp index dc3d81589..0c8cfe334 100644 --- a/input/include/NovelRT/Input/IInputDevice.hpp +++ b/input/include/NovelRT/Input/IInputDevice.hpp @@ -28,8 +28,8 @@ namespace NovelRT::Input [[nodiscard]] virtual NovelKey& GetAvailableKey(const std::string& keyRequested) = 0; [[nodiscard]] virtual NovelRT::Maths::GeoVector2F GetMousePosition() = 0; [[nodiscard]] virtual NovelRT::Utilities::Misc::Span GetAllMappings() = 0; - [[nodiscard]] virtual KeyStateFrameChangeLog GetCurrentChangeLog(std::string& key) = 0; - [[nodiscard]] virtual KeyStateFrameChangeLog GetPreviousChangeLog(std::string& key) = 0; + [[nodiscard]] virtual KeyStateFrameChangeLog GetCurrentChangeLog(const std::string& key) = 0; + [[nodiscard]] virtual KeyStateFrameChangeLog GetPreviousChangeLog(const std::string& key) = 0; [[nodiscard]] virtual NovelRT::Utilities::Misc::Span> GetAllChangeLogs() = 0; virtual ~IInputDevice() = default; From 3c57b88820fb15a1c409fb954a4d8420d4f324c1 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Wed, 1 Nov 2023 18:31:55 -0400 Subject: [PATCH 16/18] Move Input to proper header structure --- include/NovelRT/Ecs/Input/Ecs.Input.h | 6 ++- include/NovelRT/NovelRT.h | 2 - .../PluginManagement/PluginManagement.h | 2 +- input/CMakeLists.txt | 2 - input/Glfw/GlfwInputDevice.cpp | 3 +- input/Glfw/GlfwInputPluginProvider.cpp | 2 +- input/KeyStateFrameChangeLog.cpp | 2 +- input/NovelKey.cpp | 3 +- .../NovelRT/Input/Glfw/GlfwInputDevice.hpp | 14 +++++-- .../Input/Glfw/GlfwInputPluginProvider.hpp | 6 +-- .../include/NovelRT/Input/Glfw/Input.Glfw.hpp | 27 ------------- input/include/NovelRT/Input/IInputDevice.hpp | 15 ++++++-- input/include/NovelRT/Input/Input.hpp | 38 ------------------- input/include/NovelRT/Input/InputAction.hpp | 7 ++-- input/include/NovelRT/Input/KeyState.hpp | 5 +-- .../NovelRT/Input/KeyStateFrameChangeLog.hpp | 7 ++-- input/include/NovelRT/Input/NovelKey.hpp | 16 ++------ src/NovelRT.Interop/Input/NrtIInputDevice.cpp | 2 +- src/NovelRT.Interop/Input/NrtInputAction.cpp | 2 +- src/NovelRT.Interop/Input/NrtNovelKey.cpp | 2 +- .../PluginManagement/TemporaryFnPtrs.cpp | 2 +- 21 files changed, 53 insertions(+), 112 deletions(-) delete mode 100644 input/include/NovelRT/Input/Glfw/Input.Glfw.hpp delete mode 100644 input/include/NovelRT/Input/Input.hpp diff --git a/include/NovelRT/Ecs/Input/Ecs.Input.h b/include/NovelRT/Ecs/Input/Ecs.Input.h index 960321f30..489a5bf67 100644 --- a/include/NovelRT/Ecs/Input/Ecs.Input.h +++ b/include/NovelRT/Ecs/Input/Ecs.Input.h @@ -8,7 +8,11 @@ #error NovelRT does not support including types explicitly by default. Please include Ecs.h instead for the Ecs namespace subset. #endif -#include +#include +#include +#include +#include +#include #include namespace NovelRT::Ecs::Input diff --git a/include/NovelRT/NovelRT.h b/include/NovelRT/NovelRT.h index cfdeafe86..ac18b769e 100644 --- a/include/NovelRT/NovelRT.h +++ b/include/NovelRT/NovelRT.h @@ -114,8 +114,6 @@ #include #include #include - #include - #include // Plugin Management types #include diff --git a/include/NovelRT/PluginManagement/PluginManagement.h b/include/NovelRT/PluginManagement/PluginManagement.h index 560ebbc86..61bb4c003 100644 --- a/include/NovelRT/PluginManagement/PluginManagement.h +++ b/include/NovelRT/PluginManagement/PluginManagement.h @@ -8,7 +8,7 @@ #include "../ResourceManagement/ResourceManagement.h" #include "../Windowing/Windowing.h" #include -#include +#include /** * @brief The NovelRT engine plugin system for loading modules such as Vulkan, GLFW3, OpenAL, and more. diff --git a/input/CMakeLists.txt b/input/CMakeLists.txt index bbad7162a..51126a07a 100644 --- a/input/CMakeLists.txt +++ b/input/CMakeLists.txt @@ -11,13 +11,11 @@ target_sources(NovelRT-Input TYPE HEADERS BASE_DIRS include FILES - include/NovelRT/Input/Input.hpp include/NovelRT/Input/IInputDevice.hpp include/NovelRT/Input/InputAction.hpp include/NovelRT/Input/KeyState.hpp include/NovelRT/Input/KeyStateFrameChangeLog.hpp include/NovelRT/Input/NovelKey.hpp - include/NovelRT/Input/Glfw/Input.Glfw.hpp include/NovelRT/Input/Glfw/GlfwInputDevice.hpp include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp ) diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index 3d7fc70ed..0e79a4543 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -1,7 +1,8 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#include +#include +#include namespace NovelRT::Input::Glfw { diff --git a/input/Glfw/GlfwInputPluginProvider.cpp b/input/Glfw/GlfwInputPluginProvider.cpp index 30563017e..8d0222b1b 100644 --- a/input/Glfw/GlfwInputPluginProvider.cpp +++ b/input/Glfw/GlfwInputPluginProvider.cpp @@ -1,7 +1,7 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#include +#include namespace NovelRT::Input::Glfw { diff --git a/input/KeyStateFrameChangeLog.cpp b/input/KeyStateFrameChangeLog.cpp index 72837e169..f0fb79b8d 100644 --- a/input/KeyStateFrameChangeLog.cpp +++ b/input/KeyStateFrameChangeLog.cpp @@ -1,7 +1,7 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#include +#include namespace NovelRT::Input { diff --git a/input/NovelKey.cpp b/input/NovelKey.cpp index 039ee4f54..16538ce8c 100644 --- a/input/NovelKey.cpp +++ b/input/NovelKey.cpp @@ -1,8 +1,7 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#include -#include +#include namespace NovelRT::Input { diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp index 35b504d71..82f7302cc 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp @@ -1,8 +1,17 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. +#pragma once -#ifndef NOVELRT_INPUT_GLFW_GLFWINPUTDEVICE_H -#define NOVELRT_INPUT_GLFW_GLFWINPUTDEVICE_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace NovelRT::Input::Glfw { @@ -44,4 +53,3 @@ namespace NovelRT::Input::Glfw }; } -#endif // NOVELRT_INPUT_GLFW_GLFWINPUTDEVICE_H diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp index a490a7ac5..4aaee9369 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp @@ -1,8 +1,9 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. +#pragma once -#ifndef NOVELRT_INPUT_GLFW_GLFWINPUTPLUGINPROVIDER_H -#define NOVELRT_INPUT_GLFW_GLFWINPUTPLUGINPROVIDER_H +#include +#include namespace NovelRT::Input::Glfw { @@ -23,4 +24,3 @@ namespace NovelRT::Input::Glfw }; } -#endif // NOVELRT_INPUT_GLFW_GLFWINPUTPLUGINPROVIDER_H diff --git a/input/include/NovelRT/Input/Glfw/Input.Glfw.hpp b/input/include/NovelRT/Input/Glfw/Input.Glfw.hpp deleted file mode 100644 index 84cbbe0ce..000000000 --- a/input/include/NovelRT/Input/Glfw/Input.Glfw.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root -// for more information. - -#ifndef NOVELRT_INPUT_GLFW_H -#define NOVELRT_INPUT_GLFW_H - -/** - * @brief The default GLFW3 implementation of the Input plugin API. - */ -namespace NovelRT::Input::Glfw -{ - class GlfwInputDevice; -} - -// Input.Glfw dependencies -#define GLFW_INCLUDE_NONE -#include -#include "NovelRT/PluginManagement/PluginManagement.h" -#include "NovelRT/Windowing/Glfw/Windowing.Glfw.h" -#include -#include - -// Input.Glfw types -#include "GlfwInputDevice.hpp" -#include "GlfwInputPluginProvider.hpp" - -#endif // NOVELRT_INPUT_GLFW_H diff --git a/input/include/NovelRT/Input/IInputDevice.hpp b/input/include/NovelRT/Input/IInputDevice.hpp index 0c8cfe334..e9ce81dc4 100644 --- a/input/include/NovelRT/Input/IInputDevice.hpp +++ b/input/include/NovelRT/Input/IInputDevice.hpp @@ -1,8 +1,17 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include -#ifndef NOVELRT_INPUT_IINPUTSERVICE_H -#define NOVELRT_INPUT_IINPUTSERVICE_H namespace NovelRT::Input { @@ -35,5 +44,3 @@ namespace NovelRT::Input virtual ~IInputDevice() = default; }; } - -#endif // NOVELRT_INPUT_IINPUTSERVICE_H diff --git a/input/include/NovelRT/Input/Input.hpp b/input/include/NovelRT/Input/Input.hpp deleted file mode 100644 index ddd57bd8f..000000000 --- a/input/include/NovelRT/Input/Input.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root -// for more information. - -#ifndef NOVELRT_INPUT_H -#define NOVELRT_INPUT_H - -// Input Dependencies -#include "NovelRT/LoggingService.h" -#include "NovelRT/Maths/Maths.h" -#include "NovelRT/Timing/Timestamp.h" -#include "NovelRT/Utilities/Misc.h" -#include "NovelRT/Windowing/Windowing.h" -#include -#include -#include - -/** - * @brief The input plugin API. - */ -namespace NovelRT::Input -{ - enum class KeyState; - class KeyStateFrameChangeLog; - class IInputDevice; - class NovelKey; - struct InputAction; -} - -// clang-format off -// Input Types -#include "KeyState.hpp" -#include "KeyStateFrameChangeLog.hpp" -#include "NovelKey.hpp" -#include "InputAction.hpp" -#include "IInputDevice.hpp" -// clang-format on - -#endif // NOVELRT_INPUT_H diff --git a/input/include/NovelRT/Input/InputAction.hpp b/input/include/NovelRT/Input/InputAction.hpp index 2277442c1..2d15118f2 100644 --- a/input/include/NovelRT/Input/InputAction.hpp +++ b/input/include/NovelRT/Input/InputAction.hpp @@ -1,8 +1,10 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. +#pragma once -#ifndef NOVELRT_INPUT_INPUTACTION_H -#define NOVELRT_INPUT_INPUTACTION_H +#include +#include +#include namespace NovelRT::Input { @@ -14,4 +16,3 @@ namespace NovelRT::Input }; } -#endif // NOVELRT_INPUT_INPUTACTION_H diff --git a/input/include/NovelRT/Input/KeyState.hpp b/input/include/NovelRT/Input/KeyState.hpp index 5d12d7c78..30a79e446 100644 --- a/input/include/NovelRT/Input/KeyState.hpp +++ b/input/include/NovelRT/Input/KeyState.hpp @@ -1,8 +1,8 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. +#pragma once -#ifndef NOVELRT_INPUT_KEYSTATE_H -#define NOVELRT_INPUT_KEYSTATE_H +#include namespace NovelRT::Input { @@ -18,4 +18,3 @@ namespace NovelRT::Input }; } -#endif // !NOVELRT_INPUT_KEYSTATE_H diff --git a/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp b/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp index b7d9c7064..5d8e6a13b 100644 --- a/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp +++ b/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp @@ -1,8 +1,9 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. +#pragma once -#ifndef NOVELRT_INPUT_KEYSTATEFRAMECHANGELOG_H -#define NOVELRT_INPUT_KEYSTATEFRAMECHANGELOG_H +#include +#include namespace NovelRT::Input { @@ -19,4 +20,4 @@ namespace NovelRT::Input uint32_t GetChangeCount() const noexcept; }; } -#endif //! NOVELRT_INPUT_KEYSTATEFRAMECHANGELOG_H + diff --git a/input/include/NovelRT/Input/NovelKey.hpp b/input/include/NovelRT/Input/NovelKey.hpp index 176f309ff..a97f4eb39 100644 --- a/input/include/NovelRT/Input/NovelKey.hpp +++ b/input/include/NovelRT/Input/NovelKey.hpp @@ -1,8 +1,9 @@ // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. +#pragma once -#ifndef NOVELRT_INPUT_NOVELKEY_H -#define NOVELRT_INPUT_NOVELKEY_H +#include +#include namespace NovelRT::Input { @@ -24,16 +25,5 @@ namespace NovelRT::Input return (_keyName == other.GetKeyName()) && (_pairedKey == other.GetExternalKeyCode()); }; }; - - inline bool operator==(NovelKey const& lhs, NovelKey const& rhs) noexcept - { - return lhs._pairedKey == rhs._pairedKey && (lhs._modifier == rhs._modifier) && lhs._keyName == rhs._keyName; - } - - inline bool operator!=(NovelKey const& lhs, NovelKey const& rhs) noexcept - { - return lhs._pairedKey != rhs._pairedKey || (lhs._modifier == rhs._modifier) || lhs._keyName == rhs._keyName; - } } -#endif // NOVELRT_INPUT_NOVELKEY_H diff --git a/src/NovelRT.Interop/Input/NrtIInputDevice.cpp b/src/NovelRT.Interop/Input/NrtIInputDevice.cpp index d29132323..081d2beb9 100644 --- a/src/NovelRT.Interop/Input/NrtIInputDevice.cpp +++ b/src/NovelRT.Interop/Input/NrtIInputDevice.cpp @@ -4,7 +4,7 @@ #include "../LifetimeExtender.h" #include #include -#include +#include using namespace NovelRT::Input; using namespace NovelRT::Interop; diff --git a/src/NovelRT.Interop/Input/NrtInputAction.cpp b/src/NovelRT.Interop/Input/NrtInputAction.cpp index 1200fb88b..b4e87e05a 100644 --- a/src/NovelRT.Interop/Input/NrtInputAction.cpp +++ b/src/NovelRT.Interop/Input/NrtInputAction.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include using namespace NovelRT::Input; diff --git a/src/NovelRT.Interop/Input/NrtNovelKey.cpp b/src/NovelRT.Interop/Input/NrtNovelKey.cpp index e0efe6795..fae812db6 100644 --- a/src/NovelRT.Interop/Input/NrtNovelKey.cpp +++ b/src/NovelRT.Interop/Input/NrtNovelKey.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include using namespace NovelRT::Input; diff --git a/src/NovelRT/PluginManagement/TemporaryFnPtrs.cpp b/src/NovelRT/PluginManagement/TemporaryFnPtrs.cpp index 1fc675c1c..b1e9b611a 100644 --- a/src/NovelRT/PluginManagement/TemporaryFnPtrs.cpp +++ b/src/NovelRT/PluginManagement/TemporaryFnPtrs.cpp @@ -2,7 +2,7 @@ // for more information. #include -#include +#include #include #include #include From 595f71386b12f11f747015aa284512cb37b4b495 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Tue, 7 Nov 2023 06:51:59 -0500 Subject: [PATCH 17/18] Addressed code review feedback, part 2 --- input/Glfw/GlfwInputDevice.cpp | 294 ++++++++++-------- .../NovelRT/Input/Glfw/GlfwInputDevice.hpp | 4 +- .../Input/Glfw/GlfwInputPluginProvider.hpp | 3 +- input/include/NovelRT/Input/IInputDevice.hpp | 3 +- input/include/NovelRT/Input/InputAction.hpp | 3 +- input/include/NovelRT/Input/KeyState.hpp | 3 +- .../NovelRT/Input/KeyStateFrameChangeLog.hpp | 3 +- input/include/NovelRT/Input/NovelKey.hpp | 3 +- 8 files changed, 176 insertions(+), 140 deletions(-) diff --git a/input/Glfw/GlfwInputDevice.cpp b/input/Glfw/GlfwInputDevice.cpp index 0e79a4543..4627ce5a8 100644 --- a/input/Glfw/GlfwInputDevice.cpp +++ b/input/Glfw/GlfwInputDevice.cpp @@ -48,138 +48,7 @@ namespace NovelRT::Input::Glfw ProcessCursorMovement(nativePos); }; -#pragma region KeyMapping - // Map GLFW keys to NovelKeys - _availableKeys.emplace("LeftMouseButton", NovelKey("LeftMouseButton", GLFW_MOUSE_BUTTON_LEFT)); - _availableKeys.emplace("RightMouseButton", NovelKey("RightMouseButton", GLFW_MOUSE_BUTTON_RIGHT)); - _availableKeys.emplace("MiddleMouseButton", NovelKey("MiddleMouseButton", GLFW_MOUSE_BUTTON_MIDDLE)); - - _availableKeys.emplace("Backspace", NovelKey("Backspace", GLFW_KEY_BACKSPACE)); - _availableKeys.emplace("Tab", NovelKey("Tab", GLFW_KEY_TAB)); - _availableKeys.emplace("Enter", NovelKey("Enter", GLFW_KEY_ENTER)); - _availableKeys.emplace("Pause", NovelKey("Pause", GLFW_KEY_PAUSE)); - - _availableKeys.emplace("Caps Lock", NovelKey("Caps Lock", GLFW_KEY_CAPS_LOCK)); - _availableKeys.emplace("Escape", NovelKey("Escape", GLFW_KEY_ESCAPE)); - _availableKeys.emplace("Space", NovelKey("Space", GLFW_KEY_SPACE)); - _availableKeys.emplace("Page Up", NovelKey("Page Up", GLFW_KEY_PAGE_UP)); - _availableKeys.emplace("Page Down", NovelKey("Page Down", GLFW_KEY_PAGE_DOWN)); - _availableKeys.emplace("End", NovelKey("End", GLFW_KEY_END)); - _availableKeys.emplace("Home", NovelKey("Home", GLFW_KEY_HOME)); - - _availableKeys.emplace("Left", NovelKey("Left", GLFW_KEY_LEFT)); - _availableKeys.emplace("Up", NovelKey("Up", GLFW_KEY_UP)); - _availableKeys.emplace("Right", NovelKey("Right", GLFW_KEY_RIGHT)); - _availableKeys.emplace("Down", NovelKey("Down", GLFW_KEY_DOWN)); - - _availableKeys.emplace("Insert", NovelKey("Insert", GLFW_KEY_INSERT)); - _availableKeys.emplace("Delete", NovelKey("Delete", GLFW_KEY_DELETE)); - - _availableKeys.emplace("~", NovelKey("~", GLFW_KEY_GRAVE_ACCENT)); - _availableKeys.emplace("0", NovelKey("0", GLFW_KEY_0)); - _availableKeys.emplace("1", NovelKey("1", GLFW_KEY_1)); - _availableKeys.emplace("2", NovelKey("2", GLFW_KEY_2)); - _availableKeys.emplace("3", NovelKey("3", GLFW_KEY_3)); - _availableKeys.emplace("4", NovelKey("4", GLFW_KEY_4)); - _availableKeys.emplace("5", NovelKey("5", GLFW_KEY_5)); - _availableKeys.emplace("6", NovelKey("6", GLFW_KEY_6)); - _availableKeys.emplace("7", NovelKey("7", GLFW_KEY_7)); - _availableKeys.emplace("8", NovelKey("8", GLFW_KEY_8)); - _availableKeys.emplace("9", NovelKey("9", GLFW_KEY_9)); - - _availableKeys.emplace("A", NovelKey("A", GLFW_KEY_A)); - _availableKeys.emplace("B", NovelKey("B", GLFW_KEY_B)); - _availableKeys.emplace("C", NovelKey("C", GLFW_KEY_C)); - _availableKeys.emplace("D", NovelKey("D", GLFW_KEY_D)); - _availableKeys.emplace("E", NovelKey("E", GLFW_KEY_E)); - _availableKeys.emplace("F", NovelKey("F", GLFW_KEY_F)); - _availableKeys.emplace("G", NovelKey("G", GLFW_KEY_G)); - _availableKeys.emplace("H", NovelKey("H", GLFW_KEY_H)); - _availableKeys.emplace("I", NovelKey("I", GLFW_KEY_I)); - _availableKeys.emplace("J", NovelKey("J", GLFW_KEY_J)); - _availableKeys.emplace("K", NovelKey("K", GLFW_KEY_K)); - _availableKeys.emplace("L", NovelKey("L", GLFW_KEY_L)); - _availableKeys.emplace("M", NovelKey("M", GLFW_KEY_M)); - _availableKeys.emplace("N", NovelKey("N", GLFW_KEY_N)); - _availableKeys.emplace("O", NovelKey("O", GLFW_KEY_O)); - _availableKeys.emplace("P", NovelKey("P", GLFW_KEY_P)); - _availableKeys.emplace("Q", NovelKey("Q", GLFW_KEY_Q)); - _availableKeys.emplace("R", NovelKey("R", GLFW_KEY_R)); - _availableKeys.emplace("S", NovelKey("S", GLFW_KEY_S)); - _availableKeys.emplace("T", NovelKey("T", GLFW_KEY_T)); - _availableKeys.emplace("U", NovelKey("U", GLFW_KEY_U)); - _availableKeys.emplace("V", NovelKey("V", GLFW_KEY_V)); - _availableKeys.emplace("W", NovelKey("W", GLFW_KEY_W)); - _availableKeys.emplace("X", NovelKey("X", GLFW_KEY_X)); - _availableKeys.emplace("Y", NovelKey("Y", GLFW_KEY_Y)); - _availableKeys.emplace("Z", NovelKey("Z", GLFW_KEY_Z)); - - _availableKeys.emplace("Keypad 0", NovelKey("Keypad 0", GLFW_KEY_KP_0)); - _availableKeys.emplace("Keypad 1", NovelKey("Keypad 1", GLFW_KEY_KP_1)); - _availableKeys.emplace("Keypad 2", NovelKey("Keypad 2", GLFW_KEY_KP_2)); - _availableKeys.emplace("Keypad 3", NovelKey("Keypad 3", GLFW_KEY_KP_3)); - _availableKeys.emplace("Keypad 4", NovelKey("Keypad 4", GLFW_KEY_KP_4)); - _availableKeys.emplace("Keypad 5", NovelKey("Keypad 5", GLFW_KEY_KP_5)); - _availableKeys.emplace("Keypad 6", NovelKey("Keypad 6", GLFW_KEY_KP_6)); - _availableKeys.emplace("Keypad 7", NovelKey("Keypad 7", GLFW_KEY_KP_7)); - _availableKeys.emplace("Keypad 8", NovelKey("Keypad 8", GLFW_KEY_KP_8)); - _availableKeys.emplace("Keypad 9", NovelKey("Keypad 9", GLFW_KEY_KP_9)); - - _availableKeys.emplace("Multiply", NovelKey("Multiply", GLFW_KEY_KP_MULTIPLY)); - _availableKeys.emplace("Add", NovelKey("Add", GLFW_KEY_KP_ADD)); - _availableKeys.emplace("Subtract", NovelKey("Subtract", GLFW_KEY_KP_SUBTRACT)); - _availableKeys.emplace("Decimal", NovelKey("Decimal", GLFW_KEY_KP_DECIMAL)); - _availableKeys.emplace("Divide", NovelKey("Divide", GLFW_KEY_KP_DIVIDE)); - - _availableKeys.emplace("F1", NovelKey("F1", GLFW_KEY_F1)); - _availableKeys.emplace("F2", NovelKey("F2", GLFW_KEY_F2)); - _availableKeys.emplace("F3", NovelKey("F3", GLFW_KEY_F3)); - _availableKeys.emplace("F4", NovelKey("F4", GLFW_KEY_F4)); - _availableKeys.emplace("F5", NovelKey("F5", GLFW_KEY_F5)); - _availableKeys.emplace("F6", NovelKey("F6", GLFW_KEY_F6)); - _availableKeys.emplace("F7", NovelKey("F7", GLFW_KEY_F7)); - _availableKeys.emplace("F8", NovelKey("F8", GLFW_KEY_F8)); - _availableKeys.emplace("F9", NovelKey("F9", GLFW_KEY_F9)); - _availableKeys.emplace("F10", NovelKey("F10", GLFW_KEY_F10)); - _availableKeys.emplace("F11", NovelKey("F11", GLFW_KEY_F11)); - _availableKeys.emplace("F12", NovelKey("F12", GLFW_KEY_F12)); - - _availableKeys.emplace("Num Lock", NovelKey("Num Lock", GLFW_KEY_NUM_LOCK)); - _availableKeys.emplace("Scroll Lock", NovelKey("Scroll Lock", GLFW_KEY_SCROLL_LOCK)); - - _availableKeys.emplace("Left Shift", NovelKey("Left Shift", GLFW_KEY_LEFT_SHIFT)); - _availableKeys.emplace("Right Shift", NovelKey("Right Shift", GLFW_KEY_RIGHT_SHIFT)); - _availableKeys.emplace("Left Control", NovelKey("Left Control", GLFW_KEY_LEFT_CONTROL)); - _availableKeys.emplace("Right Control", NovelKey("Right Control", GLFW_KEY_RIGHT_CONTROL)); - _availableKeys.emplace("Left Alt", NovelKey("Left Alt", GLFW_KEY_LEFT_ALT)); - _availableKeys.emplace("Right Alt", NovelKey("Right Alt", GLFW_KEY_RIGHT_ALT)); - _availableKeys.emplace("Left Super", NovelKey("Left Super", GLFW_KEY_LEFT_SUPER)); - _availableKeys.emplace("Right Super", NovelKey("Right Super", GLFW_KEY_RIGHT_SUPER)); - - _availableKeys.emplace("Semicolon", NovelKey("Semicolon", GLFW_KEY_SEMICOLON)); - _availableKeys.emplace("Equal", NovelKey("Equal", GLFW_KEY_EQUAL)); - _availableKeys.emplace("Comma", NovelKey("Comma", GLFW_KEY_COMMA)); - _availableKeys.emplace("Minus", NovelKey("Minus", GLFW_KEY_MINUS)); - _availableKeys.emplace("Period", NovelKey("Period", GLFW_KEY_PERIOD)); - _availableKeys.emplace("Slash", NovelKey("Slash", GLFW_KEY_SLASH)); - _availableKeys.emplace("Left Bracket", NovelKey("Left Bracket", GLFW_KEY_LEFT_BRACKET)); - _availableKeys.emplace("Backslash", NovelKey("Backslash", GLFW_KEY_BACKSLASH)); - _availableKeys.emplace("Right Bracket", NovelKey("Right Bracket", GLFW_KEY_RIGHT_BRACKET)); - _availableKeys.emplace("Apostrophe", NovelKey("Apostrophe", GLFW_KEY_APOSTROPHE)); - - _availableKeys.emplace("Ampersand", NovelKey("Ampersand", GLFW_KEY_7, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Asterisk", NovelKey("Asterisk", GLFW_KEY_8, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Caret", NovelKey("Caret", GLFW_KEY_6, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Colon", NovelKey("Colon", GLFW_KEY_SEMICOLON, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Dollar", NovelKey("Dollar", GLFW_KEY_4, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Exclamation", NovelKey("Exclamation", GLFW_KEY_1, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Left Brace", NovelKey("Left Brace", GLFW_KEY_LEFT_BRACKET, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Right Brace", NovelKey("Right Brace", GLFW_KEY_RIGHT_BRACKET, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Quote", NovelKey("Quote", GLFW_KEY_APOSTROPHE, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Underscore", NovelKey("Underscore", GLFW_KEY_MINUS, GLFW_MOD_SHIFT)); - _availableKeys.emplace("Tilde", NovelKey("Tilde", GLFW_KEY_GRAVE_ACCENT, GLFW_MOD_SHIFT)); -#pragma endregion KeyMapping - + MapAllGlfwKeysToNovelKeys(); _isInitialised = true; int32_t width = 0; @@ -222,7 +91,9 @@ namespace NovelRT::Input::Glfw for (auto& action : _mappedActions) { if (action.actionName != key) + { continue; + } auto externalKeyCode = action.pairedKey.GetExternalKeyCode(); @@ -244,14 +115,18 @@ namespace NovelRT::Input::Glfw for (auto& action : _mappedActions) { if (action.actionName != input) + { continue; + } auto key = action.pairedKey.GetExternalKeyCode(); auto& currentBuffer = _keyStates.at(_currentBufferIndex); for (auto& [currentKey, currentLog] : currentBuffer) { if (currentKey != key) + { continue; + } return currentLog.GetCurrentState() == KeyState::KeyDown; } @@ -266,14 +141,18 @@ namespace NovelRT::Input::Glfw for (auto& action : _mappedActions) { if (action.actionName != input) + { continue; + } auto key = action.pairedKey.GetExternalKeyCode(); auto& currentBuffer = _keyStates.at(_currentBufferIndex); for (auto& [currentKey, currentLog] : currentBuffer) { if (currentKey != key) + { continue; + } return currentLog.GetCurrentState() == KeyState::KeyDownHeld; } @@ -288,14 +167,18 @@ namespace NovelRT::Input::Glfw for (auto& action : _mappedActions) { if (action.actionName != input) + { continue; + } auto key = action.pairedKey.GetExternalKeyCode(); auto& currentBuffer = _keyStates.at(_currentBufferIndex); for (auto& [currentKey, currentLog] : currentBuffer) { if (currentKey != key) + { continue; + } return currentLog.GetCurrentState() == KeyState::KeyUp; } @@ -374,15 +257,18 @@ namespace NovelRT::Input::Glfw for (auto& mapped : _mappedActions) { if (mapped.pairedKey.GetExternalKeyCode() != key) + { continue; + } KeyStateFrameChangeLog log{}; bool mouseMod = false; for (auto& [currentKey, currentLog] : map) { if (currentKey != mapped.pairedKey.GetExternalKeyCode()) + { continue; - + } log = currentLog; if (currentKey == GLFW_MOUSE_BUTTON_LEFT || currentKey == GLFW_MOUSE_BUTTON_MIDDLE || currentKey == GLFW_MOUSE_BUTTON_RIGHT) @@ -442,6 +328,7 @@ namespace NovelRT::Input::Glfw switch (state) { case KeyState::KeyDown: + { if (previousStateResult == KeyState::KeyDown) { changeLogObject.PushNewState(KeyState::KeyDownHeld); @@ -451,13 +338,18 @@ namespace NovelRT::Input::Glfw changeLogObject.PushNewState(KeyState::KeyDown); } break; + } case KeyState::KeyDownHeld: case KeyState::KeyUp: + { changeLogObject.PushNewState((previousStateResult == KeyState::KeyUp) ? KeyState::Idle : state); break; + } case KeyState::Idle: default: + { break; + } } currentBuffer.insert_or_assign(key, changeLogObject); @@ -474,7 +366,9 @@ namespace NovelRT::Input::Glfw for (auto& action : _mappedActions) { if (action.actionName != key) + { continue; + } return _keyStates.at(_currentBufferIndex).at(action.pairedKey.GetExternalKeyCode()); } @@ -487,7 +381,9 @@ namespace NovelRT::Input::Glfw for (auto& action : _mappedActions) { if (action.actionName != key) + { continue; + } return _keyStates.at(_previousBufferIndex).at(action.pairedKey.GetExternalKeyCode()); } @@ -500,6 +396,138 @@ namespace NovelRT::Input::Glfw return _keyStates; } + void GlfwInputDevice::MapAllGlfwKeysToNovelKeys() + { + _availableKeys.emplace("LeftMouseButton", NovelKey("LeftMouseButton", GLFW_MOUSE_BUTTON_LEFT)); + _availableKeys.emplace("RightMouseButton", NovelKey("RightMouseButton", GLFW_MOUSE_BUTTON_RIGHT)); + _availableKeys.emplace("MiddleMouseButton", NovelKey("MiddleMouseButton", GLFW_MOUSE_BUTTON_MIDDLE)); + + _availableKeys.emplace("Backspace", NovelKey("Backspace", GLFW_KEY_BACKSPACE)); + _availableKeys.emplace("Tab", NovelKey("Tab", GLFW_KEY_TAB)); + _availableKeys.emplace("Enter", NovelKey("Enter", GLFW_KEY_ENTER)); + _availableKeys.emplace("Pause", NovelKey("Pause", GLFW_KEY_PAUSE)); + + _availableKeys.emplace("Caps Lock", NovelKey("Caps Lock", GLFW_KEY_CAPS_LOCK)); + _availableKeys.emplace("Escape", NovelKey("Escape", GLFW_KEY_ESCAPE)); + _availableKeys.emplace("Space", NovelKey("Space", GLFW_KEY_SPACE)); + _availableKeys.emplace("Page Up", NovelKey("Page Up", GLFW_KEY_PAGE_UP)); + _availableKeys.emplace("Page Down", NovelKey("Page Down", GLFW_KEY_PAGE_DOWN)); + _availableKeys.emplace("End", NovelKey("End", GLFW_KEY_END)); + _availableKeys.emplace("Home", NovelKey("Home", GLFW_KEY_HOME)); + + _availableKeys.emplace("Left", NovelKey("Left", GLFW_KEY_LEFT)); + _availableKeys.emplace("Up", NovelKey("Up", GLFW_KEY_UP)); + _availableKeys.emplace("Right", NovelKey("Right", GLFW_KEY_RIGHT)); + _availableKeys.emplace("Down", NovelKey("Down", GLFW_KEY_DOWN)); + + _availableKeys.emplace("Insert", NovelKey("Insert", GLFW_KEY_INSERT)); + _availableKeys.emplace("Delete", NovelKey("Delete", GLFW_KEY_DELETE)); + + _availableKeys.emplace("~", NovelKey("~", GLFW_KEY_GRAVE_ACCENT)); + _availableKeys.emplace("0", NovelKey("0", GLFW_KEY_0)); + _availableKeys.emplace("1", NovelKey("1", GLFW_KEY_1)); + _availableKeys.emplace("2", NovelKey("2", GLFW_KEY_2)); + _availableKeys.emplace("3", NovelKey("3", GLFW_KEY_3)); + _availableKeys.emplace("4", NovelKey("4", GLFW_KEY_4)); + _availableKeys.emplace("5", NovelKey("5", GLFW_KEY_5)); + _availableKeys.emplace("6", NovelKey("6", GLFW_KEY_6)); + _availableKeys.emplace("7", NovelKey("7", GLFW_KEY_7)); + _availableKeys.emplace("8", NovelKey("8", GLFW_KEY_8)); + _availableKeys.emplace("9", NovelKey("9", GLFW_KEY_9)); + + _availableKeys.emplace("A", NovelKey("A", GLFW_KEY_A)); + _availableKeys.emplace("B", NovelKey("B", GLFW_KEY_B)); + _availableKeys.emplace("C", NovelKey("C", GLFW_KEY_C)); + _availableKeys.emplace("D", NovelKey("D", GLFW_KEY_D)); + _availableKeys.emplace("E", NovelKey("E", GLFW_KEY_E)); + _availableKeys.emplace("F", NovelKey("F", GLFW_KEY_F)); + _availableKeys.emplace("G", NovelKey("G", GLFW_KEY_G)); + _availableKeys.emplace("H", NovelKey("H", GLFW_KEY_H)); + _availableKeys.emplace("I", NovelKey("I", GLFW_KEY_I)); + _availableKeys.emplace("J", NovelKey("J", GLFW_KEY_J)); + _availableKeys.emplace("K", NovelKey("K", GLFW_KEY_K)); + _availableKeys.emplace("L", NovelKey("L", GLFW_KEY_L)); + _availableKeys.emplace("M", NovelKey("M", GLFW_KEY_M)); + _availableKeys.emplace("N", NovelKey("N", GLFW_KEY_N)); + _availableKeys.emplace("O", NovelKey("O", GLFW_KEY_O)); + _availableKeys.emplace("P", NovelKey("P", GLFW_KEY_P)); + _availableKeys.emplace("Q", NovelKey("Q", GLFW_KEY_Q)); + _availableKeys.emplace("R", NovelKey("R", GLFW_KEY_R)); + _availableKeys.emplace("S", NovelKey("S", GLFW_KEY_S)); + _availableKeys.emplace("T", NovelKey("T", GLFW_KEY_T)); + _availableKeys.emplace("U", NovelKey("U", GLFW_KEY_U)); + _availableKeys.emplace("V", NovelKey("V", GLFW_KEY_V)); + _availableKeys.emplace("W", NovelKey("W", GLFW_KEY_W)); + _availableKeys.emplace("X", NovelKey("X", GLFW_KEY_X)); + _availableKeys.emplace("Y", NovelKey("Y", GLFW_KEY_Y)); + _availableKeys.emplace("Z", NovelKey("Z", GLFW_KEY_Z)); + + _availableKeys.emplace("Keypad 0", NovelKey("Keypad 0", GLFW_KEY_KP_0)); + _availableKeys.emplace("Keypad 1", NovelKey("Keypad 1", GLFW_KEY_KP_1)); + _availableKeys.emplace("Keypad 2", NovelKey("Keypad 2", GLFW_KEY_KP_2)); + _availableKeys.emplace("Keypad 3", NovelKey("Keypad 3", GLFW_KEY_KP_3)); + _availableKeys.emplace("Keypad 4", NovelKey("Keypad 4", GLFW_KEY_KP_4)); + _availableKeys.emplace("Keypad 5", NovelKey("Keypad 5", GLFW_KEY_KP_5)); + _availableKeys.emplace("Keypad 6", NovelKey("Keypad 6", GLFW_KEY_KP_6)); + _availableKeys.emplace("Keypad 7", NovelKey("Keypad 7", GLFW_KEY_KP_7)); + _availableKeys.emplace("Keypad 8", NovelKey("Keypad 8", GLFW_KEY_KP_8)); + _availableKeys.emplace("Keypad 9", NovelKey("Keypad 9", GLFW_KEY_KP_9)); + + _availableKeys.emplace("Multiply", NovelKey("Multiply", GLFW_KEY_KP_MULTIPLY)); + _availableKeys.emplace("Add", NovelKey("Add", GLFW_KEY_KP_ADD)); + _availableKeys.emplace("Subtract", NovelKey("Subtract", GLFW_KEY_KP_SUBTRACT)); + _availableKeys.emplace("Decimal", NovelKey("Decimal", GLFW_KEY_KP_DECIMAL)); + _availableKeys.emplace("Divide", NovelKey("Divide", GLFW_KEY_KP_DIVIDE)); + + _availableKeys.emplace("F1", NovelKey("F1", GLFW_KEY_F1)); + _availableKeys.emplace("F2", NovelKey("F2", GLFW_KEY_F2)); + _availableKeys.emplace("F3", NovelKey("F3", GLFW_KEY_F3)); + _availableKeys.emplace("F4", NovelKey("F4", GLFW_KEY_F4)); + _availableKeys.emplace("F5", NovelKey("F5", GLFW_KEY_F5)); + _availableKeys.emplace("F6", NovelKey("F6", GLFW_KEY_F6)); + _availableKeys.emplace("F7", NovelKey("F7", GLFW_KEY_F7)); + _availableKeys.emplace("F8", NovelKey("F8", GLFW_KEY_F8)); + _availableKeys.emplace("F9", NovelKey("F9", GLFW_KEY_F9)); + _availableKeys.emplace("F10", NovelKey("F10", GLFW_KEY_F10)); + _availableKeys.emplace("F11", NovelKey("F11", GLFW_KEY_F11)); + _availableKeys.emplace("F12", NovelKey("F12", GLFW_KEY_F12)); + + _availableKeys.emplace("Num Lock", NovelKey("Num Lock", GLFW_KEY_NUM_LOCK)); + _availableKeys.emplace("Scroll Lock", NovelKey("Scroll Lock", GLFW_KEY_SCROLL_LOCK)); + + _availableKeys.emplace("Left Shift", NovelKey("Left Shift", GLFW_KEY_LEFT_SHIFT)); + _availableKeys.emplace("Right Shift", NovelKey("Right Shift", GLFW_KEY_RIGHT_SHIFT)); + _availableKeys.emplace("Left Control", NovelKey("Left Control", GLFW_KEY_LEFT_CONTROL)); + _availableKeys.emplace("Right Control", NovelKey("Right Control", GLFW_KEY_RIGHT_CONTROL)); + _availableKeys.emplace("Left Alt", NovelKey("Left Alt", GLFW_KEY_LEFT_ALT)); + _availableKeys.emplace("Right Alt", NovelKey("Right Alt", GLFW_KEY_RIGHT_ALT)); + _availableKeys.emplace("Left Super", NovelKey("Left Super", GLFW_KEY_LEFT_SUPER)); + _availableKeys.emplace("Right Super", NovelKey("Right Super", GLFW_KEY_RIGHT_SUPER)); + + _availableKeys.emplace("Semicolon", NovelKey("Semicolon", GLFW_KEY_SEMICOLON)); + _availableKeys.emplace("Equal", NovelKey("Equal", GLFW_KEY_EQUAL)); + _availableKeys.emplace("Comma", NovelKey("Comma", GLFW_KEY_COMMA)); + _availableKeys.emplace("Minus", NovelKey("Minus", GLFW_KEY_MINUS)); + _availableKeys.emplace("Period", NovelKey("Period", GLFW_KEY_PERIOD)); + _availableKeys.emplace("Slash", NovelKey("Slash", GLFW_KEY_SLASH)); + _availableKeys.emplace("Left Bracket", NovelKey("Left Bracket", GLFW_KEY_LEFT_BRACKET)); + _availableKeys.emplace("Backslash", NovelKey("Backslash", GLFW_KEY_BACKSLASH)); + _availableKeys.emplace("Right Bracket", NovelKey("Right Bracket", GLFW_KEY_RIGHT_BRACKET)); + _availableKeys.emplace("Apostrophe", NovelKey("Apostrophe", GLFW_KEY_APOSTROPHE)); + + _availableKeys.emplace("Ampersand", NovelKey("Ampersand", GLFW_KEY_7, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Asterisk", NovelKey("Asterisk", GLFW_KEY_8, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Caret", NovelKey("Caret", GLFW_KEY_6, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Colon", NovelKey("Colon", GLFW_KEY_SEMICOLON, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Dollar", NovelKey("Dollar", GLFW_KEY_4, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Exclamation", NovelKey("Exclamation", GLFW_KEY_1, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Left Brace", NovelKey("Left Brace", GLFW_KEY_LEFT_BRACKET, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Right Brace", NovelKey("Right Brace", GLFW_KEY_RIGHT_BRACKET, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Quote", NovelKey("Quote", GLFW_KEY_APOSTROPHE, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Underscore", NovelKey("Underscore", GLFW_KEY_MINUS, GLFW_MOD_SHIFT)); + _availableKeys.emplace("Tilde", NovelKey("Tilde", GLFW_KEY_GRAVE_ACCENT, GLFW_MOD_SHIFT)); + } + GlfwInputDevice::~GlfwInputDevice() { } diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp index 82f7302cc..62d928b3e 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputDevice.hpp @@ -1,6 +1,7 @@ +#pragma once // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#pragma once + #include #include @@ -30,6 +31,7 @@ namespace NovelRT::Input::Glfw void ProcessCursorMovement(NovelRT::Maths::GeoVector2F& pos); void ProcessKeyState(int32_t action, KeyState state); NovelRT::Maths::GeoVector2F DetermineMouseScreenPosition(NovelRT::Maths::GeoVector2F& pos); + void MapAllGlfwKeysToNovelKeys(); public: GlfwInputDevice() noexcept; diff --git a/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp b/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp index 4aaee9369..29b858fcf 100644 --- a/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp +++ b/input/include/NovelRT/Input/Glfw/GlfwInputPluginProvider.hpp @@ -1,6 +1,7 @@ +#pragma once // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#pragma once + #include #include diff --git a/input/include/NovelRT/Input/IInputDevice.hpp b/input/include/NovelRT/Input/IInputDevice.hpp index e9ce81dc4..0d2b4c9c0 100644 --- a/input/include/NovelRT/Input/IInputDevice.hpp +++ b/input/include/NovelRT/Input/IInputDevice.hpp @@ -1,6 +1,7 @@ +#pragma once // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#pragma once + #include #include diff --git a/input/include/NovelRT/Input/InputAction.hpp b/input/include/NovelRT/Input/InputAction.hpp index 2d15118f2..bc981152b 100644 --- a/input/include/NovelRT/Input/InputAction.hpp +++ b/input/include/NovelRT/Input/InputAction.hpp @@ -1,6 +1,7 @@ +#pragma once // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#pragma once + #include #include diff --git a/input/include/NovelRT/Input/KeyState.hpp b/input/include/NovelRT/Input/KeyState.hpp index 30a79e446..0fbc3ded0 100644 --- a/input/include/NovelRT/Input/KeyState.hpp +++ b/input/include/NovelRT/Input/KeyState.hpp @@ -1,6 +1,7 @@ +#pragma once // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#pragma once + #include diff --git a/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp b/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp index 5d8e6a13b..60b32fa6a 100644 --- a/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp +++ b/input/include/NovelRT/Input/KeyStateFrameChangeLog.hpp @@ -1,6 +1,7 @@ +#pragma once // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#pragma once + #include #include diff --git a/input/include/NovelRT/Input/NovelKey.hpp b/input/include/NovelRT/Input/NovelKey.hpp index a97f4eb39..68252e931 100644 --- a/input/include/NovelRT/Input/NovelKey.hpp +++ b/input/include/NovelRT/Input/NovelKey.hpp @@ -1,6 +1,7 @@ +#pragma once // Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root // for more information. -#pragma once + #include #include From b68dddaa56d7706ee8fef47d0dd12b155a403b1a Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Tue, 7 Nov 2023 14:04:46 -0500 Subject: [PATCH 18/18] Update build-system.yml for perms (Test action fix) --- .github/workflows/build-system.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-system.yml b/.github/workflows/build-system.yml index 76bf690da..51a43c437 100644 --- a/.github/workflows/build-system.yml +++ b/.github/workflows/build-system.yml @@ -89,6 +89,7 @@ jobs: runs-on: ubuntu-latest permissions: checks: write + pull-requests: write if: always() steps: