Add sub-biomes (#17855)
This commit is contained in:
27
Content.Shared/Parallax/Biomes/Layers/BiomeMetaLayer.cs
Normal file
27
Content.Shared/Parallax/Biomes/Layers/BiomeMetaLayer.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using Robust.Shared.Noise;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||||
|
|
||||||
|
namespace Content.Shared.Parallax.Biomes.Layers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains more biome layers recursively via a biome template.
|
||||||
|
/// Can be used for sub-biomes.
|
||||||
|
/// </summary>
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class BiomeMetaLayer : IBiomeLayer
|
||||||
|
{
|
||||||
|
[DataField("noise")]
|
||||||
|
public FastNoiseLite Noise { get; } = new(0);
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
[DataField("threshold")]
|
||||||
|
public float Threshold { get; } = -1f;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
[DataField("invert")]
|
||||||
|
public bool Invert { get; }
|
||||||
|
|
||||||
|
[DataField("template", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<BiomeTemplatePrototype>))]
|
||||||
|
public string Template = string.Empty;
|
||||||
|
}
|
||||||
@@ -106,6 +106,23 @@ public abstract class SharedBiomeSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
var layer = layers[i];
|
var layer = layers[i];
|
||||||
|
|
||||||
|
// Check if the tile is from meta layer, otherwise fall back to default layers.
|
||||||
|
if (layer is BiomeMetaLayer meta)
|
||||||
|
{
|
||||||
|
SetNoise(noise, oldSeed, layer.Noise);
|
||||||
|
var found = noise.GetNoise(indices.X, indices.Y);
|
||||||
|
found *= layer.Invert ? -1 : 1;
|
||||||
|
|
||||||
|
if (found > layer.Threshold && TryGetBiomeTile(indices, ProtoManager.Index<BiomeTemplatePrototype>(meta.Template).Layers, noise,
|
||||||
|
grid, out tile))
|
||||||
|
{
|
||||||
|
noise.SetSeed(oldSeed);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (layer is not BiomeTileLayer tileLayer)
|
if (layer is not BiomeTileLayer tileLayer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -184,6 +201,8 @@ public abstract class SharedBiomeSystem : EntitySystem
|
|||||||
if (!worldLayer.AllowedTiles.Contains(tileId))
|
if (!worldLayer.AllowedTiles.Contains(tileId))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case BiomeMetaLayer:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
@@ -195,7 +214,16 @@ public abstract class SharedBiomeSystem : EntitySystem
|
|||||||
value = invert ? value * -1 : value;
|
value = invert ? value * -1 : value;
|
||||||
|
|
||||||
if (value < layer.Threshold)
|
if (value < layer.Threshold)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (layer is BiomeMetaLayer meta)
|
||||||
{
|
{
|
||||||
|
if (TryGetEntity(indices, ProtoManager.Index<BiomeTemplatePrototype>(meta.Template).Layers, noise, grid, out entity))
|
||||||
|
{
|
||||||
|
noise.SetSeed(oldSeed);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +272,8 @@ public abstract class SharedBiomeSystem : EntitySystem
|
|||||||
if (!worldLayer.AllowedTiles.Contains(tileId))
|
if (!worldLayer.AllowedTiles.Contains(tileId))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case BiomeMetaLayer:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
@@ -252,6 +282,20 @@ public abstract class SharedBiomeSystem : EntitySystem
|
|||||||
SetNoise(noise, oldSeed, layer.Noise);
|
SetNoise(noise, oldSeed, layer.Noise);
|
||||||
var invert = layer.Invert;
|
var invert = layer.Invert;
|
||||||
|
|
||||||
|
if (layer is BiomeMetaLayer meta)
|
||||||
|
{
|
||||||
|
var found = noise.GetNoise(indices.X, indices.Y);
|
||||||
|
found *= layer.Invert ? -1 : 1;
|
||||||
|
|
||||||
|
if (found > layer.Threshold && TryGetDecals(indices, ProtoManager.Index<BiomeTemplatePrototype>(meta.Template).Layers, noise, grid, out decals))
|
||||||
|
{
|
||||||
|
noise.SetSeed(oldSeed);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the other layer should even render, if not then keep going.
|
// Check if the other layer should even render, if not then keep going.
|
||||||
if (layer is not BiomeDecalLayer decalLayer)
|
if (layer is not BiomeDecalLayer decalLayer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,40 @@
|
|||||||
|
# Contains several biomes
|
||||||
|
- type: biomeTemplate
|
||||||
|
id: Continental
|
||||||
|
layers:
|
||||||
|
- !type:BiomeMetaLayer
|
||||||
|
template: Lava
|
||||||
|
- !type:BiomeMetaLayer
|
||||||
|
template: Caves
|
||||||
|
threshold: -0.5
|
||||||
|
noise:
|
||||||
|
frequency: 0.001
|
||||||
|
noiseType: OpenSimplex2
|
||||||
|
fractalType: FBm
|
||||||
|
octaves: 2
|
||||||
|
lacunarity: 2
|
||||||
|
gain: 0.5
|
||||||
|
- !type:BiomeMetaLayer
|
||||||
|
template: Grasslands
|
||||||
|
threshold: 0
|
||||||
|
noise:
|
||||||
|
frequency: 0.001
|
||||||
|
noiseType: OpenSimplex2
|
||||||
|
fractalType: FBm
|
||||||
|
octaves: 2
|
||||||
|
lacunarity: 2
|
||||||
|
gain: 0.5
|
||||||
|
- !type:BiomeMetaLayer
|
||||||
|
template: Snow
|
||||||
|
threshold: 0.5
|
||||||
|
noise:
|
||||||
|
frequency: 0.001
|
||||||
|
noiseType: OpenSimplex2
|
||||||
|
fractalType: FBm
|
||||||
|
octaves: 2
|
||||||
|
lacunarity: 2
|
||||||
|
gain: 0.5
|
||||||
|
|
||||||
# Desert
|
# Desert
|
||||||
# TODO: Water in desert
|
# TODO: Water in desert
|
||||||
- type: biomeTemplate
|
- type: biomeTemplate
|
||||||
|
|||||||
Reference in New Issue
Block a user