Nelaric Unreal Gameplay
Gameplay framework API
Loading...
Searching...
No Matches
SessionTransitionSubsystem.h
Go to the documentation of this file.
1// Copyright (c) 2026 Nelaric
2
6
7#pragma once
8
9#include "CoreTypes.h"
10#include "Containers/Ticker.h"
12#include "Delegates/Delegate.h"
13#include "Engine/EngineBaseTypes.h"
14#include "Misc/Optional.h"
15#include "Subsystems/GameInstanceSubsystem.h"
16#include "Templates/UniquePtr.h"
17#include "UObject/WeakObjectPtr.h"
18
19#include "SessionTransitionSubsystem.generated.h"
20
21class UWorld;
22
23namespace Nelaric
24{
25class FGameplayRuntimeInternalAccessKey;
26
41
43DECLARE_DELEGATE_RetVal_TwoParams(bool, FStartTransitionApproval, uint64, const FTransitionDestination&);
44
46DECLARE_DELEGATE_OneParam(FOnTransitionTerminated, uint64);
47
50{
52 uint64 Id = 0;
53};
54
88
90DECLARE_DELEGATE_TwoParams(FOnTransitionSucceeded, FTransitionHandle, ENetMode);
91
94
97
100
107{
109 FOnTransitionSucceeded OnSucceeded;
110
112 FOnTransitionCancelled OnCancelled;
113
115 FOnTransitionTimedOut OnTimedOut;
116
118 FOnTransitionFailed OnFailed;
119};
120} // namespace Nelaric
121
129UCLASS(MinimalAPI)
130class USessionTransitionSubsystem : public UGameInstanceSubsystem
131{
132 GENERATED_BODY()
133
134public:
150 GAMEPLAYRUNTIME_API Nelaric::FTransitionHandle RequestTransition(ENetMode TargetMode,
151 const Nelaric::FTransitionDestination& Destination,
152 const Nelaric::FTransitionCallbacks& Callbacks);
153
163 GAMEPLAYRUNTIME_API bool CancelTransition(Nelaric::FTransitionHandle Handle);
164
172 GAMEPLAYRUNTIME_API TOptional<ENetMode> GetNetMode() const;
173
174public:
181 GAMEPLAYRUNTIME_API void InternalConfigureApprovalTransport(const Nelaric::FGameplayRuntimeInternalAccessKey& Key,
182 const Nelaric::FStartTransitionApproval& Source,
183 const Nelaric::FStartTransitionApproval& Target,
184 const Nelaric::FOnTransitionTerminated& Terminated);
185
189 GAMEPLAYRUNTIME_API void InternalClearApprovalTransport(const Nelaric::FGameplayRuntimeInternalAccessKey& Key);
190
196 GAMEPLAYRUNTIME_API void InternalReportSourceApproval(const Nelaric::FGameplayRuntimeInternalAccessKey& Key,
197 uint64 RequestId, bool bApproved);
198
204 GAMEPLAYRUNTIME_API void InternalReportTargetApproval(const Nelaric::FGameplayRuntimeInternalAccessKey& Key,
205 uint64 RequestId, bool bApproved);
206
211 GAMEPLAYRUNTIME_API void InternalReportTargetUnavailable(const Nelaric::FGameplayRuntimeInternalAccessKey& Key,
212 uint64 RequestId);
213
214protected:
216 GAMEPLAYRUNTIME_API virtual void Initialize(FSubsystemCollectionBase& Collection) override;
217
219 GAMEPLAYRUNTIME_API virtual void Deinitialize() override;
220
221private:
222 struct FActiveTransition
223 {
227 TWeakObjectPtr<UWorld> SourceWorld;
228 double DeadlineSeconds = 0.0;
229 bool bSourceApproved = false;
230 bool bTargetApproved = false;
231 bool bTravelStarted = false;
232 };
233
234 bool Tick(float DeltaTime);
235 void TryStartTravel();
236 void Fail(Nelaric::ETransitionError Error);
237 void FinishSucceeded(ENetMode Mode);
238 void FinishTimedOut();
239 void FinishCancelled();
240
241 Nelaric::FStartTransitionApproval StartSourceApproval;
242 Nelaric::FStartTransitionApproval StartTargetApproval;
243 Nelaric::FOnTransitionTerminated OnTerminated;
244 TUniquePtr<FActiveTransition> Active;
245 FTSTicker::FDelegateHandle TickHandle;
246 uint64 NextRequestId = 1;
247};
DECLARE_DELEGATE_TwoParams(FOnTransitionSucceeded, FTransitionHandle, ENetMode)
Reports a verified destination mode on the game thread.
DECLARE_DELEGATE_RetVal_TwoParams(bool, FStartTransitionApproval, uint64, const FTransitionDestination &)
Starts approval for a request and its destination endpoints.
ETransitionError
Reason a network-mode request could not complete.
Definition SessionTransitionSubsystem.h:57
@ MissingDestination
A required map or remote destination is unavailable.
Definition SessionTransitionSubsystem.h:65
@ NoWorld
No game world is available for the request.
Definition SessionTransitionSubsystem.h:62
@ AuthorityRejected
The source or destination authority denied the request.
Definition SessionTransitionSubsystem.h:71
@ UnsupportedMode
The target mode or source-to-target route is unsupported.
Definition SessionTransitionSubsystem.h:59
@ ConfirmationInvalid
A confirmation expired or no longer matches this request.
Definition SessionTransitionSubsystem.h:77
@ NetworkFailed
Network setup or connection failed.
Definition SessionTransitionSubsystem.h:83
@ TravelFailed
Map travel did not establish the requested world.
Definition SessionTransitionSubsystem.h:80
@ UnexpectedNetMode
The resulting world has a different network mode.
Definition SessionTransitionSubsystem.h:86
@ Busy
Another transition is already active.
Definition SessionTransitionSubsystem.h:68
@ AuthorityUnavailable
A required authority could not be reached for confirmation.
Definition SessionTransitionSubsystem.h:74
DECLARE_DELEGATE_OneParam(FOnTransitionTerminated, uint64)
Releases transport state for a terminal request.
Coordinates requests for a game world's network role.
Definition SessionTransitionSubsystem.h:131
GAMEPLAYRUNTIME_API void InternalClearApprovalTransport(const Nelaric::FGameplayRuntimeInternalAccessKey &Key)
Removes the internal approval transport on the game thread.
GAMEPLAYRUNTIME_API TOptional< ENetMode > GetNetMode() const
Reads the current game world's observed network mode.
GAMEPLAYRUNTIME_API bool CancelTransition(Nelaric::FTransitionHandle Handle)
Requests cancellation of an active transition.
GAMEPLAYRUNTIME_API void InternalConfigureApprovalTransport(const Nelaric::FGameplayRuntimeInternalAccessKey &Key, const Nelaric::FStartTransitionApproval &Source, const Nelaric::FStartTransitionApproval &Target, const Nelaric::FOnTransitionTerminated &Terminated)
Binds the internal approval transport on the game thread.
GAMEPLAYRUNTIME_API void InternalReportTargetApproval(const Nelaric::FGameplayRuntimeInternalAccessKey &Key, uint64 RequestId, bool bApproved)
Reports the target authority's decision.
GAMEPLAYRUNTIME_API void InternalReportTargetUnavailable(const Nelaric::FGameplayRuntimeInternalAccessKey &Key, uint64 RequestId)
Reports that the target authority could not be reached.
virtual GAMEPLAYRUNTIME_API void Deinitialize() override
Ends active work before the game instance subsystem is destroyed.
GAMEPLAYRUNTIME_API void InternalReportSourceApproval(const Nelaric::FGameplayRuntimeInternalAccessKey &Key, uint64 RequestId, bool bApproved)
Reports the source authority's decision.
virtual GAMEPLAYRUNTIME_API void Initialize(FSubsystemCollectionBase &Collection) override
Registers the coordinator's tick while its game instance lives.
GAMEPLAYRUNTIME_API Nelaric::FTransitionHandle RequestTransition(ENetMode TargetMode, const Nelaric::FTransitionDestination &Destination, const Nelaric::FTransitionCallbacks &Callbacks)
Requests a move from one remote server to another.
Host address and transport port of one network endpoint.
Definition NetworkEndpoint.h:20
Terminal callbacks for one asynchronous mode request.
Definition SessionTransitionSubsystem.h:107
FOnTransitionSucceeded OnSucceeded
Called after the destination connection passes verification.
Definition SessionTransitionSubsystem.h:109
FOnTransitionFailed OnFailed
Called when the request cannot complete.
Definition SessionTransitionSubsystem.h:118
FOnTransitionTimedOut OnTimedOut
Called when the request exceeds its bounded timeout.
Definition SessionTransitionSubsystem.h:115
FOnTransitionCancelled OnCancelled
Called when the request is cancelled before completion.
Definition SessionTransitionSubsystem.h:112
Game and approval endpoints of one destination server.
Definition SessionTransitionSubsystem.h:34
FNetworkEndpoint BeaconEndpoint
Destination approval beacon address and port.
Definition SessionTransitionSubsystem.h:39
FNetworkEndpoint GameEndpoint
Destination game server address and port.
Definition SessionTransitionSubsystem.h:36
Stable identity of one accepted transition request.
Definition SessionTransitionSubsystem.h:50
uint64 Id
Zero is not an active request identity.
Definition SessionTransitionSubsystem.h:52