LEAP Documentation 40220
Documentation for the LEAP project
ActorPruningSystem.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/Actor.h"
8#include "ActorPruningSystem.generated.h"
9
10#define CHUNK_SIZE 256
11#define CHUNK_DELAY 0.2f
12
13USTRUCT(Blueprintable)
15{
16 GENERATED_USTRUCT_BODY()
17
18public:
19 /* Class of actor to prune and eventually show based on conditions below. */
20 UPROPERTY(EditAnywhere, BlueprintReadWrite)
21 TSubclassOf<AActor> ActorClassToPrune = nullptr;
22 /* Minimum number of actors to show. The system will throw an error if this value is higher than the number of available actors */
23 UPROPERTY(EditAnywhere, BlueprintReadWrite)
24 int32 MinCount = 0;
25 /* Show actors once the match has begun. */
26 UPROPERTY(EditAnywhere, BlueprintReadWrite)
27 bool bShowAllAtMatchStart = true;
28 /* Begin showing actors when the match elapsed time is equal to this value. */
29 UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (EditCondition = "!bShowAllAtMatchStart"))
30 float StartShowingAtMatchTime = 0.0f;
31 /* Constrains the actor spawn volume to this actor's bounds rather than using it's own. Mincount will potentially be ignored if this is active since there may not be enough actors within that region. */
32 UPROPERTY(EditAnywhere, BlueprintReadWrite)
33 AActor* ActorBoundsOverride = nullptr;
34
35 bool bSpawned = false;
36};
37
38UCLASS()
39class PROJECTX_API AActorPruningSystem : public AActor, public IReactsToMatchEvents
40{
41 GENERATED_BODY()
42
43public:
44 /* Class and configuration of actors to be removed and shown at a later stage in the match */
45 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ActorPruning)
46 TArray<FActorPruneInfo> ActorsToPrune;
47 /* Show helpful debugging information regarding spawning/chunking */
48 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ActorPruning)
49 bool bDebug = false;
50
52
53 static int ShownActorCount;
54
55 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
56 virtual void BeginPlay() override;
57 virtual void Tick(float DeltaSeconds) override;
58 virtual void MatchStarted() override;
59
60 void SetActorEnabled(AActor* Actor, const bool bToggle);
61
62 void SendChunk(const TArray<AActor*> Chunk);
63 void HideAllActors();
64 void ValidateActorList(TArray<AActor*>& ActorList);
65 void BuildShowActorList();
66 void SpawnInitialActorsOnServer();
67 void ChunkAndSendShowActorArray(const TArray<AActor*>& ActorsToShow);
68 bool BuildActorBoundsOverrideList(const FActorPruneInfo& ActorPruneInfo);
69
70 /* Any UObjects that subscribe to IReactsToActorPruner will receive Enable and Disable events so that an actor can disable itself in its own way without technically being destroyed */
71 static void CallActorPrunerEvents(UObject* Object, const bool bToggle);
72
73 UFUNCTION(NetMulticast, Reliable)
74 void Multicast_ShowActors(const TArray<AActor*>& ActorsToShow);
75
76private:
77 TMap<TSubclassOf<AActor>, TArray<AActor*>> ShowActorList;
78};
Definition: ActorPruningSystem.h:40
Definition: ReactsToMatchEvents.h:16
Definition: ActorPruningSystem.h:15