VR-Engage  2.2
Loading...
Searching...
No Matches
chooseRoleState.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file chooseRoleState.h
7//! \brief Defines the DtChooseRoleState class for entity and role selection
8//!
9//! This file contains the DtChooseRoleState class which represents the application
10//! state where users select entities to control or create new entities. It manages
11//! the UI interactions for role selection and coordinates with other components
12//! to transition into engaged gameplay.
13
14#pragma once
15
17
19
21
22#include <vrvCore/DtUniqueID.h>
23
24namespace makVrv
25{
26class DtObserverViewsWidget;
27class DtObserverViewsWidgetLogic;
28} // namespace makVrv
29
30namespace makVre
31{
32//! \brief Forward declaration of the player station application class
34
35//! \brief Forward declaration of the player selection dialog
36class DtChoosePlayerDialog;
37
38//! \brief Forward declaration of the initializer class
39class DtInitializer;
40
41//! \brief Forward declaration of the role selection panel
43
44//! \brief Forward declaration of the role selection page
46
47//! \brief Forward declaration of the role assignment message
49
50//! \brief Application state for selecting entities and roles
51//!
52//! DtChooseRoleState represents the application state where users can
53//! select existing entities to control or create new entities. It manages
54//! the UI interactions, entity creation, and transitions to the engaged state.
56{
57public:
58 //! \brief Constructor
59 //! \param app Reference to the player station application
60 //!
61 //! Creates a new role selection state associated with the given application.
63
64 //! \brief Virtual destructor
65 //!
66 //! Ensures proper cleanup of the role selection state resources.
67 virtual ~DtChooseRoleState() override;
68
69 //! \brief Called when the state is entered
70 //! \param args Pointer to arguments from the previous state
71 //!
72 //! Sets up the role selection UI and observer views, registers message handlers,
73 //! and initializes the state's data structures. This is called when the player
74 //! first enters the role selection state.
75 virtual void onEnter(const DtPlayerStationStateArgs* args) override;
76
77 //! \brief Called when the state is exited
78 //!
79 //! Cleans up resources, hides UI elements, and unregisters message handlers.
80 //! This is called when the player leaves the role selection state.
81 virtual void onExit() override;
82
83 //! \brief Updates the state each frame
84 //! \param dt Time in seconds since the last update
85 //!
86 //! Handles per-frame processing, such as updating entity status, managing
87 //! user interactions, and handling deferred operations.
88 virtual void tick(double dt) override;
89
90 //! \brief Called when the state becomes the topmost state again
91 //!
92 //! Restores UI visibility and updates the panel when this state is exposed
93 //! after another state has been popped from the stack.
94 virtual void onExposed() override;
95
96 //! \brief Called when another state is pushed on top of this one
97 //!
98 //! Hides UI elements and pauses processing while this state is covered
99 //! by another state on the stack.
100 virtual void onStacked() override;
101
102 //! \brief Entity creation methods
103 //! @{
104
105 //! \brief Sets whether a new entity should be created
106 //! \param newNotExisting True to create a new entity, false to use an existing one
107 //!
108 //! Determines whether the player will create a new entity or control an existing one.
109 virtual void setCreatingOwnship(bool newNotExisting);
110
111 //! \brief Sets the name for a new entity
112 //! \param name Name to assign to the new entity
113 //!
114 //! Sets the display name for the entity being created.
115 virtual void setNewEntityName(const std::string& name);
116
117 //! \brief Sets the type for a new entity
118 //! \param type Type identifier for the new entity
119 //!
120 //! Sets the type of entity to create (e.g., aircraft, vehicle, infantry).
121 virtual void setNewEntityType(const DtEntityType& type);
122
123 //! \brief Sets the force type for a new entity
124 //! \param force Force type for the new entity (friendly, hostile, etc.)
125 //!
126 //! Sets the force affiliation for the entity being created.
127 virtual void setNewEntityForce(const DtForceType& force);
128
129 //! \brief Sets the location for a new entity
130 //! \param location 3D position for the new entity (at ground level)
131 //!
132 //! Sets the ground location where the entity will be created.
133 virtual void setNewEntityLocation(const DtVector& location);
134
135 //! \brief Sets the location and altitude for a new entity
136 //! \param location 3D position for the new entity (ground reference)
137 //! \param altitude Height above ground in meters
138 //!
139 //! Sets both the ground position and altitude for the entity being created.
140 virtual void setNewEntityLocationAtAltitude(const DtVector& location, double altitude);
141
142 //! \brief Sets whether the entity should be clamped to terrain
143 //! \param clamp True to clamp to terrain, false otherwise
144 //!
145 //! Determines whether the entity should be constrained to follow terrain contours.
146 virtual void setNewEntityClamp(bool clamp);
147
148 //! \brief Sets the heading for a new entity
149 //! \param headingInDegrees Heading in degrees (0-360, clockwise from north)
150 //!
151 //! Sets the initial heading for the entity being created.
152 //! This assumes the location has already been set.
153 virtual void setNewEntityHeading(const double headingInDegrees);
154
155 //! \brief Sets the pitch for a new entity
156 //! \param pitch Pitch angle in degrees
157 //!
158 //! Sets the initial pitch angle for the entity being created.
159 virtual void setNewEntityPitch(const double pitch);
160
161 //! \brief Sets a parent entity for embarking
162 //! \param host Entity identifier of the host/parent entity
163 //! \param offset Relative offset from the host entity's position
164 //!
165 //! Specifies that the new entity should be created as embarked on another entity.
166 virtual void setNewEntityEmbarkedOn(const DtEntityIdentifier& host, const DtVector& offset);
167 //! @}
168
169 //! \brief Gets the type of the entity being created
170 //! \return Reference to the entity type
171 //!
172 //! Retrieves the entity type that has been set for creation.
173 virtual const DtEntityType& getNewEntityType() { return myNewEntityDef.type; }
174
175 //! \brief Gets the identifier of the created entity
176 //! \return Reference to the entity identifier
177 //!
178 //! Retrieves the unique identifier of the entity that was created.
179 //! Only valid after entity creation is complete.
180 virtual const DtEntityIdentifier& getCreatedOwnshipEntity() const;
181
182 //! \brief Gets the element ID of the created entity
183 //! \return Element ID in the display engine
184 //!
185 //! Retrieves the display engine element ID for the created entity.
186 //! Only valid after entity creation is complete.
187 virtual makVrv::DtElementID getCreatedOwnshipElement() const;
188
189 //! \brief Updates the player station with role information
190 //! \param role Name of the role to play
191 //! \param entityId Identifier of the entity to control (null for new entities)
192 //! \param displayLayout Name of the display layout to use
193 //!
194 //! Sets up the player station with the selected role, entity, and display layout
195 //! in preparation for transitioning to the engaged state.
196 virtual void playStation(const std::string& role, const DtEntityIdentifier& entityId = DtEntityIdentifier::nullId(),
197 const std::string& displayLayout = "");
198
199 //! \brief Initiates engagement with the selected entity
200 //! \param asSpectator True to engage as a spectator, false as a controller
201 //!
202 //! Transitions from the role selection state to the engaged state,
203 //! starting gameplay with the selected entity and role.
204 virtual void play(bool asSpectator = false);
205
206 //! \brief Handles role assignment messages
207 //! \param message Pointer to the role assignment message
208 //! \return Message handling result
209 //!
210 //! Processes messages related to assigning roles to players,
211 //! which may come from network or local sources.
213
214 //! \brief Controls visibility of the observer views panel
215 //! \param visible True to show the panel, false to hide it
216 //!
217 //! Shows or hides the observer views panel that provides
218 //! alternative viewpoints of the simulated environment.
219 virtual void setObserverViewsPanelVisible(bool visible);
220
221protected:
222 //! \brief Controls visibility of the UI components
223 //! \param visible True to show UI elements, false to hide them
224 //!
225 //! Manages the visibility of the choose role page and entity panel components.
226 //! Used when entering/exiting the state or when stacked/exposed.
227 virtual void setUIVisibility(bool visible);
228
229 //! \brief Resets the entity panel to its default state
230 //!
231 //! Clears all selections and inputs in the entity panel,
232 //! preparing it for a fresh interaction.
233 virtual void resetEntityPanel();
234
235 //! \brief Structure containing definition data for a new entity
236 //!
237 //! Contains all the parameters needed to create a new entity in the simulation,
238 //! including its type, position, orientation, and attributes.
240 {
241 //! \brief Constructor that initializes with default values
243 : force(DtForceOther)
244 , clamp(true)
245 , altitude(0.0)
246 , heading(0.0)
247 , pitch(0.0)
248 {
249 }
250
251 std::string name; //!< Display name for the entity
252 DtEntityType type; //!< Type identifier for the entity
253 DtForceType force; //!< Force affiliation (friendly, hostile, etc.)
254 DtVector location; //!< Geocentric position at ground level
255 bool clamp; //!< Whether to clamp to terrain
256 double altitude; //!< Height above ground in meters
257 DtVector position; //!< Geocentric position at specified altitude
258 double heading; //!< Heading in degrees (0-360, clockwise from north)
259 double pitch; //!< Pitch angle in degrees
260 };
261
262 //! \brief Structure defining a player station configuration
263 //!
264 //! Contains the information needed to set up a player station,
265 //! including which entity to control and how to display it.
267 {
268 DtEntityIdentifier entityId; //!< Identifier of the entity to control
269 std::string stationName; //!< Name of the role or station
270 std::string displayLayout; //!< Name of the display layout to use
271 };
272
273 //! \brief Structure for entity attachment configuration
274 //!
275 //! Contains the configuration for attaching to an existing entity,
276 //! including role and display layout information.
278 {
279 std::string name; //!< Name of the entity to attach to
280 std::string displayLayout; //!< Display layout to use
281 std::string role; //!< Role to play in the entity
282 bool spectator; //!< Whether to attach as a spectator
283 };
284
285 //! \brief Message handlers
286 //! @{
287
288 //! \brief Handles messages about newly created ownship entities
289 //! \param message Pointer to the message about the new entity
290 //! \return Message handling result
292
293 //! \brief Handles messages about entities being realized in the simulation
294 //! \param message Pointer to the entity realization message
295 //! \return Message handling result
297
298 //! \brief Handles messages about application mode changes
299 //! \param message Pointer to the application mode message
300 //! \return Message handling result
302
303 //! \brief Handles escape key press messages
304 //! \param msg Pointer to the key press message
305 //! \return Message handling result
307
308 //! \brief Handles back button click messages
309 //! \param msg Pointer to the button click message
310 //! \return Message handling result
312 //! \brief Handles choose role button click messages
313 //! \param msg Pointer to the button click message
314 //! \return Message handling result
316
317 //! \brief Handles VRF rewind messages
318 //! \param msg Pointer to the rewind message
319 //! \return Message handling result
321 //! @}
322
323 //! \brief Entity management methods
324 //! @{
325
326 //! \brief Creates a new entity in the simulation
327 //!
328 //! Uses the information in myNewEntityDef to create a new entity
329 //! in the simulation and start tracking its realization.
330 virtual void createNewEntity();
331
332 //! \brief Updates an existing new entity
333 //! \return True if the update was successful, false otherwise
334 //!
335 //! Applies changes from myNewEntityDef to the entity that is
336 //! currently being created or modified.
337 virtual bool updateNewEntity();
338
339 //! \brief Destroys a new entity that was being created
340 //!
341 //! Removes the entity that was being created from the simulation.
342 //! Typically called when canceling entity creation or during cleanup.
343 virtual void destroyNewEntity();
344
345 //! \brief Checks if a new ownship entity has been realized
346 //! \return True if the entity exists and is ready, false otherwise
347 //!
348 //! Determines whether a newly created entity has been fully
349 //! realized in the simulation and is ready for interaction.
350 virtual bool haveNewRealizedOwnshipEntity() const;
351
352 //! \brief Called when a new ownship entity is realized
353 //!
354 //! Handles the completion of entity creation, transitioning
355 //! to the next step in the engagement process.
356 virtual void onNewOwnshipRealized();
357 //! @}
358
359 //! \brief Gets the display layout for a station
360 //! \param station Station definition to get layout for
361 //! \return Name of the display layout to use
362 //!
363 //! Determines the appropriate display layout for the given station,
364 //! using defaults if necessary.
365 virtual std::string getDisplayLayout(const StationDefinition& station) const;
366
367 //! \brief Validates an entity definition
368 //! \param def Entity definition to validate
369 //! \param error Optional pointer to receive error message
370 //! \return True if the definition is valid, false otherwise
371 //!
372 //! Checks whether an entity definition contains all the required
373 //! information to create a valid entity.
374 virtual bool verifyEntityDefinition(EntityDefinition const& def, QString* error = NULL) const;
375
376 //! \brief Validates a station definition
377 //! \param def Station definition to validate
378 //! \param error Optional pointer to receive error message
379 //! \return True if the definition is valid, false otherwise
380 //!
381 //! Checks whether a station definition contains all the required
382 //! information to set up a player station.
383 virtual bool verifyStationDefinition(StationDefinition const& def, QString* error = NULL) const;
384
385 //! \brief Flag indicating whether to create a new entity
387
388 //! \brief Flag indicating that entity creation is in progress
390
391 //! \brief Flag indicating that a new entity has been created
393
394 //! \brief Definition of the entity to create
396
397 //! \brief Definition of the station to set up
399
400 //! \brief Identifier of the host entity for embarking
401 DtEntityIdentifier myHostId;
402
403 //! \brief Offset from the host entity for embarking
404 DtVector myHostOffset;
405
406 //! \brief Flags indicating which entity properties have changed
407 //!
408 //! Used to track which properties of the entity definition have been
409 //! modified and need to be updated in the simulation.
411 {
412 DirtyName = 1 << 0, //!< Entity name has changed
413 DirtyType = 1 << 1, //!< Entity type has changed
414 DirtyForce = 1 << 2, //!< Entity force type has changed
415 DirtyPosition = 1 << 3, //!< Entity position has changed
416 DirtyHeading = 1 << 4, //!< Entity heading has changed
417 DirtyPitch = 1 << 5, //!< Entity pitch has changed
418 DirtyRoll = 1 << 6 //!< Entity roll has changed
419 };
420
421 //! \brief Bitmap of dirty flags for the entity definition
423
424 //! \brief Pointer to the entity selection panel UI
426
427 //! \brief Shared pointer to the role selection page
428 std::shared_ptr<DtVreChooseRolePage> myChooseRolePage;
429
430 //! \brief Shared pointer to the entity attachment configuration
431 std::shared_ptr<AttachToEntity> myAttachToEntity;
432};
433
434} // namespace makVre
UI panel for selecting and engaging with entities and roles.
Definition chooseRolePanel.h:60
virtual bool verifyEntityDefinition(EntityDefinition const &def, QString *error=NULL) const
Validates an entity definition.
virtual void createNewEntity()
Entity management methods.
virtual void setNewEntityLocation(const DtVector &location)
Sets the location for a new entity.
virtual makVrv::DtElementID getCreatedOwnshipElement() const
Gets the element ID of the created entity.
virtual bool updateNewEntity()
Updates an existing new entity.
bool myHaveNewEntity
Flag indicating that a new entity has been created.
Definition chooseRoleState.h:392
DtEntityIdentifier myHostId
Identifier of the host entity for embarking.
Definition chooseRoleState.h:401
virtual ~DtChooseRoleState() override
Virtual destructor.
virtual DtVreMessageResult handleAssignRolePlayer(DtVreMessage *message)
Handles role assignment messages.
virtual void setNewEntityType(const DtEntityType &type)
Sets the type for a new entity.
bool myAwaitingNewRealizedEntity
Flag indicating that entity creation is in progress.
Definition chooseRoleState.h:389
virtual void playStation(const std::string &role, const DtEntityIdentifier &entityId=DtEntityIdentifier::nullId(), const std::string &displayLayout="")
Updates the player station with role information.
virtual void onExposed() override
Called when the state becomes the topmost state again.
virtual void setCreatingOwnship(bool newNotExisting)
Entity creation methods.
virtual bool haveNewRealizedOwnshipEntity() const
Checks if a new ownship entity has been realized.
virtual void setNewEntityPitch(const double pitch)
Sets the pitch for a new entity.
int myDirtyBits
Bitmap of dirty flags for the entity definition.
Definition chooseRoleState.h:422
bool myWantNewEntity
Flag indicating whether to create a new entity.
Definition chooseRoleState.h:386
virtual void setNewEntityLocationAtAltitude(const DtVector &location, double altitude)
Sets the location and altitude for a new entity.
std::shared_ptr< DtVreChooseRolePage > myChooseRolePage
Shared pointer to the role selection page.
Definition chooseRoleState.h:428
virtual void tick(double dt) override
Updates the state each frame.
virtual DtVreMessageResult handleNewOwnshipCreated(DtVreMessage *message)
Message handlers.
DtChooseRoleState(DtPlayerStationApp &app)
Constructor.
virtual DtVreMessageResult handleBackButtonClicked(DtVreMessage *msg)
Handles back button click messages.
std::shared_ptr< AttachToEntity > myAttachToEntity
Shared pointer to the entity attachment configuration.
Definition chooseRoleState.h:431
virtual const DtEntityIdentifier & getCreatedOwnshipEntity() const
Gets the identifier of the created entity.
virtual DtVreMessageResult handleApplicationMode(makVre::DtVreMessage *message)
Handles messages about application mode changes.
virtual DtVreMessageResult handleEntityRealized(DtVreMessage *message)
Handles messages about entities being realized in the simulation.
DtChooseRolePanel * myEntityPanel
Pointer to the entity selection panel UI.
Definition chooseRoleState.h:425
virtual void setNewEntityHeading(const double headingInDegrees)
Sets the heading for a new entity.
StationDefinition myStationDef
Definition of the station to set up.
Definition chooseRoleState.h:398
virtual void onNewOwnshipRealized()
Called when a new ownship entity is realized.
virtual DtVreMessageResult handleChooseRoleButtonClicked(DtVreMessage *msg)
Handles choose role button click messages.
virtual void play(bool asSpectator=false)
Initiates engagement with the selected entity.
virtual void setNewEntityForce(const DtForceType &force)
Sets the force type for a new entity.
EntityDefinition myNewEntityDef
Definition of the entity to create.
Definition chooseRoleState.h:395
virtual void setNewEntityName(const std::string &name)
Sets the name for a new entity.
virtual std::string getDisplayLayout(const StationDefinition &station) const
Gets the display layout for a station.
virtual void onStacked() override
Called when another state is pushed on top of this one.
virtual void setObserverViewsPanelVisible(bool visible)
Controls visibility of the observer views panel.
virtual void destroyNewEntity()
Destroys a new entity that was being created.
virtual void setNewEntityClamp(bool clamp)
Sets whether the entity should be clamped to terrain.
virtual void setNewEntityEmbarkedOn(const DtEntityIdentifier &host, const DtVector &offset)
Sets a parent entity for embarking.
virtual void setUIVisibility(bool visible)
Controls visibility of the UI components.
virtual bool verifyStationDefinition(StationDefinition const &def, QString *error=NULL) const
Validates a station definition.
virtual void resetEntityPanel()
Resets the entity panel to its default state.
virtual void onExit() override
Called when the state is exited.
virtual const DtEntityType & getNewEntityType()
Gets the type of the entity being created.
Definition chooseRoleState.h:173
DirtyBits
Flags indicating which entity properties have changed.
Definition chooseRoleState.h:411
@ DirtyForce
Entity force type has changed.
Definition chooseRoleState.h:414
@ DirtyPitch
Entity pitch has changed.
Definition chooseRoleState.h:417
@ DirtyPosition
Entity position has changed.
Definition chooseRoleState.h:415
@ DirtyRoll
Entity roll has changed.
Definition chooseRoleState.h:418
@ DirtyType
Entity type has changed.
Definition chooseRoleState.h:413
@ DirtyHeading
Entity heading has changed.
Definition chooseRoleState.h:416
@ DirtyName
Entity name has changed.
Definition chooseRoleState.h:412
virtual void onEnter(const DtPlayerStationStateArgs *args) override
Called when the state is entered.
virtual DtVreMessageResult handleEscKey(DtVreMessage *msg)
Handles escape key press messages.
virtual DtVreMessageResult handleVrfRewind(DtVreMessage *msg)
Handles VRF rewind messages.
DtVector myHostOffset
Offset from the host entity for embarking.
Definition chooseRoleState.h:404
Configuration initializer for VREngage components.
Definition initializer.h:80
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:163
Class for passing arguments during state transitions.
Definition playerStationState.h:45
DtPlayerStationApp & app() const
Gets a reference to the player station application.
DtPlayerStationState(DtPlayerStationApp &app, std::string stateType)
Constructor.
UI controller for the role selection screen.
Definition vreChooseRolePage.h:183
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Definition vreAssignRolePlayer.h:30
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
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
Defines base classes for the VR-Engage state management system.
Structure for entity attachment configuration.
Definition chooseRoleState.h:278
bool spectator
Whether to attach as a spectator.
Definition chooseRoleState.h:282
std::string name
Name of the entity to attach to.
Definition chooseRoleState.h:279
std::string role
Role to play in the entity.
Definition chooseRoleState.h:281
std::string displayLayout
Display layout to use.
Definition chooseRoleState.h:280
Structure containing definition data for a new entity.
Definition chooseRoleState.h:240
DtVector position
Geocentric position at specified altitude.
Definition chooseRoleState.h:257
double heading
Heading in degrees (0-360, clockwise from north)
Definition chooseRoleState.h:258
bool clamp
Whether to clamp to terrain.
Definition chooseRoleState.h:255
double altitude
Height above ground in meters.
Definition chooseRoleState.h:256
DtForceType force
Force affiliation (friendly, hostile, etc.)
Definition chooseRoleState.h:253
double pitch
Pitch angle in degrees.
Definition chooseRoleState.h:259
DtEntityType type
Type identifier for the entity.
Definition chooseRoleState.h:252
EntityDefinition()
Constructor that initializes with default values.
Definition chooseRoleState.h:242
std::string name
Display name for the entity.
Definition chooseRoleState.h:251
DtVector location
Geocentric position at ground level.
Definition chooseRoleState.h:254
Structure defining a player station configuration.
Definition chooseRoleState.h:267
std::string stationName
Name of the role or station.
Definition chooseRoleState.h:269
std::string displayLayout
Name of the display layout to use.
Definition chooseRoleState.h:270
DtEntityIdentifier entityId
Identifier of the entity to control.
Definition chooseRoleState.h:268
Defines the base class for all VREngage messages.