VR-Engage  2.3
Loading...
Searching...
No Matches
engagedState.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file engagedState.h
7//! \brief Defines the DtEngagedState class for gameplay control
8//!
9//! This file contains the DtEngagedState class which represents the application
10//! state where the user is actively controlling an entity in the simulation.
11//! This state handles gameplay-related messages, controls, and transitions
12//! while the player is engaged with a role.
13
14#pragma once
15
18#include <vrvCore/DtUniqueID.h>
19
22
23#include <QString>
24#include <string>
25
26namespace makVre
27{
28//! \brief Forward declaration of the player station application class
30
31//! \brief Forward declaration of the persistent notification class
33
34//! \brief Forward declaration of the VR-Forces set-embark message
36
37//! \brief Application state for active entity control and gameplay
38//!
39//! DtEngagedState represents the application state where the user is actively
40//! controlling an entity in the simulation. It manages gameplay controls,
41//! processes relevant messages, and handles transitions between gameplay-related
42//! states such as pausing and resuming. This state is typically nested within
43//! the network connected state.
45{
46public:
47 //! \brief Constructor
48 //! \param app Reference to the player station application
49 //!
50 //! Creates a new engaged state associated with the given application.
52
53 //! \brief Virtual destructor
54 //!
55 //! Ensures proper cleanup of the engaged state resources.
56 virtual ~DtEngagedState() override;
57
58 //! \brief Called when the state is entered
59 //! \param args Pointer to arguments from the previous state
60 //!
61 //! Sets up the gameplay environment, registers message handlers,
62 //! and initializes the player controls. This is called when the player
63 //! first enters the engaged state, typically after selecting a role.
64 //!
65 //! When LOADING_PLAYER_STATE chained an embarked-host load (re-engaging an entity
66 //! that was already embarked), this method also syncs the embarkation
67 //! tracking fields so that subsequent SimulationStateMessage handlers
68 //! see the correct baseline.
69 virtual void onEnter(const DtPlayerStationStateArgs* args) override;
70
71 //! \brief Called when the state is exited
72 //!
73 //! Cleans up resources, disconnects from the controlled entity,
74 //! and unregisters message handlers. This is called when the player
75 //! leaves the engaged state, typically when disengaging from a role.
76 virtual void onExit() override;
77
78 //! \brief Updates the state each frame
79 //! \param dt Time in seconds since the last update
80 //!
81 //! Handles per-frame processing for gameplay, including checking
82 //! for entity status changes and updating UI elements as needed.
83 virtual void tick(double dt) override;
84
85 //! \brief Called when the state becomes the topmost state again
86 //! \param args Pointer to arguments from the popped state
87 //!
88 //! Restores gameplay functionality when this state is exposed
89 //! after another state (like a menu) has been popped from the stack.
90 //! If args are non-null (LOADING_PLAYER_STATE failure), routes to
91 //! CHOOSE_ROLE_STATE instead of setting up the HUD.
92 virtual void onExposed(const DtPlayerStationStateArgs* args) override;
93
94 //! \brief Called when another state is pushed on top of this one
95 //!
96 //! Temporarily disables certain gameplay functionality while this state
97 //! is covered by another state on the stack, such as a pause menu.
98 virtual void onStacked() override;
99
100 //! \brief Checks if the simulation is currently playing
101 //! \return True if the simulation is playing, false if paused
102 //!
103 //! Reports whether the simulation is currently in a playing state
104 //! or if it's paused. This affects how inputs are processed.
105 virtual bool isPlaying() const;
106
107 //! \brief Handles escape key press messages
108 //! \param message Pointer to the key press message
109 //! \return Message handling result
110 //!
111 //! Processes escape key presses, typically bringing up the pause menu
112 //! or other options during gameplay.
114
115 //! \brief Handles back button click messages
116 //! \param message Pointer to the button click message
117 //! \return Message handling result
118 //!
119 //! Processes back button clicks, typically navigating back to a previous
120 //! screen or opening the pause menu during gameplay.
122
123 //! \brief Builds the header title for the engaged state
124 //! \return "MarkingText - Role" or a partial fallback if either is unavailable
125 QString buildEngagedTitle() const;
126
127protected:
128 //! \brief Message handlers for role assignment
129 //! @{
130
131 //! \brief Handles role assignment messages
132 //! \param message Pointer to the role assignment message
133 //! \return Message handling result
134 //!
135 //! Processes messages relating to assigning roles to players.
137
138 //! \brief Handles role unassignment messages
139 //! \param message Pointer to the role unassignment message
140 //! \return Message handling result
141 //!
142 //! Processes messages relating to removing players from roles.
144
145 //! \brief Handles entity removal messages
146 //! \param message Pointer to the entity removal message
147 //! \return Message handling result
148 //!
149 //! Processes messages relating to entities being removed from the simulation,
150 //! which may require disengaging if the player's entity is removed.
152
153 //! \brief Handles choose role button click messages
154 //! \param message Pointer to the button click message
155 //! \return Message handling result
156 //!
157 //! Processes clicking the choose role button, typically returning
158 //! to the role selection screen from gameplay.
160 //! @}
161
162 //! \brief Handles simulation state update messages
163 //! \param msg Pointer to the simulation state message
164 //! \return Message handling result
165 //!
166 //! Processes simulation state updates, particularly tracking the
167 //! role-driving state that can force the current player station
168 //! to be recreated or switched.
170
171 //! \brief Intercepts player-initiated embark/disembark requests
172 //! \param msg Pointer to the VrfSetEmbarkMessage
173 //! \return Message handling result
174 //!
175 //! Handles VrfSetEmbarkMessage to trigger immediate role transitions
176 //! for player-initiated embark/disembark, bypassing the SimulationStateMessage
177 //! polling delay. Falls back to handleSimulationStateMessage for cases where
178 //! the role cannot be determined from the embark message alone, or for
179 //! VRF-initiated embarkation changes.
181
182 //! \brief Handles entity element removal signals
183 //! \param elementId ID of the removed element
184 //!
185 //! Callback for EntityResolver signals when elements are removed.
186 //! Used to detect when the player's controlled entity is removed
187 //! from the simulation, which requires disengagement.
188 void elementRemoved(makVrv::DtElementID elementId);
189
190 //! \brief Handles session play state messages
191 //! \param message Pointer to the play state message
192 //! \return Message handling result
193 //!
194 //! Processes messages about changes to the session's play state
195 //! (playing/paused), updating UI and control systems accordingly.
197
198 //! \brief Handles modal dialog state messages
199 //! \param message Pointer to the modal state message
200 //! \return Message handling result
201 //!
202 //! Processes messages about modal dialogs opening or closing,
203 //! adjusting gameplay controls and input handling accordingly.
205
206 //! \brief Handles VR-Forces simulation rewind messages
207 //! \param message Pointer to the VrfRewindMessage
208 //! \return Message handling result (HANDLED)
209 //!
210 //! Processes rewind requests from VR-Forces, transitioning the player
211 //! back to the role selection state. The rewind message is copied and
212 //! passed as state arguments to allow the choose role state to clean up
213 //! and reset appropriately.
215
216 //! \brief Updates the state of player controls
217 //!
218 //! Enables or disables player controls based on current application state,
219 //! such as whether the simulation is playing, paused, or a modal dialog is open.
220 //! This ensures that controls are only active when appropriate.
222
223 //! \brief Checks whether a player load is pending or active
224 //!
225 //! Covers both the interval after a load is queued and the time that
226 //! LOADING_PLAYER_STATE is present in the state stack.
228
229 //! \brief Pushes LOADING_PLAYER_STATE on top to create or resume a player station
230 //! \param entityId The entity identifier to load the player station for
231 //! \param stationName The station/role name to load
232 //! \param loadPolicy Controls whether existing player stations are preserved
233 //! (embarkation) or replaced (authoritative role reassignment).
234 //! \param destroyEntityId Entity whose player station should be destroyed
235 //! before the new station is created. Null means no targeted destruction.
236 //! \param destroyStationName Station name of the player to destroy.
237 //! \param isEmbarkation True when the load was triggered by an embarkation
238 //! event. Passed through to LoadPlayerRequestMessage so ownership
239 //! acquisition retains the base entity while loading an embarked-host role.
240 //! \param isEmbarkationTransition True when the load follows an authoritative
241 //! embark or disembark update. LOADING_PLAYER_STATE skips its stale-state
242 //! embark probe but retains its normal settle window.
243 //!
244 //! Sets myLoadingPlayer, packages the entity/station into args, and pushes
245 //! LOADING_PLAYER_STATE. When loading completes, onExposed clears the flag.
246 void loadPlayer(const DtEntityIdentifier& entityId, const std::string& stationName,
248 const DtEntityIdentifier& destroyEntityId = DtEntityIdentifier::nullId(),
249 const std::string& destroyStationName = std::string(),
250 bool isEmbarkation = false,
251 bool isEmbarkationTransition = false);
252
253 //! \brief Determines which player station should be destroyed when loading a new one.
254 //!
255 //! Compares the target load against the current player stack. If an active
256 //! embarked-host station (not the base player) exists and differs from the target,
257 //! it is returned as the destroy target. Used by processEmbarkationChange
258 //! and other callers to centralise the destroy-target decision.
259 //!
260 //! \param targetEntity Entity for the station being loaded
261 //! \param targetStation Station/role name being loaded
262 //! \param[out] outDestroyEntity Entity whose station should be destroyed (nullId if none)
263 //! \param[out] outDestroyStation Station name to destroy (empty if none)
265 const DtEntityIdentifier& targetEntity, const std::string& targetStation,
266 DtEntityIdentifier& outDestroyEntity, std::string& outDestroyStation);
267
268 //! \brief Unified handler for embarkation, disembarkation, and role switches.
269 //!
270 //! Called by both handleSimulationStateMessage and handleVrfSetEmbarkMessage
271 //! after they determine the new (host, role) pair. Updates tracking state,
272 //! resolves which station to destroy, restores base display settings on
273 //! disembark, and calls loadPlayer.
274 //!
275 //! \param newHost Host entity (nullId for disembark)
276 //! \param newRole Role name (empty for disembark)
278 const DtEntityIdentifier& newHost, const std::string& newRole);
279
280 //! \brief Resolves the player-station role for a VrfSetEmbarkMessage slot.
281 //!
282 //! Looks up the parent host's entity type via the entity resolver, then
283 //! consults the player-creation palette to find a role matching the slot
284 //! name (preferred) or slot type. Returns an empty string if the slot
285 //! info is insufficient to determine a role; callers should fall back to
286 //! waiting for the next SimulationStateMessage.
287 //!
288 //! \param embarkMsg Source message; its parent entity ID and slot
289 //! name/type are read.
290 //! \return The resolved role name, or empty string if unresolved.
292
293 //! \brief Synchronises embarkation tracking with the active player station.
294 //!
295 //! Called from onExposed after LOADING_PLAYER_STATE pops. When a chained
296 //! embarked-host load has occurred, the base player (index 0) and active
297 //! player differ; in that case the active player's identity is mirrored into
298 //! myEmbarkedHost/myEmbarkedRole and myBasePlayerIsInvisible is set so the
299 //! next SimulationStateMessage does not see a stale mismatch and trigger
300 //! a redundant processEmbarkationChange. When base == active (no
301 //! embarkation), the tracking fields are cleared.
303
304protected:
305 // --- Runtime UI state ---
306
307 //! \brief Persistent notification displayed during gameplay
308 std::shared_ptr<DtVreHeaderFooterUI> myPersistentNotification;
309
310 //! \brief Flag indicating whether the simulation is currently playing
312
313 //! \brief Flag indicating whether a modal dialog is currently open
315
316 //! \brief Connection to the entity removed signal
317 boost::signals2::connection myEntityRemovedConnection;
318
319 // --- Base identity (captured on initial engage) ---
320 //! These fields record the human player's original role assignment.
321 //! They are restored after disembark and updated by handleAssignRolePlayer
322 //! when the server authoritatively reassigns the entity.
323
324 //! @{
325
326 //! \brief Entity identifier of the human player's original assignment
327 DtEntityIdentifier myBaseEntityId;
328
329 //! \brief Station (role) name of the human player's original assignment
330 std::string myBaseStationName;
331
332 //! \brief Display layout of the human player's original assignment
334
335 //! \brief Whether the human player was originally in spectator mode
337
338 //! @}
339
340 // --- Embarkation overlay (SimulationState / VrfSetEmbark tracking) ---
341 //! These fields track the current embarkation state reported by VRF.
342 //! They are a layered override on top of the base identity — the human
343 //! player's identity is preserved in the base fields above.
344
345 //! @{
346
347 //! \brief Role name assigned to the player through embarkation
348 std::string myEmbarkedRole;
349
350 //! \brief Entity identifier of the embarkation host
351 DtEntityIdentifier myEmbarkedHost;
352
353 //! \brief Whether the base player entity is invisible (notional embarkation slot)
355
356 //! @}
357
358 //! \brief True after a player load has been requested and before loading completes.
359 //!
360 //! Used with LOADING_PLAYER_STATE stack membership by isPlayerLoadInProgress()
361 //! to prevent duplicate load requests while the state transition is pending.
363
364 //! \brief True until the first onExposed after onEnter (for auto-run in hosted sessions)
366};
367} // namespace makVre
std::string myBaseDisplayLayout
Display layout of the human player's original assignment.
Definition engagedState.h:333
void syncEmbarkationTrackingFromActivePlayer()
Synchronises embarkation tracking with the active player station.
bool myIsModalOpen
Flag indicating whether a modal dialog is currently open.
Definition engagedState.h:314
DtEntityIdentifier myEmbarkedHost
Entity identifier of the embarkation host.
Definition engagedState.h:351
virtual DtVreMessageResult handleAssignRolePlayer(DtVreMessage *message)
Message handlers for role assignment.
virtual bool isPlaying() const
Checks if the simulation is currently playing.
std::string resolveEmbarkedRoleFromSlot(const VrfSetEmbarkMessage *embarkMsg)
Resolves the player-station role for a VrfSetEmbarkMessage slot.
virtual void onStacked() override
Called when another state is pushed on top of this one.
virtual void onExit() override
Called when the state is exited.
void elementRemoved(makVrv::DtElementID elementId)
Handles entity element removal signals.
virtual void updatePlayerControlsState()
Updates the state of player controls.
virtual DtVreMessageResult handleSimulationStateMessage(DtVreMessage *msg)
Handles simulation state update messages.
virtual void tick(double dt) override
Updates the state each frame.
virtual DtVreMessageResult handleSessionPlayState(DtVreMessage *message)
Handles session play state messages.
std::string myBaseStationName
Station (role) name of the human player's original assignment.
Definition engagedState.h:330
bool myIsPlaying
Flag indicating whether the simulation is currently playing.
Definition engagedState.h:311
virtual DtVreMessageResult handleChooseRoleButtonClicked(DtVreMessage *message)
Handles choose role button click messages.
virtual void onExposed(const DtPlayerStationStateArgs *args) override
Called when the state becomes the topmost state again.
DtEntityIdentifier myBaseEntityId
These fields record the human player's original role assignment. They are restored after disembark an...
Definition engagedState.h:327
virtual DtVreMessageResult handleVrfSetEmbarkMessage(DtVreMessage *msg)
Intercepts player-initiated embark/disembark requests.
std::shared_ptr< DtVreHeaderFooterUI > myPersistentNotification
Persistent notification displayed during gameplay.
Definition engagedState.h:308
QString buildEngagedTitle() const
Builds the header title for the engaged state.
virtual DtVreMessageResult handleBackButtonClicked(DtVreMessage *message)
Handles back button click messages.
virtual DtVreMessageResult handleEntityRemoved(DtVreMessage *message)
Handles entity removal messages.
std::string myEmbarkedRole
These fields track the current embarkation state reported by VRF. They are a layered override on top ...
Definition engagedState.h:348
boost::signals2::connection myEntityRemovedConnection
Connection to the entity removed signal.
Definition engagedState.h:317
bool myBasePlayerIsInvisible
Whether the base player entity is invisible (notional embarkation slot)
Definition engagedState.h:354
bool myLoadingPlayer
True after a player load has been requested and before loading completes.
Definition engagedState.h:362
virtual DtVreMessageResult handleVrfRewind(DtVreMessage *message)
Handles VR-Forces simulation rewind messages.
bool myAutoRunPending
True until the first onExposed after onEnter (for auto-run in hosted sessions)
Definition engagedState.h:365
void loadPlayer(const DtEntityIdentifier &entityId, const std::string &stationName, LoadPlayerRequestMessage::LoadPolicy loadPolicy=LoadPlayerRequestMessage::LoadPolicy_PreserveExisting, const DtEntityIdentifier &destroyEntityId=DtEntityIdentifier::nullId(), const std::string &destroyStationName=std::string(), bool isEmbarkation=false, bool isEmbarkationTransition=false)
Pushes LOADING_PLAYER_STATE on top to create or resume a player station.
void resolveDestroyTarget(const DtEntityIdentifier &targetEntity, const std::string &targetStation, DtEntityIdentifier &outDestroyEntity, std::string &outDestroyStation)
Determines which player station should be destroyed when loading a new one.
void processEmbarkationChange(const DtEntityIdentifier &newHost, const std::string &newRole)
Unified handler for embarkation, disembarkation, and role switches.
DtEngagedState(DtPlayerStationApp &app)
Constructor.
virtual ~DtEngagedState() override
Virtual destructor.
bool isPlayerLoadInProgress() const
Checks whether a player load is pending or active.
virtual DtVreMessageResult handleEscKey(DtVreMessage *message)
Handles escape key press messages.
virtual DtVreMessageResult handleUnassignRolePlayer(DtVreMessage *message)
Handles role unassignment messages.
virtual DtVreMessageResult handleModalState(DtVreMessage *message)
Handles modal dialog state messages.
bool myBaseSpectatorMode
Whether the human player was originally in spectator mode.
Definition engagedState.h:336
virtual void onEnter(const DtPlayerStationStateArgs *args) override
Called when the state is entered.
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:155
Class for passing arguments during state transitions.
Definition playerStationState.h:47
DtPlayerStationApp & app() const
Gets a reference to the player station application.
DtPlayerStationState(DtPlayerStationApp &app, std::string stateType)
Constructor.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
LoadPolicy
LoadPolicy enumeration.
Definition loadPlayerRequest.h:38
@ LoadPolicy_PreserveExisting
Definition loadPlayerRequest.h:39
Send to the DtVrfRemoteControlConnector to generate a VRF set embarked request.
Definition vrfSetEmbark.h:35
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
!
Definition glsVreMessageUtil.h:50
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Defines base classes for the VR-Engage state management system.
Defines the base class for all VREngage messages.