diff --git a/OpenTESArena/src/Game/Game.h b/OpenTESArena/src/Game/Game.h index cfb28a234..a1a5757e0 100644 --- a/OpenTESArena/src/Game/Game.h +++ b/OpenTESArena/src/Game/Game.h @@ -75,7 +75,7 @@ class Game bool shouldRenderScene; private: // Listener IDs are optional in case of failed Game construction. - std::optional applicationExitListenerID, windowResizedListenerID, + std::optional applicationExitListenerID, windowResizedListenerID, renderTargetsResetListenerID, takeScreenshotListenerID, debugProfilerListenerID; bool requestedSubPanelPop; diff --git a/OpenTESArena/src/Input/InputManager.cpp b/OpenTESArena/src/Input/InputManager.cpp index 62e112e0b..2468b500a 100644 --- a/OpenTESArena/src/Input/InputManager.cpp +++ b/OpenTESArena/src/Input/InputManager.cpp @@ -286,9 +286,9 @@ bool InputManager::isTextInput(const SDL_Event &e) const return e.type == SDL_TEXTINPUT; } -InputManager::ListenerID InputManager::getNextListenerID() +InputListenerID InputManager::getNextListenerID() { - ListenerID listenerID; + InputListenerID listenerID; if (!this->freedListenerIDs.empty()) { listenerID = this->freedListenerIDs.back(); @@ -336,8 +336,8 @@ bool InputManager::setInputActionMapActive(const std::string &name, bool active) } } -template -InputManager::ListenerID InputManager::addListenerInternal(CallbackType &&callback, ListenerType listenerType, +template +InputListenerID InputManager::addListenerInternal(CallbackType &&callback, ListenerType listenerType, std::vector &listeners, std::vector &freedListenerIndices) { int insertIndex; @@ -356,7 +356,7 @@ InputManager::ListenerID InputManager::addListenerInternal(CallbackType &&callba EntryType &listenerEntry = listeners[insertIndex]; listenerEntry.init(callback); - const ListenerID listenerID = this->getNextListenerID(); + const InputListenerID listenerID = this->getNextListenerID(); ListenerLookupEntry lookupEntry; lookupEntry.init(listenerType, insertIndex); @@ -365,8 +365,7 @@ InputManager::ListenerID InputManager::addListenerInternal(CallbackType &&callba return listenerID; } -InputManager::ListenerID InputManager::addInputActionListener(const std::string_view actionName, - const InputActionCallback &callback) +InputListenerID InputManager::addInputActionListener(const std::string_view actionName, const InputActionCallback &callback) { int insertIndex; if (!this->freedInputActionListenerIndices.empty()) @@ -384,7 +383,7 @@ InputManager::ListenerID InputManager::addInputActionListener(const std::string_ InputActionListenerEntry &listenerEntry = this->inputActionListeners[insertIndex]; listenerEntry.init(actionName, callback); - const ListenerID listenerID = this->getNextListenerID(); + const InputListenerID listenerID = this->getNextListenerID(); ListenerLookupEntry lookupEntry; lookupEntry.init(ListenerType::InputAction, insertIndex); @@ -393,49 +392,49 @@ InputManager::ListenerID InputManager::addInputActionListener(const std::string_ return listenerID; } -InputManager::ListenerID InputManager::addMouseButtonChangedListener(const MouseButtonChangedCallback &callback) +InputListenerID InputManager::addMouseButtonChangedListener(const MouseButtonChangedCallback &callback) { return this->addListenerInternal(callback, ListenerType::MouseButtonChanged, this->mouseButtonChangedListeners, this->freedMouseButtonChangedListenerIndices); } -InputManager::ListenerID InputManager::addMouseButtonHeldListener(const MouseButtonHeldCallback &callback) +InputListenerID InputManager::addMouseButtonHeldListener(const MouseButtonHeldCallback &callback) { return this->addListenerInternal(callback, ListenerType::MouseButtonHeld, this->mouseButtonHeldListeners, this->freedMouseButtonHeldListenerIndices); } -InputManager::ListenerID InputManager::addMouseScrollChangedListener(const MouseScrollChangedCallback &callback) +InputListenerID InputManager::addMouseScrollChangedListener(const MouseScrollChangedCallback &callback) { return this->addListenerInternal(callback, ListenerType::MouseScrollChanged, this->mouseScrollChangedListeners, this->freedMouseScrollChangedListenerIndices); } -InputManager::ListenerID InputManager::addMouseMotionListener(const MouseMotionCallback &callback) +InputListenerID InputManager::addMouseMotionListener(const MouseMotionCallback &callback) { return this->addListenerInternal(callback, ListenerType::MouseMotion, this->mouseMotionListeners, this->freedMouseMotionListenerIndices); } -InputManager::ListenerID InputManager::addApplicationExitListener(const ApplicationExitCallback &callback) +InputListenerID InputManager::addApplicationExitListener(const ApplicationExitCallback &callback) { return this->addListenerInternal(callback, ListenerType::ApplicationExit, this->applicationExitListeners, this->freedApplicationExitListenerIndices); } -InputManager::ListenerID InputManager::addWindowResizedListener(const WindowResizedCallback &callback) +InputListenerID InputManager::addWindowResizedListener(const WindowResizedCallback &callback) { return this->addListenerInternal(callback, ListenerType::WindowResized, this->windowResizedListeners, this->freedWindowResizedListenerIndices); } -InputManager::ListenerID InputManager::addRenderTargetsResetListener(const RenderTargetsResetCallback &callback) +InputListenerID InputManager::addRenderTargetsResetListener(const RenderTargetsResetCallback &callback) { return this->addListenerInternal(callback, ListenerType::RenderTargetsReset, this->renderTargetsResetListeners, this->freedRenderTargetsResetListenerIndices); } -InputManager::ListenerID InputManager::addTextInputListener(const TextInputCallback &callback) +InputListenerID InputManager::addTextInputListener(const TextInputCallback &callback) { return this->addListenerInternal(callback, ListenerType::TextInput, this->textInputListeners, this->freedTextInputListenerIndices); @@ -453,7 +452,7 @@ void InputManager::setTextInputMode(bool active) } } -void InputManager::removeListener(ListenerID id) +void InputManager::removeListener(InputListenerID id) { auto resetListenerEntry = [](auto &listeners, auto &freedIndices, int removeIndex) { @@ -524,7 +523,7 @@ void InputManager::removeListener(ListenerID id) } } -void InputManager::setListenerEnabled(ListenerID id, bool enabled) +void InputManager::setListenerEnabled(InputListenerID id, bool enabled) { const auto iter = this->listenerLookupEntries.find(id); if (iter == this->listenerLookupEntries.end()) diff --git a/OpenTESArena/src/Input/InputManager.h b/OpenTESArena/src/Input/InputManager.h index 44212fed9..932d68367 100644 --- a/OpenTESArena/src/Input/InputManager.h +++ b/OpenTESArena/src/Input/InputManager.h @@ -21,11 +21,11 @@ struct ButtonProxy; +using InputListenerID = int; + // Handles active input action maps, input listeners, and pointer input events. class InputManager { -public: - using ListenerID = int; private: enum class ListenerType { @@ -145,7 +145,7 @@ class InputManager std::vector textInputListeners; // Look-up values for valid listener entries, shared by all listener containers. - std::unordered_map listenerLookupEntries; + std::unordered_map listenerLookupEntries; // Indices to listener entries that were used but can be reclaimed by a future registration. std::vector freedInputActionListenerIndices; @@ -158,17 +158,17 @@ class InputManager std::vector freedRenderTargetsResetListenerIndices; std::vector freedTextInputListenerIndices; - ListenerID nextListenerID; - std::vector freedListenerIDs; + InputListenerID nextListenerID; + std::vector freedListenerIDs; Int2 mouseDelta; - ListenerID getNextListenerID(); + InputListenerID getNextListenerID(); bool isInTextEntryMode() const; template - ListenerID addListenerInternal(CallbackType &&callback, ListenerType listenerType, std::vector &listeners, + InputListenerID addListenerInternal(CallbackType &&callback, ListenerType listenerType, std::vector &listeners, std::vector &freedListenerIndices); void handleHeldInputs(Game &game, BufferView activeMaps, @@ -203,20 +203,20 @@ class InputManager bool setInputActionMapActive(const std::string &name, bool active); - ListenerID addInputActionListener(const std::string_view actionName, const InputActionCallback &callback); - ListenerID addMouseButtonChangedListener(const MouseButtonChangedCallback &callback); - ListenerID addMouseButtonHeldListener(const MouseButtonHeldCallback &callback); - ListenerID addMouseScrollChangedListener(const MouseScrollChangedCallback &callback); - ListenerID addMouseMotionListener(const MouseMotionCallback &callback); - ListenerID addApplicationExitListener(const ApplicationExitCallback &callback); - ListenerID addWindowResizedListener(const WindowResizedCallback &callback); - ListenerID addRenderTargetsResetListener(const RenderTargetsResetCallback &callback); - ListenerID addTextInputListener(const TextInputCallback &callback); + InputListenerID addInputActionListener(const std::string_view actionName, const InputActionCallback &callback); + InputListenerID addMouseButtonChangedListener(const MouseButtonChangedCallback &callback); + InputListenerID addMouseButtonHeldListener(const MouseButtonHeldCallback &callback); + InputListenerID addMouseScrollChangedListener(const MouseScrollChangedCallback &callback); + InputListenerID addMouseMotionListener(const MouseMotionCallback &callback); + InputListenerID addApplicationExitListener(const ApplicationExitCallback &callback); + InputListenerID addWindowResizedListener(const WindowResizedCallback &callback); + InputListenerID addRenderTargetsResetListener(const RenderTargetsResetCallback &callback); + InputListenerID addTextInputListener(const TextInputCallback &callback); - void removeListener(ListenerID id); + void removeListener(InputListenerID id); // Sets whether a valid listener can hear input callbacks. - void setListenerEnabled(ListenerID id, bool enabled); + void setListenerEnabled(InputListenerID id, bool enabled); // Sets whether the mouse should move during motion events (for player camera). void setRelativeMouseMode(bool active); diff --git a/OpenTESArena/src/Interface/Panel.cpp b/OpenTESArena/src/Interface/Panel.cpp index d54bef832..24f8fec16 100755 --- a/OpenTESArena/src/Interface/Panel.cpp +++ b/OpenTESArena/src/Interface/Panel.cpp @@ -32,32 +32,32 @@ Panel::~Panel() InputManager &inputManager = this->game.inputManager; // Free all the input listener IDs. - for (const InputManager::ListenerID listenerID : this->inputActionListenerIDs) + for (const InputListenerID listenerID : this->inputActionListenerIDs) { inputManager.removeListener(listenerID); } - for (const InputManager::ListenerID listenerID : this->mouseButtonChangedListenerIDs) + for (const InputListenerID listenerID : this->mouseButtonChangedListenerIDs) { inputManager.removeListener(listenerID); } - for (const InputManager::ListenerID listenerID : this->mouseButtonHeldListenerIDs) + for (const InputListenerID listenerID : this->mouseButtonHeldListenerIDs) { inputManager.removeListener(listenerID); } - for (const InputManager::ListenerID listenerID : this->mouseScrollChangedListenerIDs) + for (const InputListenerID listenerID : this->mouseScrollChangedListenerIDs) { inputManager.removeListener(listenerID); } - for (const InputManager::ListenerID listenerID : this->mouseMotionListenerIDs) + for (const InputListenerID listenerID : this->mouseMotionListenerIDs) { inputManager.removeListener(listenerID); } - for (const InputManager::ListenerID listenerID : this->textInputListenerIDs) + for (const InputListenerID listenerID : this->textInputListenerIDs) { inputManager.removeListener(listenerID); } @@ -78,9 +78,9 @@ void Panel::onPauseChanged(bool paused) this->paused = paused; InputManager &inputManager = this->game.inputManager; - auto setListenersEnabled = [paused, &inputManager](std::vector &listenerIDs) + auto setListenersEnabled = [paused, &inputManager](std::vector &listenerIDs) { - for (const InputManager::ListenerID listenerID : listenerIDs) + for (const InputListenerID listenerID : listenerIDs) { inputManager.setListenerEnabled(listenerID, !paused); } diff --git a/OpenTESArena/src/Interface/Panel.h b/OpenTESArena/src/Interface/Panel.h index bd16367f6..d72bf9aa7 100755 --- a/OpenTESArena/src/Interface/Panel.h +++ b/OpenTESArena/src/Interface/Panel.h @@ -37,12 +37,12 @@ class Panel Game &game; // Allocated input listener IDs that must be freed when the panel is done with them. - std::vector inputActionListenerIDs; - std::vector mouseButtonChangedListenerIDs; - std::vector mouseButtonHeldListenerIDs; - std::vector mouseScrollChangedListenerIDs; - std::vector mouseMotionListenerIDs; - std::vector textInputListenerIDs; + std::vector inputActionListenerIDs; + std::vector mouseButtonChangedListenerIDs; + std::vector mouseButtonHeldListenerIDs; + std::vector mouseScrollChangedListenerIDs; + std::vector mouseMotionListenerIDs; + std::vector textInputListenerIDs; std::vector buttonProxies;