Remove transform methods from mapgrid (#12233)
This commit is contained in:
@@ -43,7 +43,7 @@ namespace Content.Client.Atmos.EntitySystems
|
||||
|
||||
var overlayManager = IoCManager.Resolve<IOverlayManager>();
|
||||
if(!overlayManager.HasOverlay<AtmosDebugOverlay>())
|
||||
overlayManager.AddOverlay(new AtmosDebugOverlay());
|
||||
overlayManager.AddOverlay(new AtmosDebugOverlay(this));
|
||||
}
|
||||
|
||||
private void OnGridRemoved(GridRemovalEvent ev)
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Content.Client.Atmos.EntitySystems
|
||||
SubscribeNetworkEvent<GasOverlayUpdateEvent>(HandleGasOverlayUpdate);
|
||||
SubscribeLocalEvent<GridRemovalEvent>(OnGridRemoved);
|
||||
|
||||
_overlay = new GasTileOverlay(this, _resourceCache, ProtoMan, _spriteSys);
|
||||
_overlay = new GasTileOverlay(this, EntityManager, _resourceCache, ProtoMan, _spriteSys);
|
||||
_overlayMan.AddOverlay(_overlay);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,15 +14,16 @@ namespace Content.Client.Atmos.Overlays
|
||||
{
|
||||
private readonly AtmosDebugOverlaySystem _atmosDebugOverlaySystem;
|
||||
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
|
||||
public AtmosDebugOverlay()
|
||||
internal AtmosDebugOverlay(AtmosDebugOverlaySystem system)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_atmosDebugOverlaySystem = EntitySystem.Get<AtmosDebugOverlaySystem>();
|
||||
_atmosDebugOverlaySystem = system;
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
@@ -41,10 +42,11 @@ namespace Content.Client.Atmos.Overlays
|
||||
|
||||
foreach (var mapGrid in _mapManager.FindGridsIntersecting(mapId, worldBounds))
|
||||
{
|
||||
if (!_atmosDebugOverlaySystem.HasData(mapGrid.GridEntityId))
|
||||
if (!_atmosDebugOverlaySystem.HasData(mapGrid.GridEntityId) ||
|
||||
!_entManager.TryGetComponent<TransformComponent>(mapGrid.GridEntityId, out var xform))
|
||||
continue;
|
||||
|
||||
drawHandle.SetTransform(mapGrid.WorldMatrix);
|
||||
drawHandle.SetTransform(xform.WorldMatrix);
|
||||
|
||||
for (var pass = 0; pass < 2; pass++)
|
||||
{
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace Content.Client.Atmos.Overlays
|
||||
{
|
||||
public sealed class GasTileOverlay : Overlay
|
||||
{
|
||||
private readonly GasTileOverlaySystem _system;
|
||||
private readonly IEntityManager _entManager;
|
||||
private readonly IMapManager _mapManager;
|
||||
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpaceEntities;
|
||||
private readonly ShaderInstance _shader;
|
||||
|
||||
@@ -43,14 +43,14 @@ namespace Content.Client.Atmos.Overlays
|
||||
|
||||
public const int GasOverlayZIndex = (int) Content.Shared.DrawDepth.DrawDepth.Effects; // Under ghosts, above mostly everything else
|
||||
|
||||
public GasTileOverlay(GasTileOverlaySystem system, IResourceCache resourceCache, IPrototypeManager protoMan, SpriteSystem spriteSys)
|
||||
public GasTileOverlay(GasTileOverlaySystem system, IEntityManager entManager, IResourceCache resourceCache, IPrototypeManager protoMan, SpriteSystem spriteSys)
|
||||
{
|
||||
_system = system;
|
||||
_entManager = entManager;
|
||||
_mapManager = IoCManager.Resolve<IMapManager>();
|
||||
_shader = protoMan.Index<ShaderPrototype>("unshaded").Instance();
|
||||
ZIndex = GasOverlayZIndex;
|
||||
|
||||
_gasCount = _system.VisibleGasId.Length;
|
||||
_gasCount = system.VisibleGasId.Length;
|
||||
_timer = new float[_gasCount];
|
||||
_frameDelays = new float[_gasCount][];
|
||||
_frameCounter = new int[_gasCount];
|
||||
@@ -58,7 +58,7 @@ namespace Content.Client.Atmos.Overlays
|
||||
|
||||
for (var i = 0; i < _gasCount; i++)
|
||||
{
|
||||
var gasPrototype = protoMan.Index<GasPrototype>(_system.VisibleGasId[i].ToString());
|
||||
var gasPrototype = protoMan.Index<GasPrototype>(system.VisibleGasId[i].ToString());
|
||||
|
||||
SpriteSpecifier overlay;
|
||||
|
||||
@@ -138,14 +138,17 @@ namespace Content.Client.Atmos.Overlays
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
var drawHandle = args.WorldHandle;
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
foreach (var mapGrid in _mapManager.FindGridsIntersecting(args.MapId, args.WorldBounds))
|
||||
{
|
||||
if (!TileData.TryGetValue(mapGrid.GridEntityId, out var gridData))
|
||||
if (!TileData.TryGetValue(mapGrid.GridEntityId, out var gridData) ||
|
||||
!xformQuery.TryGetComponent(mapGrid.GridEntityId, out var gridXform))
|
||||
continue;
|
||||
|
||||
drawHandle.SetTransform(mapGrid.WorldMatrix);
|
||||
var floatBounds = mapGrid.InvWorldMatrix.TransformBox(in args.WorldBounds).Enlarged(mapGrid.TileSize);
|
||||
var (_, _, worldMatrix, invMatrix) = gridXform.GetWorldPositionRotationMatrixWithInv();
|
||||
drawHandle.SetTransform(worldMatrix);
|
||||
var floatBounds = invMatrix.TransformBox(in args.WorldBounds).Enlarged(mapGrid.TileSize);
|
||||
var localBounds = new Box2i(
|
||||
(int) MathF.Floor(floatBounds.Left),
|
||||
(int) MathF.Floor(floatBounds.Bottom),
|
||||
@@ -166,7 +169,7 @@ namespace Content.Client.Atmos.Overlays
|
||||
if (gas.Value.Opacity == null)
|
||||
continue;
|
||||
|
||||
var tilePosition = chunk.Origin + (enumerator.X, enumerator.Y);
|
||||
var tilePosition = chunk.Origin + (enumerator.X, enumerator.Y);
|
||||
if (!localBounds.Contains(tilePosition))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -164,6 +164,7 @@ namespace Content.Client.NPC
|
||||
var mousePos = _inputManager.MouseScreenPosition;
|
||||
var mouseWorldPos = _eyeManager.ScreenToMap(mousePos);
|
||||
var aabb = new Box2(mouseWorldPos.Position - SharedPathfindingSystem.ChunkSize, mouseWorldPos.Position + SharedPathfindingSystem.ChunkSize);
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
if ((_system.Modes & PathfindingDebugMode.Crumb) != 0x0 &&
|
||||
mouseWorldPos.MapId == args.MapId)
|
||||
@@ -172,11 +173,11 @@ namespace Content.Client.NPC
|
||||
|
||||
foreach (var grid in _mapManager.FindGridsIntersecting(mouseWorldPos.MapId, aabb))
|
||||
{
|
||||
if (found || !_system.Breadcrumbs.TryGetValue(grid.GridEntityId, out var crumbs))
|
||||
if (found || !_system.Breadcrumbs.TryGetValue(grid.GridEntityId, out var crumbs) || !xformQuery.TryGetComponent(grid.GridEntityId, out var gridXform))
|
||||
continue;
|
||||
|
||||
var localAABB = grid.InvWorldMatrix.TransformBox(aabb.Enlarged(float.Epsilon - SharedPathfindingSystem.ChunkSize));
|
||||
var worldMatrix = grid.WorldMatrix;
|
||||
var (_, _, worldMatrix, invWorldMatrix) = gridXform.GetWorldPositionRotationMatrixWithInv();
|
||||
var localAABB = invWorldMatrix.TransformBox(aabb.Enlarged(float.Epsilon - SharedPathfindingSystem.ChunkSize));
|
||||
|
||||
foreach (var chunk in crumbs)
|
||||
{
|
||||
@@ -242,7 +243,7 @@ namespace Content.Client.NPC
|
||||
if ((_system.Modes & PathfindingDebugMode.Poly) != 0x0 &&
|
||||
mouseWorldPos.MapId == args.MapId)
|
||||
{
|
||||
if (!_mapManager.TryFindGridAt(mouseWorldPos, out var grid))
|
||||
if (!_mapManager.TryFindGridAt(mouseWorldPos, out var grid) || !xformQuery.TryGetComponent(grid.GridEntityId, out var gridXform))
|
||||
return;
|
||||
|
||||
var found = false;
|
||||
@@ -261,7 +262,7 @@ namespace Content.Client.NPC
|
||||
return;
|
||||
}
|
||||
|
||||
var invGridMatrix = grid.InvWorldMatrix;
|
||||
var invGridMatrix = gridXform.InvWorldMatrix;
|
||||
DebugPathPoly? nearest = null;
|
||||
var nearestDistance = float.MaxValue;
|
||||
|
||||
@@ -316,17 +317,20 @@ namespace Content.Client.NPC
|
||||
var mousePos = _inputManager.MouseScreenPosition;
|
||||
var mouseWorldPos = _eyeManager.ScreenToMap(mousePos);
|
||||
var aabb = new Box2(mouseWorldPos.Position - Vector2.One / 4f, mouseWorldPos.Position + Vector2.One / 4f);
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
if ((_system.Modes & PathfindingDebugMode.Breadcrumbs) != 0x0 &&
|
||||
mouseWorldPos.MapId == args.MapId)
|
||||
{
|
||||
foreach (var grid in _mapManager.FindGridsIntersecting(mouseWorldPos.MapId, aabb))
|
||||
{
|
||||
if (!_system.Breadcrumbs.TryGetValue(grid.GridEntityId, out var crumbs))
|
||||
if (!_system.Breadcrumbs.TryGetValue(grid.GridEntityId, out var crumbs) ||
|
||||
!xformQuery.TryGetComponent(grid.GridEntityId, out var gridXform))
|
||||
continue;
|
||||
|
||||
worldHandle.SetTransform(grid.WorldMatrix);
|
||||
var localAABB = grid.InvWorldMatrix.TransformBox(aabb);
|
||||
var (_, _, worldMatrix, invWorldMatrix) = gridXform.GetWorldPositionRotationMatrixWithInv();
|
||||
worldHandle.SetTransform(worldMatrix);
|
||||
var localAABB = invWorldMatrix.TransformBox(aabb);
|
||||
|
||||
foreach (var chunk in crumbs)
|
||||
{
|
||||
@@ -374,11 +378,13 @@ namespace Content.Client.NPC
|
||||
{
|
||||
foreach (var grid in _mapManager.FindGridsIntersecting(args.MapId, aabb))
|
||||
{
|
||||
if (!_system.Polys.TryGetValue(grid.GridEntityId, out var data))
|
||||
if (!_system.Polys.TryGetValue(grid.GridEntityId, out var data) ||
|
||||
!xformQuery.TryGetComponent(grid.GridEntityId, out var gridXform))
|
||||
continue;
|
||||
|
||||
worldHandle.SetTransform(grid.WorldMatrix);
|
||||
var localAABB = grid.InvWorldMatrix.TransformBox(aabb);
|
||||
var (_, _, worldMatrix, invWorldMatrix) = gridXform.GetWorldPositionRotationMatrixWithInv();
|
||||
worldHandle.SetTransform(worldMatrix);
|
||||
var localAABB = invWorldMatrix.TransformBox(aabb);
|
||||
|
||||
foreach (var chunk in data)
|
||||
{
|
||||
@@ -407,7 +413,7 @@ namespace Content.Client.NPC
|
||||
foreach (var grid in _mapManager.FindGridsIntersecting(args.MapId, aabb))
|
||||
{
|
||||
if (!_system.Polys.TryGetValue(grid.GridEntityId, out var data) ||
|
||||
!_entManager.TryGetComponent<TransformComponent>(grid.GridEntityId, out var gridXform))
|
||||
!xformQuery.TryGetComponent(grid.GridEntityId, out var gridXform))
|
||||
continue;
|
||||
|
||||
var (_, _, worldMatrix, invMatrix) = gridXform.GetWorldPositionRotationMatrixWithInv();
|
||||
@@ -460,11 +466,13 @@ namespace Content.Client.NPC
|
||||
{
|
||||
foreach (var grid in _mapManager.FindGridsIntersecting(args.MapId, args.WorldBounds))
|
||||
{
|
||||
if (!_system.Breadcrumbs.TryGetValue(grid.GridEntityId, out var crumbs))
|
||||
if (!_system.Breadcrumbs.TryGetValue(grid.GridEntityId, out var crumbs) ||
|
||||
!xformQuery.TryGetComponent(grid.GridEntityId, out var gridXform))
|
||||
continue;
|
||||
|
||||
worldHandle.SetTransform(grid.WorldMatrix);
|
||||
var localAABB = grid.InvWorldMatrix.TransformBox(args.WorldBounds);
|
||||
var (_, _, worldMatrix, invWorldMatrix) = gridXform.GetWorldPositionRotationMatrixWithInv();
|
||||
worldHandle.SetTransform(worldMatrix);
|
||||
var localAABB = invWorldMatrix.TransformBox(args.WorldBounds);
|
||||
|
||||
foreach (var chunk in crumbs)
|
||||
{
|
||||
|
||||
@@ -140,7 +140,9 @@ namespace Content.Client.NodeContainer
|
||||
foreach (var (gridId, gridDict) in _gridIndex)
|
||||
{
|
||||
var grid = _mapManager.GetGrid(gridId);
|
||||
var lCursorBox = grid.InvWorldMatrix.TransformBox(cursorBox);
|
||||
var (_, _, worldMatrix, invMatrix) = _entityManager.GetComponent<TransformComponent>(grid.GridEntityId).GetWorldPositionRotationMatrixWithInv();
|
||||
|
||||
var lCursorBox = invMatrix.TransformBox(cursorBox);
|
||||
foreach (var (pos, list) in gridDict)
|
||||
{
|
||||
var centerPos = (Vector2) pos + grid.TileSize / 2f;
|
||||
@@ -159,7 +161,7 @@ namespace Content.Client.NodeContainer
|
||||
}
|
||||
}
|
||||
|
||||
handle.SetTransform(grid.WorldMatrix);
|
||||
handle.SetTransform(worldMatrix);
|
||||
|
||||
foreach (var nodeRenderData in _nodeIndex.Values)
|
||||
{
|
||||
|
||||
@@ -136,16 +136,19 @@ public class DockingControl : Control
|
||||
Matrix3.Multiply(in gridInvMatrix, in matrix, out var invMatrix);
|
||||
|
||||
// TODO: Getting some overdraw so need to fix that.
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
foreach (var grid in _mapManager.FindGridsIntersecting(gridXform.MapID,
|
||||
new Box2(worldPos - _range, worldPos + _range)))
|
||||
{
|
||||
if (grid.GridEntityId == GridEntity) continue;
|
||||
if (grid.GridEntityId == GridEntity)
|
||||
continue;
|
||||
|
||||
// Draw the fixtures before drawing any docks in range.
|
||||
if (!_entManager.TryGetComponent<FixturesComponent>(grid.GridEntityId, out var gridFixtures)) continue;
|
||||
if (!_entManager.TryGetComponent<FixturesComponent>(grid.GridEntityId, out var gridFixtures))
|
||||
continue;
|
||||
|
||||
var gridMatrix = grid.WorldMatrix;
|
||||
var gridMatrix = xformQuery.GetComponent(grid.GridEntityId).WorldMatrix;
|
||||
|
||||
Matrix3.Multiply(in gridMatrix, in invMatrix, out var matty);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user