From e6d639b21b0e67fa1dd6f992278c8b0f04e9debd Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Wed, 12 Jul 2023 14:26:19 +1000 Subject: [PATCH] Fix biome recursion (#17982) --- Content.Server/Parallax/BiomeSystem.cs | 27 +++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Content.Server/Parallax/BiomeSystem.cs b/Content.Server/Parallax/BiomeSystem.cs index 9d38df8d5c..d54293f568 100644 --- a/Content.Server/Parallax/BiomeSystem.cs +++ b/Content.Server/Parallax/BiomeSystem.cs @@ -417,7 +417,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem var startNodeY = rand.Next(lower, upper + 1); var startNode = new Vector2i(startNodeX, startNodeY); frontier.Clear(); - frontier.Add(startNode); + frontier.Add(startNode + chunk); while (groupCount > 0 && frontier.Count > 0) { @@ -434,40 +434,39 @@ public sealed partial class BiomeSystem : SharedBiomeSystem continue; var neighbor = new Vector2i(x + node.X, y + node.Y); + var chunkOffset = neighbor - chunk; // Check if it's inbounds. - if (neighbor.X < lower || - neighbor.Y < lower || - neighbor.X > upper || - neighbor.Y > upper) + if (chunkOffset.X < lower || + chunkOffset.Y < lower || + chunkOffset.X > upper || + chunkOffset.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(actualNode); + var enumerator = grid.GetAnchoredEntitiesEnumerator(node); if (enumerator.MoveNext(out _)) continue; // Check if mask matches. - TryGetEntity(actualNode, component.Layers, noiseCopy, grid, out var proto); + TryGetEntity(node, component.Layers, noiseCopy, grid, out var proto); if (proto != layerProto.EntityMask) { continue; } - var chunkOrigin = SharedMapSystem.GetChunkIndices(actualNode, ChunkSize) * ChunkSize; + var chunkOrigin = SharedMapSystem.GetChunkIndices(node, ChunkSize) * ChunkSize; if (!pending.TryGetValue(chunkOrigin, out var pendingMarkers)) { @@ -482,7 +481,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem } // Log.Info($"Added node at {actualNode} for chunk {chunkOrigin}"); - layerMarkers.Add(actualNode); + layerMarkers.Add(node); groupCount--; } }