VR-Engage  2.2
Loading...
Searching...
No Matches
loadingState.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file loadingState.h
7//! \brief Defines the loading state for terrain and scenario data in VR-Engage
8//!
9//! This file contains the DtLoadingState class which manages the application state
10//! during terrain and scenario loading operations. It provides a UI for displaying
11//! loading progress, handles the loading sequence, and transitions to the appropriate
12//! state once loading is complete.
13
14#pragma once
15
17
19
20#include <chrono>
21
23
24namespace makArchives
25{
26class DtObserverStateRecordsList;
27}
28
29namespace makVre
30{
31//! \brief Forward declaration of the session load data message class
32class SessionLoadDataMessage;
33
34//! \brief Forward declaration of the loading page UI class
35class DtVreLoadingPage;
36
37//! \brief Forward declaration of the external loading page logic class
38class DtVreExternalLoadingPageLogic;
39
40//! \brief Application state for loading terrain and scenario data
41//!
42//! DtLoadingState is responsible for loading terrain and scenario data
43//! into VR-Engage. It presents a loading UI with progress information,
44//! coordinates the loading sequence between simulation and visualization
45//! components, and handles transitions to the appropriate state once
46//! loading is complete.
48{
49public:
50 //! \brief Constructor
51 //! \param app Reference to the player station application
52 //!
53 //! Creates a new loading state associated with the given application.
55
56 //! \brief Virtual destructor
57 //!
58 //! Ensures proper cleanup of loading state resources.
59 virtual ~DtLoadingState() override;
60
61 //! \brief Called when the state is entered
62 //! \param args Pointer to arguments from the previous state
63 //!
64 //! Initializes the loading process, sets up the loading UI, and begins
65 //! the sequence of loading terrain and scenario data. The args parameter
66 //! typically contains information about what needs to be loaded.
67 virtual void onEnter(const DtPlayerStationStateArgs* args) override;
68
69 //! \brief Called when the state is exited
70 //!
71 //! Cleans up loading resources, hides the loading UI, and prepares for
72 //! the transition to the next state (typically a session state).
73 virtual void onExit() override;
74
75 //! \brief Updates the state each frame
76 //! \param dt Time in seconds since the last update
77 //!
78 //! Monitors loading progress, updates the loading UI, and checks for
79 //! completion conditions to determine when to transition to the next state.
80 virtual void tick(double dt) override;
81
82protected:
83 //! \brief Handles backend status update messages
84 //! \param msg Pointer to the backend status message
85 //! \return Message handling result
86 //!
87 //! Processes status updates from the backend system, updating the loading
88 //! progress based on the current state of backend components.
90
91 //! \brief Handles SMS load completion messages
92 //! \param msg Pointer to the load complete message
93 //! \return Message handling result
94 //!
95 //! Processes notifications that the Simulation Management System has
96 //! completed loading the requested terrain or scenario data.
98
99 //! \brief Handles session status messages
100 //! \param msg Pointer to the session status message
101 //! \return Message handling result
102 //!
103 //! Processes updates about the current session status, which may indicate
104 //! when the session is ready for player engagement after loading.
106
107 //! \brief Initiates terrain loading in the simulation component
108 //!
109 //! Starts the loading process for terrain data in the simulation system.
110 //! This prepares the terrain for simulation physics and entity interactions.
111 virtual void loadSimTerrain();
112
113 //! \brief Initiates terrain loading in the GUI/visualization component
114 //!
115 //! Starts the loading process for terrain data in the visualization system.
116 //! This prepares the terrain for visual rendering and display.
117 virtual void loadGuiTerrain();
118
119 //! \brief Loads observer views defined in the scenario file
120 //! \return True if observer views were loaded successfully, false otherwise
121 //!
122 //! Attempts to load pre-defined observer views from the scenario file,
123 //! which provide camera positions and orientations for observing the simulation.
125
126 virtual bool parseObserverViewsXml(const DtString& xml, makArchives::DtObserverStateRecordsList& record);
127
128 //! \brief Searches recursively for a file in a directory
129 //! \param directory Directory to start the search from
130 //! \param filenameToFind Filename to search for
131 //! \param foundPath [out] Path to the found file if successful
132 //! \return True if the file was found, false otherwise
133 //!
134 //! Performs a recursive search for a specified file within a directory
135 //! and its subdirectories. If found, the full path is stored in foundPath.
136 virtual bool findFileRecursive(
137 const std::string& directory, const std::string& filenameToFind, DtFilename& foundPath);
138
139 //! \brief Sets the status text in the loading UI
140 //! \param msg Text message to display
141 //!
142 //! Updates the status text shown in the loading UI to inform the user
143 //! about the current loading activity or progress.
144 virtual void setStatusText(const QString& msg);
145
146 //! \brief Sets the estimated loading time
147 //! \param ms Estimated time in milliseconds
148 //!
149 //! Sets the estimated time required to complete the loading process,
150 //! which may be used to update the progress indicator in the UI.
151 virtual void setTimeToLoad(const int ms);
152
153 //! \brief Gets the estimated loading time for a file
154 //! \param file Path to the scenario or terrain file
155 //! \return Estimated loading time in milliseconds, or -1 if file not found
156 //!
157 //! Calculates the estimated time needed to load the specified scenario
158 //! or terrain file. This starts a timer if not already started and may use
159 //! historical data to provide an estimate. Returns -1 if the file is not found.
160 int getEstimatedTimeToLoad(const std::string& file);
161
162 //! \brief Stops the loading timer and logs statistics
163 //! \param file Path to the scenario or terrain file that was loaded
164 //!
165 //! Stops the loading timer started by getEstimatedTimeToLoad() and logs
166 //! the actual loading time to a data file for future reference. This helps
167 //! improve future loading time estimates.
168 void logEstimatedTimeToLoad(const std::string& file);
169
170protected:
171 //! \brief Data message containing loading parameters
172 //!
173 //! Contains information about what terrain or scenario to load
174 //! and how it should be loaded.
175 std::shared_ptr<SessionLoadDataMessage> myLoadData;
176
177 //! \brief Loading page UI component
178 //!
179 //! Provides the user interface for displaying loading progress.
180 std::shared_ptr<DtVreLoadingPage> myLoadingPage;
181
182 //! \brief External loading page logic
183 //!
184 //! Handles advanced loading UI functionality and interactions.
185 std::shared_ptr<DtVreExternalLoadingPageLogic> myExternalLoadingLogic;
186
187 //! \brief SMS loading status bitmask
188 //!
189 //! Tracks which components of the Simulation Management System
190 //! have completed loading through a bitmask of status flags.
192
193 //! \brief Flag indicating if terrain load command was sent
195
196 //! \brief Flag indicating if simulation terrain loading is complete
198
199 //! \brief Flag indicating if GUI terrain loading is complete
201
202 //! \brief Server port number for the loaded session
204
205 //! \brief Timer start timestamp
206 //!
207 //! Records when loading began for performance measurement.
208 std::chrono::time_point<std::chrono::steady_clock> myTimerStart;
209
210 //! \brief Timer end timestamp
211 //!
212 //! Records when loading completed for performance measurement.
213 std::chrono::time_point<std::chrono::steady_clock> myTimerEnd;
214};
215
216} // namespace makVre
virtual bool loadScenarioObserverViews()
Loads observer views defined in the scenario file.
virtual void tick(double dt) override
Updates the state each frame.
int mySmsLoadStatusBits
SMS loading status bitmask.
Definition loadingState.h:191
void logEstimatedTimeToLoad(const std::string &file)
Stops the loading timer and logs statistics.
std::shared_ptr< SessionLoadDataMessage > myLoadData
Data message containing loading parameters.
Definition loadingState.h:175
virtual void loadGuiTerrain()
Initiates terrain loading in the GUI/visualization component.
virtual void setTimeToLoad(const int ms)
Sets the estimated loading time.
std::chrono::time_point< std::chrono::steady_clock > myTimerStart
Timer start timestamp.
Definition loadingState.h:208
virtual DtVreMessageResult handleSmsLoadComplete(DtVreMessage *msg)
Handles SMS load completion messages.
bool myDidGuiLoad
Flag indicating if GUI terrain loading is complete.
Definition loadingState.h:200
bool myDidSimLoad
Flag indicating if simulation terrain loading is complete.
Definition loadingState.h:197
DtLoadingState(DtPlayerStationApp &app)
Constructor.
virtual void loadSimTerrain()
Initiates terrain loading in the simulation component.
virtual bool parseObserverViewsXml(const DtString &xml, makArchives::DtObserverStateRecordsList &record)
virtual DtVreMessageResult handleBackendStatus(DtVreMessage *msg)
Handles backend status update messages.
int getEstimatedTimeToLoad(const std::string &file)
Gets the estimated loading time for a file.
virtual void onEnter(const DtPlayerStationStateArgs *args) override
Called when the state is entered.
virtual bool findFileRecursive(const std::string &directory, const std::string &filenameToFind, DtFilename &foundPath)
Searches recursively for a file in a directory.
std::shared_ptr< DtVreLoadingPage > myLoadingPage
Loading page UI component.
Definition loadingState.h:180
int myServerPort
Server port number for the loaded session.
Definition loadingState.h:203
std::shared_ptr< DtVreExternalLoadingPageLogic > myExternalLoadingLogic
External loading page logic.
Definition loadingState.h:185
virtual ~DtLoadingState() override
Virtual destructor.
virtual DtVreMessageResult handleSessionStatus(DtVreMessage *msg)
Handles session status messages.
virtual void onExit() override
Called when the state is exited.
std::chrono::time_point< std::chrono::steady_clock > myTimerEnd
Timer end timestamp.
Definition loadingState.h:213
bool mySentTerrainLoad
Flag indicating if terrain load command was sent.
Definition loadingState.h:194
virtual void setStatusText(const QString &msg)
Sets the status text in the loading UI.
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.
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
Definition loadingState.h:25
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.