Skip to content

Commit

Permalink
Hotfix: Biome temperature/moisture not working. Also exposed the prop…
Browse files Browse the repository at this point in the history
…erties on IslandMap better.
  • Loading branch information
Jay2645 committed Dec 29, 2018
1 parent 98d44d4 commit bcade49
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 53 deletions.
Binary file modified Content/BP_BigIslandGenerator.uasset
Binary file not shown.
Binary file modified Content/BP_IslandGenerator.uasset
Binary file not shown.
Binary file modified Content/BiomeTable.uasset
Binary file not shown.
8 changes: 4 additions & 4 deletions Source/PolygonalMapGenerator/Private/Biomes/IslandBiome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void UIslandBiome::AssignCoast_Implementation(TArray<bool>& r_coast, UTriangleDu
}
}

void UIslandBiome::AssignTemperature_Implementation(TArray<int32>& r_temperature, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<float>& r_elevation, const TArray<int32>& r_moisture, float NorthernTemperature, float SouthernTemperature) const
void UIslandBiome::AssignTemperature_Implementation(TArray<float>& r_temperature, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<float>& r_elevation, const TArray<float>& r_moisture, float NorthernTemperature, float SouthernTemperature) const
{
r_temperature.Empty(Mesh->NumRegions);
r_temperature.SetNumZeroed(Mesh->NumRegions);
Expand All @@ -51,7 +51,7 @@ void UIslandBiome::AssignTemperature_Implementation(TArray<int32>& r_temperature
}
}

void UIslandBiome::AssignBiome_Implementation(TArray<FBiomeData>& r_biome, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<bool>& r_coast, const TArray<int32>& r_temperature, const TArray<int32>& r_moisture) const
void UIslandBiome::AssignBiome_Implementation(TArray<FBiomeData>& r_biome, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<bool>& r_coast, const TArray<float>& r_temperature, const TArray<float>& r_moisture) const
{
r_biome.Empty(Mesh->NumRegions);
r_biome.SetNumZeroed(Mesh->NumRegions);
Expand All @@ -66,12 +66,12 @@ void UIslandBiome::assign_r_coast(TArray<bool>& r_coast, UTriangleDualMesh* Mesh
AssignCoast(r_coast, Mesh, r_ocean);
}

void UIslandBiome::assign_r_temperature(TArray<int32>& r_temperature, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<float>& r_elevation, const TArray<int32>& r_moisture, float NorthernTemperature, float SouthernTemperature) const
void UIslandBiome::assign_r_temperature(TArray<float>& r_temperature, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<float>& r_elevation, const TArray<float>& r_moisture, float NorthernTemperature, float SouthernTemperature) const
{
AssignTemperature(r_temperature, Mesh, r_ocean, r_water, r_elevation, r_moisture, NorthernTemperature, SouthernTemperature);
}

void UIslandBiome::assign_r_biome(TArray<FBiomeData>& r_biome, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<bool>& r_coast, const TArray<int32>& r_temperature, const TArray<int32>& r_moisture) const
void UIslandBiome::assign_r_biome(TArray<FBiomeData>& r_biome, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<bool>& r_coast, const TArray<float>& r_temperature, const TArray<float>& r_moisture) const
{
AssignBiome(r_biome, Mesh, r_ocean, r_water, r_coast, r_temperature, r_moisture);
}
202 changes: 201 additions & 1 deletion Source/PolygonalMapGenerator/Private/IslandMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,204 @@ void AIslandMap::GenerateIsland_Implementation()
void AIslandMap::OnIslandGenComplete_Implementation()
{
// Do nothing by default
}
}

TArray<bool>& AIslandMap::GetWaterRegions()
{
return r_water;
}

bool AIslandMap::IsPointWater(FPointIndex Region) const
{
if (r_water.IsValidIndex(Region))
{
return r_water[Region];
}
else
{
return false;
}
}

TArray<bool>& AIslandMap::GetOceanRegions()
{
return r_ocean;
}

bool AIslandMap::IsPointOcean(FPointIndex Region) const
{
if (r_ocean.IsValidIndex(Region))
{
return r_ocean[Region];
}
else
{
return false;
}
}

TArray<bool>& AIslandMap::GetCoastalRegions()
{
return r_coast;
}

bool AIslandMap::IsPointCoast(FPointIndex Region) const
{
if (r_coast.IsValidIndex(Region))
{
return r_coast[Region];
}
else
{
return false;
}
}

TArray<float>& AIslandMap::GetRegionElevations()
{
return r_elevation;
}

float AIslandMap::GetPointElevation(FPointIndex Region) const
{
if (r_elevation.IsValidIndex(Region))
{
return r_elevation[Region];
}
else
{
return -1.0f;
}
}

TArray<int32>& AIslandMap::GetRegionWaterDistance()
{
return r_waterdistance;
}

int32 AIslandMap::GetPointWaterDistance(FPointIndex Region) const
{
if (r_waterdistance.IsValidIndex(Region))
{
return r_waterdistance[Region];
}
else
{
return -1;
}
}

TArray<float>& AIslandMap::GetRegionMoisture()
{
return r_moisture;
}

float AIslandMap::GetPointMoisture(FPointIndex Region) const
{
if (r_moisture.IsValidIndex(Region))
{
return r_moisture[Region];
}
else
{
return -1.0f;
}
}

TArray<float>& AIslandMap::GetRegionTemperature()
{
return r_temperature;
}

float AIslandMap::GetPointTemperature(FPointIndex Region) const
{
if (r_temperature.IsValidIndex(Region))
{
return r_temperature[Region];
}
else
{
return -1.0f;
}
}

TArray<FBiomeData>& AIslandMap::GetRegionBiomes()
{
return r_biome;
}

FBiomeData AIslandMap::GetPointBiome(FPointIndex Region) const
{
if (r_biome.IsValidIndex(Region))
{
return r_biome[Region];
}
else
{
return FBiomeData();
}
}

TArray<int32>& AIslandMap::GetTriangleCoastDistances()
{
return t_coastdistance;
}

int32 AIslandMap::GetTriangleCoastDistance(FTriangleIndex Triangle) const
{
if (t_coastdistance.IsValidIndex(Triangle))
{
return t_coastdistance[Triangle];
}
else
{
return -1;
}
}

TArray<float>& AIslandMap::GetTriangleElevations()
{
return t_elevation;
}

float AIslandMap::GetTriangleElevation(FTriangleIndex Triangle) const
{
if (t_elevation.IsValidIndex(Triangle))
{
return t_elevation[Triangle];
}
else
{
return -1.0f;
}
}

TArray<FSideIndex>& AIslandMap::GetTriangleDownslopes()
{
return t_downslope_s;
}

TArray<int32>& AIslandMap::GetSideFlow()
{
return s_flow;
}

TArray<FTriangleIndex>& AIslandMap::GetSpringTriangles()
{
return spring_t;
}

bool AIslandMap::IsTriangleSpring(FTriangleIndex Triangle) const
{
return spring_t.Contains(Triangle);
}

TArray<FTriangleIndex>& AIslandMap::GetRiverTriangles()
{
return river_t;
}

bool AIslandMap::IsTriangleRiver(FTriangleIndex Triangle) const
{
return river_t.Contains(Triangle);
}
17 changes: 15 additions & 2 deletions Source/PolygonalMapGenerator/Private/IslandMapUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ FBiomeData UIslandMapUtils::GetBiome(const UDataTable* BiomeData, bool bIsOcean,
}
else if (possibleBiomes.Num() == 0)
{
UE_LOG(LogMapGen, Error, TEXT("Could not find any biomes with moisture %f!"), Moisture);
UE_LOG(LogMapGen, Error, TEXT("Could not find any biomes with moisture %f! Is ocean? %d Is coast? %d Is water? %d"), Moisture, (uint8)bIsOcean, (uint8)bIsCoast, (uint8)bIsWater);
return FBiomeData();
}
newPossibleBiomes.Empty();
Expand All @@ -244,7 +244,7 @@ FBiomeData UIslandMapUtils::GetBiome(const UDataTable* BiomeData, bool bIsOcean,
}
else if (possibleBiomes.Num() == 0)
{
UE_LOG(LogMapGen, Error, TEXT("Could not find any biomes with moisture %f!"), Moisture);
UE_LOG(LogMapGen, Error, TEXT("Could not find any biomes with temperature %f! Is ocean? %d; Is coast? %d; Is water? %d; Moisture: %f"), Temperature, (uint8)bIsOcean, (uint8)bIsCoast, (uint8)bIsWater, Moisture);
return FBiomeData();
}

Expand Down Expand Up @@ -344,8 +344,21 @@ void UIslandMapUtils::DrawVoronoiMesh(AActor* Context, const TArray<FIslandPolyg
}
}

void UIslandMapUtils::GenerateMesh(class AIslandMap* Map, UProceduralMeshComponent* MapMesh, float ZScale)
{
if (Map == NULL)
{
return;
}
GenerateMapMesh(Map->Mesh, MapMesh, ZScale, Map->r_elevation);
}

void UIslandMapUtils::GenerateMapMesh(UTriangleDualMesh* Mesh, UProceduralMeshComponent* MapMesh, float ZScale, const TArray<float>& RegionElevation)
{
if (Mesh == NULL || MapMesh == NULL)
{
return;
}
const TArray<FVector2D>& points = Mesh->GetPoints();
const FDualMesh& rawMesh = Mesh->GetRawMesh();
TArray<FVector> vertices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TSet<FPointIndex> UIslandMoisture::FindMoistureSeeds_Implementation(UTriangleDua
return seeds;
}

void UIslandMoisture::AssignRegionMoisture_Implementation(TArray<int32>& r_moisture, TArray<int32>& r_waterdistance, UTriangleDualMesh* Mesh, const TArray<bool>& r_water, const TSet<FPointIndex>& seed_r) const
void UIslandMoisture::AssignRegionMoisture_Implementation(TArray<float>& r_moisture, TArray<int32>& r_waterdistance, UTriangleDualMesh* Mesh, const TArray<bool>& r_water, const TSet<FPointIndex>& seed_r) const
{
r_moisture.Empty(Mesh->NumRegions);
r_moisture.SetNumZeroed(Mesh->NumRegions);
Expand Down Expand Up @@ -102,7 +102,7 @@ void UIslandMoisture::AssignRegionMoisture_Implementation(TArray<int32>& r_moist
}
}

void UIslandMoisture::RedistributeRegionMoisture_Implementation(TArray<int32>& r_moisture, UTriangleDualMesh* Mesh, const TArray<bool>& r_water, float MinMoisture, float MaxMoisture) const
void UIslandMoisture::RedistributeRegionMoisture_Implementation(TArray<float>& r_moisture, UTriangleDualMesh* Mesh, const TArray<bool>& r_water, float MinMoisture, float MaxMoisture) const
{
TArray<FPointIndex> land_r;
for (FPointIndex r = 0; r < Mesh->NumSolidRegions; r++)
Expand All @@ -129,12 +129,12 @@ void UIslandMoisture::RedistributeRegionMoisture_Implementation(TArray<int32>& r
}
}

void UIslandMoisture::assign_r_moisture(TArray<int32>& r_moisture, TArray<int32>& r_waterdistance, UTriangleDualMesh* Mesh, const TArray<bool>& r_water, const TSet<FPointIndex>& r_moisture_seeds) const
void UIslandMoisture::assign_r_moisture(TArray<float>& r_moisture, TArray<int32>& r_waterdistance, UTriangleDualMesh* Mesh, const TArray<bool>& r_water, const TSet<FPointIndex>& r_moisture_seeds) const
{
AssignRegionMoisture(r_moisture, r_waterdistance, Mesh, r_water, r_moisture_seeds);
}

void UIslandMoisture::redistribute_r_moisture(TArray<int32>& r_moisture, UTriangleDualMesh* Mesh, const TArray<bool>& r_water, float MinMoisture, float MaxMoisture) const
void UIslandMoisture::redistribute_r_moisture(TArray<float>& r_moisture, UTriangleDualMesh* Mesh, const TArray<bool>& r_water, float MinMoisture, float MaxMoisture) const
{
RedistributeRegionMoisture(r_moisture, Mesh, r_water, MinMoisture, MaxMoisture);
}
Expand Down
12 changes: 6 additions & 6 deletions Source/PolygonalMapGenerator/Public/Biomes/IslandBiome.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ class POLYGONALMAPGENERATOR_API UIslandBiome : public UDataAsset

protected:
virtual void AssignCoast_Implementation(TArray<bool>& r_coast, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean) const;
virtual void AssignTemperature_Implementation(TArray<int32>& r_temperature, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<float>& r_elevation, const TArray<int32>& r_moisture, float NorthernTemperature, float SouthernTemperature) const;
virtual void AssignBiome_Implementation(TArray<FBiomeData>& r_biome, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<bool>& r_coast, const TArray<int32>& r_temperature, const TArray<int32>& r_moisture) const;
virtual void AssignTemperature_Implementation(TArray<float>& r_temperature, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<float>& r_elevation, const TArray<float>& r_moisture, float NorthernTemperature, float SouthernTemperature) const;
virtual void AssignBiome_Implementation(TArray<FBiomeData>& r_biome, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<bool>& r_coast, const TArray<float>& r_temperature, const TArray<float>& r_moisture) const;

public:
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Procedural Generation|Island Generation|Biome")
void AssignCoast(UPARAM(ref) TArray<bool>& CoastalRegions, UTriangleDualMesh* Mesh, const TArray<bool>& OceanRegions) const;
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Procedural Generation|Island Generation|Biome")
void AssignTemperature(UPARAM(ref) TArray<int32>& RegionTemperatures, UTriangleDualMesh* Mesh, const TArray<bool>& OceanRegions, const TArray<bool>& WaterRegions, const TArray<float>& RegionElevations, const TArray<int32>& RegionMoisture, float NorthernTemperature, float SouthernTemperature) const;
void AssignTemperature(UPARAM(ref) TArray<float>& RegionTemperatures, UTriangleDualMesh* Mesh, const TArray<bool>& OceanRegions, const TArray<bool>& WaterRegions, const TArray<float>& RegionElevations, const TArray<float>& RegionMoisture, float NorthernTemperature, float SouthernTemperature) const;
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Procedural Generation|Island Generation|Biome")
void AssignBiome(UPARAM(ref) TArray<FBiomeData>& RegionBiomes, UTriangleDualMesh* Mesh, const TArray<bool>& OceanRegions, const TArray<bool>& WaterRegions, const TArray<bool>& CoastalRegions, const TArray<int32>& RegionTemperature, const TArray<int32>& RegionMoisture) const;
void AssignBiome(UPARAM(ref) TArray<FBiomeData>& RegionBiomes, UTriangleDualMesh* Mesh, const TArray<bool>& OceanRegions, const TArray<bool>& WaterRegions, const TArray<bool>& CoastalRegions, const TArray<float>& RegionTemperature, const TArray<float>& RegionMoisture) const;

void assign_r_coast(TArray<bool>& r_coast, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean) const;
void assign_r_temperature(TArray<int32>& r_temperature, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<float>& r_elevation, const TArray<int32>& r_moisture, float NorthernTemperature, float SouthernTemperature) const;
void assign_r_biome(TArray<FBiomeData>& r_biome, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<bool>& r_coast, const TArray<int32>& r_temperature, const TArray<int32>& r_moisture) const;
void assign_r_temperature(TArray<float>& r_temperature, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<float>& r_elevation, const TArray<float>& r_moisture, float NorthernTemperature, float SouthernTemperature) const;
void assign_r_biome(TArray<FBiomeData>& r_biome, UTriangleDualMesh* Mesh, const TArray<bool>& r_ocean, const TArray<bool>& r_water, const TArray<bool>& r_coast, const TArray<float>& r_temperature, const TArray<float>& r_moisture) const;
};
Loading

0 comments on commit bcade49

Please sign in to comment.