2020-12-03 05:52:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
2020-12-13 03:20:17 +00:00
|
|
|
#include "SaveStruct.h"
|
2020-12-03 05:52:29 +00:00
|
|
|
#include "GameFramework/Info.h"
|
|
|
|
#include "VoxelWorld.generated.h"
|
|
|
|
|
|
|
|
struct FVoxelBlock;
|
|
|
|
|
|
|
|
class AVoxelChunk;
|
|
|
|
class UVoxelHelper;
|
|
|
|
class UVoxelBlockType;
|
|
|
|
class UVoxelSubsystem;
|
|
|
|
class IVoxelAgentInterface;
|
|
|
|
|
|
|
|
USTRUCT(BlueprintType)
|
2020-12-03 14:44:18 +00:00
|
|
|
struct VOXEL_API FVoxelWorldSetting
|
2020-12-03 05:52:29 +00:00
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxel|World")
|
|
|
|
FString ArchiveFolder;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-12-13 03:20:17 +00:00
|
|
|
USTRUCT()
|
|
|
|
struct FVoxelWorldData : public FSaveStruct
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
};
|
|
|
|
|
2020-12-03 05:52:29 +00:00
|
|
|
UCLASS(BlueprintType)
|
|
|
|
class VOXEL_API AVoxelWorld : public AInfo
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
friend UVoxelHelper;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxel|World")
|
|
|
|
TScriptInterface<IVoxelAgentInterface> CenterAgent;
|
|
|
|
|
|
|
|
AVoxelWorld(const class FObjectInitializer& ObjectInitializer);
|
|
|
|
|
|
|
|
virtual void BeginPlay() override;
|
|
|
|
|
|
|
|
virtual void Tick(float DeltaSeconds) override;
|
|
|
|
|
|
|
|
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Voxel|World")
|
|
|
|
const FVoxelWorldSetting& GetWorldSetting() const { return WorldSetting; }
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Voxel|World")
|
|
|
|
const TMap<FIntPoint, AVoxelChunk*>& GetChunks() const { return Chunks; }
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Voxel|World")
|
|
|
|
const FVoxelBlock& GetBlockByWorldLocation(const FIntVector& Location) const;
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Voxel|World")
|
|
|
|
void SetBlockByWorldLocation(const FIntVector& Location, const FVoxelBlock& NewBlock);
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Voxel|World")
|
|
|
|
void AddChunkToMeshFlushBuffer(const FIntPoint& ChunkLocation) { MeshFlushBuffer.Add(ChunkLocation); }
|
|
|
|
|
|
|
|
UFUNCTION(CallInEditor, BlueprintCallable, Category = "Voxel|World")
|
|
|
|
void FlushMaterials();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
void LoadChunk(const FIntPoint& ChunkLocation);
|
|
|
|
void UnloadChunk(const FIntPoint& ChunkLocation);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Voxel|World")
|
|
|
|
FVoxelWorldSetting WorldSetting;
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
UVoxelSubsystem* VoxelSubsystem;
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
TMap<FIntPoint, AVoxelChunk*> Chunks;
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
TSet<FIntPoint> MeshFlushBuffer;
|
|
|
|
|
2020-12-13 03:20:17 +00:00
|
|
|
TSharedPtr<FSaveStructPtr<FVoxelWorldData>> Data;
|
|
|
|
|
2020-12-03 05:52:29 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
void ManageChunk();
|
|
|
|
|
|
|
|
void FlushMeshs();
|
|
|
|
|
2020-12-13 03:20:17 +00:00
|
|
|
bool TestWorldSettingValid();
|
|
|
|
|
2020-12-03 05:52:29 +00:00
|
|
|
};
|