mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 17:47:24 +02:00
* Move MapManager queries to SharedMapSystem Moves all variants of FindGridsIntersecting/TryFindGridAt to SharedMapSystem Hollows out the MapManager methods and converts them into relays to SharedMapSystem * Move CreateGrid to SharedMapSystem Moves the functionality for CreateGrid and its variants to SharedMapSystem Hollows out the MapManager methods and converts them into relays for the SharedMapSystem methods Obsoletes them too Also moves over the GetAllMapGrids and GetAllGrids methods * Move RaiseOnTileChanged to SharedMapSystem Also moves the SuppressOnTileChanged flag member to SharedMapSystem Hollows out and obsoletes the MapManager versions * Move default value constants to SharedMapSystem * Converts map pausing events into LocalizedEntityCommands * Move MapManager related delegates/structs to SharedMapSystem Moves the GridCreationOptions struct to the same namespace as SharedMapSystem and converts it into a record struct Move the GridCallback delegates to the same namespace as SharedMapSystem * Move CullDeletionHistory to SharedMapSystem Well, that was less painful than I thought it would be * Actually obsolete the NetworkedMapManager method * Rename file * Doc comments for new SharedMapSystem methods * Doc comment * Doc comments * Fix access * Purge all references to IMapManagerInternal * Cull easy IMapManager references * The rest * Purge IMapManager * Private internal FindGridsIntersecting method * please die * 41 * notes --------- Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
118 lines
4.0 KiB
C#
118 lines
4.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Enums;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Physics.Collision.Shapes;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Client.GameObjects
|
|
{
|
|
public sealed partial class GridChunkBoundsDebugSystem : EntitySystem
|
|
{
|
|
[Dependency] private IOverlayManager _overlayManager = default!;
|
|
[Dependency] private TransformSystem _transform = default!;
|
|
[Dependency] private SharedMapSystem _map = default!;
|
|
|
|
private GridChunkBoundsOverlay? _overlay;
|
|
|
|
public bool Enabled
|
|
{
|
|
get => _enabled;
|
|
set
|
|
{
|
|
if (_enabled == value) return;
|
|
|
|
_enabled = value;
|
|
|
|
if (_enabled)
|
|
{
|
|
DebugTools.Assert(_overlay == null);
|
|
_overlay = new GridChunkBoundsOverlay(
|
|
EntityManager,
|
|
_transform,
|
|
_map);
|
|
|
|
_overlayManager.AddOverlay(_overlay);
|
|
}
|
|
else
|
|
{
|
|
_overlayManager.RemoveOverlay(_overlay!);
|
|
_overlay = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _enabled;
|
|
}
|
|
|
|
internal sealed class GridChunkBoundsOverlay : Overlay
|
|
{
|
|
private readonly IEntityManager _entityManager;
|
|
private readonly SharedTransformSystem _transformSystem;
|
|
private readonly SharedMapSystem _mapSystem;
|
|
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
|
|
|
private List<Entity<MapGridComponent>> _grids = new();
|
|
|
|
public GridChunkBoundsOverlay(IEntityManager entManager, SharedTransformSystem transformSystem, SharedMapSystem mapSystem)
|
|
{
|
|
_entityManager = entManager;
|
|
_transformSystem = transformSystem;
|
|
_mapSystem = mapSystem;
|
|
}
|
|
|
|
protected internal override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
var currentMap = args.MapId;
|
|
var viewport = args.WorldBounds;
|
|
var worldHandle = args.WorldHandle;
|
|
|
|
var fixturesQuery = _entityManager.GetEntityQuery<FixturesComponent>();
|
|
_grids.Clear();
|
|
_mapSystem.FindGridsIntersecting(currentMap, viewport, ref _grids);
|
|
foreach (var grid in _grids)
|
|
{
|
|
var worldMatrix = _transformSystem.GetWorldMatrix(grid);
|
|
worldHandle.SetTransform(worldMatrix);
|
|
var transform = new Transform(Vector2.Zero, Angle.Zero);
|
|
var fixtures = fixturesQuery.Comp(grid.Owner);
|
|
|
|
var chunkEnumerator = _mapSystem.GetMapChunks(grid.Owner, grid.Comp, viewport);
|
|
|
|
while (chunkEnumerator.MoveNext(out var chunk))
|
|
{
|
|
foreach (var id in chunk.Fixtures)
|
|
{
|
|
var fixture = fixtures.Fixtures[id];
|
|
var poly = (PolygonShape) fixture.Shape;
|
|
|
|
var verts = new Vector2[poly.VertexCount];
|
|
|
|
for (var i = 0; i < poly.VertexCount; i++)
|
|
{
|
|
verts[i] = Transform.Mul(transform, poly.Vertices[i]);
|
|
}
|
|
|
|
worldHandle.DrawPrimitives(DrawPrimitiveTopology.TriangleFan, verts, Color.Green.WithAlpha(0.2f));
|
|
|
|
for (var i = 0; i < fixture.Shape.ChildCount; i++)
|
|
{
|
|
var aabb = fixture.Shape.ComputeAABB(transform, i);
|
|
|
|
args.WorldHandle.DrawRect(aabb, Color.Red.WithAlpha(0.5f), false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
worldHandle.SetTransform(Matrix3x2.Identity);
|
|
}
|
|
}
|
|
}
|