Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
EmbeddedCommunication.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/Map.h"
7#include "Containers/UnrealString.h"
8#include "CoreTypes.h"
9#include "Delegates/Delegate.h"
10#include "Delegates/MulticastDelegateBase.h"
11#include "HAL/CriticalSection.h"
12#include "Templates/Function.h"
13#include "UObject/NameTypes.h"
14#include "UObject/UnrealNames.h"
15
17
18// wraps parameters and a completion delegate
20{
21 // the command for this call. something like "console" would be a command for the engine to run a console command
23
24 // a map of arbitrary key-value string pairs.
26
27 // a delegate to call back on the other end when the command is completed. if this is set, it is expected it will be called
28 // but at least one handler of this
30};
31
33{
34public:
35
36 // delegate for calling between native wrapper app and embedded ue
37 DECLARE_MULTICAST_DELEGATE_OneParam(FEmbeddedCommunicationParamsDelegate, const FEmbeddedCallParamsHelper&);
38
39 // calling in from native wrapper to engine
40 static FEmbeddedCommunicationParamsDelegate& GetNativeToEmbeddedParamsDelegateForSubsystem(FName SubsystemName);
41
42 // calling out from engine to native wrapper
43 static FEmbeddedCommunicationParamsDelegate& GetEmbeddedToNativeParamsDelegateForSubsystem(FName SubsystemName);
44
45 // returns true if NativeToEmbedded delegate for subsystem exists
46 static bool IsEmbeddedSubsystemAvailable(FName SubsystemName);
47
48 // FTSTicker-like delegate, to bind things to be ticked at a regular interval while the game thread is otherwise asleep.
49 static FSimpleMulticastDelegate SleepTickDelegate;
50
51 // get/set an object by name, thread safe
52 static void SetNamedObject(const FString& Name, void* Object);
53 static void* GetNamedObject(const FString& Name);
54
55private:
56
57 // This class is only for namespace use (like FCoreDelegates)
59
60 // the per-subsystem delegates
63
64 // named object registry, with thread protection
67};
68
69
71{
72public:
73
74 // called early in UE lifecycle - RunOnGameThread can be called before this is called
75 static void Init();
76
77 // force some ticking to happen - used to process messages during otherwise blocking operations like boot
78 static void ForceTick(int ID, float MinTimeSlice=0.1f, float MaxTimeSlice=0.5f);
79
80 // queue up a function to call on game thread
81 static void RunOnGameThread(int Priority, TFunction<void()> Lambda);
82
83 // wake up the game thread to process something put onto the game thread
84 static void WakeGameThread();
85
86 // called from game thread to pull off
87 static bool TickGameThread(float DeltaTime);
88
89 // tell UE to stay awake (or allow it to sleep when nothing to do). Repeated calls with the same Requester are
90 // allowed, but bNeedsRendering must match
91 static void KeepAwake(FName Requester, bool bNeedsRendering);
92 static void AllowSleep(FName Requester);
93
94 static void UELogFatal(const TCHAR* String);
95 static void UELogError(const TCHAR* String);
96 static void UELogWarning(const TCHAR* String);
97 static void UELogDisplay(const TCHAR* String);
98 static void UELogLog(const TCHAR* String);
99 static void UELogVerbose(const TCHAR* String);
100
101 static bool IsAwakeForTicking();
102 static bool IsAwakeForRendering();
103
105};
106
107// RAII for keep awake functionality
108// This may seem a bit over engineered, but it needs to have move semantics so that any aggregate that
109// includes it doesn't lose move semantics.
111{
112public:
113 // tell UE to stay awake (or allow it to sleep when nothing to do). Repeated calls with the same Requester are
114 // allowed, but bNeedsRendering must match
115 FEmbeddedKeepAwake(FName InRequester, bool bInNeedsRendering)
116 : Requester(InRequester)
117 , bNeedsRendering(bInNeedsRendering)
118 {
120 }
121
123 : Requester(Other.Requester)
125 , bIsValid(Other.bIsValid)
126 {
127 if (bIsValid)
128 {
130 }
131 }
132
134 {
135 Requester = Other.Requester;
137 bIsValid = Other.bIsValid;
138
139 Other.Requester = NAME_None;
140 Other.bNeedsRendering = false;
141 Other.bIsValid = false;
142 }
143
145 {
146 if (bIsValid)
147 {
149 }
150 }
151
153 {
154 bool bOldIsValid = bIsValid;
155 FName OldRequester = Requester;
156
157 Requester = Other.Requester;
159 bIsValid = Other.bIsValid;
160 if (bIsValid)
161 {
163 }
164
165 if (bOldIsValid)
166 {
168 }
169
170 return *this;
171 }
172
174 {
175 if (bIsValid)
176 {
178 }
179
180 Requester = Other.Requester;
182 bIsValid = Other.bIsValid;
183
184 Other.Requester = NAME_None;
185 Other.bNeedsRendering = false;
186 Other.bIsValid = false;
187 return *this;
188 }
189
190 bool GetNeedsRendering() const { return bNeedsRendering; }
191 FName GetRequester() const { return Requester; }
192
193private:
195 bool bNeedsRendering = false;
196 bool bIsValid = true;
197};
#define DECLARE_MULTICAST_DELEGATE_OneParam(DelegateName, Param1Type)
TMap< FString, FString > FEmbeddedCommunicationMap
FWindowsCriticalSection FCriticalSection
static void RunOnGameThread(int Priority, TFunction< void()> Lambda)
static bool IsAwakeForTicking()
static void ForceTick(int ID, float MinTimeSlice=0.1f, float MaxTimeSlice=0.5f)
static void UELogLog(const TCHAR *String)
static void UELogFatal(const TCHAR *String)
static void WakeGameThread()
static bool IsAwakeForRendering()
static void KeepAwake(FName Requester, bool bNeedsRendering)
static FString GetDebugInfo()
static void UELogError(const TCHAR *String)
static void AllowSleep(FName Requester)
static void UELogDisplay(const TCHAR *String)
static void UELogVerbose(const TCHAR *String)
static void UELogWarning(const TCHAR *String)
static bool TickGameThread(float DeltaTime)
static TMap< FName, FEmbeddedCommunicationParamsDelegate > EmbeddedToNativeDelegateMap
static bool IsEmbeddedSubsystemAvailable(FName SubsystemName)
static TMap< FString, void * > NamedObjectRegistry
static FCriticalSection NamedObjectRegistryLock
static FEmbeddedCommunicationParamsDelegate & GetNativeToEmbeddedParamsDelegateForSubsystem(FName SubsystemName)
static void * GetNamedObject(const FString &Name)
static void SetNamedObject(const FString &Name, void *Object)
static FSimpleMulticastDelegate SleepTickDelegate
static FEmbeddedCommunicationParamsDelegate & GetEmbeddedToNativeParamsDelegateForSubsystem(FName SubsystemName)
static TMap< FName, FEmbeddedCommunicationParamsDelegate > NativeToEmbeddedDelegateMap
FEmbeddedKeepAwake(FEmbeddedKeepAwake &&Other)
FEmbeddedKeepAwake & operator=(FEmbeddedKeepAwake &&Other) &
FEmbeddedKeepAwake & operator=(const FEmbeddedKeepAwake &Other) &
FEmbeddedKeepAwake(const FEmbeddedKeepAwake &Other)
FEmbeddedKeepAwake(FName InRequester, bool bInNeedsRendering)
FEmbeddedCommunicationMap Parameters
TFunction< void(const FEmbeddedCommunicationMap &, FString) OnCompleteDelegate)