]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Worldgen spring cleaning (#36199)
authorJ <billsmith116@gmail.com>
Mon, 14 Apr 2025 03:36:54 +0000 (03:36 +0000)
committerGitHub <noreply@github.com>
Mon, 14 Apr 2025 03:36:54 +0000 (13:36 +1000)
* Worldgen warnings cleanup

* DebrisFeaturePlacerSystem general cleanup

Content.Server/Worldgen/Systems/Carvers/NoiseRangeCarverSystem.cs
Content.Server/Worldgen/Systems/Debris/DebrisFeaturePlacerSystem.cs
Content.Server/Worldgen/Systems/Debris/NoiseDrivenDebrisSelectorSystem.cs

index f2e051669a219d51ef2baca679f1e62095312dcf..1207d6f157e9a213c8de0c5fd5e1c5d9b897e8fd 100644 (file)
@@ -1,4 +1,4 @@
-using Content.Server.Worldgen.Components.Carvers;
+using Content.Server.Worldgen.Components.Carvers;
 using Content.Server.Worldgen.Systems.Debris;
 
 namespace Content.Server.Worldgen.Systems.Carvers;
@@ -20,7 +20,7 @@ public sealed class NoiseRangeCarverSystem : EntitySystem
     private void OnPrePlaceDebris(EntityUid uid, NoiseRangeCarverComponent component,
         ref PrePlaceDebrisFeatureEvent args)
     {
-        var coords = WorldGen.WorldToChunkCoords(args.Coords.ToMapPos(EntityManager, _transform));
+        var coords = WorldGen.WorldToChunkCoords(_transform.ToMapCoordinates(args.Coords).Position);
         var val = _index.Evaluate(uid, component.NoiseChannel, coords);
 
         foreach (var (low, high) in component.Ranges)
index 47ee6f62149adb92ea6abbf4225244a446f2d881..b609f7e1f7e619a2dd2422c3e333b6eab67920e2 100644 (file)
@@ -1,4 +1,4 @@
-using System.Linq;
+using System.Linq;
 using System.Numerics;
 using Content.Server.Worldgen.Components;
 using Content.Server.Worldgen.Components.Debris;
@@ -26,6 +26,8 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
 
     private ISawmill _sawmill = default!;
 
+    private List<Entity<MapGridComponent>> _mapGrids = new();
+
     /// <inheritdoc />
     public override void Initialize()
     {
@@ -139,7 +141,14 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
 
         component.DoSpawns = false; // Don't repeat yourself if this crashes.
 
-        var chunk = Comp<WorldChunkComponent>(args.Chunk);
+        if (!TryComp<WorldChunkComponent>(args.Chunk, out var chunk))
+            return;
+
+        var chunkMap = chunk.Map;
+
+        if (!TryComp<MapComponent>(chunkMap, out var map))
+            return;
+
         var densityChannel = component.DensityNoiseChannel;
         var density = _noiseIndex.Evaluate(uid, densityChannel, chunk.Coordinates + new Vector2(0.5f, 0.5f));
         if (density == 0)
@@ -157,7 +166,9 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
                 .ToList();
         }
 
-        points ??= GeneratePointsInChunk(args.Chunk, density, chunk.Coordinates, chunk.Map);
+        points ??= GeneratePointsInChunk(args.Chunk, density, chunk.Coordinates, chunkMap);
+
+        var mapId = map.MapId;
 
         var safetyBounds = Box2.UnitCentered.Enlarged(component.SafetyZoneRadius);
         var failures = 0; // Avoid severe log spam.
@@ -173,11 +184,10 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
             if (pointDensity == 0 && component.DensityClip || _random.Prob(component.RandomCancellationChance))
                 continue;
 
-            var coords = new EntityCoordinates(chunk.Map, point);
+            if (HasCollisions(mapId, safetyBounds.Translated(point)))
+                continue;
 
-            if (_mapManager
-                .FindGridsIntersecting(Comp<MapComponent>(chunk.Map).MapId, safetyBounds.Translated(point)).Any())
-                continue; // Oops, gonna collide.
+            var coords = new EntityCoordinates(chunkMap, point);
 
             var preEv = new PrePlaceDebrisFeatureEvent(coords, args.Chunk);
             RaiseLocalEvent(uid, ref preEv);
@@ -216,6 +226,19 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
             _sawmill.Error($"Failed to place {failures} debris at chunk {args.Chunk}");
     }
 
+    /// <summary>
+    /// Checks to see if the potential spawn point is clear
+    /// </summary>
+    /// <param name="mapId"></param>
+    /// <param name="point"></param>
+    /// <returns></returns>
+    private bool HasCollisions(MapId mapId, Box2 point)
+    {
+        _mapGrids.Clear();
+        _mapManager.FindGridsIntersecting(mapId, point, ref _mapGrids);
+        return _mapGrids.Count > 0;
+    }
+
     /// <summary>
     ///     Generates the points to put into a chunk using a poisson disk sampler.
     /// </summary>
index 8d8ca1b6c7c817ad5063702ca7011354d17e505a..a02ff81362c296d218509d49de99e2817cedaf96 100644 (file)
@@ -1,5 +1,6 @@
-using Content.Server.Worldgen.Components.Debris;
+using Content.Server.Worldgen.Components.Debris;
 using Robust.Server.GameObjects;
+using Robust.Shared.Physics;
 using Robust.Shared.Random;
 
 namespace Content.Server.Worldgen.Systems.Debris;
@@ -28,7 +29,7 @@ public sealed class NoiseDrivenDebrisSelectorSystem : BaseWorldSystem
     private void OnSelectDebrisKind(EntityUid uid, NoiseDrivenDebrisSelectorComponent component,
         ref TryGetPlaceableDebrisFeatureEvent args)
     {
-        var coords = WorldGen.WorldToChunkCoords(args.Coords.ToMapPos(EntityManager, _xformSys));
+        var coords = WorldGen.WorldToChunkCoords(_xformSys.ToMapCoordinates(args.Coords).Position);
         var prob = _index.Evaluate(uid, component.NoiseChannel, coords);
 
         if (prob is < 0 or > 1)