// Copyright 2020 Phyronnaz #pragma once #include "CoreMinimal.h" #include "VoxelTickable.h" #include "VoxelRender/IVoxelLODManager.h" #include "VoxelInvokerSettings.h" #include "VoxelMinimal.h" #include "VoxelAsyncWork.h" class FVoxelRenderOctreeAsyncBuilder; class FVoxelRenderOctree; class UVoxelInvokerComponentBase; class AVoxelWorldInterface; struct FVoxelLODDynamicSettings { int32 MinLOD; int32 MaxLOD; // In world space float InvokerDistanceThreshold; int32 ChunksCullingLOD; bool bEnableRender; bool bEnableCollisions; bool bComputeVisibleChunksCollisions; int32 VisibleChunksCollisionsMaxLOD; bool bEnableNavmesh; bool bComputeVisibleChunksNavmesh; int32 VisibleChunksNavmeshMaxLOD; }; class FVoxelDefaultLODManager : public IVoxelLODManager, public FVoxelTickable, public TVoxelSharedFromThis { public: static TVoxelSharedRef Create( const FVoxelLODSettings& LODSettings, TWeakObjectPtr VoxelWorldInterface, const TVoxelSharedRef& DynamicSettings); ~FVoxelDefaultLODManager(); //~ Begin IVoxelLODManager Interface virtual int32 UpdateBounds(const FVoxelIntBox& Bounds, const FVoxelOnChunkUpdateFinished& FinishDelegate) override final; virtual int32 UpdateBounds(const TArray& Bounds, const FVoxelOnChunkUpdateFinished& FinishDelegate) override final; virtual void ForceLODsUpdate() override final; virtual bool AreCollisionsEnabled(const FIntVector& Position, uint8& OutLOD) const override final; virtual void Destroy() override final; //~ End IVoxelLODManager Interface //~ Begin FVoxelTickable Interface virtual void Tick(float DeltaTime) override; virtual bool IsTickableInEditor() const override { return true; } //~ End FVoxelTickable Interface private: FVoxelDefaultLODManager( const FVoxelLODSettings& LODSettings, TWeakObjectPtr VoxelWorldInterface, const TVoxelSharedRef& DynamicSettings); const TWeakObjectPtr VoxelWorldInterface; const TVoxelSharedRef DynamicSettings; TUniquePtr> Task; TVoxelSharedPtr Octree; struct FVoxelInvokerInfo { FIntVector LocalPosition{ForceInit}; FVoxelInvokerSettings Settings; }; TMap, FVoxelInvokerInfo> InvokerComponentsInfos; TArray> SortedInvokerComponents; bool bAsyncTaskWorking = false; bool bLODUpdateQueued = true; double LastLODUpdateTime = 0; double LastInvokersUpdateTime = 0; void UpdateInvokers(); void UpdateLODs(); void ClearInvokerComponents(); };