23 #include "Subjective.h"
25 #include "Components/ActorComponent.h"
26 #include "CoreMinimal.h"
27 #include "Fingerprint.h"
29 #include "UObject/NoExportTypes.h"
31 #include "Belt.generated.h"
33 DECLARE_STATS_GROUP(TEXT(
"Belt"), STATGROUP_Belt, STATCAT_Advanced);
35 FORCEINLINE uint32 GetTypeHash(
const TArray<const UClass*>& Types)
38 for (
auto Type : Types)
40 h += Type->GetUniqueID();
45 FORCEINLINE uint32 GetTypeHash(
const TArray<UClass*>& Types)
48 for (
auto Type : Types)
50 h += Type->GetUniqueID();
59 class APPARATUSRUNTIME_API
UBelt : public UObject
66 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Belt,
67 Meta = (AllowPrivateAccess =
"true"))
73 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Transient, Category = Belt,
74 Meta = (AllowPrivateAccess =
"true"))
80 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Transient, Category = Belt,
81 Meta = (AllowPrivateAccess =
"true"))
82 uint32 bBuffering : 1;
87 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Belt,
88 Meta = (AllowPrivateAccess =
"true"))
106 FORCEINLINE
bool IsSparse()
const {
return bSparse; }
124 UBelt* Owner =
nullptr;
141 check(Owner !=
nullptr);
152 check(Owner !=
nullptr);
154 const auto IndexSave = Index;
161 check(Owner !=
nullptr);
162 if (Owner != other.Owner)
164 if (Index == other.Index)
166 if (Index >= Owner->
Num() && other.Index == -1)
168 if (other.Index >= other.Owner->
Num() && Index == -1)
175 check(Owner !=
nullptr);
176 if (Owner != other.Owner)
178 if (Index == other.Index)
180 if (Index >= Owner->
Num() && other.Index == -1)
182 if (other.Index >= other.Owner->
Num() && Index == -1)
189 check(Owner !=
nullptr);
191 return Owner->Slots[Index];
199 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Transient, Category = Belt,
200 Meta = (AllowPrivateAccess =
"true"))
225 const static TArray<
UBelt*> NoBelts;
235 const EBootFilter BootFilter = EBootFilter::None);
242 FORCEINLINE int32
Num()
const {
return Count; }
249 FORCEINLINE int32
GetCount()
const {
return Count; }
303 UFUNCTION(BlueprintCallable, Category =
"Apparatus")
311 UFUNCTION(BlueprintCallable, Category = "Apparatus")
328 const TArray<class
UDetail*>& Details);
338 static class
UBelt*
New(UObject* Owner,
344 static class
UBelt*
New(UObject* Owner,
351 static class
UBelt*
New(UObject* Owner,
354 const EBootFilter BootFilter);
375 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Apparatus")
377 const int32 DetailIndex);
382 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Apparatus",
383 Meta = (DeterminesOutputType = "DetailType", KeyWords = "belt"))
385 const TSubclassOf<
UDetail> DetailType);
390 UFUNCTION(BlueprintCallable, Category = "Apparatus",
391 Meta = (DeterminesOutputType = "DetailType"))
393 const TSubclassOf<
UDetail> DetailType) const;
398 UFUNCTION(BlueprintCallable, Category = "Apparatus",
399 Meta = (DeterminesOutputType = "DetailType",
400 BlueprintInternalUseOnly))
403 const TSubclassOf<
UDetail> DetailType,
404 const int32 IndexHint);
409 UFUNCTION(BlueprintCallable, Category = "Apparatus")
416 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Apparatus",
417 Meta = (KeyWords = "belt"))
423 UFUNCTION(BlueprintCallable, Category = "Apparatus")
429 UFUNCTION(BlueprintCallable, Category = "Apparatus",
430 Meta = (KeyWords = "belt"))
436 UFUNCTION(BlueprintCallable, Category = "Apparatus")
442 UFUNCTION(BlueprintCallable, Category = "Apparatus")
448 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Apparatus")
456 if (Slot.Owner ==
nullptr)
465 return Filter.
Matches(InFilter);
475 const int32 DetailIndex)
482 const TSubclassOf<UDetail> DetailType)
489 const TSubclassOf<UDetail> DetailType)
const
491 const FBeltSlot& Slot = Slots[SlotIndex];
497 const TSubclassOf<UDetail> DetailType,
498 const int32 IndexHint)
500 const FBeltSlot& Slot = Slots[SlotIndex];
502 checkfSlow(rDetail->IsA(DetailType),
503 TEXT(
"The hinted type is not the same."));
507 FORCEINLINE TScriptInterface<ISubjective>
510 const FBeltSlot& Slot = Slots[SlotIndex];
533 if (SlotIndex >= Count)
556 Index = Belt->Slots.
Num();
561 return Subjective !=
nullptr && Owner !=
nullptr && Index >= 0 &&
562 Index < Owner->Num();
Definition: ApparatusRuntime.h:28
An interface for all sorts of subjects.
Definition: Subjective.h:42
The iterator for the belt.
Definition: Belt.h:120
bool operator==(const iterator &other) const
Definition: Belt.h:159
iterator operator++(int)
Get the next iterator.
Definition: Belt.h:150
FBeltSlot & operator*()
Definition: Belt.h:187
iterator & operator++()
Get the next iterator.
Definition: Belt.h:139
bool operator!=(const iterator &other) const
Definition: Belt.h:173
The conveyor belt consisting of subjects.
Definition: Belt.h:60
void BufferDetailsFromBelts(const TArray< class UBelt * > &Belts, const FFilter &TargetFilter)
Fetch the details from other belts, using the specified filter.
Definition: Belt.cpp:314
int32 Num() const
The number of slots currently in the belt.
Definition: Belt.h:242
static UDetail * GetDetailFromSlot(const FBeltSlot &Slot, const TSubclassOf< UDetail > DetailType)
Get a detail from a slot using a detail type.
Definition: Belt.h:481
int32 GetCount() const
Get the number of slots currently in the belt.
Definition: Belt.h:249
static FBeltSlot & GetNextSlot(const FBeltSlot &Slot)
Get the next iteratable slot.
Definition: Belt.h:547
static class UBelt * New(UObject *Owner, const FFingerprint &Fingerprint)
Create a new belt instance.
Definition: Belt.cpp:56
TScriptInterface< ISubjective > GetSubjectFromSlotAtIndex(const int32 SlotIndex)
Get the subject from a slot at specified index.
Definition: Belt.h:508
void FetchDetails()
Fetch all of the current active details in this belt.
Definition: Belt.cpp:267
iterator begin()
Get the first slot for iteration.
Definition: Belt.h:278
FBeltSlot & GetFirstSlot()
Get the first iteratable slot.
Definition: Belt.cpp:109
int32 GetNextSlotIndex(const int32 SlotIndex)
Get the next iteratable slot index.
Definition: Belt.h:531
static const int32 InvalidSlotIndex
Is this a special buffering belt?
Definition: Belt.h:96
static bool IsEndSlot(const FBeltSlot &Slot)
Get a detail from a slot using a detail type.
Definition: Belt.h:454
bool Expand(const FFingerprint &NewFingerprint, const EBootFilter BootFilter=EBootFilter::None)
Expand a belt to accommodate the new fingerprint.
Definition: Belt.cpp:87
int32 GetFirstSlotIndex()
Get the first iteratable slot.
Definition: Belt.h:515
FBeltSlot & GetEndSlot()
Get the ending iteratable slot.
Definition: Belt.h:452
iterator end()
The ending iterator.
Definition: Belt.h:291
bool Remove(TScriptInterface< ISubjective > Subjective)
Remove a subject from the belt.
Definition: Belt.cpp:144
UDetail * GetDetailFromSlotAtIndexHinted(const int32 SlotIndex, const TSubclassOf< UDetail > DetailType, const int32 IndexHint)
Get the detail from a slot at specified index with a hint.
Definition: Belt.h:496
void BufferDetailsFromBelt(UBelt *Belt, const FFilter &TargetFilter)
Fetch the details from another belt, using the specified filter.
Definition: Belt.cpp:288
bool IsBuffering() const
Is this a special belt, used for buffering other belts?
Definition: Belt.h:101
bool Matches(const FFilter &Filter) const
Check if the belt matches a filter.
Definition: Belt.h:461
static class UBelt * NewBuffering(UObject *Owner)
Create a new buffering belt instance.
Definition: Belt.cpp:80
const FFilter & GetFilter() const
The active filter of the belt.
Definition: Belt.h:111
static UDetail * GetDetailFromSlotByIndex(const FBeltSlot &Slot, const int32 DetailIndex)
Get a detail from a slot using an index.
Definition: Belt.h:474
FBeltSlot & operator[](int32 Index)
Get a belt slot by its index.
Definition: Belt.h:257
void Refresh(TScriptInterface< ISubjective > Subjective)
Refresh a subjective within the belt.
Definition: Belt.cpp:164
const FBeltSlot & operator[](int32 Index) const
Get a belt slot by its index.
Definition: Belt.h:268
bool IsSparse() const
Is this a sparse belt allowing some empty detail spaces?
Definition: Belt.h:106
UDetail * GetDetailFromSlotAtIndex(const int32 SlotIndex, const TSubclassOf< UDetail > DetailType) const
Get the detail from a slot at specified index.
Definition: Belt.h:488
The base subject detail (component) class.
Definition: Detail.h:35
The main Mechanism function library.
Definition: Mechanism.h:63
Definition: SubjectiveActorComponent.h:39
The belt slot, containing the cached details.
Definition: BeltSlot.h:40
class UBelt * GetOwner() const
Get the owning belt of the slot.
Definition: BeltSlot.h:96
UDetail * GetDetail(const int32 DetailIndex) const
Get the detail by its index.
Definition: BeltSlot.cpp:389
static const int32 InvalidIndex
Invalid belt index.
Definition: BeltSlot.h:48
TScriptInterface< class ISubjective > GetSubjective() const
Get the subjective of the slot.
Definition: BeltSlot.h:290
int32 GetIndex() const
Get the index of the slot in the belt.
Definition: BeltSlot.h:108
const FFilter & GetFilter() const
The active filter of the slot, which is the same as its owning belt's.
Definition: Belt.h:570
bool IsBuffering() const
Check if this is a buffering slot, part of the buffering belt.
Definition: Belt.h:565
FBeltSlot()
The default slot constructor.
Definition: BeltSlot.h:135
FBeltSlot & GetNext()
The next slot used for iteration.
Definition: BeltSlot.cpp:57
bool IsValid() const
Is this slot actually valid?
Definition: Belt.h:559
bool IncludesPartially(const FBitMask &BitMask) const
Check if the mask has any of the bits set in the supplied mask.
Definition: BitMask.h:260
bool Includes(const FBitMask &BitMask) const
Does the mask has all of the bits set in the supplied mask.
Definition: BitMask.h:241
The details filter specification.
Definition: Filter.h:44
const FBitMask & GetExcludedDetailsMask() const
Get the excluded details mask of the filter.
Definition: Filter.h:135
const FBitMask & GetDetailsMask() const
Get the included details mask of the filter.
Definition: Filter.h:130
bool Matches(const FFilter &Filter) const
Check if the filter matches an another filter.
Definition: Filter.h:640
The details fingerprint.
Definition: Fingerprint.h:117