Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Salvage Fix #86

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions Content.Server/Parallax/BiomeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private void LoadChunks(
var startNodeY = rand.Next(lower, upper + 1);
var startNode = new Vector2i(startNodeX, startNodeY);
frontier.Clear();
frontier.Add(startNode + chunk);
frontier.Add(startNode);

while (groupCount > 0 && frontier.Count > 0)
{
Expand All @@ -434,39 +434,40 @@ private void LoadChunks(
continue;

var neighbor = new Vector2i(x + node.X, y + node.Y);
var chunkOffset = neighbor - chunk;

// Check if it's inbounds.
if (chunkOffset.X < lower ||
chunkOffset.Y < lower ||
chunkOffset.X > upper ||
chunkOffset.Y > upper)
if (neighbor.X < lower ||
neighbor.Y < lower ||
neighbor.X > upper ||
neighbor.Y > upper)
{
continue;
}

if (!spawnSet.Add(neighbor))
continue;

frontier.Add(neighbor);
}
}

var actualNode = node + chunk;

if (!spawnSet.Add(actualNode))
continue;

// Check if it's a valid spawn, if so then use it.
var enumerator = grid.GetAnchoredEntitiesEnumerator(node);
var enumerator = grid.GetAnchoredEntitiesEnumerator(actualNode);

if (enumerator.MoveNext(out _))
continue;

// Check if mask matches.
TryGetEntity(node, component.Layers, noiseCopy, grid, out var proto);
TryGetEntity(actualNode, component.Layers, noiseCopy, grid, out var proto);

if (proto != layerProto.EntityMask)
{
continue;
}

var chunkOrigin = SharedMapSystem.GetChunkIndices(node, ChunkSize) * ChunkSize;
var chunkOrigin = SharedMapSystem.GetChunkIndices(actualNode, ChunkSize) * ChunkSize;

if (!pending.TryGetValue(chunkOrigin, out var pendingMarkers))
{
Expand All @@ -481,7 +482,7 @@ private void LoadChunks(
}

// Log.Info($"Added node at {actualNode} for chunk {chunkOrigin}");
layerMarkers.Add(node);
layerMarkers.Add(actualNode);
groupCount--;
}
}
Expand Down
27 changes: 0 additions & 27 deletions Content.Shared/Parallax/Biomes/Layers/BiomeMetaLayer.cs

This file was deleted.

44 changes: 0 additions & 44 deletions Content.Shared/Parallax/Biomes/SharedBiomeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,6 @@ public bool TryGetBiomeTile(Vector2i indices, List<IBiomeLayer> layers, FastNois
{
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;

Expand Down Expand Up @@ -204,8 +187,6 @@ protected bool TryGetEntity(Vector2i indices, List<IBiomeLayer> layers, FastNois
if (!worldLayer.AllowedTiles.Contains(tileId))
continue;

break;
case BiomeMetaLayer:
break;
default:
continue;
Expand All @@ -217,16 +198,7 @@ protected bool TryGetEntity(Vector2i indices, List<IBiomeLayer> layers, FastNois
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;
}

Expand Down Expand Up @@ -276,8 +248,6 @@ public bool TryGetDecals(Vector2i indices, List<IBiomeLayer> layers, FastNoiseLi
if (!worldLayer.AllowedTiles.Contains(tileId))
continue;

break;
case BiomeMetaLayer:
break;
default:
continue;
Expand All @@ -286,20 +256,6 @@ public bool TryGetDecals(Vector2i indices, List<IBiomeLayer> layers, FastNoiseLi
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)
{
Expand Down
37 changes: 0 additions & 37 deletions Resources/Prototypes/Procedural/biome_templates.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
# 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
# TODO: Water in desert
- type: biomeTemplate
Expand Down
Loading