UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MPCollector.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_EDITOR
6#include "Async/Future.h"
7#include "Containers/Array.h"
10#include "HAL/Platform.h"
11#include "Misc/Guid.h"
13#include "Templates/Function.h"
15#include "UObject/CookEnums.h"
16#endif
17
18#if WITH_EDITOR
19
20class FCbObject;
21class FCbObjectView;
22class FCbWriter;
23class ITargetPlatform;
24
25namespace UE::Cook { class FCookWorkerClient; }
26namespace UE::Cook { class FCookWorkerServer; }
27
28namespace UE::Cook
29{
30
35struct FWorkerId
36{
37public:
38 FWorkerId() { Id = InvalidId; }
39 constexpr static FWorkerId Invalid() { return FWorkerId(InvalidId); }
40 constexpr static FWorkerId Local() { return FWorkerId(LocalId); }
41 static FWorkerId FromRemoteIndex(uint8 Index) { check(Index < InvalidId - 1U); return FWorkerId(Index + 1U); }
42 static FWorkerId FromLocalOrRemoteIndex(uint8 Index) { check(Index < InvalidId); return FWorkerId(Index); }
43 static int32 GetMaxCookWorkerCount() { return static_cast<int32>(InvalidId - 1); }
44
45 bool IsValid() const { return Id != InvalidId; }
46 bool IsInvalid() const { return Id == InvalidId; }
47 bool IsLocal() const { return Id == LocalId; }
48 bool IsRemote() const { return Id != InvalidId && Id != LocalId; }
49 uint8 GetRemoteIndex() const { check(IsRemote()); return Id - 1U; }
50 uint8 GetMultiprocessId() const { check(IsValid()); return Id; }
51 bool operator==(const FWorkerId& Other) const { return Id == Other.Id; }
52 bool operator!=(const FWorkerId& Other) const { return Id != Other.Id; }
53 bool operator<(const FWorkerId& Other) const { return Id < Other.Id; }
54 inline friend int32 GetTypeHash(const FWorkerId& WorkerId) { return WorkerId.Id; }
55
56 FString ToString();
57
58private:
59 constexpr explicit FWorkerId(uint8 InId) : Id(InId) {}
60
61private:
62 uint8 Id;
63
64 constexpr static uint8 InvalidId = 255;
65 constexpr static uint8 LocalId = 0;
66};
67
69{
70public:
71 TConstArrayView<const ITargetPlatform*> GetPlatforms() const { return Platforms; }
72 bool IsFlush() const { return bFlush; }
73
74 COREUOBJECT_API void AddMessage(FCbObject Object);
75
78
79private:
81 TArray<FCbObject> Messages;
82 bool bFlush = false;
83
84 friend class FCookWorkerClient;
85};
86
88{
89public:
90 enum class EServerEventType : uint8
91 {
93 Count
94 };
95
97
98 TConstArrayView<const ITargetPlatform*> GetPlatforms() const { return Platforms; }
99
100 COREUOBJECT_API void AddMessage(FCbObject Object);
101
104
105 EServerEventType GetEventType() const { return EventType; }
106
107private:
109 TArray<FCbObject> Messages;
110 EServerEventType EventType;
111 bool bFlush = false;
112
113 friend class FCookDirector;
114};
115
117{
118public:
119 struct FPlatformData
120 {
121 const ITargetPlatform* TargetPlatform = nullptr;
122 ECookResult CookResults = ECookResult::NotAttempted;
123 };
124 TConstArrayView<const ITargetPlatform*> GetPlatforms() const { return Platforms; }
126 FName GetPackageName() const { return PackageName; }
127
128 COREUOBJECT_API void AddMessage(FCbObject Object);
132
135
136private:
141 FName PackageName;
142
143 friend class FCookWorkerClient;
144};
145
147{
148public:
149 struct FPlatformData
150 {
151 const ITargetPlatform* TargetPlatform = nullptr;
152 ECookResult CookResults = ECookResult::NotAttempted;
153 };
154 FName GetPackageName() const { return PackageName; }
155
156 COREUOBJECT_API void AddMessage(FCbObject Object);
157
160
161private:
162 TArray<FCbObject> Messages;
165 FName PackageName;
166
167 friend class FCookDirector;
168};
169
171{
172public:
174 // Name of the relevant package or NAME_None if not available
175 FName GetPackageName() const { return PackageName; }
176
179
180private:
182 FName PackageName;
183
184 friend class FCookWorkerClient;
185};
186
188{
189public:
191
194 FWorkerId GetWorkerId() const { return WorkerId; }
195 int32 GetProfileId() const { return ProfileId; }
197
198 bool HasPackageName() const { return !PackageName.IsNone(); }
199 FName GetPackageName() const { return PackageName; }
200 bool HasTargetPlatform() const { return TargetPlatform != nullptr; }
201 const ITargetPlatform* GetTargetPlatform() const { return TargetPlatform; }
202
203private:
205 FName PackageName;
206 FCookWorkerServer* Server = nullptr;
207 const ITargetPlatform* TargetPlatform = nullptr;
209 FWorkerId WorkerId;
210
211 friend class FCookWorkerServer;
212};
213
218class IMPCollector : public FRefCountBase
219{
220public:
221 virtual ~IMPCollector() {}
222
227 virtual FGuid GetMessageType() const = 0;
229 virtual const TCHAR* GetDebugName() const = 0;
230
259};
260
261
264{
265public:
266 virtual ~IMPCollectorMessage() {}
267
269 virtual void Write(FCbWriter& Writer) const = 0;
271 virtual bool TryRead(FCbObjectView Object) = 0;
273 virtual FGuid GetMessageType() const = 0;
275 virtual const TCHAR* GetDebugName() const = 0;
276};
277
278
280template <typename MessageType>
282{
283public:
284 virtual void ClientReceiveMessage(FMPCollectorClientMessageContext& Context, bool bReadSuccessful,
285 MessageType&& Message) {}
286 virtual void ServerReceiveMessage(FMPCollectorServerMessageContext& Context, bool bReadSuccessful,
287 MessageType&& Message) {}
288
289 virtual FGuid GetMessageType() const override
290 {
291 return MessageType().GetMessageType();
292 }
293
294 virtual const TCHAR* GetDebugName() const override
295 {
296 return MessageType().GetDebugName();
297 }
298
300 {
301 MessageType CBMessage;
302 bool bReadSuccessful = CBMessage.TryRead(Message);
304 }
305
307 {
308 MessageType CBMessage;
309 bool bReadSuccessful = CBMessage.TryRead(Message);
311 }
312};
313
318template <typename MessageType>
320{
321public:
323 MessageType&& Message)>&& InCallback)
324 : Callback(MoveTemp(InCallback))
325 {
326 check(Callback);
327 }
328
329 virtual void ClientReceiveMessage(FMPCollectorClientMessageContext& Context, bool bReadSuccessful,
330 MessageType&& Message) override
331 {
332 Callback(Context, bReadSuccessful, MoveTemp(Message));
333 }
334
335private:
336 TUniqueFunction<void(FMPCollectorClientMessageContext& Context, bool bReadSuccessful, MessageType&& Message)> Callback;
337};
338
343template <typename MessageType>
345{
346public:
348 MessageType&& Message)>&& InCallback)
349 : Callback(MoveTemp(InCallback))
350 {
351 check(Callback);
352 }
353
354 virtual void ServerReceiveMessage(FMPCollectorServerMessageContext& Context, bool bReadSuccessful,
355 MessageType&& Message) override
356 {
357 Callback(Context, bReadSuccessful, MoveTemp(Message));
358 }
359
360private:
361 TUniqueFunction<void(FMPCollectorServerMessageContext& Context, bool bReadSuccessful, MessageType&& Message)> Callback;
362};
363
364inline FString FWorkerId::ToString()
365{
366 return IsInvalid() ? TEXT("<Invalid>") : (IsLocal() ? TEXT("Local") :
367 FString::Printf(TEXT("CookWorker %u"), static_cast<uint32>(GetRemoteIndex())));
368}
369
370} // namespace UE::Cook
371
372#endif // WITH_EDITOR
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
bool operator<(const FTextFormatString &LHS, const FTextFormatString &RHS)
Definition ITextFormatArgumentModifier.h:147
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition CompactBinary.h:1025
Definition CompactBinary.h:1392
Definition CompactBinaryWriter.h:68
Definition NameTypes.h:617
Definition RefCounting.h:213
Definition Array.h:670
Definition Future.h:393
Definition FunctionFwd.h:19
uint32 GetTypeHash(const FKey &Key)
Definition BlackboardKey.h:35
FString ToString(uint16 Value)
Definition PathFollowingComponent.cpp:82
const FId InvalidId
Definition TaskTrace.h:39
bool operator==(const FCachedAssetKey &A, const FCachedAssetKey &B)
Definition AssetDataMap.h:501
Definition CookOnTheFly.h:19
ECookResult
Definition CookEnums.h:43
bool IsRemote(FRemoteObjectId ObjectId)
Definition RemoteObject.cpp:535
int32 GetMultiprocessId()
Definition CoreGlobals.cpp:969
U16 Index
Definition radfft.cpp:71
Definition Guid.h:109