Files
BusyRabbit/Source/BusyRabbit/Public/Level/Generator/VoronoiTerrainGenerator.h
2025-09-30 02:52:12 +08:00

79 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "Utils/MitchellBestCandidate.h"
#include "Level/Generator/VoronoiDiagram.h"
#include "Level/Generator/TerrainGeneratorBase.h"
#include "VoronoiTerrainGenerator.generated.h"
/**
* @brief 泰森多边形地形生成器
*
* 结合米切尔最佳候选算法和泰森多边形算法的高级地形生成器。
* 使用米切尔算法生成均匀分布的点集,然后使用泰森多边形划分区域,
* 最后根据权重分配地形类型到各个区域。
*/
UCLASS(BlueprintType, Blueprintable)
class BUSYRABBIT_API UVoronoiTerrainGenerator : public UTerrainGeneratorBase
{
GENERATED_BODY()
public:
UVoronoiTerrainGenerator();
/**
* @brief 设置泰森多边形区域数量
*
* 控制地图被划分的泰森多边形区域数量,影响地形的粒度。
*
* @param Count 区域数量至少为1
*/
UFUNCTION(BlueprintCallable, Category = "Voronoi Terrain Generator")
void SetVoronoiRegionCount(int32 Count);
/**
* @brief 设置米切尔候选点数
*
* 控制米切尔算法中每个点生成的候选点数,影响点集的质量。
*
* @param Count 候选点数至少为1
*/
UFUNCTION(BlueprintCallable, Category = "Voronoi Terrain Generator")
void SetMitchellCandidateCount(int32 Count);
virtual bool GenerateWithNodes(TArray<FGameplayTag>& Map, int32 Width, int32 Height, const TArray<int32>& ValidLeafNodes)override;
private:
/** 泰森多边形区域数量参数 */
int32 VoronoiRegionCount;
/** 米切尔候选点数参数 */
int32 MitchellCandidateCount;
/** 米切尔最佳候选算法实例 */
UPROPERTY()
UMitchellBestCandidate* MitchellGenerator;
/** 泰森多边形算法实例 */
UPROPERTY()
UVoronoiDiagram* VoronoiGenerator;
/**
* @brief 使用泰森多边形算法生成地图
*
* 核心生成算法,结合米切尔最佳候选和泰森多边形技术。
*
* @param Map 输出的地图数组
* @param Width 地图宽度
* @param Height 地图高度
* @param ValidLeafNodes 有效的叶子节点列表
*/
void GenerateWithVoronoi(TArray<FGameplayTag>& Map, int32 Width, int32 Height,
const TArray<int32>& ValidLeafNodes) const;
};