UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MassArchetypeTypes.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6
6#include "UObject/Class.h"
7#endif // UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6
9#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6
12#endif // UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6
13#include "MassEntityTypes.h"
14
15#define UE_API MASSENTITY_API
16
20struct FMassFragment;
23struct FMassEntityQuery;
25struct FMassEntityView;
26struct FMassDebugger;
29
30using FMassEntityExecuteFunction = TFunction< void(FMassExecutionContext& /*ExecutionContext*/, int32 /*EntityIndex*/) >;
31using FMassExecuteFunction = TFunction< void(FMassExecutionContext& /*ExecutionContext*/) >;
32using FMassChunkConditionFunction = TFunction< bool(const FMassExecutionContext& /*ExecutionContext*/) >;
33
34//-----------------------------------------------------------------------------
35// FMassArchetypeHandle
36//-----------------------------------------------------------------------------
39{
41 bool IsValid() const;
42
43 bool operator==(const FMassArchetypeHandle& Other) const;
44 bool operator!=(const FMassArchetypeHandle& Other) const;
45
47
48 void Reset();
49
50private:
52
54
56 friend FMassEntityManager;
58};
59
84
85//-----------------------------------------------------------------------------
86// FMassArchetypeEntityCollection
87//-----------------------------------------------------------------------------
93{
94public:
96 {
108
112 bool IsSet() const { return ChunkIndex != INDEX_NONE && SubchunkStart >= 0; }
113
116 {
117 return ChunkIndex == Other.ChunkIndex && SubchunkStart + Length == Other.SubchunkStart;
118 }
119
121 {
122 return ChunkIndex == Other.ChunkIndex
123 && (*this < Other
124 // note that Length == 0 means "all the entities starting from SubchunkStart
125 ? (SubchunkStart + Length > Other.SubchunkStart || Length == 0)
126 : (Other.SubchunkStart + Other.Length > SubchunkStart || Other.Length == 0)
127 );
128 }
129
131 {
132 return ChunkIndex == Other.ChunkIndex && SubchunkStart == Other.SubchunkStart && Length == Other.Length;
133 }
134 bool operator!=(const FArchetypeEntityRange& Other) const { return !(*this == Other); }
135
137 {
138 return (ChunkIndex != Other.ChunkIndex)
139 ? ChunkIndex < Other.ChunkIndex
140 : (SubchunkStart != Other.SubchunkStart
141 ? SubchunkStart < Other.SubchunkStart
142 : Length < Other.Length);
143 }
144 };
145
147 {
148 NoDuplicates, // indicates that the caller guarantees there are no duplicates in the input Entities collection
149 // note that in no-shipping builds a `check` will fail if duplicates are present.
150 FoldDuplicates, // indicates that it's possible that Entities contains duplicates. The input Entities collection
151 // will be processed and duplicates will be removed.
152 };
153
155 {
156 GatherAll, // default behavior, makes given FMassArchetypeEntityCollection instance represent all entities of the given archetype
157 DoNothing, // meant for procedural population by external code (like child classes)
158 };
159
162
163private:
164 FEntityRangeArray Ranges;
167
168public:
180
183 bool IsEmpty() const;
184 bool IsUpToDate() const;
185
186 UE_DEPRECATED(5.6, "This function is deprecated. Use !IsEmpty() instead.")
187 bool IsSet() const;
188
189 void Reset()
190 {
191 Archetype = FMassArchetypeVersionedHandle();
192 Ranges.Reset();
193 }
194
198
206 template<typename T>
207 requires std::is_same_v<typename TDecay<T>::Type, FMassArchetypeEntityCollection>
208 void Append(T&& Other);
209
216
218
219#if WITH_MASSENTITY_DEBUG
221#endif // WITH_MASSENTITY_DEBUG
222
223protected:
227
228private:
229 void GatherChunksFromArchetype();
230};
231
257
258//-----------------------------------------------------------------------------
259// FMassArchetypeChunkIterator
260//-----------------------------------------------------------------------------
266{
267private:
269 int32 CurrentChunkIndex = 0;
270
271public:
273
274 operator bool() const { return EntityRanges.IsValidIndex(CurrentChunkIndex) && EntityRanges[CurrentChunkIndex].IsSet(); }
275 FMassArchetypeChunkIterator& operator++() { ++CurrentChunkIndex; return *this; }
276
277 const FMassArchetypeEntityCollection::FArchetypeEntityRange* operator->() const { check(bool(*this)); return &EntityRanges[CurrentChunkIndex]; }
278 const FMassArchetypeEntityCollection::FArchetypeEntityRange& operator*() const { check(bool(*this)); return EntityRanges[CurrentChunkIndex]; }
279};
280
281//-----------------------------------------------------------------------------
282// FMassRawEntityInChunkData
283//-----------------------------------------------------------------------------
295
296//-----------------------------------------------------------------------------
297// FMassEntityInChunkDataHandle
298//-----------------------------------------------------------------------------
319
320//-----------------------------------------------------------------------------
321// FMassQueryRequirementIndicesMapping
322//-----------------------------------------------------------------------------
324
338
339
340//-----------------------------------------------------------------------------
341// INLINES
342//-----------------------------------------------------------------------------
344{
345 return ArchetypeHandle.IsValid();
346}
347
349{
350 return ArchetypeHandle == Other.ArchetypeHandle && HandleVersion == Other.HandleVersion;
351}
352
354{
355 return !(*this == Other);
356}
357
358inline FMassArchetypeVersionedHandle::operator FMassArchetypeHandle() const
359{
360 return ArchetypeHandle;
361}
362
364{
365 return DataPtr.IsValid();
366}
367
369{
370 return DataPtr == Other.DataPtr;
371}
372
374{
375 return DataPtr != Other.DataPtr;
376}
377
379{
380 DataPtr.Reset();
381}
382
384 : DataPtr(InDataPtr)
385{
386
387}
388
393
395{
396 return Archetype;
397}
398
400{
401 return Ranges.Num() == 0 && Archetype.IsValid() == false;
402}
403
405{
406 return IsEmpty() || Archetype.IsUpToDate();
407}
408
410{
411 return !IsEmpty();
412}
413
415{
416 return Archetype == Other.Archetype;
417}
418
419template<typename T>
420requires std::is_same_v<typename TDecay<T>::Type, FMassArchetypeEntityCollection>
422{
423 const bool bWasEmpty = Ranges.IsEmpty();
424 checkf(IsSameArchetype(Other), TEXT("Unable to merge two entity collections representing different archetypes"));
425
426 Ranges.Append(Forward<T>(Other).Ranges);
427
428 if (bWasEmpty == false)
429 {
430 Ranges.Sort();
432 , TEXT("Entity collection ranges overlap as a result of %hs"), __FUNCTION__);
433 }
434}
435
439
441{
442 return ChunkRawMemory != nullptr && IndexWithinChunk != INDEX_NONE;
443}
444
446{
447 return ChunkRawMemory == Other.ChunkRawMemory && IndexWithinChunk == Other.IndexWithinChunk;
448}
449
455
461
467
469{
471 && ChunkIndex == Other.ChunkIndex
472 && ChunkSerialNumber == Other.ChunkSerialNumber;
473}
474
475#undef UE_API
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define checkfSlow(expr, format,...)
Definition AssertionMacros.h:333
#define check(expr)
Definition AssertionMacros.h:314
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
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
#define UE_API
Definition MassArchetypeTypes.h:15
const bool
Definition NetworkReplayStreaming.h:178
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTempIfPossible(T &&Obj) noexcept
Definition UnrealTemplate.h:538
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_REWRITE bool IsEmpty() const
Definition Array.h:1133
void Append(const TArray< OtherElementType, OtherAllocatorType > &Source)
Definition Array.h:2412
Definition AndroidPlatformMisc.h:14
Definition SharedPointer.h:692
UE_FORCEINLINE_HINT void Reset()
Definition SharedPointer.h:1120
UE_FORCEINLINE_HINT const bool IsValid() const
Definition SharedPointer.h:1085
Definition StridedView.h:44
Definition MassArchetypeTypes.h:266
const FMassArchetypeEntityCollection::FArchetypeEntityRange & operator*() const
Definition MassArchetypeTypes.h:278
FMassArchetypeChunkIterator & operator++()
Definition MassArchetypeTypes.h:275
const FMassArchetypeEntityCollection::FArchetypeEntityRange * operator->() const
Definition MassArchetypeTypes.h:277
FMassArchetypeChunkIterator(const FMassArchetypeEntityCollection::FConstEntityRangeArrayView &InEntityRanges)
Definition MassArchetypeTypes.h:272
Definition MassArchetypeData.h:172
Definition MassArchetypeTypes.h:233
const FMassArchetypeEntityCollection & GetEntityCollection() const
Definition MassArchetypeTypes.h:248
FMassArchetypeEntityCollectionWithPayload(FMassArchetypeEntityCollection &&InEntityCollection)
Definition MassArchetypeTypes.h:239
const FMassGenericPayloadViewSlice & GetPayload() const
Definition MassArchetypeTypes.h:249
FMassArchetypeEntityCollectionWithPayload(const FMassArchetypeEntityCollection &InEntityCollection)
Definition MassArchetypeTypes.h:234
static UE_API void CreateEntityRangesWithPayload(const FMassEntityManager &EntityManager, const TConstArrayView< FMassEntityHandle > Entities, const FMassArchetypeEntityCollection::EDuplicatesHandling DuplicatesHandling, FMassGenericPayloadView Payload, TArray< FMassArchetypeEntityCollectionWithPayload > &OutEntityCollections)
Definition MassArchetypeTypes.cpp:306
bool IsSet() const
Definition MassArchetypeTypes.h:112
bool IsOverlapping(const FArchetypeEntityRange &Other) const
Definition MassArchetypeTypes.h:120
bool operator<(const FArchetypeEntityRange &Other) const
Definition MassArchetypeTypes.h:136
int32 ChunkIndex
Definition MassArchetypeTypes.h:97
int32 Length
Definition MassArchetypeTypes.h:107
bool operator!=(const FArchetypeEntityRange &Other) const
Definition MassArchetypeTypes.h:134
bool IsAdjacentAfter(const FArchetypeEntityRange &Other) const
Definition MassArchetypeTypes.h:115
FArchetypeEntityRange(const int32 InChunkIndex, const int32 InSubchunkStart=0, const int32 InLength=0)
Definition MassArchetypeTypes.h:110
int32 SubchunkStart
Definition MassArchetypeTypes.h:101
bool operator==(const FArchetypeEntityRange &Other) const
Definition MassArchetypeTypes.h:130
Definition MassArchetypeTypes.h:93
bool IsEmpty() const
Definition MassArchetypeTypes.h:399
UE_API void BuildEntityRanges(TStridedView< const int32 > TrueIndices)
Definition MassArchetypeTypes.cpp:161
static UE_API bool DoesContainOverlappingRanges(FConstEntityRangeArrayView Ranges)
Definition MassArchetypeTypes.cpp:266
bool IsSet() const
Definition MassArchetypeTypes.h:409
TConstArrayView< FArchetypeEntityRange > FConstEntityRangeArrayView
Definition MassArchetypeTypes.h:161
bool IsSameArchetype(const FMassArchetypeEntityCollection &Other) const
Definition MassArchetypeTypes.h:414
FMassArchetypeEntityCollection(const FMassArchetypeHandle &InArchetypeHandle, FEntityRangeArray &&InEntityRanges)
Definition MassArchetypeTypes.h:176
FConstEntityRangeArrayView GetRanges() const
Definition MassArchetypeTypes.h:389
EInitializationType
Definition MassArchetypeTypes.h:155
@ DoNothing
Definition MassArchetypeTypes.h:157
@ GatherAll
Definition MassArchetypeTypes.h:156
bool IsUpToDate() const
Definition MassArchetypeTypes.h:404
UE_API bool ExportEntityHandles(TArray< FMassEntityHandle > &InOutHandles) const
Definition MassArchetypeTypes.cpp:246
void Reset()
Definition MassArchetypeTypes.h:189
static UE_API FArchetypeEntityRange CreateRangeForEntity(const FMassArchetypeHandle &InArchetype, const FMassEntityHandle EntityHandle)
Definition MassArchetypeTypes.cpp:41
void Append(T &&Other)
Definition MassArchetypeTypes.h:421
EDuplicatesHandling
Definition MassArchetypeTypes.h:147
@ NoDuplicates
Definition MassArchetypeTypes.h:148
@ FoldDuplicates
Definition MassArchetypeTypes.h:150
FMassArchetypeHandle GetArchetype() const
Definition MassArchetypeTypes.h:394
UE_API bool IsSame(const FMassArchetypeEntityCollection &Other) const
Definition MassArchetypeTypes.cpp:229
Definition MassArchetypeTypes.h:39
MASSENTITY_API friend uint32 GetTypeHash(const FMassArchetypeHandle &Instance)
Definition MassArchetypeTypes.cpp:13
bool operator==(const FMassArchetypeHandle &Other) const
Definition MassArchetypeTypes.h:368
void Reset()
Definition MassArchetypeTypes.h:378
bool operator!=(const FMassArchetypeHandle &Other) const
Definition MassArchetypeTypes.h:373
FMassArchetypeHandle()=default
bool IsValid() const
Definition MassArchetypeTypes.h:363
Definition MassArchetypeData.h:507
Definition MassArchetypeTypes.h:61
MASSENTITY_API friend uint32 GetTypeHash(const FMassArchetypeHandle &Instance)
Definition MassArchetypeTypes.cpp:13
bool operator!=(const FMassArchetypeVersionedHandle &Other) const
Definition MassArchetypeTypes.h:353
MASSENTITY_API bool IsUpToDate() const
Definition MassArchetypeTypes.cpp:33
bool IsValid() const
Definition MassArchetypeTypes.h:343
bool operator==(const FMassArchetypeVersionedHandle &Other) const
Definition MassArchetypeTypes.h:348
Definition MassDebugger.h:441
Definition MassEntityHandle.h:13
Definition MassArchetypeTypes.h:304
bool operator==(const FMassEntityInChunkDataHandle &Other) const
Definition MassArchetypeTypes.h:468
FMassEntityInChunkDataHandle(FMassEntityInChunkDataHandle &&)=default
const int32 ChunkSerialNumber
Definition MassArchetypeTypes.h:317
FMassEntityInChunkDataHandle & operator=(const FMassEntityInChunkDataHandle &)
Definition MassArchetypeTypes.h:450
FMassEntityInChunkDataHandle(const FMassEntityInChunkDataHandle &)=default
const int32 ChunkIndex
Definition MassArchetypeTypes.h:316
Definition MassEntityManager.h:96
Definition MassEntityQuery.h:51
Definition MassEntityView.h:24
Definition MassExecutionContext.h:29
Definition MassEntityElementTypes.h:10
Definition MassEntityTypes.h:658
Definition MassEntityTypes.h:623
Definition MassArchetypeTypes.h:326
FMassFragmentIndicesMapping EntityFragments
Definition MassArchetypeTypes.h:329
FMassFragmentIndicesMapping ConstSharedFragments
Definition MassArchetypeTypes.h:331
bool IsEmpty() const
Definition MassArchetypeTypes.h:333
FMassFragmentIndicesMapping ChunkFragments
Definition MassArchetypeTypes.h:330
FMassFragmentIndicesMapping SharedFragments
Definition MassArchetypeTypes.h:332
Definition MassArchetypeTypes.h:285
const int32 IndexWithinChunk
Definition MassArchetypeTypes.h:293
bool IsSet() const
Definition MassArchetypeTypes.h:440
FMassRawEntityInChunkData()=default
bool operator==(const FMassRawEntityInChunkData &Other) const
Definition MassArchetypeTypes.h:445
uint8 *const ChunkRawMemory
Definition MassArchetypeTypes.h:292