VR-Engage  2.2
Loading...
Searching...
No Matches
vreJoystickController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreJoystickController.h
7//! \ingroup vreVrfmodel
8//! \brief Controller for handling joystick input
9//!
10//! This file defines the DtVreJoystickController class which enables joystick
11//! control for entities and automatically creates output ports for joystick inputs.
12//! It serves as a bridge between physical joystick inputs and entity controls.
13
14#pragma once
15
16#include "vreVrfmodel/export.h"
17#include "vreVrfModel/vreSimComponent.h"
18
20
21#include <vrfmodel/joystickControllerInterface.h>
22
23#include <vrfobjcore/controllerComponent.h>
24
25class DtString;
26class DtSimulationServices;
27class DtGroundVehicleStateRepository;
28class DtBooleanOutputPort;
29class DtAnalogOutputPort;
30
31namespace makVre
32{
33
34//! \brief Type identifier for the VRE joystick controller component
35const char DtVreJoystickControllerType[] = "vre-joystick-controller";
36
37//! \brief Controller that enables joystick control for entities
38//!
39//! DtVreJoystickController enables joystick control for entities by creating
40//! and managing the appropriate output ports for joystick inputs. It serves as a
41//! bridge between physical joystick inputs and the simulation, translating joystick
42//! actions into appropriate entity control commands. The controller handles connect
43//! and disconnect events, commander override states, and port value updates.
44//!
45//! Uses Descriptor Type: DtVreJoystickControllerDescriptor
46class VREVRFMODEL_DLL DtVreJoystickController : public DtVreSimComponent<DtControllerComponent>,
47 public DtJoystickControllerInterface
48{
49public:
50 //! \brief Constructor
51 //! \param name The name of this component
52 //! \param owner The local object that owns this component
53 //! \param simManager The simulation services manager
54 //! \param desc Component descriptor with configuration parameters
55 //! \param parentRegistry Optional parent registry for reader/writer functionality
56 //!
57 //! Creates a new joystick controller component with the specified parameters.
58 //! The descriptor contains configuration information for setting up appropriate
59 //! output ports based on the controlled entity type.
60 DtVreJoystickController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
61 DtComponentDescriptor* desc, DtReaderWriterRegistry* parentRegistry = 0);
62
63 //! \brief Virtual destructor
64 //!
65 //! Cleans up resources used by the joystick controller component, including
66 //! output ports and port groups.
67 virtual ~DtVreJoystickController() override;
68
69 //! \brief Gets the type identifier for this component
70 //! \return String identifying the component type (DtVreJoystickControllerType)
71 //!
72 //! Implements the DtSimComponent::type() method to return the
73 //! type identifier for this component.
74 virtual const char* type() const override;
75
76 //! \brief Initializes the joystick controller
77 //! \return True if initialization is successful, false otherwise
78 //!
79 //! Performs initial setup of the joystick controller, including creating
80 //! port groups and ports for joystick inputs. This method is called during
81 //! component initialization.
82 virtual bool init() override;
83
84 //! \brief Creates output port groups for joystick inputs
85 //! \return True if port groups are successfully created, false otherwise
86 //!
87 //! Creates and initializes the output port groups needed for joystick control.
88 //! These port groups organize the output ports by function (movement controls,
89 //! weapon controls, etc.) for proper routing to other components.
90 virtual bool createPortGroups() override;
91
92 //! \brief Creates output ports for joystick inputs
93 //! \return True if ports are successfully created, false otherwise
94 //!
95 //! Creates and initializes the output ports needed for joystick control.
96 //! These ports transmit joystick input values to other components that
97 //! handle actual entity movement and actions.
98 virtual bool createPorts() override;
99
100 //! \brief Factory method to create a new instance of this component
101 //! \param name The name for the new component
102 //! \param owner The local object that will own this component
103 //! \param simManager The simulation services manager
104 //! \param desc Optional component descriptor
105 //! \param parentRegistry Optional parent registry for reader/writer functionality
106 //! \return Pointer to the newly created component
107 //!
108 //! Static factory method used by the component creation system to instantiate
109 //! new instances of this component type.
110 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
111 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
112
113private:
114 //! \brief Default constructor (not implemented)
115 //!
116 //! Default constructor is private and not implemented to prevent
117 //! creation of instances without proper initialization.
119
120 //! \brief Copy constructor (not implemented)
121 //!
122 //! Copy constructor is private and not implemented to prevent
123 //! copy construction.
125
126 //! \brief Assignment operator (not implemented)
127 //! \return Reference to this object
128 //!
129 //! Assignment operator is private and not implemented to prevent assignment.
131
132protected:
133 //! \brief Handles commander override messages
134 //! \param msg The message containing override parameters
135 //! \return Message processing result indicating success or failure
136 //!
137 //! Processes CommanderOverride messages, which activate or deactivate commander
138 //! override mode. When in commander override mode, direct control inputs take
139 //! precedence over AI control or other input methods.
141
142 //! \brief Calculates and sets port values based on function input
143 //! \param functionGroup The function group identifier
144 //! \param function The specific function name
145 //! \param value The input value to process
146 //! \param repeat Flag indicating whether the function should repeat
147 //!
148 //! Processes input from joystick functions and applies the appropriate
149 //! transforms to set the corresponding output port values. This is the main
150 //! method for translating joystick inputs to simulation control values.
152 const DtString& functionGroup, const DtString& function, double value, bool repeat) override;
153 //! \brief Handles joystick connection events
154 //!
155 //! Called when a joystick is connected to the system. Updates internal state
156 //! and performs any necessary setup to begin processing joystick inputs.
157 virtual void joystickConnected() override;
158 //! \brief Handles joystick disconnection events
159 //!
160 //! Called when a joystick is disconnected from the system. Updates internal state
161 //! and performs any necessary cleanup to handle the loss of joystick input.
162 virtual void joystickDisconnected() override;
163
164 //! \brief Updates the controller state each simulation frame
165 //!
166 //! Processes joystick inputs and updates output port values during each
167 //! simulation frame. This ensures that the entity's behavior reflects the
168 //! current joystick state.
169 virtual void tick() override;
170
171protected:
172 //! \brief Name of the output port group
173 //!
174 //! Stores the name of the output port group used for organizing
175 //! joystick control output ports.
177
178 //! \brief Pointer to the output port group
179 //!
180 //! Contains all the output ports used to transmit joystick control values.
181 DtOutputPortGroup* myOutputGroup;
182
183 //! \brief Type definition for mapping port names to port objects
184 using OutputPortMap = std::map<std::string, DtOutputPort*>;
185
186 //! \brief Map of output ports indexed by name
187 //!
188 //! Stores all output ports created for joystick control, indexed by their names
189 //! for easy access when updating port values.
191
192 //! \brief Flag indicating whether commander override mode is active
193 //!
194 //! When true, indicates that commander override mode is active, which gives
195 //! direct control inputs precedence over AI control or other input methods.
197};
198
199} // namespace makVre
bool myCommanderOverrideActive
Flag indicating whether commander override mode is active.
Definition vreJoystickController.h:196
DtVreJoystickController(const DtVreJoystickController &orig)
Copy constructor (not implemented)
virtual const char * type() const override
Gets the type identifier for this component.
std::string myOutputPortGroupName
Name of the output port group.
Definition vreJoystickController.h:176
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Factory method to create a new instance of this component.
virtual void joystickDisconnected() override
Handles joystick disconnection events.
DtVreJoystickController()
Default constructor (not implemented)
virtual bool createPortGroups() override
Creates output port groups for joystick inputs.
virtual void joystickConnected() override
Handles joystick connection events.
DtOutputPortGroup * myOutputGroup
Pointer to the output port group.
Definition vreJoystickController.h:181
DtVreJoystickController & operator=(const DtVreJoystickController &orig)
Assignment operator (not implemented)
virtual DtVreMessageResult handleCommanderOverride(DtVreMessage *msg)
Handles commander override messages.
virtual void tick() override
Updates the controller state each simulation frame.
std::map< std::string, DtOutputPort * > OutputPortMap
Type definition for mapping port names to port objects.
Definition vreJoystickController.h:184
DtVreJoystickController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
virtual bool createPorts() override
Creates output ports for joystick inputs.
virtual void calcAndSetPortValues(const DtString &functionGroup, const DtString &function, double value, bool repeat) override
Calculates and sets port values based on function input.
virtual bool init() override
Initializes the joystick controller.
virtual ~DtVreJoystickController() override
Virtual destructor.
OutputPortMap myOutputPorts
Map of output ports indexed by name.
Definition vreJoystickController.h:190
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
DtVreSimComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Definition vreSimComponent.h:54
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
const char DtVreJoystickControllerType[]
Type identifier for the VRE joystick controller component.
Definition vreJoystickController.h:35
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the base class for all VREngage messages.