-
Notifications
You must be signed in to change notification settings - Fork 1
/
BeamRuntimeSubsystem.h
159 lines (131 loc) · 6.12 KB
/
BeamRuntimeSubsystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BeamRuntimeSettings.h"
#include "UObject/Object.h"
#include "Runtime/BeamRuntime.h"
#include "BeamRuntimeSubsystem.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FRuntimeUserSlotDataChangedEvent, FUserSlot, UserSlot);
UCLASS(Abstract, Blueprintable, meta=(IsBlueprintBase=true, ShowWorldContextPin))
class BEAMABLECORERUNTIME_API UBeamRuntimeSubsystem : public UGameInstanceSubsystem, public FTickableGameObject
{
GENERATED_BODY()
protected:
/** @brief Initializes the subsystem. */
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
/** Cleans up the system. */
virtual void Deinitialize() override;
virtual bool ShouldCreateSubsystem(UObject* Outer) const override;
virtual void Tick(float DeltaTime) override
{
}
virtual bool IsAllowedToTick() const override
{
return true;
}
virtual TStatId GetStatId() const override
{
RETURN_QUICK_DECLARE_CYCLE_STAT(UBeamRuntimeSubsystem, STATGROUP_Tickables);
}
public:
UPROPERTY()
UBeamRuntime* Runtime;
/**
* @brief This is just a flag that informs the caller on whether or not this specific subsystem has finished it's initialization flow.
* This should never be set before OnBeamableReady has been called. This may be called at some later point if this subsystem's initialization flow needs to kick-off Operations
* on OnBeamableReady in order to get ready for use.
*/
UPROPERTY(BlueprintReadWrite, EditAnywhere)
bool bIsStarted = false;
/**
* @brief This is just a flag that informs the caller on whether or not this specific subsystem has finished it's initialization flow.
* This should never be set before OnBeamableReady has been called. This may be called at some later point if this subsystem's initialization flow needs to kick-off Operations
* on OnBeamableReady in order to get ready for use.
*/
UPROPERTY(BlueprintReadWrite, EditAnywhere)
bool bIsReady = false;
UFUNCTION(Category="Beam")
virtual FBeamOperationHandle InitializeWhenUnrealReady();
/**
* @brief Called whenever a user authenticates into a user slot.
* The returned operation is added to a list of operations containing all other subsystem's OnUserSignedIn operation.
* We wait for this list of operations to finish and then call OnPostUserSignedIn.
*/
virtual FBeamOperationHandle OnUserSignedIn(const FUserSlot& UserSlot, const FBeamRealmUser& BeamRealmUser, const bool bIsFirstAuth);
/**
* @brief Called whenever a user signs out of a user slot.
* The returned operation is added to a list of operations containing all other subsystem's OnUserSignedOut operation.
* We wait for this list of operations to finish and then call OnPostUserSignedOut.
*/
virtual FBeamOperationHandle OnUserSignedOut(const FUserSlot& UserSlot, const EUserSlotClearedReason Reason,
const FBeamRealmUser& BeamRealmUser);
/**
* @brief Called on each BeamRuntimeSubsystem after the OnUserSignedIn operations of ALL BeamRuntimeSubsystems have run to completion (success or otherwise).
*/
UFUNCTION(BlueprintNativeEvent)
void OnPostUserSignedIn(const FUserSlot& UserSlot, const FBeamRealmUser& BeamRealmUser);
virtual void OnPostUserSignedIn_Implementation(const FUserSlot& UserSlot, const FBeamRealmUser& BeamRealmUser);
/**
* @brief Called on each BeamRuntimeSubsystem after the OnUserSignedOut operations of ALL BeamRuntimeSubsystems have run to completion (success or otherwise).
*/
UFUNCTION(BlueprintNativeEvent)
void OnPostUserSignedOut(const FUserSlot& UserSlot, const EUserSlotClearedReason Reason,
const FBeamRealmUser& BeamRealmUser);
virtual void OnPostUserSignedOut_Implementation(const FUserSlot& UserSlot, const EUserSlotClearedReason Reason,
const FBeamRealmUser& BeamRealmUser);
/**
* @brief Called whenever UBeamRuntime is fully initialized. You can think of this as OnBeginPlay, but for use with Beamable.
*/
UFUNCTION(BlueprintNativeEvent)
FBeamOperationHandle OnBeamableReady();
virtual FBeamOperationHandle OnBeamableReady_Implementation();
/**
* @brief Called whenever UBeamRuntime is ready for users to be authenticated into Beamable. This is only called if you disable automatic frictionless authentication in order to control
* when the owner player signs into Beamable in your game. By default, sign in is automatic and you can expect OnBeamableReady to be called when the current local user is signed in and
* ready to make requests to Beamable.
*/
UFUNCTION(BlueprintNativeEvent)
FBeamOperationHandle OnBeamableStarted();
virtual FBeamOperationHandle OnBeamableStarted_Implementation();
};
/**
* @brief Used to initialize all Blueprint-first subsystems that we make. See the link below for more info on why this is needed.
* TLDR: Blueprints that inherit from UGameInstanceSubsystems/UWorldSubsystem are not loaded unless they are opened in the editor.
* If you want a guarantee, you need to add them to a list and forcibly initialize that list.
*
* https://forums.unrealengine.com/t/configuring-subsystems-via-editor/134784/20
*/
UCLASS(Hidden)
class BEAMABLECORERUNTIME_API UBeamRuntimeBlueprintSubsystems : public UGameInstanceSubsystem
{
GENERATED_BODY()
/** @brief Initializes the subsystem. */
virtual void Initialize(FSubsystemCollectionBase& Collection) override
{
Super::Initialize(Collection);
const auto RuntimeSettings = GetDefault<UBeamRuntimeSettings>();
for (const auto SubsystemBlueprint : RuntimeSettings->RuntimeSubsystemBlueprints)
{
Collection.InitializeDependency(SubsystemBlueprint);
}
if (IsRunningDedicatedServer())
{
for (const auto SubsystemBlueprint : RuntimeSettings->ServerOnlyRuntimeSubsystemBlueprints)
{
Collection.InitializeDependency(SubsystemBlueprint);
}
}
else
{
for (const auto SubsystemBlueprint : RuntimeSettings->ClientRuntimeSubsystemBlueprints)
{
Collection.InitializeDependency(SubsystemBlueprint);
}
}
}
/** Cleans up the system. */
virtual void Deinitialize() override
{
Super::Deinitialize();
}
};