Apparatus Version 1.0.0
ECS-like data-driven workflow for Unreal Engine.
BeltSlotCache.h
1 /*
2  * ░▒▓ APPARATUS ▓▒░
3  *
4  * File: BeltSlot.h
5  * Created: Friday, 23rd October 2020 7:00:48 pm
6  * Author: Vladislav Dmitrievich Turbanov (vladislav@turbanov.ru)
7  * ───────────────────────────────────────────────────────────────────
8  * Last Modified: Friday, 26th March 2021 3:55:26 pm
9  * Modified By: Vladislav Dmitrievich Turbanov (vladislav@turbanov.ru)
10  * ───────────────────────────────────────────────────────────────────
11  *
12  * The Apparatus source code is for your internal usage only.
13  * Redistribution of this file is strictly prohibited.
14  *
15  * Community forums: https://talk.turbanov.ru
16  *
17  * Copyright 2020 - 2021, SP Vladislav Dmitrievich Turbanov
18  * Made in Russia, Moscow City, Chekhov City
19  */
20 
21 #pragma once
22 
23 #include "CoreMinimal.h"
24 #include "UObject/NoExportTypes.h"
25 #include "Detail.h"
26 
27 #include "BeltSlotCache.generated.h"
28 
32 USTRUCT(BlueprintType)
33 struct APPARATUSRUNTIME_API FBeltSlotCache
34 {
35  GENERATED_BODY()
36 
37  friend class UBelt;
38 
42  TArray<TWeakObjectPtr<class UDetail>> Details;
43 
44  public:
45  FORCEINLINE TSubclassOf<UDetail> GetDetailType() const
46  {
47  if (Details.Num() == 0) return nullptr;
48  return Details[0]->GetClass();
49  }
50 
54  FORCEINLINE const TArray<TWeakObjectPtr<class UDetail>>& GetDetails() const
55  {
56  return Details;
57  }
58 
62  FORCEINLINE int32 GetDetailsCount() const { return Details.Num(); }
63 
67  FORCEINLINE FBeltSlotCache() {}
68 
72  FORCEINLINE FBeltSlotCache(const int32 Capacity)
73  {
74  Details.Reserve(Capacity);
75  }
76 
80  FORCEINLINE void Reset() { Details.Reset(); }
81 
85  bool Fetch(const TScriptInterface<class ISubjective> Subjective,
86  const TSubclassOf<UDetail> Type);
87 
91  bool Fetch(const TSubclassOf<UDetail> Type,
92  const TArray<class UDetail *> &InDetails);
93 
97  FBeltSlotCache &operator=(const FBeltSlotCache &Cache);
98 
102  FBeltSlotCache &operator+=(const FBeltSlotCache &Cache);
103 }; // class FBeltSlotCache
The conveyor belt consisting of subjects.
Definition: Belt.h:60
The base subject detail (component) class.
Definition: Detail.h:35
TSubclassOf< UDetail > GetClass() const
Get the detail class.
Definition: Detail.h:76
A detail caching for subjects used in the belts' slots.
Definition: BeltSlotCache.h:34
bool Fetch(const TSubclassOf< UDetail > Type, const TArray< class UDetail * > &InDetails)
Fetch the detail instances from the user-provided list of details.
int32 GetDetailsCount() const
Get the current number of fetched details.
Definition: BeltSlotCache.h:62
FBeltSlotCache()
Create a new belt slot cache instance.
Definition: BeltSlotCache.h:67
const TArray< TWeakObjectPtr< class UDetail > > & GetDetails() const
Get the list of all fetched details.
Definition: BeltSlotCache.h:54
FBeltSlotCache(const int32 Capacity)
Create a new belt slot cache instance.
Definition: BeltSlotCache.h:72
bool Fetch(const TScriptInterface< class ISubjective > Subjective, const TSubclassOf< UDetail > Type)
Fetch the detail instances from the subject.
void Reset()
Clear the cache, without any deallocations.
Definition: BeltSlotCache.h:80