32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using Arch.Core;
|
|
using TheLivingWorld.Core.Ecs;
|
|
using TheLivingWorld.Core.Geo;
|
|
using TheLivingWorld.Core.Worlds;
|
|
|
|
namespace TheLivingWorld.Core.Systems;
|
|
|
|
/// <summary>Fills every feature's cached world-space extent from the geometry it points at.</summary>
|
|
public sealed class ComputeBoundsSystem : IWorldSystem
|
|
{
|
|
private static readonly QueryDescription AreaFeatures = new QueryDescription().WithAll<Outline, Bounds>();
|
|
private static readonly QueryDescription LineFeatures = new QueryDescription().WithAll<Polyline, Bounds>();
|
|
|
|
public string Name => nameof(ComputeBoundsSystem);
|
|
|
|
public void Execute(GameWorld world)
|
|
{
|
|
var shapes = world.Shapes;
|
|
|
|
// Holes are contained by their outline, so the outline alone determines the extent.
|
|
world.Ecs.Query(in AreaFeatures, (ref Outline outline, ref Bounds bounds) =>
|
|
{
|
|
bounds.Value = RectBounds.FromPoints(shapes.Get(outline.ShapeId));
|
|
});
|
|
|
|
world.Ecs.Query(in LineFeatures, (ref Polyline line, ref Bounds bounds) =>
|
|
{
|
|
bounds.Value = RectBounds.FromPoints(shapes.Get(line.ShapeId));
|
|
});
|
|
}
|
|
}
|