Worldgen spring cleaning (#36199)
* Worldgen warnings cleanup * DebrisFeaturePlacerSystem general cleanup
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using Content.Server.Worldgen.Components.Carvers;
|
using Content.Server.Worldgen.Components.Carvers;
|
||||||
using Content.Server.Worldgen.Systems.Debris;
|
using Content.Server.Worldgen.Systems.Debris;
|
||||||
|
|
||||||
namespace Content.Server.Worldgen.Systems.Carvers;
|
namespace Content.Server.Worldgen.Systems.Carvers;
|
||||||
@@ -20,7 +20,7 @@ public sealed class NoiseRangeCarverSystem : EntitySystem
|
|||||||
private void OnPrePlaceDebris(EntityUid uid, NoiseRangeCarverComponent component,
|
private void OnPrePlaceDebris(EntityUid uid, NoiseRangeCarverComponent component,
|
||||||
ref PrePlaceDebrisFeatureEvent args)
|
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);
|
var val = _index.Evaluate(uid, component.NoiseChannel, coords);
|
||||||
|
|
||||||
foreach (var (low, high) in component.Ranges)
|
foreach (var (low, high) in component.Ranges)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Content.Server.Worldgen.Components;
|
using Content.Server.Worldgen.Components;
|
||||||
using Content.Server.Worldgen.Components.Debris;
|
using Content.Server.Worldgen.Components.Debris;
|
||||||
@@ -26,6 +26,8 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
|
|||||||
|
|
||||||
private ISawmill _sawmill = default!;
|
private ISawmill _sawmill = default!;
|
||||||
|
|
||||||
|
private List<Entity<MapGridComponent>> _mapGrids = new();
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -139,7 +141,14 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
|
|||||||
|
|
||||||
component.DoSpawns = false; // Don't repeat yourself if this crashes.
|
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 densityChannel = component.DensityNoiseChannel;
|
||||||
var density = _noiseIndex.Evaluate(uid, densityChannel, chunk.Coordinates + new Vector2(0.5f, 0.5f));
|
var density = _noiseIndex.Evaluate(uid, densityChannel, chunk.Coordinates + new Vector2(0.5f, 0.5f));
|
||||||
if (density == 0)
|
if (density == 0)
|
||||||
@@ -157,7 +166,9 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
|
|||||||
.ToList();
|
.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 safetyBounds = Box2.UnitCentered.Enlarged(component.SafetyZoneRadius);
|
||||||
var failures = 0; // Avoid severe log spam.
|
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))
|
if (pointDensity == 0 && component.DensityClip || _random.Prob(component.RandomCancellationChance))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var coords = new EntityCoordinates(chunk.Map, point);
|
if (HasCollisions(mapId, safetyBounds.Translated(point)))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (_mapManager
|
var coords = new EntityCoordinates(chunkMap, point);
|
||||||
.FindGridsIntersecting(Comp<MapComponent>(chunk.Map).MapId, safetyBounds.Translated(point)).Any())
|
|
||||||
continue; // Oops, gonna collide.
|
|
||||||
|
|
||||||
var preEv = new PrePlaceDebrisFeatureEvent(coords, args.Chunk);
|
var preEv = new PrePlaceDebrisFeatureEvent(coords, args.Chunk);
|
||||||
RaiseLocalEvent(uid, ref preEv);
|
RaiseLocalEvent(uid, ref preEv);
|
||||||
@@ -216,6 +226,19 @@ public sealed class DebrisFeaturePlacerSystem : BaseWorldSystem
|
|||||||
_sawmill.Error($"Failed to place {failures} debris at chunk {args.Chunk}");
|
_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>
|
/// <summary>
|
||||||
/// Generates the points to put into a chunk using a poisson disk sampler.
|
/// Generates the points to put into a chunk using a poisson disk sampler.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Content.Server.Worldgen.Components.Debris;
|
using Content.Server.Worldgen.Components.Debris;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
namespace Content.Server.Worldgen.Systems.Debris;
|
namespace Content.Server.Worldgen.Systems.Debris;
|
||||||
@@ -28,7 +29,7 @@ public sealed class NoiseDrivenDebrisSelectorSystem : BaseWorldSystem
|
|||||||
private void OnSelectDebrisKind(EntityUid uid, NoiseDrivenDebrisSelectorComponent component,
|
private void OnSelectDebrisKind(EntityUid uid, NoiseDrivenDebrisSelectorComponent component,
|
||||||
ref TryGetPlaceableDebrisFeatureEvent args)
|
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);
|
var prob = _index.Evaluate(uid, component.NoiseChannel, coords);
|
||||||
|
|
||||||
if (prob is < 0 or > 1)
|
if (prob is < 0 or > 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user