mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Fix grid fixture warnings (#4180)
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Robust.Client.Physics
|
||||
{
|
||||
[Dependency] private readonly IOverlayManager _overlay = default!;
|
||||
[Dependency] private readonly IMapManager _map = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
public bool EnableDebug
|
||||
{
|
||||
@@ -27,7 +28,7 @@ namespace Robust.Client.Physics
|
||||
|
||||
if (_enableDebug)
|
||||
{
|
||||
var overlay = new GridSplitNodeOverlay(EntityManager, _map, this);
|
||||
var overlay = new GridSplitNodeOverlay(_map, this, _transform);
|
||||
_overlay.AddOverlay(overlay);
|
||||
RaiseNetworkEvent(new RequestGridNodesMessage());
|
||||
}
|
||||
@@ -39,7 +40,7 @@ namespace Robust.Client.Physics
|
||||
}
|
||||
}
|
||||
|
||||
private bool _enableDebug = false;
|
||||
private bool _enableDebug;
|
||||
private readonly Dictionary<EntityUid, Dictionary<Vector2i, List<List<Vector2i>>>> _nodes = new();
|
||||
private readonly Dictionary<EntityUid, List<(Vector2, Vector2)>> _connections = new();
|
||||
|
||||
@@ -69,71 +70,76 @@ namespace Robust.Client.Physics
|
||||
{
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
|
||||
private IEntityManager _entManager;
|
||||
private IMapManager _mapManager;
|
||||
private GridFixtureSystem _system;
|
||||
private readonly IMapManager _mapManager;
|
||||
private readonly GridFixtureSystem _system;
|
||||
private readonly SharedTransformSystem _transform;
|
||||
|
||||
public GridSplitNodeOverlay(IEntityManager entManager, IMapManager mapManager, GridFixtureSystem system)
|
||||
public GridSplitNodeOverlay(IMapManager mapManager, GridFixtureSystem system, SharedTransformSystem transform)
|
||||
{
|
||||
_entManager = entManager;
|
||||
_mapManager = mapManager;
|
||||
_system = system;
|
||||
_transform = transform;
|
||||
}
|
||||
|
||||
protected internal override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
var worldHandle = args.WorldHandle;
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
foreach (var iGrid in _mapManager.FindGridsIntersecting(args.MapId, args.WorldBounds))
|
||||
{
|
||||
// May not have received nodes yet.
|
||||
if (!_system._nodes.TryGetValue(iGrid.Owner, out var nodes)) continue;
|
||||
var state = (_system, _transform, args.WorldBounds, worldHandle);
|
||||
|
||||
var gridXform = xformQuery.GetComponent(iGrid.Owner);
|
||||
worldHandle.SetTransform(gridXform.WorldMatrix);
|
||||
var chunkEnumerator = iGrid.GetMapChunks(args.WorldBounds);
|
||||
|
||||
while (chunkEnumerator.MoveNext(out var chunk))
|
||||
_mapManager.FindGridsIntersecting(args.MapId, args.WorldBounds, ref state,
|
||||
static (EntityUid uid, MapGridComponent grid,
|
||||
ref (GridFixtureSystem system, SharedTransformSystem transform, Box2Rotated worldBounds, DrawingHandleWorld worldHandle) tuple) =>
|
||||
{
|
||||
if (!nodes.TryGetValue(chunk.Indices, out var chunkNodes)) continue;
|
||||
// May not have received nodes yet.
|
||||
if (!tuple.system._nodes.TryGetValue(uid, out var nodes))
|
||||
return true;
|
||||
|
||||
for (var i = 0; i < chunkNodes.Count; i++)
|
||||
tuple.worldHandle.SetTransform(tuple.transform.GetWorldMatrix(uid));
|
||||
var chunkEnumerator = grid.GetMapChunks(tuple.worldBounds);
|
||||
|
||||
while (chunkEnumerator.MoveNext(out var chunk))
|
||||
{
|
||||
var group = chunkNodes[i];
|
||||
var offset = chunk.Indices * chunk.ChunkSize;
|
||||
var color = GetColor(chunk, i);
|
||||
if (!nodes.TryGetValue(chunk.Indices, out var chunkNodes)) continue;
|
||||
|
||||
foreach (var index in group)
|
||||
for (var i = 0; i < chunkNodes.Count; i++)
|
||||
{
|
||||
worldHandle.DrawRect(new Box2(offset + index, offset + index + 1).Enlarged(-0.1f), color);
|
||||
var group = chunkNodes[i];
|
||||
var offset = chunk.Indices * chunk.ChunkSize;
|
||||
var color = GetColor(chunk, i);
|
||||
|
||||
foreach (var index in group)
|
||||
{
|
||||
tuple.worldHandle.DrawRect(new Box2(offset + index, offset + index + 1).Enlarged(-0.1f), color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var connections = _system._connections[iGrid.Owner];
|
||||
var connections = tuple.system._connections[uid];
|
||||
|
||||
foreach (var (start, end) in connections)
|
||||
{
|
||||
worldHandle.DrawLine(start, end, Color.Aquamarine);
|
||||
}
|
||||
}
|
||||
foreach (var (start, end) in connections)
|
||||
{
|
||||
tuple.worldHandle.DrawLine(start, end, Color.Aquamarine);
|
||||
}
|
||||
|
||||
static Color GetColor(MapChunk chunk, int index)
|
||||
{
|
||||
// Just want something that doesn't give similar indices at 0,0 but is also deterministic.
|
||||
// Add an offset to yIndex so we at least have some colour that isn't grey at 0,0
|
||||
var actualIndex = chunk.Indices.X * 20 + (chunk.Indices.Y + 20) * 35 + index * 50;
|
||||
|
||||
var red = (byte) (actualIndex % 255);
|
||||
var green = (byte) (actualIndex * 20 % 255);
|
||||
var blue = (byte) (actualIndex * 30 % 255);
|
||||
|
||||
return new Color(red, green, blue, 85);
|
||||
}
|
||||
|
||||
return true;
|
||||
}, true);
|
||||
|
||||
worldHandle.SetTransform(Matrix3.Identity);
|
||||
}
|
||||
|
||||
private Color GetColor(MapChunk chunk, int index)
|
||||
{
|
||||
// Just want something that doesn't give similar indices at 0,0 but is also deterministic.
|
||||
// Add an offset to yIndex so we at least have some colour that isn't grey at 0,0
|
||||
var actualIndex = chunk.Indices.X * 20 + (chunk.Indices.Y + 20) * 35 + index * 50;
|
||||
|
||||
var red = (byte) (actualIndex % 255);
|
||||
var green = (byte) (actualIndex * 20 % 255);
|
||||
var blue = (byte) (actualIndex * 30 % 255);
|
||||
|
||||
return new Color(red, green, blue, 85);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,11 @@ namespace Robust.Shared.Map
|
||||
|
||||
void FindGridsIntersecting<TState>(MapId mapId, Box2 worldAABB, ref TState state, GridCallback<TState> callback, bool approx = false, bool includeMap = true);
|
||||
|
||||
void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, GridCallback callback, bool approx = false, bool includeMap = true);
|
||||
|
||||
void FindGridsIntersecting<TState>(MapId mapId, Box2Rotated worldBounds, ref TState state, GridCallback<TState> callback, bool approx = false, bool includeMap = true);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the grids intersecting this AABB.
|
||||
/// </summary>
|
||||
|
||||
@@ -107,6 +107,18 @@ internal partial class MapManager
|
||||
state = state2.state;
|
||||
}
|
||||
|
||||
public void FindGridsIntersecting(MapId mapId, Box2Rotated worldBounds, GridCallback callback, bool approx = false,
|
||||
bool includeMap = true)
|
||||
{
|
||||
FindGridsIntersecting(mapId, worldBounds.CalcBoundingBox(), callback, approx, includeMap);
|
||||
}
|
||||
|
||||
public void FindGridsIntersecting<TState>(MapId mapId, Box2Rotated worldBounds, ref TState state, GridCallback<TState> callback,
|
||||
bool approx = false, bool includeMap = true)
|
||||
{
|
||||
FindGridsIntersecting(mapId, worldBounds.CalcBoundingBox(), ref state, callback, approx, includeMap);
|
||||
}
|
||||
|
||||
private static bool IsIntersecting(
|
||||
Box2 aabb,
|
||||
EntityUid gridUid,
|
||||
|
||||
@@ -3,6 +3,7 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user