query ??= EntityManager.GetEntityQuery<AirtightComponent>();
var damageQuery = EntityManager.GetEntityQuery<DamageableComponent>();
var destructibleQuery = EntityManager.GetEntityQuery<DestructibleComponent>();
- var anchoredEnumerator = grid.GetAnchoredEntitiesEnumerator(tile);
+ var anchoredEnumerator = _mapSystem.GetAnchoredEntitiesEnumerator(gridId, grid, tile);
while (anchoredEnumerator.MoveNext(out var uid))
{
if (!TryComp<MapGridComponent>(transform.GridUid, out var grid))
return;
- UpdateAirtightMap(transform.GridUid.Value, grid, grid.CoordinatesToTile(transform.Coordinates));
+ UpdateAirtightMap(transform.GridUid.Value, grid, _mapSystem.CoordinatesToTile(transform.GridUid.Value, grid, transform.Coordinates));
}
/// <summary>
using System.Linq;
using System.Numerics;
using Content.Shared.Administration;
-using Content.Shared.Explosion;
using Content.Shared.Explosion.Components;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
public sealed partial class ExplosionSystem
{
+ /// <summary>
+ /// A list of grids to be reused by <see cref="GetLocalGrids"/> to avoid allocating twice for each call.
+ /// </summary>
+ private List<Entity<MapGridComponent>> _grids = [];
+
/// <summary>
/// This is the main explosion generating function.
/// </summary>
// get the epicenter tile indices
if (_mapManager.TryFindGridAt(epicenter, out var gridUid, out var candidateGrid) &&
- candidateGrid.TryGetTileRef(candidateGrid.WorldToTile(epicenter.Position), out var tileRef) &&
+ _mapSystem.TryGetTileRef(gridUid, candidateGrid, _mapSystem.WorldToTile(gridUid, candidateGrid, epicenter.Position), out var tileRef) &&
!tileRef.Tile.IsEmpty)
{
epicentreGrid = gridUid;
else if (referenceGrid != null)
{
// reference grid defines coordinate system that the explosion in space will use
- initialTile = Comp<MapGridComponent>(referenceGrid.Value).WorldToTile(epicenter.Position);
+ var gridComp = Comp<MapGridComponent>(referenceGrid.Value);
+ initialTile = _mapSystem.WorldToTile(referenceGrid.Value, gridComp, epicenter.Position);
}
else
{
// this is a space-based explosion that (should) not touch any grids.
initialTile = new Vector2i(
- (int) Math.Floor(epicenter.Position.X / DefaultTileSize),
- (int) Math.Floor(epicenter.Position.Y / DefaultTileSize));
+ (int)Math.Floor(epicenter.Position.X / DefaultTileSize),
+ (int)Math.Floor(epicenter.Position.Y / DefaultTileSize));
}
// Main data for the exploding tiles in space and on various grids
var spaceAngle = Angle.Zero;
if (referenceGrid != null)
{
- var xform = Transform(Comp<MapGridComponent>(referenceGrid.Value).Owner);
+ var xform = Transform(referenceGrid.Value);
(_, spaceAngle, spaceMatrix) = _transformSystem.GetWorldPositionRotationMatrix(xform);
}
// These variables keep track of the total intensity we have distributed
List<int> tilesInIteration = new() { 1 };
- List<float> iterationIntensity = new() {stepSize};
+ List<float> iterationIntensity = new() { stepSize };
var totalTiles = 1;
var remainingIntensity = totalIntensity - stepSize;
// diameter x diameter sized box, use a smaller box with radius sized sides:
var box = Box2.CenteredAround(epicenter.Position, new Vector2(radius, radius));
- foreach (var grid in _mapManager.FindGridsIntersecting(epicenter.MapId, box))
+ _grids.Clear();
+ _mapManager.FindGridsIntersecting(epicenter.MapId, box, ref _grids);
+ foreach (var grid in _grids)
{
if (TryComp(grid.Owner, out PhysicsComponent? physics) && physics.Mass > mass)
{
radius *= 4;
box = Box2.CenteredAround(epicenter.Position, new Vector2(radius, radius));
- var mapGrids = _mapManager.FindGridsIntersecting(epicenter.MapId, box).ToList();
- var grids = mapGrids.Select(x => x.Owner).ToList();
+ _grids.Clear();
+ _mapManager.FindGridsIntersecting(epicenter.MapId, box, ref _grids);
+ var grids = _grids.Select(x => x.Owner).ToList();
if (referenceGrid != null)
return (grids, referenceGrid, radius);
// We still don't have are reference grid. So lets also look in the enlarged region
- foreach (var grid in mapGrids)
+ foreach (var grid in _grids)
{
if (TryComp(grid.Owner, out PhysicsComponent? physics) && physics.Mass > mass)
{
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnReset);
// Handled by ExplosionSystem.Processing.cs
- SubscribeLocalEvent<MapChangedEvent>(OnMapChanged);
+ SubscribeLocalEvent<MapRemovedEvent>(OnMapRemoved);
// handled in ExplosionSystemAirtight.cs
SubscribeLocalEvent<AirtightComponent, DamageChangedEvent>(OnAirtightDamaged);
// Override the explosion intensity if optional arguments were provided.
if (radius != null)
- totalIntensity ??= RadiusToIntensity((float) radius, explosive.IntensitySlope, explosive.MaxIntensity);
+ totalIntensity ??= RadiusToIntensity((float)radius, explosive.IntensitySlope, explosive.MaxIntensity);
totalIntensity ??= explosive.TotalIntensity;
QueueExplosion(uid,
explosive.ExplosionType,
- (float) totalIntensity,
+ (float)totalIntensity,
explosive.IntensitySlope,
explosive.MaxIntensity,
explosive.TileBreakScale,
private Explosion? SpawnExplosion(QueuedExplosion queued)
{
var pos = queued.Epicenter;
- if (!_mapManager.MapExists(pos.MapId))
+ if (!_mapSystem.MapExists(pos.MapId))
return null;
var results = GetExplosionTiles(pos, queued.Proto.ID, queued.TotalIntensity, queued.Slope, queued.MaxTileIntensity);