VR-Engage  2.3
Loading...
Searching...
No Matches
vreJoystickController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2026 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
22
23#include <vrfobjcore/controllerComponent.h>
24
25class DtString;
26class DtSimulationServices;
27class DtGroundVehicleStateRepository;
28class DtBooleanOutputPort;
29class DtAnalogOutputPort;
30class DtLocalObject;
31
32namespace makVre
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//! The shared joystick interface preserves connectivity during ownership handoff.
45//!
46//! Uses Descriptor Type: DtVreJoystickControllerDescriptor
47class VREVRFMODEL_DLL DtVreJoystickController : public DtVreSimComponent<DtControllerComponent>,
49{
50public:
51 //! \brief Constructor
52 //! \param name The name of this component
53 //! \param owner The local object that owns this component
54 //! \param simManager The simulation services manager
55 //! \param desc Component descriptor with configuration parameters
56 //! \param parentRegistry Optional parent registry for reader/writer functionality
57 //!
58 //! Creates a new joystick controller component with the specified parameters.
59 //! The descriptor contains configuration information for setting up appropriate
60 //! output ports based on the controlled entity type.
61 DtVreJoystickController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
62 DtComponentDescriptor* desc, DtReaderWriterRegistry* parentRegistry = 0);
63
64 //! \brief Virtual destructor
65 //!
66 //! Cleans up resources used by the joystick controller component, including
67 //! output ports and port groups.
68 virtual ~DtVreJoystickController() override;
69
70 //! \brief Gets the type identifier for this component
71 //! \return String identifying the component type (DtVreJoystickControllerType)
72 //!
73 //! Implements the DtSimComponent::type() method to return the
74 //! type identifier for this component.
75 virtual const char* type() const override;
76
77 //! \brief Calls base first-tick initialization and restores incoming joystick state.
78 virtual void preFirstTickInit() override;
79
80 //! \brief Initializes the joystick controller
81 //! \return True if initialization is successful, false otherwise
82 //!
83 //! Performs initial setup of the joystick controller, including creating
84 //! port groups and ports for joystick inputs. This method is called during
85 //! component initialization.
86 virtual bool init() override;
87
88 //! \brief Creates output port groups for joystick inputs
89 //! \return True if port groups are successfully created, false otherwise
90 //!
91 //! Creates and initializes the output port groups needed for joystick control.
92 //! These port groups organize the output ports by function (movement controls,
93 //! weapon controls, etc.) for proper routing to other components.
94 virtual bool createPortGroups() override;
95
96 //! \brief Creates output ports for joystick inputs
97 //! \return True if ports are successfully created, false otherwise
98 //!
99 //! Creates and initializes the output ports needed for joystick control.
100 //! These ports transmit joystick input values to other components that
101 //! handle actual entity movement and actions.
102 virtual bool createPorts() override;
103
104 //! \brief Factory method to create a new instance of this component
105 //! \param name The name for the new component
106 //! \param owner The local object that will own this component
107 //! \param simManager The simulation services manager
108 //! \param desc Optional component descriptor
109 //! \param parentRegistry Optional parent registry for reader/writer functionality
110 //! \return Pointer to the newly created component
111 //!
112 //! Static factory method used by the component creation system to instantiate
113 //! new instances of this component type.
114 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
115 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
116
117private:
118 //! \brief Default constructor (not implemented)
119 //!
120 //! Default constructor is private and not implemented to prevent
121 //! creation of instances without proper initialization.
123
124 //! \brief Copy constructor (not implemented)
125 //!
126 //! Copy constructor is private and not implemented to prevent
127 //! copy construction.
129
130 //! \brief Assignment operator (not implemented)
131 //! \return Reference to this object
132 //!
133 //! Assignment operator is private and not implemented to prevent assignment.
135
136protected:
137 //! \brief Handles commander override messages
138 //! \param msg The message containing override parameters
139 //! \return Message processing result indicating success or failure
140 //!
141 //! Processes CommanderOverride messages, which activate or deactivate commander
142 //! override mode. When in commander override mode, direct control inputs take
143 //! precedence over AI control or other input methods.
145
146 //! \brief Calculates and sets port values based on function input
147 //! \param functionGroup The function group identifier
148 //! \param function The specific function name
149 //! \param value The input value to process
150 //! \param repeat Flag indicating whether the function should repeat
151 //!
152 //! Processes input from joystick functions and applies the appropriate
153 //! transforms to set the corresponding output port values. This is the main
154 //! method for translating joystick inputs to simulation control values.
156 const DtString& functionGroup, const DtString& function, double value, bool repeat) override;
157 //! \brief Handles joystick connection events
158 //!
159 //! Called when a joystick is connected to the system. Updates internal state
160 //! and performs any necessary setup to begin processing joystick inputs.
161 virtual void joystickConnected() override;
162 //! \brief Handles joystick disconnection events
163 //!
164 //! Called when a joystick is disconnected from the system. Updates internal state
165 //! and performs any necessary cleanup to handle the loss of joystick input.
166 virtual void joystickDisconnected() override;
167
168 //! \brief Updates the controller state each simulation frame
169 //!
170 //! Processes joystick inputs and updates output port values during each
171 //! simulation frame. This ensures that the entity's behavior reflects the
172 //! current joystick state.
173 virtual void tick() override;
174
175protected:
176 //! \brief Name of the output port group
177 //!
178 //! Stores the name of the output port group used for organizing
179 //! joystick control output ports.
181
182 //! \brief Pointer to the output port group
183 //!
184 //! Contains all the output ports used to transmit joystick control values.
185 DtOutputPortGroup* myOutputGroup;
186
187 //! \brief Type definition for mapping port names to port objects
188 using OutputPortMap = std::map<std::string, DtOutputPort*>;
189
190 //! \brief Map of output ports indexed by name
191 //!
192 //! Stores all output ports created for joystick control, indexed by their names
193 //! for easy access when updating port values.
195
196 //! \brief Flag indicating whether commander override mode is active
197 //!
198 //! When true, indicates that commander override mode is active, which gives
199 //! direct control inputs precedence over AI control or other input methods.
201};
202
203} // namespace makVre
bool myCommanderOverrideActive
Flag indicating whether commander override mode is active.
Definition vreJoystickController.h:200
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:180
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:185
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:188
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 void preFirstTickInit() override
Calls base first-tick initialization and restores incoming joystick state.
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:194
DtVreJoystickControllerInterface(DtSimComponent *component, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc)
Constructs an interface alongside an existing component base.
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:63
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
!
Definition glsVreMessageUtil.h:50
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
Internal-state persistence for VRE joystick controllers.
Defines the base class for all VREngage messages.