game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
launch_controller.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// launch_controller.h
4// ==============================================================================
5// Controller for game launching operations - UI-agnostic business logic
6// Coordinates game launching, process management, and state tracking
7// ==============================================================================
8
9#pragma once
10
11#include <chrono>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <string>
16#include <vector>
17
18// Forward declarations
19class Game;
20
21namespace core
22{
23
24// ==============================================================================
25// Launch State & Events
26// ==============================================================================
27
28enum class LaunchState
29{
31 PreparingLaunch, // Checking settings, validating paths
32 WaitingForSteam, // Waiting for Steam to be ready (for Steam games)
33 Launching, // Actually starting the process
34 VerifyingStart, // Confirming process started successfully
35 Running, // Game is running
36 Stopping, // Graceful stop requested
37 Killing, // Force kill in progress
38 Failed, // Launch failed
39 Completed // Game exited normally
40};
41
43{
44 std::string gameId;
47 std::string message; // Human-readable status message
48};
49
51{
52 std::string gameId;
54 std::string processName; // e.g., "WowClassic.exe" for tracked Wine games
55};
56
58{
59 std::string gameId;
61 std::chrono::seconds sessionDuration;
62};
63
65{
66 std::string gameId;
67 std::string errorMessage;
69};
70
71// ==============================================================================
72// Running Game Info
73// ==============================================================================
74
76{
77 std::string gameId;
78 std::string gameName;
79 int primaryPid = 0; // Main launcher/process PID
80 int trackedPid = 0; // Actual game PID (may differ for launchers)
81 std::string trackedProcessName; // e.g., "WowClassic.exe"
82 std::chrono::steady_clock::time_point startTime;
84
85 // Launch configuration summary (not the full LaunchInfo to avoid incomplete type issues)
86 std::string winePrefix;
87 std::string protonVersion;
88 bool gameModeEnabled = false;
89 bool mangoHudEnabled = false;
90};
91
92// ==============================================================================
93// LaunchController
94// ==============================================================================
95// Provides UI-agnostic interface for launching and managing game processes.
96// Wraps GameProcessManager and GameLaunchManager functionality.
97// ==============================================================================
98
100{
101 public:
102 // Callback types
103 using OnStateChanged = std::function<void(const LaunchStateChangedEvent&)>;
104 using OnProcessStarted = std::function<void(const ProcessStartedEvent&)>;
105 using OnProcessExited = std::function<void(const ProcessExitedEvent&)>;
106 using OnLaunchError = std::function<void(const LaunchErrorEvent&)>;
107
110
111 // Non-copyable, movable
115 LaunchController& operator=(LaunchController&&) noexcept;
116
117 // =========================================================================
118 // Launch Operations
119 // =========================================================================
120
121 /// Launch a game
122 /// Returns true if launch was initiated (doesn't mean success yet)
123 bool launchGame(const std::string& gameId, const Game& game);
124
125 /// Request graceful stop of a running game
126 bool stopGame(const std::string& gameId);
127
128 /// Force kill a running game
129 bool killGame(const std::string& gameId);
130
131 /// Stop all running games
132 void stopAllGames();
133
134 // =========================================================================
135 // Query Running State
136 // =========================================================================
137
138 /// Check if any game is currently running
139 bool hasRunningGames() const;
140
141 /// Check if a specific game is running
142 bool isGameRunning(const std::string& gameId) const;
143
144 /// Get current launch state for a game
145 LaunchState getGameState(const std::string& gameId) const;
146
147 /// Get info about a running game (returns nullopt if not running)
148 std::optional<RunningGameInfo> getRunningGameInfo(const std::string& gameId) const;
149
150 /// Get all currently running games
151 std::vector<RunningGameInfo> getAllRunningGames() const;
152
153 /// Get the number of running games
154 size_t getRunningGameCount() const;
155
156 // =========================================================================
157 // Steam Integration
158 // =========================================================================
159
160 /// Check if Steam is running
161 bool isSteamRunning() const;
162
163 /// Request Steam to start (async)
164 void requestSteamStart();
165
166 /// Get Steam state description
167 std::string getSteamStateDescription() const;
168
169 // =========================================================================
170 // Session Statistics
171 // =========================================================================
172
173 /// Get current session duration for a running game
174 std::chrono::seconds getSessionDuration(const std::string& gameId) const;
175
176 /// Get total play time recorded for this session
177 std::chrono::seconds getTotalSessionPlayTime() const;
178
179 // =========================================================================
180 // Event Subscriptions
181 // =========================================================================
182
183 void setOnStateChanged(OnStateChanged callback);
185 void setOnProcessExited(OnProcessExited callback);
186 void setOnLaunchError(OnLaunchError callback);
187
188 // =========================================================================
189 // Background Processing
190 // =========================================================================
191
192 /// Called periodically to update internal state (process monitoring, etc.)
193 /// UI layer should call this from its main loop or a timer
194 void update();
195
196 private:
197 class Impl;
198 std::unique_ptr<Impl> impl_;
199};
200
201} // namespace core
Complete representation of a game in the library.
Definition game.h:767
std::chrono::seconds getSessionDuration(const std::string &gameId) const
Get current session duration for a running game.
bool stopGame(const std::string &gameId)
Request graceful stop of a running game.
void setOnProcessStarted(OnProcessStarted callback)
void stopAllGames()
Stop all running games.
LaunchController(LaunchController &&) noexcept
std::vector< RunningGameInfo > getAllRunningGames() const
Get all currently running games.
void setOnProcessExited(OnProcessExited callback)
bool killGame(const std::string &gameId)
Force kill a running game.
std::function< void(const LaunchStateChangedEvent &)> OnStateChanged
void setOnLaunchError(OnLaunchError callback)
LaunchController & operator=(const LaunchController &)=delete
void setOnStateChanged(OnStateChanged callback)
bool launchGame(const std::string &gameId, const Game &game)
Launch a game Returns true if launch was initiated (doesn't mean success yet).
size_t getRunningGameCount() const
Get the number of running games.
std::optional< RunningGameInfo > getRunningGameInfo(const std::string &gameId) const
Get info about a running game (returns nullopt if not running).
std::chrono::seconds getTotalSessionPlayTime() const
Get total play time recorded for this session.
std::string getSteamStateDescription() const
Get Steam state description.
bool hasRunningGames() const
Check if any game is currently running.
std::function< void(const LaunchErrorEvent &)> OnLaunchError
bool isSteamRunning() const
Check if Steam is running.
void requestSteamStart()
Request Steam to start (async).
void update()
Called periodically to update internal state (process monitoring, etc.) UI layer should call this fro...
LaunchState getGameState(const std::string &gameId) const
Get current launch state for a game.
std::function< void(const ProcessExitedEvent &)> OnProcessExited
bool isGameRunning(const std::string &gameId) const
Check if a specific game is running.
std::function< void(const ProcessStartedEvent &)> OnProcessStarted
LaunchController(const LaunchController &)=delete
std::chrono::seconds sessionDuration
std::chrono::steady_clock::time_point startTime