A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
BucketUpdateSubsystem.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Subsystems/WorldSubsystem.h"
7#include "Tickable.h"
8#include "BucketUpdateSubsystem.generated.h"
9//#include "GrippablePhysicsReplication.generated.h"
10
11
12//DECLARE_DYNAMIC_MULTICAST_DELEGATE(FVRPhysicsReplicationDelegate, void, Return);
13
14
15DECLARE_DELEGATE_RetVal(bool, FBucketUpdateTickSignature);
16DECLARE_DYNAMIC_DELEGATE(FDynamicBucketUpdateTickSignature);
17
18USTRUCT()
19struct VREXPANSIONPLUGIN_API FUpdateBucketDrop
20{
21 GENERATED_BODY()
22public:
23 FBucketUpdateTickSignature NativeCallback;
24 FDynamicBucketUpdateTickSignature DynamicCallback;
26 FName FunctionName;
27
28 bool ExecuteBoundCallback();
29 bool IsBoundToObjectFunction(UObject * Obj, FName & FuncName);
30 bool IsBoundToObjectDelegate(FDynamicBucketUpdateTickSignature & DynEvent);
31 bool IsBoundToObject(UObject * Obj);
33 FUpdateBucketDrop(FDynamicBucketUpdateTickSignature & DynCallback);
34 FUpdateBucketDrop(UObject * Obj, FName FuncName);
35};
36
37
38USTRUCT()
39struct VREXPANSIONPLUGIN_API FUpdateBucket
40{
41 GENERATED_BODY()
42
43public:
44
45 float nUpdateRate;
46 float nUpdateCount;
47
48 TArray<FUpdateBucketDrop> Callbacks;
50 bool Update(float DeltaTime);
51
53
54 FUpdateBucket(uint32 UpdateHTZ) :
55 nUpdateRate(1.0f / UpdateHTZ),
56 nUpdateCount(0.0f)
57 {
58 }
59};
60
61USTRUCT()
62struct VREXPANSIONPLUGIN_API FUpdateBucketContainer
63{
64 GENERATED_BODY()
65public:
66
67
68 bool bNeedsUpdate;
69 TMap<uint32, FUpdateBucket> ReplicationBuckets;
71 void UpdateBuckets(float DeltaTime);
72
73 bool AddBucketObject(uint32 UpdateHTZ, UObject* InObject, FName FunctionName);
74 bool AddBucketObject(uint32 UpdateHTZ, FDynamicBucketUpdateTickSignature &Delegate);
76 /*
77 template<typename classType>
78 bool AddReplicatingObject(uint32 UpdateHTZ, classType* InObject, void(classType::* _Func)())
79 {
80 }
81 */
82
83 bool RemoveBucketObject(UObject * ObjectToRemove, FName FunctionName);
84 bool RemoveBucketObject(FDynamicBucketUpdateTickSignature &DynEvent);
85 bool RemoveObjectFromAllBuckets(UObject * ObjectToRemove);
86
87 bool IsObjectInBucket(UObject * ObjectToRemove);
88 bool IsObjectFunctionInBucket(UObject * ObjectToRemove, FName FunctionName);
89 bool IsObjectDelegateInBucket(FDynamicBucketUpdateTickSignature &DynEvent);
90
92 {
93 bNeedsUpdate = false;
94 };
95
96};
98UCLASS()
99class VREXPANSIONPLUGIN_API UBucketUpdateSubsystem : public UTickableWorldSubsystem
100{
101 GENERATED_BODY()
102
103public:
105 Super()
106 {
108 }
110 virtual bool DoesSupportWorldType(EWorldType::Type WorldType) const override
111 {
112 return WorldType == EWorldType::Game || WorldType == EWorldType::PIE;
113 // Not allowing for editor type as this is a replication subsystem
114 }
115
116 //UPROPERTY()
117 FUpdateBucketContainer BucketContainer;
119 // Adds an object to an update bucket with the set HTZ, calls the passed in UFUNCTION name
120 // If one of the bucket contains an entry with the function already then the existing one is removed and the new one is added
121 bool AddObjectToBucket(int32 UpdateHTZ, UObject* InObject, FName FunctionName);
122
123 // Adds an object to an update bucket with the set HTZ, calls the passed in UFUNCTION name
124 // If one of the bucket contains an entry with the function already then the existing one is removed and the new one is added
125 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Add Object to Bucket Updates", ScriptName = "AddObjectToBucket"), Category = "BucketUpdateSubsystem")
126 bool K2_AddObjectToBucket(int32 UpdateHTZ = 100, UObject* InObject = nullptr, FName FunctionName = NAME_None);
127
128 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Add Object to Bucket Updates by Event", ScriptName = "AddBucketObjectEvent"), Category = "BucketUpdateSubsystem")
129 bool K2_AddObjectEventToBucket(UPARAM(DisplayName = "Event") FDynamicBucketUpdateTickSignature Delegate, int32 UpdateHTZ = 100);
130
131 // Remove the entry in the bucket updates with the passed in UFUNCTION name
132 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Remove Object From Bucket Updates By Function", ScriptName = "RemoveObjectFromBucketByFunction"), Category = "BucketUpdateSubsystem")
133 bool RemoveObjectFromBucketByFunctionName(UObject* InObject = nullptr, FName FunctionName = NAME_None);
134
135 // Remove the entry in the bucket updates with the passed in UFUNCTION name
136 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Remove Object From Bucket Updates By Event", ScriptName = "RemoveObjectFromBucketByEvent"), Category = "BucketUpdateSubsystem")
137 bool RemoveObjectFromBucketByEvent(UPARAM(DisplayName = "Event") FDynamicBucketUpdateTickSignature Delegate);
138
139 // Removes ALL entries in the bucket update system with the specified object
140 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Remove Object From All Bucket Updates", ScriptName = "RemoveObjectFromAllBuckets"), Category = "BucketUpdateSubsystem")
141 bool RemoveObjectFromAllBuckets(UObject* InObject = nullptr);
142
143 // Returns if an update bucket contains an entry with the passed in function
144 UFUNCTION(BlueprintCallable, meta = (DisplayName = "Is Object In Bucket", ScriptName = "IsObjectInBucket"), Category = "BucketUpdateSubsystem")
145 bool IsObjectFunctionInBucket(UObject* InObject = nullptr, FName FunctionName = NAME_None);
146
147 // Returns if an update bucket contains an entry with the passed in function
148 UFUNCTION(BlueprintPure, Category = "BucketUpdateSubsystem")
149 bool IsActive();
150
151 // FTickableGameObject functions
159 virtual void Tick(float DeltaTime) override;
160 virtual bool IsTickable() const override;
161 virtual UWorld* GetTickableGameObjectWorld() const override;
162 virtual bool IsTickableInEditor() const;
163 virtual bool IsTickableWhenPaused() const override;
164 virtual ETickableTickType GetTickableTickType() const;
165 virtual TStatId GetStatId() const override;
166
167 // End tickable object information
168
169};
DECLARE_DYNAMIC_DELEGATE(FDynamicBucketUpdateTickSignature)
DECLARE_DELEGATE_RetVal(bool, FBucketUpdateTickSignature)
virtual bool DoesSupportWorldType(EWorldType::Type WorldType) const override
FUpdateBucketContainer BucketContainer
TMap< uint32, FUpdateBucket > ReplicationBuckets
FDynamicBucketUpdateTickSignature DynamicCallback
FBucketUpdateTickSignature NativeCallback
FUpdateBucket(uint32 UpdateHTZ)
TArray< FUpdateBucketDrop > Callbacks