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 14:44:18 +00:00
|
|
|
#include "Block/VoxelBlock.h"
|
2020-12-03 05:52:29 +00:00
|
|
|
#include "GameFramework/Actor.h"
|
|
|
|
#include "VoxelChunk.generated.h"
|
|
|
|
|
|
|
|
class AVoxelWorld;
|
|
|
|
class UVoxelSubsystem;
|
|
|
|
class UProceduralMeshComponent;
|
|
|
|
|
2020-12-13 03:20:17 +00:00
|
|
|
USTRUCT()
|
|
|
|
struct FVoxelChunkData : public FSaveStruct
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
FVoxelBlock Blocks[16][16][256];
|
|
|
|
|
|
|
|
bool Serialize(FArchive& Slot);
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct TStructOpsTypeTraits<FVoxelChunkData> : public TStructOpsTypeTraitsBase2<FVoxelChunkData>
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
WithSerializer = true,
|
|
|
|
};
|
|
|
|
};
|
2020-12-03 05:52:29 +00:00
|
|
|
|
|
|
|
UCLASS(BlueprintType)
|
|
|
|
class VOXEL_API AVoxelChunk : public AActor
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
friend AVoxelWorld;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
AVoxelChunk(const class FObjectInitializer& ObjectInitializer);
|
|
|
|
|
|
|
|
virtual void BeginPlay() override;
|
|
|
|
|
2020-12-13 03:20:17 +00:00
|
|
|
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
|
|
|
|
2020-12-03 05:52:29 +00:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Voxel|Chunk")
|
|
|
|
AVoxelWorld* GetVoxelWorld() const { return VoxelWorld; }
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Voxel|Chunk")
|
|
|
|
FIntPoint GetChunkLocation() const { return ChunkLocation; }
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Voxel|Chunk")
|
|
|
|
const FVoxelBlock& GetBlockByRelativeLocation(const FIntVector& Location) const;
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Voxel|Chunk")
|
|
|
|
void SetBlockByRelativeLocation(const FIntVector& Location, const FVoxelBlock& NewBlock);
|
|
|
|
|
|
|
|
UFUNCTION(CallInEditor, BlueprintCallable, Category = "Voxel|Chunk")
|
|
|
|
void FlushMeshs();
|
|
|
|
|
|
|
|
UFUNCTION(CallInEditor, BlueprintCallable, Category = "Voxel|Chunk")
|
|
|
|
void FlushMaterials();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
UVoxelSubsystem* VoxelSubsystem;
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
AVoxelWorld* VoxelWorld;
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
TArray<UProceduralMeshComponent*> MeshComponents;
|
|
|
|
|
|
|
|
FString ArchiveFile;
|
|
|
|
|
|
|
|
FIntPoint ChunkLocation;
|
|
|
|
|
|
|
|
uint16 FlushMeshFlags;
|
|
|
|
|
2020-12-13 03:20:17 +00:00
|
|
|
TSharedPtr<FSaveStructPtr<FVoxelChunkData>> Data;
|
2020-12-03 05:52:29 +00:00
|
|
|
|
|
|
|
FVoxelMeshData MeshSectionBuffer;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void FlushMeshSection(int32 SectionIndex);
|
|
|
|
|
2020-12-13 03:20:17 +00:00
|
|
|
UFUNCTION()
|
|
|
|
void OnDataLoaded(const FString& Filename);
|
|
|
|
|
2020-12-03 05:52:29 +00:00
|
|
|
};
|