Remove transform methods from mapgrid (#12233)

This commit is contained in:
metalgearsloth
2022-11-01 11:27:18 +11:00
committed by GitHub
parent 297686c4ff
commit c9a2ab1cee
25 changed files with 144 additions and 78 deletions

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -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++)
{

View File

@@ -14,7 +14,7 @@ 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;
@@ -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),

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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<EvaporationComponent>(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

View File

@@ -59,18 +59,26 @@ namespace Content.IntegrationTests.Tests
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<TransformComponent>(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<TransformComponent>(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)));
}
});

View File

@@ -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<TransformComponent>();
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<Rgba32>(gridCanvas)
{
GridUid = grid.GridEntityId,
Offset = grid.WorldPosition
Offset = xformQuery.GetComponent(grid.GridEntityId).WorldPosition
};
yield return renderedImage;

View File

@@ -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<CompletionOption>();
if (playerMap == null)
return CompletionResult.FromOptions(options);
foreach (var grid in _mapManager.GetAllMapGrids(playerMap.Value).OrderBy(o => o.GridEntityId))
{
if (!TryComp<TransformComponent>(grid.GridEntityId, out var gridXform))
continue;
options.Add(new CompletionOption(grid.GridEntityId.ToString(), $"{MetaData(grid.GridEntityId).EntityName} - Map {gridXform.MapID}"));
}
return CompletionResult.FromOptions(options);
}

View File

@@ -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);

View File

@@ -387,10 +387,12 @@ public sealed partial class CargoSystem
var center = new Vector2();
var minRadius = 0f;
Box2? aabb = null;
var xformQuery = GetEntityQuery<TransformComponent>();
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)

View File

@@ -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;

View File

@@ -149,9 +149,11 @@ public sealed class PiratesRuleSystem : GameRuleSystem
}
var map = "/Maps/pirate.yml";
var xformQuery = GetEntityQuery<TransformComponent>();
var aabbs = _stationSystem.Stations.SelectMany(x =>
Comp<StationDataComponent>(x).Grids.Select(x => _mapManager.GetGridComp(x).Grid.WorldAABB)).ToArray();
Comp<StationDataComponent>(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++)

View File

@@ -32,10 +32,13 @@ namespace Content.Server.Objectives.Conditions
var entMan = IoCManager.Resolve<IEntityManager>();
if (!entMan.TryGetComponent<IMapGridComponent>(shuttle, out var shuttleGrid))
if (!entMan.TryGetComponent<IMapGridComponent>(shuttle, out var shuttleGrid) ||
!entMan.TryGetComponent<TransformComponent>(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

View File

@@ -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<TransformComponent>(mapGrid.GridEntityId).WorldMatrix.TransformBox(mapGrid.LocalAABB);
if (first)
{
total = aabb;

View File

@@ -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<TransformComponent>(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<SalvageMagnetComponent>();

View File

@@ -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);

View File

@@ -90,9 +90,12 @@ public sealed partial class ShuttleSystem
reason = null;
if (!TryComp<IMapGridComponent>(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<PhysicsComponent>();
foreach (var other in _mapManager.FindGridsIntersecting(xform.MapID, bounds))

View File

@@ -295,7 +295,7 @@ public sealed class StationSystem : EntitySystem
bounds.Add(bound);
if (!mapIds.Contains(mapId))
{
mapIds.Add(grid.ParentMapId);
mapIds.Add(xform.MapID);
}
}

View File

@@ -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<PhysicsComponent>(grid.GridEntityId, out var gridBody))
{
continue;
}
var aabb = gridBody.GetWorldAABB();
playableArea = playableArea?.Union(aabb) ?? aabb;
}

View File

@@ -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<IMapGridComponent>(targetGrid, out var gridComp))
return false;
var grid = gridComp.Grid;
var atmosphereSystem = Get<AtmosphereSystem>();
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;

View File

@@ -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);
}

View File

@@ -250,19 +250,23 @@ namespace Content.Shared.Maps
/// <summary>
/// Creates a box the size of a tile, at the same position in the world as the tile.
/// </summary>
[Obsolete]
private static bool GetWorldTileBox(TileRef turf, out Box2Rotated res)
{
var entManager = IoCManager.Resolve<IEntityManager>();
var map = IoCManager.Resolve<IMapManager>();
if (map.TryGetGrid(turf.GridUid, out var tileGrid))
{
var gridRot = entManager.GetComponent<TransformComponent>(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;
}