Dynamic space world generation and debris. (#15120)
* World generation (squash) * Test fixes. * command * o * Access cleanup. * Documentation touchups. * Use a prototype serializer for BiomeSelectionComponent * Struct enumerator in SimpleFloorPlanPopulatorSystem * Safety margins around PoissonDiskSampler, cookie acquisition methodologies * Struct enumerating PoissonDiskSampler; internal side * Struct enumerating PoissonDiskSampler: Finish it * Update WorldgenConfigSystem.cs awa --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com> Co-authored-by: 20kdc <asdd2808@gmail.com>
This commit is contained in:
59
Content.Server/Worldgen/Systems/LocalityLoaderSystem.cs
Normal file
59
Content.Server/Worldgen/Systems/LocalityLoaderSystem.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Content.Server.Worldgen.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.Worldgen.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// This handles loading in objects based on distance from player, using some metadata on chunks.
|
||||
/// </summary>
|
||||
public sealed class LocalityLoaderSystem : BaseWorldSystem
|
||||
{
|
||||
[Dependency] private readonly TransformSystem _xformSys = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var e = EntityQueryEnumerator<LocalityLoaderComponent, TransformComponent>();
|
||||
var loadedQuery = GetEntityQuery<LoadedChunkComponent>();
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var controllerQuery = GetEntityQuery<WorldControllerComponent>();
|
||||
|
||||
while (e.MoveNext(out var uid, out var loadable, out var xform))
|
||||
{
|
||||
if (!controllerQuery.TryGetComponent(xform.MapUid, out var controller))
|
||||
return;
|
||||
|
||||
var coords = GetChunkCoords(uid, xform);
|
||||
var done = false;
|
||||
for (var i = -1; i < 2 && !done; i++)
|
||||
{
|
||||
for (var j = -1; j < 2 && !done; j++)
|
||||
{
|
||||
var chunk = GetOrCreateChunk(coords + (i, j), xform.MapUid!.Value, controller);
|
||||
if (!loadedQuery.TryGetComponent(chunk, out var loaded) || loaded.Loaders is null)
|
||||
continue;
|
||||
|
||||
foreach (var loader in loaded.Loaders)
|
||||
{
|
||||
if (!xformQuery.TryGetComponent(loader, out var loaderXform))
|
||||
continue;
|
||||
|
||||
if ((_xformSys.GetWorldPosition(loaderXform) - _xformSys.GetWorldPosition(xform)).Length > loadable.LoadingDistance)
|
||||
continue;
|
||||
|
||||
RaiseLocalEvent(uid, new LocalStructureLoadedEvent());
|
||||
RemCompDeferred<LocalityLoaderComponent>(uid);
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A directed fired on a loadable entity when a local loader enters it's vicinity.
|
||||
/// </summary>
|
||||
public record struct LocalStructureLoadedEvent;
|
||||
|
||||
Reference in New Issue
Block a user