VR-Engage  2.2
Loading...
Searching...
No Matches
vreExternalLoadingPageLogic.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file vreExternalLoadingPageLogic.h
7//! \brief Defines the logic for managing external loading screens in VR-Engage
8//!
9//! This file contains the DtVreExternalLoadingPageLogic class which manages
10//! an external loading screen process. It handles communication with the
11//! loading screen through a TCP socket connection, allowing VR-Engage
12//! to display loading progress and status updates during resource-intensive operations.
13
14#pragma once
15
17
19
20#include <QObject>
21#include <QProcess>
22#include <QtNetwork/QTcpSocket>
23
24class QQuickItem;
25class QTcpServer;
26class QTcpSocket;
27
28namespace makVre
29{
30//! \brief Manager class for external loading screen process and communication
31//!
32//! DtVreExternalLoadingPageLogic manages a separate process that displays a
33//! loading screen with a progress bar. It communicates with this process via
34//! TCP sockets to update loading status, progress, and estimated completion time.
35//! This allows resource-intensive operations like terrain loading to display
36//! progress without blocking the main application.
38{
39 Q_OBJECT;
40
41public:
42 //! \brief Constructor
43 //!
44 //! Creates a new external loading page logic manager with default state.
46
47 //! \brief Destructor
48 //!
49 //! Cleans up resources, including shutting down the TCP server and
50 //! terminating the external process if they are still running.
52
53 //! \brief Initializes the TCP server for loading screen communication
54 //! \param port Specific port to use for the server, or 0 to use process ID
55 //!
56 //! Sets up the TCP server that will communicate with the external loading
57 //! screen process. If port is 0, the server will use the current process ID
58 //! as the port number to avoid conflicts with other instances.
59 virtual void initializeServer(unsigned short int port = 0);
60
61 //! \brief Starts the external loading page process
62 //! \param timeoutTime Maximum expected loading time in milliseconds
63 //! \param currentTime Current loading progress in milliseconds
64 //! \param seed Random seed for loading screen visuals
65 //! \param initialMessage Initial status message to display
66 //!
67 //! Launches the external loading screen process with initial parameters.
68 //! The process will display a progress bar based on the current and maximum times,
69 //! along with the provided status message. The seed parameter can be used
70 //! to generate consistent random visuals across multiple launches.
71 virtual void initializeProcess(
72 int timeoutTime, int currentTime, int seed, const QString& initialMessage = "Loading...");
73
74 //! \brief Shuts down the external process and TCP server
75 //!
76 //! Terminates the external loading screen process if it's running
77 //! and stops the TCP server. This should be called when loading
78 //! is complete or if the loading operation is canceled.
79 virtual void shutdown();
80
81 //! \brief Sends a status message to the loading screen
82 //! \param msg Text message to display on the loading screen
83 //!
84 //! Updates the status text displayed on the loading screen.
85 //! This is typically used to indicate the current operation being performed,
86 //! such as "Loading terrain..." or "Initializing entities...".
87 virtual void sendStatus(const QString& msg);
88
89 //! \brief Updates the current progress time
90 //! \param ms Current progress time in milliseconds
91 //!
92 //! Updates the current progress value displayed on the loading screen.
93 //! This affects the position of the progress bar indicator and any
94 //! numerical progress display. The value should be between 0 and
95 //! the maximum time set with sendMaximumTime().
96 virtual void sendCurrentTime(int ms);
97
98 //! \brief Sets the maximum expected loading time
99 //! \param ms Maximum loading time in milliseconds
100 //!
101 //! Updates the maximum expected loading time for the progress bar.
102 //! This affects the scale of the progress bar, allowing it to provide
103 //! an accurate visual representation of progress. The current time
104 //! sent with sendCurrentTime() will be shown as a proportion of this maximum.
105 virtual void sendMaximumTime(int ms);
106
107 //! \brief Checks if the loading screen is ready
108 //! \return True if the loading screen is connected and ready, false otherwise
109 //!
110 //! Determines whether the external loading screen process has
111 //! connected to the TCP server and is ready to receive updates.
112 //! This can be used to ensure the loading screen is functioning
113 //! before attempting to send status or progress updates.
114 virtual bool isLoadingScreenReady();
115
116public slots:
117 //! \brief Handles new client connections to the TCP server
118 //!
119 //! Slot called when a new client (the loading screen process)
120 //! connects to the TCP server. Sets up the connection and
121 //! updates the internal state to reflect the connection.
122 virtual void newConnection();
123
124 //! \brief Handles client disconnections
125 //!
126 //! Slot called when a client disconnects from the TCP server.
127 //! Updates the internal state and emits the smbDisconnected signal.
129
130 //! \brief Processes data received from clients
131 //!
132 //! Slot called when data is received from a connected client.
133 //! Parses and processes the messages sent by the loading screen process.
135
136signals:
137 //! \brief Signal emitted when a client disconnects
138 //!
139 //! This signal is emitted when the loading screen process
140 //! disconnects from the TCP server. It can be used by the
141 //! application to respond to unexpected disconnections.
143
144protected:
145 //! \brief Sends data to all connected clients
146 //! \param msg Message to send to clients
147 //!
148 //! Internal method that handles the low-level details of sending
149 //! messages to all connected clients. This is used by the public
150 //! methods to communicate with the loading screen process.
151 virtual void sendData(const QString& msg);
152
153protected:
154 //! \brief List of connected client sockets
155 //!
156 //! Contains pointers to all TCP socket connections to clients.
157 //! Typically there will be only one client (the loading screen process).
158 QList<QTcpSocket*> myClients;
159
160 //! \brief TCP server for communicating with the loading screen
161 //!
162 //! Manages the TCP server that listens for connections from
163 //! the external loading screen process.
164 std::shared_ptr<QTcpServer> myTCPServer;
165
166 //! \brief Size of the next block to read
167 //!
168 //! Used during message parsing to determine the size of the
169 //! next block of data to read from the socket.
171
172 //! \brief External process for the loading screen
173 //!
174 //! Manages the external process that displays the loading screen.
175 QProcess myProcess;
176
177 //! \brief Flag indicating whether the loading screen is ready
178 //!
179 //! When true, indicates that the loading screen process has connected
180 //! to the TCP server and is ready to receive updates.
182};
183
184} // namespace makVre
bool myScreenReady
Flag indicating whether the loading screen is ready.
Definition vreExternalLoadingPageLogic.h:181
virtual void sendMaximumTime(int ms)
Sets the maximum expected loading time.
virtual bool isLoadingScreenReady()
Checks if the loading screen is ready.
quint16 myNextBlockSize
Size of the next block to read.
Definition vreExternalLoadingPageLogic.h:170
virtual void sendStatus(const QString &msg)
Sends a status message to the loading screen.
virtual void shutdown()
Shuts down the external process and TCP server.
virtual void sendData(const QString &msg)
Sends data to all connected clients.
virtual void newConnection()
Handles new client connections to the TCP server.
void readClient()
Processes data received from clients.
virtual ~DtVreExternalLoadingPageLogic() override
Destructor.
virtual void initializeProcess(int timeoutTime, int currentTime, int seed, const QString &initialMessage="Loading...")
Starts the external loading page process.
virtual void initializeServer(unsigned short int port=0)
Initializes the TCP server for loading screen communication.
QProcess myProcess
External process for the loading screen.
Definition vreExternalLoadingPageLogic.h:175
virtual void sendCurrentTime(int ms)
Updates the current progress time.
void gotDisconnection()
Handles client disconnections.
QList< QTcpSocket * > myClients
List of connected client sockets.
Definition vreExternalLoadingPageLogic.h:158
void smbDisconnected()
Signal emitted when a client disconnects.
std::shared_ptr< QTcpServer > myTCPServer
TCP server for communicating with the loading screen.
Definition vreExternalLoadingPageLogic.h:164
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
Defines the base class for all VREngage messages.