VR-Engage  2.2
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 <string>
21#include <unordered_map>
22
23namespace makVre
24{
25//! \brief Class for managing input configuration and handling in VR-Engage
26//!
27//! DtInputLogic provides a centralized mechanism for managing input configurations
28//! and handling input events in VR-Engage. It allows loading input mapping configurations,
29//! registering callback functions for specific actions, and managing raw input handlers.
30//!
31//! Input is organized into groups, which can be loaded, enabled, and disabled as units.
32//! This allows different parts of the application to manage their own input requirements
33//! without interfering with each other.
35{
36public:
37 //! \brief Constructor
38 //!
39 //! Creates a new input logic handler with no configurations loaded.
41
42 //! \brief Virtual destructor
43 //!
44 //! Ensures proper cleanup of derived input logic handlers.
45 virtual ~DtInputLogic();
46
47 //! \brief Initializes the input logic system
48 //!
49 //! Sets up the input manager and prepares the system for input handling.
50 //! This should be called before any other input logic methods.
51 virtual void initialize();
52
53 //! \brief Shuts down the input logic system
54 //!
55 //! Removes all loaded input mappings and action callbacks from the input manager.
56 //! This should be called when the system is no longer needed to properly
57 //! clean up resources and prevent callback execution after destruction.
58 virtual void shutdown();
59
60 //! \brief Loads input mappings from a configuration file
61 //! \param config Name of the configuration file to load
62 //! \param group Name of the group to associate with these mappings
63 //! \param alwaysOnTop Whether these mappings should always be at the top of the priority stack
64 //! \param alwaysEnabled Whether these mappings should always be enabled
65 //! \return True if the configuration was loaded successfully, false otherwise
66 //!
67 //! Loads mappings from the specified configuration file into the input manager,
68 //! associating them with the given group name. The alwaysOnTop and alwaysEnabled
69 //! parameters control the priority and activation state of the mappings.
70 virtual bool loadInputConfig(
71 const std::string& config, const std::string& group, bool alwaysOnTop = false, bool alwaysEnabled = false);
72
73 //! \brief Removes previously loaded input mappings
74 //! \param category Name of the mapping category to unload
75 //! \param group Name of the group to unload
76 //!
77 //! Removes input mappings previously loaded from the specified category and group.
78 //! This will prevent the mappings from triggering actions but does not remove
79 //! the action handlers themselves.
80 virtual void unloadInputConfig(const std::string& category, const std::string& group);
81
82 //! \brief Registers a callback function to handle an input-triggered action
83 //! \param group Name of the group to associate this handler with
84 //! \param action Name of the action to handle
85 //! \param handler Delegate function to call when the action is triggered
86 //!
87 //! Registers a callback function that will be called when the specified action
88 //! is triggered by user input. The handler is associated with the given group,
89 //! allowing for management of related action handlers as a unit.
90 virtual void addActionHandler(const std::string& group, const std::string& action, const DtActionDelegate& handler);
91
92 //! \brief Removes all action handlers in a group
93 //! \param group Name of the group to remove
94 //!
95 //! Removes all action handlers associated with the specified group.
96 //! This is useful for cleaning up handlers when a component is being disabled
97 //! or destroyed.
98 virtual void removeActionGroup(const std::string& group);
99
100 //! \brief Sets a handler for raw input events
101 //! \param inputDelegate Delegate function to call for raw input events
102 //!
103 //! Sets a function to receive all raw input events before they are processed
104 //! by the normal action system. This allows for custom input handling beyond
105 //! the configured actions.
106 virtual void setRawInputHandler(const DtInputDelegate& inputDelegate);
107
108 //! \brief Removes the current raw input handler
109 //!
110 //! Removes any previously set raw input handler, stopping the delivery
111 //! of raw input events to the handler function.
112 virtual void removeRawInputHandler();
113
114 //! \brief Unregisters a specific action callback
115 //! \param group Name of the group containing the action
116 //! \param action Name of the action to remove the handler for
117 //!
118 //! Removes the callback function for the specified action within the given group.
119 //! After removal, the action will no longer trigger the callback.
120 virtual void removeActionHandler(const std::string& group, const std::string& action);
121
122protected:
123 //! \brief Pointer to the VR-Engage input manager
125
126 //! \brief List of loaded input configurations (category, group pairs)
127 std::vector<std::pair<std::string, std::string>> myInputConfigurations;
128
129 //! \brief Map of action groups to lists of action names
130 std::unordered_map<std::string, std::vector<std::string>> myActionGroups;
131
132 //! \brief Flag indicating whether raw input handling is active
134};
135
136} // namespace makVre
std::vector< std::pair< std::string, std::string > > myInputConfigurations
List of loaded input configurations (category, group pairs)
Definition inputLogic.h:127
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:130
bool myHandlingRawInput
Flag indicating whether raw input handling is active.
Definition inputLogic.h:133
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:124
Central manager for input device handling, action mapping, and input processing.
Definition vreInputManager.h:81
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
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
Input management system for handling device input and action mapping.