VR-Engage  2.3
Loading...
Searching...
No Matches
ballisticGunJoyController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file ballisticGunJoyController.h
7//! \ingroup vreVrfmodel
8//! \brief Controller for ballistic guns with joystick input support
9//!
10//! This file defines the DtBallisticGunJoyController class which extends the standard
11//! ballistic gun controller with joystick input capabilities, allowing manual control
12//! of weapon aiming and firing.
13
14#pragma once
15
16#include "vreVrfmodel/export.h"
17
18#include <vrfmodel/ballisticGunController.h>
20
21class DtConstrainedAnalogOutputPort;
22class DtBooleanOutputPort;
23class DtOutputPortGroup;
24class DtJoyDeviceControllerDescriptor;
25
26//! \brief Type identifier for the ballistic gun joy controller component
27const char DtBallisticGunJoyControllerType[] = "ballistic-gun-joy-controller";
28
29namespace makVre
30{
31//! \brief Controller for ballistic guns with joystick input capabilities
32//!
33//! DtBallisticGunJoyController extends the DtBallisticGunController class
34//! with the ability to be controlled from a joystick. It implements the
35//! DtVreJoystickControllerInterface to process joystick input and translate
36//! it to appropriate gun control outputs.
37//!
38//! Uses Descriptor Type: DtBallisticGunJoyControllerDescriptor
39class VREVRFMODEL_DLL DtBallisticGunJoyController : public DtBallisticGunController,
41{
42public:
43 //! \brief Constructor
44 //! \param name The name of this component
45 //! \param owner The local object that owns this component
46 //! \param simManager The simulation services manager
47 //! \param desc Component descriptor with configuration parameters
48 //! \param parentRegistry Optional parent registry for reader/writer functionality
49 //!
50 //! Creates a new ballistic gun joy controller component with the specified parameters.
51 DtBallisticGunJoyController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
52 DtComponentDescriptor* desc, DtReaderWriterRegistry* const parentRegistry = 0);
53
54 //! \brief Virtual destructor
55 //!
56 //! Cleans up resources used by the ballistic gun joy controller component.
57 virtual ~DtBallisticGunJoyController() override;
58
59 //! \brief Gets the type identifier for this component
60 //! \return String identifying the component type (DtBallisticGunJoyControllerType)
61 //!
62 //! Implements the DtSimComponent::type() method to return the
63 //! type identifier for this component.
64 virtual const char* type() const override;
65
66 //! \brief Calls base first-tick initialization and restores incoming joystick state.
67 virtual void preFirstTickInit() override;
68
69 //! \brief Creates the joystick active state output port
70 //! \return True if port was created successfully, false otherwise
71 //!
72 //! Creates the output port used to indicate when joystick control is active.
73 //! This is called during initialization to set up communication with the actuator.
75
76 //! \brief Gets the joystick active state output port
77 //! \return Pointer to the joystick active output port
78 //!
79 //! Provides access to the port that indicates when joystick control is active.
80 virtual DtBooleanOutputPort* activeJoystickPort() const;
81
82 //! \brief Creates the elevation control output port
83 //! \return True if port was created successfully, false otherwise
84 //!
85 //! Creates the output port used to control gun elevation via joystick input.
86 virtual bool createElevationPort();
87
88 //! \brief Gets the elevation control output port
89 //! \return Pointer to the elevation output port
90 //!
91 //! Provides access to the port that controls gun elevation.
92 virtual DtConstrainedAnalogOutputPort* elevationPort() const;
93
94 //! \brief Selects ammunition type for the weapon
95 //! \param name The entity type of ammunition to select, or null for default
96 //! \return True if ammunition selection was successful, false otherwise
97 //!
98 //! Attempts to select the specified ammunition type for the weapon.
99 //! If no type is specified (nullType), uses the default ammunition.
100 virtual bool chooseAmmo(const DtEntityType& name = DtEntityType::nullType());
101
102 //! \brief Checks if the weapon can currently fire
103 //! \return True if the weapon can fire, false otherwise
104 //!
105 //! Determines whether the weapon is currently able to fire based on
106 //! ammunition availability and other weapon state conditions.
107 virtual bool canFire();
108
109 //! \brief Queries the resource store for the current munition's round count
110 //! \return Number of rounds available for the currently selected munition
111 //!
112 //! Mirrors the per-tick resource re-query performed by the VRF base
113 //! controller so magazine loaders load the correct number of rounds.
115
116 //! \brief Factory method to create a new instance of this component
117 //! \param name The name for the new component
118 //! \param owner The local object that will own this component
119 //! \param simManager The simulation services manager
120 //! \param desc Optional component descriptor
121 //! \param parentRegistry Optional parent registry for reader/writer functionality
122 //! \return Pointer to the newly created component
123 //!
124 //! Static factory method used by the component creation system to instantiate
125 //! new instances of this component type.
126 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
127 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
128
129protected:
130 //! \brief Updates the controller state each simulation frame
131 //!
132 //! Processes joystick input and updates output ports to control
133 //! the associated ballistic gun actuator component.
134 virtual void tick() override;
135
136 //! \brief Processes joystick input and updates output ports
137 //! \param functionGroup The function group identifier for the input
138 //! \param function The specific function identifier within the group
139 //! \param value The input value from the joystick
140 //! \param repeat Flag indicating if this is a repeated input
141 //!
142 //! Implements the DtJoystickControllerInterface method to process joystick
143 //! input and update the controller's output ports accordingly.
145 const DtString& functionGroup, const DtString& function, double value, bool repeat) override;
146 //! \brief Handles joystick connection event
147 //!
148 //! Called when a joystick is connected to the system.
149 //! Activates joystick control mode for this controller.
150 virtual void joystickConnected() override;
151 //! \brief Handles joystick disconnection event
152 //!
153 //! Called when a joystick is disconnected from the system.
154 //! Deactivates joystick control mode for this controller.
155 virtual void joystickDisconnected() override;
156
157 //! \brief Creates all required output ports for this controller
158 //! \return True if all ports were created successfully, false otherwise
159 //!
160 //! Overridden to create the specific output ports needed by this controller,
161 //! including elevation control and joystick active state ports.
162 virtual bool createPorts() override;
163
164private:
165 //! \brief Default constructor (not implemented)
166 //!
167 //! Default constructor is private and not implemented to prevent
168 //! creation of instances without proper initialization.
170
171 //! \brief Copy constructor (not implemented)
172 //!
173 //! Copy constructor is private and not implemented to prevent
174 //! copy construction.
176
177 //! \brief Assignment operator (not implemented)
178 //! \return Reference to this object
179 //!
180 //! Assignment operator is private and not implemented to prevent assignment.
182
183protected:
184 //! \name Ports and Port Groups
185 //! @{
186
187 //! Output Port Name: elevation\n
188 //! Output Port Description: \n
189 //! Output Port Range: -1. to 1.\n
190 //! Output Port Default Value: \n
191 //! Output Group Parent:
192 DtConstrainedAnalogOutputPort* myElevationPort;
193
194 //! Output Port Name: joystick-active\n
195 //! Output Port Description: Indicates whether controller behavior is being
196 //! executed through a joystick.\n
197 //! Output Port Range: \n
198 //! Output Port Default Value: false\n
199 //! Output Group Parent:
200 DtBooleanOutputPort* myActiveJoystickPort;
201
202 //! @}
203
204 //! \brief Flag indicating if the weapon is currently firing
206
207 //! \brief Flag indicating if the fire button is currently pressed
209};
210} // namespace makVre
const char DtBallisticGunJoyControllerType[]
Type identifier for the ballistic gun joy controller component.
Definition ballisticGunJoyController.h:27
virtual void joystickDisconnected() override
Handles joystick disconnection event.
virtual bool createElevationPort()
Creates the elevation control output port.
virtual ~DtBallisticGunJoyController() override
Virtual destructor.
DtBallisticGunJoyController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *const parentRegistry=0)
Constructor.
const DtBallisticGunJoyController & operator=(const DtBallisticGunJoyController &orig)
Assignment operator (not implemented)
virtual bool canFire()
Checks if the weapon can currently fire.
virtual void tick() override
Updates the controller state each simulation frame.
DtBallisticGunJoyController()
Default constructor (not implemented)
DtConstrainedAnalogOutputPort * myElevationPort
Output Port Name: elevation Output Port Description: Output Port Range: -1. to 1....
Definition ballisticGunJoyController.h:192
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.
bool myFireButtonDown
Flag indicating if the fire button is currently pressed.
Definition ballisticGunJoyController.h:208
virtual DtBooleanOutputPort * activeJoystickPort() const
Gets the joystick active state output port.
DtBooleanOutputPort * myActiveJoystickPort
Output Port Name: joystick-active Output Port Description: Indicates whether controller behavior is b...
Definition ballisticGunJoyController.h:200
bool myFiring
Flag indicating if the weapon is currently firing.
Definition ballisticGunJoyController.h:205
virtual void calcAndSetPortValues(const DtString &functionGroup, const DtString &function, double value, bool repeat) override
Processes joystick input and updates output ports.
int roundsAvailableForCurrentMunition() const
Queries the resource store for the current munition's round count.
DtBallisticGunJoyController(const DtBallisticGunJoyController &orig)
Copy constructor (not implemented)
virtual void joystickConnected() override
Handles joystick connection event.
virtual bool createActiveJoystickPort()
Creates the joystick active state output port.
virtual bool createPorts() override
Creates all required output ports for this controller.
virtual DtConstrainedAnalogOutputPort * elevationPort() const
Gets the elevation control output port.
virtual const char * type() const override
Gets the type identifier for this component.
virtual void preFirstTickInit() override
Calls base first-tick initialization and restores incoming joystick state.
virtual bool chooseAmmo(const DtEntityType &name=DtEntityType::nullType())
Selects ammunition type for the weapon.
DtVreJoystickControllerInterface(DtSimComponent *component, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc)
Constructs an interface alongside an existing component base.
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
!
Definition glsVreMessageUtil.h:50
Internal-state persistence for VRE joystick controllers.