VR-Engage  2.3
Loading...
Searching...
No Matches
inputLogic.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file inputLogic.h
7//! \brief Defines the DtInputLogic class for handling input in VR-Engage
8//!
9//! This file contains the DtInputLogic class which provides a layer of abstraction
10//! for handling user input in VR-Engage. It manages the loading and unloading of
11//! input configuration files, and the registration and removal of action handlers
12//! for responding to input events.
13
14#pragma once
15
17
19
20#include "vreUtil/attribute.h"
21
23
24#include <string>
25#include <unordered_map>
26
27namespace makVre
28{
29//! \brief Class for managing input configuration and handling in VR-Engage
30//!
31//! DtInputLogic provides a centralized mechanism for managing input configurations
32//! and handling input events in VR-Engage. It allows loading input mapping configurations,
33//! registering callback functions for specific actions, and managing raw input handlers.
34//!
35//! Input is organized into groups, which can be loaded, enabled, and disabled as units.
36//! This allows different parts of the application to manage their own input requirements
37//! without interfering with each other.
39{
40public:
41 //! \brief Constructor
42 //!
43 //! Creates a new input logic handler with no configurations loaded.
45
46 //! \brief Virtual destructor
47 //!
48 //! Ensures proper cleanup of derived input logic handlers.
49 virtual ~DtInputLogic();
50
51 //! \brief Initializes the input logic system
52 //!
53 //! Sets up the input manager and prepares the system for input handling.
54 //! This should be called before any other input logic methods.
55 virtual void initialize();
56
57 //! \brief Shuts down the input logic system
58 //!
59 //! Removes all loaded input mappings and action callbacks from the input manager.
60 //! This should be called when the system is no longer needed to properly
61 //! clean up resources and prevent callback execution after destruction.
62 virtual void shutdown();
63
64 //! \brief Loads input mappings from a configuration file
65 //! \param config Name of the configuration file to load
66 //! \param group Name of the group to associate with these mappings
67 //! \param alwaysOnTop Whether these mappings should always be at the top of the priority stack
68 //! \param alwaysEnabled Whether these mappings should always be enabled
69 //! \return True if the configuration was loaded successfully, false otherwise
70 //!
71 //! Loads mappings from the specified configuration file into the input manager,
72 //! associating them with the given group name. The alwaysOnTop and alwaysEnabled
73 //! parameters control the priority and activation state of the mappings.
74 virtual bool loadInputConfig(
75 const std::string& config, const std::string& group, bool alwaysOnTop = false, bool alwaysEnabled = false);
76
77 //! \brief Removes previously loaded input mappings
78 //! \param category Name of the mapping category to unload
79 //! \param group Name of the group to unload
80 //!
81 //! Removes input mappings previously loaded from the specified category and group.
82 //! This will prevent the mappings from triggering actions but does not remove
83 //! the action handlers themselves.
84 virtual void unloadInputConfig(const std::string& category, const std::string& group);
85
86 //! \brief Registers a callback function to handle an input-triggered action
87 //! \param group Name of the group to associate this handler with
88 //! \param action Name of the action to handle
89 //! \param handler Delegate function to call when the action is triggered
90 //!
91 //! Registers a callback function that will be called when the specified action
92 //! is triggered by user input. The handler is associated with the given group,
93 //! allowing for management of related action handlers as a unit.
94 virtual void addActionHandler(const std::string& group, const std::string& action, const DtActionDelegate& handler);
95
96 //! \brief Removes all action handlers in a group
97 //! \param group Name of the group to remove
98 //!
99 //! Removes all action handlers associated with the specified group.
100 //! This is useful for cleaning up handlers when a component is being disabled
101 //! or destroyed.
102 virtual void removeActionGroup(const std::string& group);
103
104 //! \brief Sets a handler for raw input events
105 //! \param inputDelegate Delegate function to call for raw input events
106 //!
107 //! Sets a function to receive all raw input events before they are processed
108 //! by the normal action system. This allows for custom input handling beyond
109 //! the configured actions.
110 virtual void setRawInputHandler(const DtInputDelegate& inputDelegate);
111
112 //! \brief Removes the current raw input handler
113 //!
114 //! Removes any previously set raw input handler, stopping the delivery
115 //! of raw input events to the handler function.
116 virtual void removeRawInputHandler();
117
118 //! \brief Unregisters a specific action callback
119 //! \param group Name of the group containing the action
120 //! \param action Name of the action to remove the handler for
121 //!
122 //! Removes the callback function for the specified action within the given group.
123 //! After removal, the action will no longer trigger the callback.
124 virtual void removeActionHandler(const std::string& group, const std::string& action);
125
126protected:
127 //! \brief Pointer to the VR-Engage input manager
129
130 //! \brief List of loaded input configurations (category, group pairs)
131 std::vector<std::pair<std::string, std::string>> myInputConfigurations;
132
133 //! \brief Map of action groups to lists of action names
134 std::unordered_map<std::string, std::vector<std::string>> myActionGroups;
135
136 //! \brief Flag indicating whether raw input handling is active
138
139 //! \brief Member-scope instance of Attribute callback manager
140 //!
141 //! Used to manage Attribute change callback connections and ensure that all
142 //! callbacks are unregistered when this class instance is destroyed.
144
145 //! \brief Member-scope instance of VreMessageHandlerGroup
146 //!
147 //! Used to manage message handler connections and ensure that all handlers
148 //! are disconnected when this class instance is destroyed.
150};
151
152} // namespace makVre
Provides attribute handling system for hierarchical data storage and manipulation.
Convenience manager that owns and organises a collection of attribute callbacks.
Definition attributeCallback.h:223
std::vector< std::pair< std::string, std::string > > myInputConfigurations
List of loaded input configurations (category, group pairs)
Definition inputLogic.h:131
virtual void initialize()
Initializes the input logic system.
virtual void setRawInputHandler(const DtInputDelegate &inputDelegate)
Sets a handler for raw input events.
virtual void addActionHandler(const std::string &group, const std::string &action, const DtActionDelegate &handler)
Registers a callback function to handle an input-triggered action.
virtual void removeActionGroup(const std::string &group)
Removes all action handlers in a group.
DtInputLogic()
Constructor.
virtual void removeActionHandler(const std::string &group, const std::string &action)
Unregisters a specific action callback.
virtual void shutdown()
Shuts down the input logic system.
virtual void unloadInputConfig(const std::string &category, const std::string &group)
Removes previously loaded input mappings.
virtual ~DtInputLogic()
Virtual destructor.
std::unordered_map< std::string, std::vector< std::string > > myActionGroups
Map of action groups to lists of action names.
Definition inputLogic.h:134
bool myHandlingRawInput
Flag indicating whether raw input handling is active.
Definition inputLogic.h:137
DtVreMessageHandlerGroup myMessageHandlers
Member-scope instance of VreMessageHandlerGroup.
Definition inputLogic.h:149
virtual void removeRawInputHandler()
Removes the current raw input handler.
virtual bool loadInputConfig(const std::string &config, const std::string &group, bool alwaysOnTop=false, bool alwaysEnabled=false)
Loads input mappings from a configuration file.
DtVreInputManager * myInputManager
Pointer to the VR-Engage input manager.
Definition inputLogic.h:128
DtAttributeCallbackManager myAttributeCallbacks
Member-scope instance of Attribute callback manager.
Definition inputLogic.h:143
Central manager for input device handling, action mapping, and input processing.
Definition vreInputManager.h:81
Manager class for connecting message handlers to message types.
Definition vreMessageManager.h:292
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
!
Definition glsVreMessageUtil.h:50
DtDelegate< void, float > DtActionDelegate
Delegate type for handling action events.
Definition vreInputManager.h:66
DtDelegate< bool, const DtInputData & > DtInputDelegate
Delegate type for handling raw input data events.
Definition vreInputManager.h:73
Defines the central message manager for the VREngage messaging system.
Input management system for handling device input and action mapping.