VR-Engage  2.2
Loading...
Searching...
No Matches
vreBullseyeController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreBullseyeController.h
7//! \ingroup vreVrfmodel
8//! \brief Controller for managing bullseye target selection
9//!
10//! This file defines the DtVreBullseyeController class which handles player selection
11//! of bullseye targets in VRE stations. It manages saving the selected bullseye entity
12//! ID and updating the BullseyeLocation state data accordingly. This controller works
13//! in conjunction with the GUI definitions in pilot.lua for the "Select Bullseye" feature.
14
15#pragma once
16
17#include "vreVrfmodel/export.h"
19#include <vrfobjcore/simObjectReference.h>
21#include <boost/signals2.hpp>
22
23//! \brief Special controller for handling bullseye targeting in VRE stations
24//!
25//! This controller enables players to select a bullseye target in VRE stations and
26//! maintains that selection. It is responsible for saving the selected bullseye entity ID
27//! and updating the BullseyeLocation state-data accordingly. This component integrates
28//! with the GUI definitions in pilot.lua for the "Select Bullseye" functionality.
29
30namespace makVre
31{
32//! \brief Type identifier for the VRE bullseye controller component
33const char DtVreBullseyeControllerType[] = "vre-bullseye-controller";
34
35//! \brief Controller for managing bullseye target selection and location
36//!
37//! DtVreBullseyeController handles player selections of bullseye targets in VRE stations.
38//! It manages the reference to the selected bullseye entity and updates the BullseyeLocation
39//! state data whenever the entity's location changes or when a new bullseye is selected.
40//! This controller also properly handles scenario reloads and entity removal events to
41//! maintain consistent bullseye targeting.
43{
44private:
45 //! \brief Default constructor (not implemented)
46 //!
47 //! Default constructor is private and not implemented to prevent
48 //! creation of instances without proper initialization.
50
51 //! \brief Copy constructor (not implemented)
52 //!
53 //! Copy constructor is private and not implemented to prevent
54 //! copy construction.
56
57 //! \brief Assignment operator (not implemented)
58 //! \return Reference to this object
59 //!
60 //! Assignment operator is private and not implemented to prevent assignment.
62
63public:
64 //! \brief Constructor
65 //! \param name The name of this component
66 //! \param owner The local object that owns this component
67 //! \param simManager The simulation services manager
68 //! \param desc Component descriptor with configuration parameters
69 //! \param parentRegistry Optional parent registry for reader/writer functionality
70 //!
71 //! Creates a new bullseye controller component with the specified parameters.
72 DtVreBullseyeController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
73 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
74
75 //! \brief Virtual destructor
76 //!
77 //! Cleans up resources used by the bullseye controller component,
78 //! including any signal connections.
79 virtual ~DtVreBullseyeController() override;
80
81 //! \brief Gets the type identifier for this component
82 //! \return String identifying the component type (DtVreBullseyeControllerType)
83 //!
84 //! Implements the DtSimComponent::type() method to return the
85 //! type identifier for this component.
86 virtual const char* type() const override;
87
88 //! \brief Initializes the bullseye controller
89 //! \return True if initialization is successful, false otherwise
90 //!
91 //! Registers message handlers to process vrfSetBullseyeIdMessage messages
92 //! sent by pilotSimLogic. Also sets up entity event connections.
93 virtual bool init() override;
94
95 //! \brief Factory method to create a new instance of this component
96 //! \param name The name for the new component
97 //! \param owner The local object that will own this component
98 //! \param simManager The simulation services manager
99 //! \param desc Optional component descriptor
100 //! \param parentRegistry Optional parent registry for reader/writer functionality
101 //! \return Pointer to the newly created component
102 //!
103 //! Static factory method used by the component creation system to instantiate
104 //! new instances of this component type.
105 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
106 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
107
108 //! \brief Updates the controller state each simulation frame
109 //!
110 //! Checks if VRE has just received control over the entity and, if so,
111 //! sets the "BullseyeLocation" value based on the current bullseye target.
112 //! This ensures proper bullseye tracking when player control changes.
113 virtual void tick() override;
114
115 //! \brief Processes simulation object added events
116 //! \param simObject Reference to the simulation object that was added
117 //!
118 //! Handles the case where a VRF scenario is reloaded. When this happens,
119 //! VRE will reset the bullseye target according to the saved bullseye ID.
120 //! This ensures continuity of bullseye targeting across scenario reloads.
121 void processSimObjectAdded(DtSimObjectReference simObject);
122
123 //! \brief Processes simulation object removal events
124 //! \param simObject Reference to the simulation object that will be removed
125 //!
126 //! Removes all callbacks related to the bullseye object if it is the one being removed
127 //! and resets the "BullseyeLocation" value to 0. This ensures proper cleanup when
128 //! the current bullseye entity is removed from the simulation.
129 void processSimObjectToBeRemoved(DtSimObjectReference simObject);
130
131protected:
132 //! \brief Handles bullseye ID set messages from the user
133 //! \param message Pointer to the message containing the bullseye ID information
134 //! \return Message processing result indicating success or failure
135 //!
136 //! Processes SetBullseyeIdMessage messages sent from the user interface
137 //! and updates the current bullseye object based on the entity ID in the message.
139
140private:
141 //! \brief Updates the BullseyeLocation state data with the entity's position
142 //! \param simObject Reference to the bullseye simulation object
143 //!
144 //! Sets the "BullseyeLocation" value to be the geocentric world location
145 //! of the specified DtLocalObject. This is used to track the current position
146 //! of the bullseye entity for navigation and targeting purposes.
147 void updateLocation(DtSimObjectReference simObject);
148
149 //! \brief Sets a new bullseye target and updates its location
150 //! \param simObject Reference to the new bullseye simulation object
151 //!
152 //! Updates the current bullseye object reference and the "BullseyeLocation" value
153 //! to reflect the new bullseye entity. This method is called when the player
154 //! selects a new bullseye target or when restoring a previously selected target.
155 void setNewBullseye(DtSimObjectReference simObject);
156
157private:
158 //! \brief Reference to the currently selected bullseye entity
159 //!
160 //! Holds a reference to the simulation object that is currently selected
161 //! as the bullseye target. This reference is updated when the player
162 //! selects a new bullseye entity.
163 DtRwSimObjectReference myBullseyeEntity;
164
165 //! \brief Flag tracking the entity's player-controlled state
166 //!
167 //! Saves the last known state of whether the owning entity is player-controlled.
168 //! This is used to detect when player control changes, which triggers an update
169 //! of the bullseye location.
171
172 //! \brief Connection for simulation object added events
173 //!
174 //! Manages the connection to simulation object added events, which is used
175 //! to handle scenario reloads and re-establish bullseye targeting.
176 boost::signals2::scoped_connection mySimObjectAddedConnection;
177
178 //! \brief Connection for simulation object deleted events
179 //!
180 //! Manages the connection to simulation object deleted events, which is used
181 //! to handle cleanup when bullseye entities are removed from the simulation.
182 boost::signals2::scoped_connection mySimObjectDeletedConnection;
183};
184} // namespace makVre
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 ~DtVreBullseyeController() override
Virtual destructor.
const DtVreBullseyeController & operator=(const DtVreBullseyeController &orig)
Assignment operator (not implemented)
DtVreBullseyeController(const DtVreBullseyeController &orig)
Copy constructor (not implemented)
bool myIsPlayerControlled
Flag tracking the entity's player-controlled state.
Definition vreBullseyeController.h:170
virtual bool init() override
Initializes the bullseye controller.
DtVreBullseyeController()
Default constructor (not implemented)
DtVreBullseyeController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
void processSimObjectAdded(DtSimObjectReference simObject)
Processes simulation object added events.
void processSimObjectToBeRemoved(DtSimObjectReference simObject)
Processes simulation object removal events.
boost::signals2::scoped_connection mySimObjectAddedConnection
Connection for simulation object added events.
Definition vreBullseyeController.h:176
virtual makVre::DtVreMessageResult handleSetBullseyeId(makVre::DtVreMessage *message)
Handles bullseye ID set messages from the user.
virtual void tick() override
Updates the controller state each simulation frame.
virtual const char * type() const override
Gets the type identifier for this component.
void setNewBullseye(DtSimObjectReference simObject)
Sets a new bullseye target and updates its location.
DtRwSimObjectReference myBullseyeEntity
Reference to the currently selected bullseye entity.
Definition vreBullseyeController.h:163
void updateLocation(DtSimObjectReference simObject)
Updates the BullseyeLocation state data with the entity's position.
boost::signals2::scoped_connection mySimObjectDeletedConnection
Connection for simulation object deleted events.
Definition vreBullseyeController.h:182
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 DtVreBullseyeControllerType[]
Type identifier for the VRE bullseye controller component.
Definition vreBullseyeController.h:33
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines the base class for all VREngage messages.
Base template class for VR-Engage simulation components.