VR-Engage  2.2
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
21
22namespace makVre
23{
24//! \brief Forward declaration of the player station application class
26
27//! \brief Forward declaration of the persistent notification class
29
30//! \brief Application state for active entity control and gameplay
31//!
32//! DtEngagedState represents the application state where the user is actively
33//! controlling an entity in the simulation. It manages gameplay controls,
34//! processes relevant messages, and handles transitions between gameplay-related
35//! states such as pausing and resuming. This state is typically nested within
36//! the network connected state.
38{
39public:
40 //! \brief Constructor
41 //! \param app Reference to the player station application
42 //!
43 //! Creates a new engaged state associated with the given application.
45
46 //! \brief Virtual destructor
47 //!
48 //! Ensures proper cleanup of the engaged state resources.
49 virtual ~DtEngagedState() override;
50
51 //! \brief Called when the state is entered
52 //! \param args Pointer to arguments from the previous state
53 //!
54 //! Sets up the gameplay environment, registers message handlers,
55 //! and initializes the player controls. This is called when the player
56 //! first enters the engaged state, typically after selecting a role.
57 virtual void onEnter(const DtPlayerStationStateArgs* args) override;
58
59 //! \brief Called when the state is exited
60 //!
61 //! Cleans up resources, disconnects from the controlled entity,
62 //! and unregisters message handlers. This is called when the player
63 //! leaves the engaged state, typically when disengaging from a role.
64 virtual void onExit() override;
65
66 //! \brief Updates the state each frame
67 //! \param dt Time in seconds since the last update
68 //!
69 //! Handles per-frame processing for gameplay, including checking
70 //! for entity status changes and updating UI elements as needed.
71 virtual void tick(double dt) override;
72
73 //! \brief Called when the state becomes the topmost state again
74 //!
75 //! Restores gameplay functionality when this state is exposed
76 //! after another state (like a menu) has been popped from the stack.
77 virtual void onExposed() override;
78
79 //! \brief Called when another state is pushed on top of this one
80 //!
81 //! Temporarily disables certain gameplay functionality while this state
82 //! is covered by another state on the stack, such as a pause menu.
83 virtual void onStacked() override;
84
85 //! \brief Checks if the simulation is currently playing
86 //! \return True if the simulation is playing, false if paused
87 //!
88 //! Reports whether the simulation is currently in a playing state
89 //! or if it's paused. This affects how inputs are processed.
90 virtual bool isPlaying() const;
91
92 //! \brief Handles escape key press messages
93 //! \param message Pointer to the key press message
94 //! \return Message handling result
95 //!
96 //! Processes escape key presses, typically bringing up the pause menu
97 //! or other options during gameplay.
99
100 //! \brief Handles back button click messages
101 //! \param message Pointer to the button click message
102 //! \return Message handling result
103 //!
104 //! Processes back button clicks, typically navigating back to a previous
105 //! screen or opening the pause menu during gameplay.
107
108protected:
109 //! \brief Message handlers for role assignment
110 //! @{
111
112 //! \brief Handles role assignment messages
113 //! \param message Pointer to the role assignment message
114 //! \return Message handling result
115 //!
116 //! Processes messages relating to assigning roles to players.
118
119 //! \brief Handles role unassignment messages
120 //! \param message Pointer to the role unassignment message
121 //! \return Message handling result
122 //!
123 //! Processes messages relating to removing players from roles.
125
126 //! \brief Handles entity removal messages
127 //! \param message Pointer to the entity removal message
128 //! \return Message handling result
129 //!
130 //! Processes messages relating to entities being removed from the simulation,
131 //! which may require disengaging if the player's entity is removed.
133
134 //! \brief Handles choose role button click messages
135 //! \param message Pointer to the button click message
136 //! \return Message handling result
137 //!
138 //! Processes clicking the choose role button, typically returning
139 //! to the role selection screen from gameplay.
141 //! @}
142
143 //! \brief Handles simulation state update messages
144 //! \param msg Pointer to the simulation state message
145 //! \return Message handling result
146 //!
147 //! Processes simulation state updates, particularly tracking changes
148 //! to embarkation status that might affect the player's entity.
150
151 //! \brief Handles entity element removal signals
152 //! \param elementId ID of the removed element
153 //!
154 //! Callback for EntityResolver signals when elements are removed.
155 //! Used to detect when the player's controlled entity is removed
156 //! from the simulation, which requires disengagement.
157 void elementRemoved(makVrv::DtElementID elementId);
158
159 //! \brief Handles session play state messages
160 //! \param message Pointer to the play state message
161 //! \return Message handling result
162 //!
163 //! Processes messages about changes to the session's play state
164 //! (playing/paused), updating UI and control systems accordingly.
166
167 //! \brief Handles modal dialog state messages
168 //! \param message Pointer to the modal state message
169 //! \return Message handling result
170 //!
171 //! Processes messages about modal dialogs opening or closing,
172 //! adjusting gameplay controls and input handling accordingly.
174
175 //! \brief Handles VR-Forces simulation rewind messages
176 //! \param message Pointer to the VrfRewindMessage
177 //! \return Message handling result (HANDLED)
178 //!
179 //! Processes rewind requests from VR-Forces, transitioning the player
180 //! back to the role selection state. The rewind message is copied and
181 //! passed as state arguments to allow the choose role state to clean up
182 //! and reset appropriately.
184
185 //! \brief Updates the state of player controls
186 //!
187 //! Enables or disables player controls based on current application state,
188 //! such as whether the simulation is playing, paused, or a modal dialog is open.
189 //! This ensures that controls are only active when appropriate.
191
192 //! \brief Updates player state after embarkation changes
193 //!
194 //! Called when embarkation status changes, such as when getting in
195 //! or out of a vehicle, to update UI and control systems accordingly.
197
198 //! \brief Starts the player station with default settings
199 //! \return True if startup was successful, false otherwise
200 //!
201 //! Initializes the player station for the current entity and role
202 //! using the default station configuration.
203 virtual bool startPlayerStation();
204
205 //! \brief Starts the player station with specific entity and station
206 //! \param entityId Identifier of the entity to control
207 //! \param station Name of the station or role to use
208 //! \return True if startup was successful, false otherwise
209 //!
210 //! Initializes the player station for a specific entity and role,
211 //! typically used when switching entities or roles during gameplay.
212 virtual bool startPlayerStation(const DtEntityIdentifier& entityId, const std::string& station);
213
214 //! \brief Ensures the application window has focus before engaging
215 //!
216 //! Checks if the application currently has active focus, and if not,
217 //! attempts to activate and raise the main window. This is called before
218 //! creating a player station to ensure that entity control logic has the
219 //! correct focus state for activating mouse control.
220 //!
221 //! \note Uses Qt window activation methods to bring the window to front
222 //! \see startPlayerStation()
223 virtual void activateWindowFocus();
224
225protected:
226 //! \brief Persistent notification displayed during gameplay
227 std::shared_ptr<DtPlayerStationPersistentNotification> myPersistentNotification;
228
229 //! \brief Flag indicating whether the simulation is currently playing
231
232 //! \brief Flag indicating whether a modal dialog is currently open
234
235 //! \brief Connection to the entity removed signal
236 boost::signals2::connection myEntityRemovedConnection;
237
238 //! \brief Role name for embarked player
240
241 //! \brief Entity identifier of the host entity for embarked player
242 DtEntityIdentifier myBasePlayerHost;
243
244 //! \brief Flag indicating whether the player entity is invisible
246
247 //! \brief Flag indicating that the entity state has changed
249};
250} // namespace makVre
bool myIsModalOpen
Flag indicating whether a modal dialog is currently open.
Definition engagedState.h:233
virtual DtVreMessageResult handleAssignRolePlayer(DtVreMessage *message)
Message handlers for role assignment.
virtual bool isPlaying() const
Checks if the simulation is currently playing.
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.
bool myOhMySomethingHasChanged
Flag indicating that the entity state has changed.
Definition engagedState.h:248
virtual void activateWindowFocus()
Ensures the application window has focus before engaging.
std::shared_ptr< DtPlayerStationPersistentNotification > myPersistentNotification
Persistent notification displayed during gameplay.
Definition engagedState.h:227
virtual void tick(double dt) override
Updates the state each frame.
virtual DtVreMessageResult handleSessionPlayState(DtVreMessage *message)
Handles session play state messages.
virtual DtVreMessageResult handleSimulationStateMessage(makVre::DtVreMessage *msg)
Handles simulation state update messages.
bool myIsPlaying
Flag indicating whether the simulation is currently playing.
Definition engagedState.h:230
virtual DtVreMessageResult handleChooseRoleButtonClicked(DtVreMessage *message)
Handles choose role button click messages.
virtual bool startPlayerStation()
Starts the player station with default settings.
virtual DtVreMessageResult handleBackButtonClicked(DtVreMessage *message)
Handles back button click messages.
virtual DtVreMessageResult handleEntityRemoved(DtVreMessage *message)
Handles entity removal messages.
boost::signals2::connection myEntityRemovedConnection
Connection to the entity removed signal.
Definition engagedState.h:236
bool myBasePlayerIsInvisible
Flag indicating whether the player entity is invisible.
Definition engagedState.h:245
virtual DtVreMessageResult handleVrfRewind(DtVreMessage *message)
Handles VR-Forces simulation rewind messages.
std::string myBasePlayerEmbarkedRole
Role name for embarked player.
Definition engagedState.h:239
virtual void onExposed() override
Called when the state becomes the topmost state again.
DtEngagedState(DtPlayerStationApp &app)
Constructor.
virtual ~DtEngagedState() override
Virtual destructor.
virtual void updatePlayersForEmbarkationChange()
Updates player state after embarkation changes.
virtual DtVreMessageResult handleEscKey(DtVreMessage *message)
Handles escape key press messages.
virtual DtVreMessageResult handleUnassignRolePlayer(DtVreMessage *message)
Handles role unassignment messages.
virtual bool startPlayerStation(const DtEntityIdentifier &entityId, const std::string &station)
Starts the player station with specific entity and station.
virtual DtVreMessageResult handleModalState(DtVreMessage *message)
Handles modal dialog state messages.
DtEntityIdentifier myBasePlayerHost
Entity identifier of the host entity for embarked player.
Definition engagedState.h:242
virtual void onEnter(const DtPlayerStationStateArgs *args) override
Called when the state is entered.
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:163
Persistent notification UI component for VR-Engage.
Definition playerStationPersistentNotification.h:35
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.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
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
Defines base classes for the VR-Engage state management system.
Defines the base class for all VREngage messages.