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];
|
||||
|
||||
// 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)
|
||||
continue;
|
||||
|
||||
@@ -184,6 +201,8 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
if (!worldLayer.AllowedTiles.Contains(tileId))
|
||||
continue;
|
||||
|
||||
break;
|
||||
case BiomeMetaLayer:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
@@ -195,7 +214,16 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
value = invert ? value * -1 : value;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -244,6 +272,8 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
if (!worldLayer.AllowedTiles.Contains(tileId))
|
||||
continue;
|
||||
|
||||
break;
|
||||
case BiomeMetaLayer:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
@@ -252,6 +282,20 @@ public abstract class SharedBiomeSystem : EntitySystem
|
||||
SetNoise(noise, oldSeed, layer.Noise);
|
||||
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.
|
||||
if (layer is not BiomeDecalLayer decalLayer)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user