diff --git a/Content.Client/Atmos/EntitySystems/AtmosDebugOverlaySystem.cs b/Content.Client/Atmos/EntitySystems/AtmosDebugOverlaySystem.cs index 419be50c42..db8421d8cc 100644 --- a/Content.Client/Atmos/EntitySystems/AtmosDebugOverlaySystem.cs +++ b/Content.Client/Atmos/EntitySystems/AtmosDebugOverlaySystem.cs @@ -43,7 +43,7 @@ namespace Content.Client.Atmos.EntitySystems var overlayManager = IoCManager.Resolve(); if(!overlayManager.HasOverlay()) - overlayManager.AddOverlay(new AtmosDebugOverlay()); + overlayManager.AddOverlay(new AtmosDebugOverlay(this)); } private void OnGridRemoved(GridRemovalEvent ev) diff --git a/Content.Client/Atmos/EntitySystems/GasTileOverlaySystem.cs b/Content.Client/Atmos/EntitySystems/GasTileOverlaySystem.cs index dc37dca7a3..2d12d50ef3 100644 --- a/Content.Client/Atmos/EntitySystems/GasTileOverlaySystem.cs +++ b/Content.Client/Atmos/EntitySystems/GasTileOverlaySystem.cs @@ -24,7 +24,7 @@ namespace Content.Client.Atmos.EntitySystems SubscribeNetworkEvent(HandleGasOverlayUpdate); SubscribeLocalEvent(OnGridRemoved); - _overlay = new GasTileOverlay(this, _resourceCache, ProtoMan, _spriteSys); + _overlay = new GasTileOverlay(this, EntityManager, _resourceCache, ProtoMan, _spriteSys); _overlayMan.AddOverlay(_overlay); } diff --git a/Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs b/Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs index 10e7828381..fe49fc1d7a 100644 --- a/Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs +++ b/Content.Client/Atmos/Overlays/AtmosDebugOverlay.cs @@ -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 = 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(mapGrid.GridEntityId, out var xform)) continue; - drawHandle.SetTransform(mapGrid.WorldMatrix); + drawHandle.SetTransform(xform.WorldMatrix); for (var pass = 0; pass < 2; pass++) { diff --git a/Content.Client/Atmos/Overlays/GasTileOverlay.cs b/Content.Client/Atmos/Overlays/GasTileOverlay.cs index c8e5971783..01dbd5b145 100644 --- a/Content.Client/Atmos/Overlays/GasTileOverlay.cs +++ b/Content.Client/Atmos/Overlays/GasTileOverlay.cs @@ -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(); _shader = protoMan.Index("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(_system.VisibleGasId[i].ToString()); + var gasPrototype = protoMan.Index(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(); 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; diff --git a/Content.Client/NPC/PathfindingSystem.cs b/Content.Client/NPC/PathfindingSystem.cs index 1495f20044..5b3847691e 100644 --- a/Content.Client/NPC/PathfindingSystem.cs +++ b/Content.Client/NPC/PathfindingSystem.cs @@ -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(); 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(); 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(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) { diff --git a/Content.Client/NodeContainer/NodeVisualizationOverlay.cs b/Content.Client/NodeContainer/NodeVisualizationOverlay.cs index 7b4aa55707..9ca30ad2c3 100644 --- a/Content.Client/NodeContainer/NodeVisualizationOverlay.cs +++ b/Content.Client/NodeContainer/NodeVisualizationOverlay.cs @@ -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(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) { diff --git a/Content.Client/Shuttles/UI/DockingControl.cs b/Content.Client/Shuttles/UI/DockingControl.cs index 7fb819f2e7..95e45d786e 100644 --- a/Content.Client/Shuttles/UI/DockingControl.cs +++ b/Content.Client/Shuttles/UI/DockingControl.cs @@ -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(); 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(grid.GridEntityId, out var gridFixtures)) continue; + if (!_entManager.TryGetComponent(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); diff --git a/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs b/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs index dc45eb39e7..c7c7882a27 100644 --- a/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs +++ b/Content.IntegrationTests/Tests/Fluids/PuddleTest.cs @@ -116,7 +116,7 @@ namespace Content.IntegrationTests.Tests.Fluids // Check that the map and grid are paused await server.WaitAssertion(() => { - Assert.True(sMapManager.IsGridPaused(sGridId)); + Assert.True(metaSystem.EntityPaused(sGridId)); Assert.True(sMapManager.IsMapPaused(sMapId)); }); @@ -143,7 +143,7 @@ namespace Content.IntegrationTests.Tests.Fluids evaporation = entityManager.GetComponent(puddle.Owner); metaSystem.SetEntityPaused(puddle.Owner, true, meta); // See https://github.com/space-wizards/RobustToolbox/issues/1445 - Assert.True(meta.EntityPaused); + Assert.True(metaSystem.EntityPaused(puddle.Owner, meta)); // Check that the puddle is going to evaporate Assert.Positive(evaporation.EvaporateTime); @@ -174,7 +174,7 @@ namespace Content.IntegrationTests.Tests.Fluids await server.WaitAssertion(() => { Assert.False(sMapManager.IsMapPaused(sMapId)); - Assert.False(sMapManager.IsGridPaused(sGridId)); + Assert.False(metaSystem.EntityPaused(sGridId)); Assert.False(meta.EntityPaused); // Check that the puddle still exists diff --git a/Content.IntegrationTests/Tests/SaveLoadMapTest.cs b/Content.IntegrationTests/Tests/SaveLoadMapTest.cs index 1aba319c99..8244c2299a 100644 --- a/Content.IntegrationTests/Tests/SaveLoadMapTest.cs +++ b/Content.IntegrationTests/Tests/SaveLoadMapTest.cs @@ -53,24 +53,32 @@ namespace Content.IntegrationTests.Tests await server.WaitPost(() => { Assert.Multiple(() => mapLoader.LoadMap(new MapId(10), mapPath)); - + }); await server.WaitIdleAsync(); await server.WaitAssertion(() => { { - if (!mapManager.TryFindGridAt(new MapId(10), new Vector2(10, 10), out var mapGrid)) + if (!mapManager.TryFindGridAt(new MapId(10), new Vector2(10, 10), out var mapGrid) || + !sEntities.TryGetComponent(mapGrid.GridEntityId, out var gridXform)) + { Assert.Fail(); + return; + } - Assert.That(mapGrid.WorldPosition, Is.EqualTo(new Vector2(10, 10))); + Assert.That(gridXform.WorldPosition, Is.EqualTo(new Vector2(10, 10))); Assert.That(mapGrid.GetTileRef(new Vector2i(0, 0)).Tile, Is.EqualTo(new Tile(1, (TileRenderFlag)1, 255))); } { - if (!mapManager.TryFindGridAt(new MapId(10), new Vector2(-8, -8), out var mapGrid)) + if (!mapManager.TryFindGridAt(new MapId(10), new Vector2(-8, -8), out var mapGrid) || + !sEntities.TryGetComponent(mapGrid.GridEntityId, out var gridXform)) + { Assert.Fail(); + return; + } - Assert.That(mapGrid.WorldPosition, Is.EqualTo(new Vector2(-8, -8))); + Assert.That(gridXform.WorldPosition, Is.EqualTo(new Vector2(-8, -8))); Assert.That(mapGrid.GetTileRef(new Vector2i(0, 0)).Tile, Is.EqualTo(new Tile(2, (TileRenderFlag)1, 254))); } }); diff --git a/Content.MapRenderer/Painters/MapPainter.cs b/Content.MapRenderer/Painters/MapPainter.cs index d40e0411c5..823c57e0af 100644 --- a/Content.MapRenderer/Painters/MapPainter.cs +++ b/Content.MapRenderer/Painters/MapPainter.cs @@ -7,6 +7,7 @@ using Content.IntegrationTests; using Robust.Client.GameObjects; using Robust.Server.GameObjects; using Robust.Server.Player; +using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Timing; @@ -59,6 +60,7 @@ namespace Content.MapRenderer.Painters var tilePainter = new TilePainter(client, server); var entityPainter = new GridPainter(client, server); IMapGrid[] grids = null!; + var xformQuery = sEntityManager.GetEntityQuery(); await server.WaitPost(() => { @@ -74,7 +76,8 @@ namespace Content.MapRenderer.Painters foreach (var grid in grids) { - grid.WorldRotation = Angle.Zero; + var gridXform = xformQuery.GetComponent(grid.GridEntityId); + gridXform.WorldRotation = Angle.Zero; } }); @@ -116,7 +119,7 @@ namespace Content.MapRenderer.Painters var renderedImage = new RenderedGridImage(gridCanvas) { GridUid = grid.GridEntityId, - Offset = grid.WorldPosition + Offset = xformQuery.GetComponent(grid.GridEntityId).WorldPosition }; yield return renderedImage; diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Commands.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Commands.cs index 9c6a38600b..ac3e831168 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Commands.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Commands.cs @@ -122,11 +122,18 @@ public sealed partial class AtmosphereSystem if (shell.Player is { AttachedEntity: { } playerEnt }) playerMap = Transform(playerEnt).MapID; - var options = _mapManager.GetAllGrids() - .OrderByDescending(e => playerMap != null && e.ParentMapId == playerMap) - .ThenBy(e => (int) e.ParentMapId) - .ThenBy(e => (int) e.GridEntityId) - .Select(e => new CompletionOption(e.GridEntityId.ToString(), $"{MetaData(e.GridEntityId).EntityName} - Map {e.ParentMapId}")); + var options = new List(); + + if (playerMap == null) + return CompletionResult.FromOptions(options); + + foreach (var grid in _mapManager.GetAllMapGrids(playerMap.Value).OrderBy(o => o.GridEntityId)) + { + if (!TryComp(grid.GridEntityId, out var gridXform)) + continue; + + options.Add(new CompletionOption(grid.GridEntityId.ToString(), $"{MetaData(grid.GridEntityId).EntityName} - Map {gridXform.MapID}")); + } return CompletionResult.FromOptions(options); } diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs index 9a3b4534e6..60141d14c4 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs @@ -50,7 +50,7 @@ namespace Content.Server.Atmos.EntitySystems return true; var mapGrid = mapGridComp.Grid; - var mapUid = _mapManager.GetMapEntityIdOrThrow(mapGridComp.Grid.ParentMapId); + var mapUid = _mapManager.GetMapEntityIdOrThrow(Transform(mapGridComp.Owner).MapID); var volume = GetVolumeForTiles(mapGrid, 1); diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs index 00e0bb8f81..240c84e237 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs @@ -387,10 +387,12 @@ public sealed partial class CargoSystem var center = new Vector2(); var minRadius = 0f; Box2? aabb = null; + var xformQuery = GetEntityQuery(); foreach (var grid in _mapManager.GetAllMapGrids(xform.MapID)) { - aabb = aabb?.Union(grid.WorldAABB) ?? grid.WorldAABB; + var worldAABB = xformQuery.GetComponent(grid.GridEntityId).WorldMatrix.TransformBox(grid.LocalAABB); + aabb = aabb?.Union(worldAABB) ?? worldAABB; } if (aabb != null) diff --git a/Content.Server/GameTicking/GameTicker.Spawning.cs b/Content.Server/GameTicking/GameTicker.Spawning.cs index 7996f8e1ea..2d63666adf 100644 --- a/Content.Server/GameTicking/GameTicker.Spawning.cs +++ b/Content.Server/GameTicking/GameTicker.Spawning.cs @@ -331,8 +331,10 @@ namespace Content.Server.GameTicking if (_mapManager.TryFindGridAt(toMap, out var foundGrid)) { + var gridXform = Transform(foundGrid.GridEntityId); + return new EntityCoordinates(foundGrid.GridEntityId, - foundGrid.InvWorldMatrix.Transform(toMap.Position)); + gridXform.InvWorldMatrix.Transform(toMap.Position)); } return spawn; diff --git a/Content.Server/GameTicking/Rules/PiratesRuleSystem.cs b/Content.Server/GameTicking/Rules/PiratesRuleSystem.cs index e6cb3e382c..08829de159 100644 --- a/Content.Server/GameTicking/Rules/PiratesRuleSystem.cs +++ b/Content.Server/GameTicking/Rules/PiratesRuleSystem.cs @@ -149,9 +149,11 @@ public sealed class PiratesRuleSystem : GameRuleSystem } var map = "/Maps/pirate.yml"; + var xformQuery = GetEntityQuery(); var aabbs = _stationSystem.Stations.SelectMany(x => - Comp(x).Grids.Select(x => _mapManager.GetGridComp(x).Grid.WorldAABB)).ToArray(); + Comp(x).Grids.Select(x => xformQuery.GetComponent(x).WorldMatrix.TransformBox(_mapManager.GetGridComp(x).Grid.LocalAABB))).ToArray(); + var aabb = aabbs[0]; for (var i = 1; i < aabbs.Length; i++) diff --git a/Content.Server/Objectives/Conditions/EscapeShuttleCondition.cs b/Content.Server/Objectives/Conditions/EscapeShuttleCondition.cs index 65e2556ec2..8f74f71d13 100644 --- a/Content.Server/Objectives/Conditions/EscapeShuttleCondition.cs +++ b/Content.Server/Objectives/Conditions/EscapeShuttleCondition.cs @@ -32,10 +32,13 @@ namespace Content.Server.Objectives.Conditions var entMan = IoCManager.Resolve(); - if (!entMan.TryGetComponent(shuttle, out var shuttleGrid)) + if (!entMan.TryGetComponent(shuttle, out var shuttleGrid) || + !entMan.TryGetComponent(shuttle, out var shuttleXform)) + { return false; + } - return shuttleGrid.Grid.WorldAABB.Contains(agentXform.WorldPosition); + return shuttleXform.WorldMatrix.TransformBox(shuttleGrid.Grid.LocalAABB).Contains(agentXform.WorldPosition); } public float Progress diff --git a/Content.Server/Salvage/SalvageRulerCommand.cs b/Content.Server/Salvage/SalvageRulerCommand.cs index 184c1b9083..59cfbf90e9 100644 --- a/Content.Server/Salvage/SalvageRulerCommand.cs +++ b/Content.Server/Salvage/SalvageRulerCommand.cs @@ -50,7 +50,7 @@ sealed class SalvageRulerCommand : IConsoleCommand var first = true; foreach (var mapGrid in _maps.GetAllMapGrids(entityTransform.MapID)) { - var aabb = mapGrid.WorldAABB; + var aabb = _entities.GetComponent(mapGrid.GridEntityId).WorldMatrix.TransformBox(mapGrid.LocalAABB); if (first) { total = aabb; diff --git a/Content.Server/Salvage/SalvageSystem.cs b/Content.Server/Salvage/SalvageSystem.cs index 8d74d11fef..d03e512525 100644 --- a/Content.Server/Salvage/SalvageSystem.cs +++ b/Content.Server/Salvage/SalvageSystem.cs @@ -227,9 +227,10 @@ namespace Content.Server.Salvage angle = Angle.Zero; var tsc = Transform(component.Owner); coords = new EntityCoordinates(component.Owner, component.Offset).ToMap(EntityManager); - if (_mapManager.TryGetGrid(tsc.GridUid, out var magnetGrid)) + + if (_mapManager.TryGetGrid(tsc.GridUid, out var magnetGrid) && TryComp(magnetGrid.GridEntityId, out var gridXform)) { - angle = magnetGrid.WorldRotation; + angle = gridXform.WorldRotation; } } @@ -372,7 +373,7 @@ namespace Content.Server.Salvage var gridId = gridIdAndState.Key; // Not handling the case where the salvage we spawned got paused // They both need to be paused, or it doesn't make sense - if (_mapManager.IsGridPaused(gridId)) continue; + if (MetaData(gridId).EntityPaused) continue; state.CurrentTime += secondsPassed; var deleteQueue = new RemQueue(); diff --git a/Content.Server/Shuttles/Systems/DockingSystem.cs b/Content.Server/Shuttles/Systems/DockingSystem.cs index 50791a5ddb..cc6a573c8e 100644 --- a/Content.Server/Shuttles/Systems/DockingSystem.cs +++ b/Content.Server/Shuttles/Systems/DockingSystem.cs @@ -90,17 +90,19 @@ namespace Content.Server.Shuttles.Systems var enlargedAABB = aabb.Value.Enlarged(DockingRadius * 1.5f); // Get any docking ports in range on other grids. - _mapManager.FindGridsIntersectingEnumerator(dockingXform.MapID, enlargedAABB, out var enumerator); - - while (enumerator.MoveNext(out var otherGrid)) + foreach (var otherGrid in _mapManager.FindGridsIntersecting(dockingXform.MapID, enlargedAABB)) { - if (otherGrid.GridEntityId == dockingXform.GridUid) continue; + if (otherGrid.GridEntityId == dockingXform.GridUid) + continue; foreach (var ent in otherGrid.GetAnchoredEntities(enlargedAABB)) { if (!TryComp(ent, out DockingComponent? otherDocking) || !otherDocking.Enabled || - !TryComp(ent, out PhysicsComponent? otherBody)) continue; + !TryComp(ent, out PhysicsComponent? otherBody)) + { + continue; + } var otherTransform = otherBody.GetTransform(); var otherDockingFixture = _fixtureSystem.GetFixtureOrNull(otherBody, DockingFixture); diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs index 216139a4b0..d6f34a6d05 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs @@ -90,9 +90,12 @@ public sealed partial class ShuttleSystem reason = null; if (!TryComp(uid, out var grid) || - !Resolve(uid.Value, ref xform)) return true; + !Resolve(uid.Value, ref xform)) + { + return true; + } - var bounds = grid.Grid.WorldAABB.Enlarged(ShuttleFTLRange); + var bounds = xform.WorldMatrix.TransformBox(grid.Grid.LocalAABB).Enlarged(ShuttleFTLRange); var bodyQuery = GetEntityQuery(); foreach (var other in _mapManager.FindGridsIntersecting(xform.MapID, bounds)) diff --git a/Content.Server/Station/Systems/StationSystem.cs b/Content.Server/Station/Systems/StationSystem.cs index 27c8ad7886..a744ee3600 100644 --- a/Content.Server/Station/Systems/StationSystem.cs +++ b/Content.Server/Station/Systems/StationSystem.cs @@ -295,7 +295,7 @@ public sealed class StationSystem : EntitySystem bounds.Add(bound); if (!mapIds.Contains(mapId)) { - mapIds.Add(grid.ParentMapId); + mapIds.Add(xform.MapID); } } diff --git a/Content.Server/StationEvents/Events/MeteorSwarm.cs b/Content.Server/StationEvents/Events/MeteorSwarm.cs index e11c4ae778..63fa841f78 100644 --- a/Content.Server/StationEvents/Events/MeteorSwarm.cs +++ b/Content.Server/StationEvents/Events/MeteorSwarm.cs @@ -68,9 +68,13 @@ namespace Content.Server.StationEvents.Events Box2? playableArea = null; var mapId = GameTicker.DefaultMap; - foreach (var grid in MapManager.GetAllGrids()) + foreach (var grid in MapManager.GetAllMapGrids(mapId)) { - if (grid.ParentMapId != mapId || !EntityManager.TryGetComponent(grid.GridEntityId, out PhysicsComponent? gridBody)) continue; + if (!TryComp(grid.GridEntityId, out var gridBody)) + { + continue; + } + var aabb = gridBody.GetWorldAABB(); playableArea = playableArea?.Union(aabb) ?? aabb; } diff --git a/Content.Server/StationEvents/Events/StationEventSystem.cs b/Content.Server/StationEvents/Events/StationEventSystem.cs index 46eed70731..24675adfc5 100644 --- a/Content.Server/StationEvents/Events/StationEventSystem.cs +++ b/Content.Server/StationEvents/Events/StationEventSystem.cs @@ -24,6 +24,7 @@ namespace Content.Server.StationEvents.Events [Dependency] protected readonly IAdminLogManager AdminLogManager = default!; [Dependency] protected readonly IPrototypeManager PrototypeManager = default!; [Dependency] protected readonly IMapManager MapManager = default!; + [Dependency] private readonly AtmosphereSystem _atmosphere = default!; [Dependency] protected readonly ChatSystem ChatSystem = default!; [Dependency] protected readonly StationSystem StationSystem = default!; @@ -146,12 +147,12 @@ namespace Content.Server.StationEvents.Events if (!TryComp(targetGrid, out var gridComp)) return false; + var grid = gridComp.Grid; - var atmosphereSystem = Get(); var found = false; - var gridBounds = grid.WorldAABB; - var gridPos = grid.WorldPosition; + var (gridPos, _, gridMatrix) = Transform(targetGrid).GetWorldPositionRotationMatrix(); + var gridBounds = gridMatrix.TransformBox(grid.LocalAABB); for (var i = 0; i < 10; i++) { @@ -159,8 +160,13 @@ namespace Content.Server.StationEvents.Events var randomY = RobustRandom.Next((int) gridBounds.Bottom, (int) gridBounds.Top); tile = new Vector2i(randomX - (int) gridPos.X, randomY - (int) gridPos.Y); - if (atmosphereSystem.IsTileSpace(grid.GridEntityId, Transform(targetGrid).MapUid, tile, mapGridComp:gridComp) - || atmosphereSystem.IsTileAirBlocked(grid.GridEntityId, tile, mapGridComp:gridComp)) continue; + if (_atmosphere.IsTileSpace(grid.GridEntityId, Transform(targetGrid).MapUid, tile, + mapGridComp: gridComp) + || _atmosphere.IsTileAirBlocked(grid.GridEntityId, tile, mapGridComp: gridComp)) + { + continue; + } + found = true; targetCoords = grid.GridTileToLocal(tile); break; diff --git a/Content.Server/Tiles/FloorTileSystem.cs b/Content.Server/Tiles/FloorTileSystem.cs index 52fc167283..9bef0d7e58 100644 --- a/Content.Server/Tiles/FloorTileSystem.cs +++ b/Content.Server/Tiles/FloorTileSystem.cs @@ -75,7 +75,8 @@ namespace Content.Server.Tiles else if (HasBaseTurf(currentTileDefinition, ContentTileDefinition.SpaceID)) { mapGrid = _mapManager.CreateGrid(locationMap.MapId); - mapGrid.WorldPosition = locationMap.Position; + var gridXform = Transform(mapGrid.GridEntityId); + gridXform.WorldPosition = locationMap.Position; location = new EntityCoordinates(mapGrid.GridEntityId, Vector2.Zero); PlaceAt(mapGrid, location, _tileDefinitionManager[component.OutputTiles[0]].TileId, component.PlaceTileSound, mapGrid.TileSize / 2f); } diff --git a/Content.Shared/Maps/TurfHelpers.cs b/Content.Shared/Maps/TurfHelpers.cs index 82b3c28949..4701a8633d 100644 --- a/Content.Shared/Maps/TurfHelpers.cs +++ b/Content.Shared/Maps/TurfHelpers.cs @@ -250,19 +250,23 @@ namespace Content.Shared.Maps /// /// Creates a box the size of a tile, at the same position in the world as the tile. /// + [Obsolete] private static bool GetWorldTileBox(TileRef turf, out Box2Rotated res) { + var entManager = IoCManager.Resolve(); var map = IoCManager.Resolve(); if (map.TryGetGrid(turf.GridUid, out var tileGrid)) { + var gridRot = entManager.GetComponent(tileGrid.GridEntityId).WorldRotation; + // This is scaled to 90 % so it doesn't encompass walls on other tiles. var tileBox = Box2.UnitCentered.Scale(0.9f); tileBox = tileBox.Scale(tileGrid.TileSize); var worldPos = tileGrid.GridTileToWorldPos(turf.GridIndices); tileBox = tileBox.Translated(worldPos); // Now tileBox needs to be rotated to match grid rotation - res = new Box2Rotated(tileBox, tileGrid.WorldRotation, worldPos); + res = new Box2Rotated(tileBox, gridRot, worldPos); return true; }