Remove 700 usages of Component.Owner (#21100)
This commit is contained in:
@@ -26,50 +26,49 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
/// </summary>
|
||||
private const int InvalidCoordinatesLagCheckIterations = 50;
|
||||
|
||||
private int _currentRunAtmosphereIndex = 0;
|
||||
private bool _simulationPaused = false;
|
||||
private int _currentRunAtmosphereIndex;
|
||||
private bool _simulationPaused;
|
||||
|
||||
private readonly List<GridAtmosphereComponent> _currentRunAtmosphere = new();
|
||||
private readonly List<Entity<GridAtmosphereComponent>> _currentRunAtmosphere = new();
|
||||
|
||||
/// <summary>
|
||||
/// Revalidates all invalid coordinates in a grid atmosphere.
|
||||
/// </summary>
|
||||
/// <param name="atmosphere">The grid atmosphere in question.</param>
|
||||
/// <param name="ent">The grid atmosphere in question.</param>
|
||||
/// <returns>Whether the process succeeded or got paused due to time constrains.</returns>
|
||||
private bool ProcessRevalidate(GridAtmosphereComponent atmosphere, GasTileOverlayComponent? visuals)
|
||||
private bool ProcessRevalidate(Entity<GridAtmosphereComponent> ent, GasTileOverlayComponent? visuals)
|
||||
{
|
||||
var (owner, atmosphere) = ent;
|
||||
if (!atmosphere.ProcessingPaused)
|
||||
{
|
||||
atmosphere.CurrentRunInvalidatedCoordinates = new Queue<Vector2i>(atmosphere.InvalidatedCoords);
|
||||
atmosphere.InvalidatedCoords.Clear();
|
||||
}
|
||||
|
||||
var uid = atmosphere.Owner;
|
||||
|
||||
if (!TryComp(uid, out MapGridComponent? mapGridComp))
|
||||
if (!TryComp(owner, out MapGridComponent? mapGridComp))
|
||||
return true;
|
||||
|
||||
var mapUid = _mapManager.GetMapEntityIdOrThrow(Transform(mapGridComp.Owner).MapID);
|
||||
var mapUid = _mapManager.GetMapEntityIdOrThrow(Transform(owner).MapID);
|
||||
|
||||
var volume = GetVolumeForTiles(mapGridComp, 1);
|
||||
var volume = GetVolumeForTiles(mapGridComp);
|
||||
|
||||
var number = 0;
|
||||
while (atmosphere.CurrentRunInvalidatedCoordinates.TryDequeue(out var indices))
|
||||
{
|
||||
if (!atmosphere.Tiles.TryGetValue(indices, out var tile))
|
||||
{
|
||||
tile = new TileAtmosphere(mapGridComp.Owner, indices,
|
||||
tile = new TileAtmosphere(owner, indices,
|
||||
new GasMixture(volume) { Temperature = Atmospherics.T20C });
|
||||
atmosphere.Tiles[indices] = tile;
|
||||
}
|
||||
|
||||
var airBlockedEv = new IsTileAirBlockedMethodEvent(uid, indices, MapGridComponent:mapGridComp);
|
||||
GridIsTileAirBlocked(uid, atmosphere, ref airBlockedEv);
|
||||
var airBlockedEv = new IsTileAirBlockedMethodEvent(owner, indices, MapGridComponent:mapGridComp);
|
||||
GridIsTileAirBlocked(owner, atmosphere, ref airBlockedEv);
|
||||
var isAirBlocked = airBlockedEv.Result;
|
||||
|
||||
var oldBlocked = tile.BlockedAirflow;
|
||||
var updateAdjacentEv = new UpdateAdjacentMethodEvent(uid, indices, mapGridComp);
|
||||
GridUpdateAdjacent(uid, atmosphere, ref updateAdjacentEv);
|
||||
var updateAdjacentEv = new UpdateAdjacentMethodEvent(owner, indices, mapGridComp);
|
||||
GridUpdateAdjacent(owner, atmosphere, ref updateAdjacentEv);
|
||||
|
||||
// Blocked airflow changed, rebuild excited groups!
|
||||
if (tile.Excited && tile.BlockedAirflow != oldBlocked)
|
||||
@@ -99,8 +98,8 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
if (tile.Air == null && NeedsVacuumFixing(mapGridComp, indices))
|
||||
{
|
||||
var vacuumEv = new FixTileVacuumMethodEvent(uid, indices);
|
||||
GridFixTileVacuum(uid, atmosphere, ref vacuumEv);
|
||||
var vacuumEv = new FixTileVacuumMethodEvent(owner, indices);
|
||||
GridFixTileVacuum(owner, atmosphere, ref vacuumEv);
|
||||
}
|
||||
|
||||
// Tile used to be space, but isn't anymore.
|
||||
@@ -122,11 +121,12 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
// TODO ATMOS: Query all the contents of this tile (like walls) and calculate the correct thermal conductivity and heat capacity
|
||||
var tileDef = mapGridComp.TryGetTileRef(indices, out var tileRef)
|
||||
? tileRef.GetContentTileDefinition(_tileDefinitionManager) : null;
|
||||
? tileRef.GetContentTileDefinition(_tileDefinitionManager)
|
||||
: null;
|
||||
|
||||
tile.ThermalConductivity = tileDef?.ThermalConductivity ?? 0.5f;
|
||||
tile.HeatCapacity = tileDef?.HeatCapacity ?? float.PositiveInfinity;
|
||||
InvalidateVisuals(mapGridComp.Owner, indices, visuals);
|
||||
InvalidateVisuals(owner, indices, visuals);
|
||||
|
||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||
{
|
||||
@@ -137,7 +137,9 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
AddActiveTile(atmosphere, otherTile);
|
||||
}
|
||||
|
||||
if (number++ < InvalidCoordinatesLagCheckIterations) continue;
|
||||
if (number++ < InvalidCoordinatesLagCheckIterations)
|
||||
continue;
|
||||
|
||||
number = 0;
|
||||
// Process the rest next time.
|
||||
if (_simulationStopwatch.Elapsed.TotalMilliseconds >= AtmosMaxProcessTime)
|
||||
@@ -149,22 +151,23 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ProcessTileEqualize(GridAtmosphereComponent atmosphere, GasTileOverlayComponent? visuals)
|
||||
private bool ProcessTileEqualize(Entity<GridAtmosphereComponent> ent, GasTileOverlayComponent? visuals)
|
||||
{
|
||||
if(!atmosphere.ProcessingPaused)
|
||||
var (uid, atmosphere) = ent;
|
||||
if (!atmosphere.ProcessingPaused)
|
||||
atmosphere.CurrentRunTiles = new Queue<TileAtmosphere>(atmosphere.ActiveTiles);
|
||||
|
||||
var uid = atmosphere.Owner;
|
||||
|
||||
if (!TryComp(uid, out MapGridComponent? mapGridComp))
|
||||
throw new Exception("Tried to process a grid atmosphere on an entity that isn't a grid!");
|
||||
|
||||
var number = 0;
|
||||
while (atmosphere.CurrentRunTiles.TryDequeue(out var tile))
|
||||
{
|
||||
EqualizePressureInZone(mapGridComp, atmosphere, tile, atmosphere.UpdateCounter, visuals);
|
||||
EqualizePressureInZone((uid, mapGridComp, atmosphere), tile, atmosphere.UpdateCounter, visuals);
|
||||
|
||||
if (number++ < LagCheckIterations)
|
||||
continue;
|
||||
|
||||
if (number++ < LagCheckIterations) continue;
|
||||
number = 0;
|
||||
// Process the rest next time.
|
||||
if (_simulationStopwatch.Elapsed.TotalMilliseconds >= AtmosMaxProcessTime)
|
||||
@@ -186,7 +189,9 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
ProcessCell(atmosphere, tile, atmosphere.UpdateCounter, visuals);
|
||||
|
||||
if (number++ < LagCheckIterations) continue;
|
||||
if (number++ < LagCheckIterations)
|
||||
continue;
|
||||
|
||||
number = 0;
|
||||
// Process the rest next time.
|
||||
if (_simulationStopwatch.Elapsed.TotalMilliseconds >= AtmosMaxProcessTime)
|
||||
@@ -215,7 +220,9 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
else if(excitedGroup.DismantleCooldown > Atmospherics.ExcitedGroupsDismantleCycles)
|
||||
ExcitedGroupDismantle(gridAtmosphere, excitedGroup);
|
||||
|
||||
if (number++ < LagCheckIterations) continue;
|
||||
if (number++ < LagCheckIterations)
|
||||
continue;
|
||||
|
||||
number = 0;
|
||||
// Process the rest next time.
|
||||
if (_simulationStopwatch.Elapsed.TotalMilliseconds >= AtmosMaxProcessTime)
|
||||
@@ -227,9 +234,10 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ProcessHighPressureDelta(GridAtmosphereComponent atmosphere)
|
||||
private bool ProcessHighPressureDelta(Entity<GridAtmosphereComponent> ent)
|
||||
{
|
||||
if(!atmosphere.ProcessingPaused)
|
||||
var atmosphere = ent.Comp;
|
||||
if (!atmosphere.ProcessingPaused)
|
||||
atmosphere.CurrentRunTiles = new Queue<TileAtmosphere>(atmosphere.HighPressureDelta);
|
||||
|
||||
// Note: This is still processed even if space wind is turned off since this handles playing the sounds.
|
||||
@@ -242,14 +250,15 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
while (atmosphere.CurrentRunTiles.TryDequeue(out var tile))
|
||||
{
|
||||
HighPressureMovements(atmosphere, tile, bodies, xforms, pressureQuery, metas);
|
||||
HighPressureMovements(ent, tile, bodies, xforms, pressureQuery, metas);
|
||||
tile.PressureDifference = 0f;
|
||||
tile.LastPressureDirection = tile.PressureDirection;
|
||||
tile.PressureDirection = AtmosDirection.Invalid;
|
||||
tile.PressureSpecificTarget = null;
|
||||
atmosphere.HighPressureDelta.Remove(tile);
|
||||
|
||||
if (number++ < LagCheckIterations) continue;
|
||||
if (number++ < LagCheckIterations)
|
||||
continue;
|
||||
number = 0;
|
||||
// Process the rest next time.
|
||||
if (_simulationStopwatch.Elapsed.TotalMilliseconds >= AtmosMaxProcessTime)
|
||||
@@ -271,7 +280,9 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
ProcessHotspot(atmosphere, hotspot);
|
||||
|
||||
if (number++ < LagCheckIterations) continue;
|
||||
if (number++ < LagCheckIterations)
|
||||
continue;
|
||||
|
||||
number = 0;
|
||||
// Process the rest next time.
|
||||
if (_simulationStopwatch.Elapsed.TotalMilliseconds >= AtmosMaxProcessTime)
|
||||
@@ -293,7 +304,9 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
Superconduct(atmosphere, superconductivity);
|
||||
|
||||
if (number++ < LagCheckIterations) continue;
|
||||
if (number++ < LagCheckIterations)
|
||||
continue;
|
||||
|
||||
number = 0;
|
||||
// Process the rest next time.
|
||||
if (_simulationStopwatch.Elapsed.TotalMilliseconds >= AtmosMaxProcessTime)
|
||||
@@ -315,7 +328,9 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
pipenet.Update();
|
||||
|
||||
if (number++ < LagCheckIterations) continue;
|
||||
if (number++ < LagCheckIterations)
|
||||
continue;
|
||||
|
||||
number = 0;
|
||||
// Process the rest next time.
|
||||
if (_simulationStopwatch.Elapsed.TotalMilliseconds >= AtmosMaxProcessTime)
|
||||
@@ -346,17 +361,19 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
private bool ProcessAtmosDevices(GridAtmosphereComponent atmosphere)
|
||||
{
|
||||
if(!atmosphere.ProcessingPaused)
|
||||
atmosphere.CurrentRunAtmosDevices = new Queue<AtmosDeviceComponent>(atmosphere.AtmosDevices);
|
||||
if (!atmosphere.ProcessingPaused)
|
||||
atmosphere.CurrentRunAtmosDevices = new Queue<Entity<AtmosDeviceComponent>>(atmosphere.AtmosDevices);
|
||||
|
||||
var time = _gameTiming.CurTime;
|
||||
var number = 0;
|
||||
while (atmosphere.CurrentRunAtmosDevices.TryDequeue(out var device))
|
||||
{
|
||||
RaiseLocalEvent(device.Owner, new AtmosDeviceUpdateEvent(RealAtmosTime()), false);
|
||||
device.LastProcess = time;
|
||||
RaiseLocalEvent(device, new AtmosDeviceUpdateEvent(RealAtmosTime()));
|
||||
device.Comp.LastProcess = time;
|
||||
|
||||
if (number++ < LagCheckIterations)
|
||||
continue;
|
||||
|
||||
if (number++ < LagCheckIterations) continue;
|
||||
number = 0;
|
||||
// Process the rest next time.
|
||||
if (_simulationStopwatch.Elapsed.TotalMilliseconds >= AtmosMaxProcessTime)
|
||||
@@ -376,7 +393,12 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
_currentRunAtmosphereIndex = 0;
|
||||
_currentRunAtmosphere.Clear();
|
||||
_currentRunAtmosphere.AddRange(EntityManager.EntityQuery<GridAtmosphereComponent>());
|
||||
|
||||
var query = EntityQueryEnumerator<GridAtmosphereComponent>();
|
||||
while (query.MoveNext(out var uid, out var grid))
|
||||
{
|
||||
_currentRunAtmosphere.Add((uid, grid));
|
||||
}
|
||||
}
|
||||
|
||||
// We set this to true just in case we have to stop processing due to time constraints.
|
||||
@@ -384,10 +406,11 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
for (; _currentRunAtmosphereIndex < _currentRunAtmosphere.Count; _currentRunAtmosphereIndex++)
|
||||
{
|
||||
var atmosphere = _currentRunAtmosphere[_currentRunAtmosphereIndex];
|
||||
TryComp(atmosphere.Owner, out GasTileOverlayComponent? visuals);
|
||||
var ent = _currentRunAtmosphere[_currentRunAtmosphereIndex];
|
||||
var (owner, atmosphere) = ent;
|
||||
TryComp(owner, out GasTileOverlayComponent? visuals);
|
||||
|
||||
if (atmosphere.LifeStage >= ComponentLifeStage.Stopping || Paused(atmosphere.Owner) || !atmosphere.Simulated)
|
||||
if (atmosphere.LifeStage >= ComponentLifeStage.Stopping || Paused(owner) || !atmosphere.Simulated)
|
||||
continue;
|
||||
|
||||
atmosphere.Timer += frameTime;
|
||||
@@ -401,7 +424,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
switch (atmosphere.State)
|
||||
{
|
||||
case AtmosphereProcessingState.Revalidate:
|
||||
if (!ProcessRevalidate(atmosphere, visuals))
|
||||
if (!ProcessRevalidate(ent, visuals))
|
||||
{
|
||||
atmosphere.ProcessingPaused = true;
|
||||
return;
|
||||
@@ -416,7 +439,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
: AtmosphereProcessingState.ActiveTiles;
|
||||
continue;
|
||||
case AtmosphereProcessingState.TileEqualize:
|
||||
if (!ProcessTileEqualize(atmosphere, visuals))
|
||||
if (!ProcessTileEqualize(ent, visuals))
|
||||
{
|
||||
atmosphere.ProcessingPaused = true;
|
||||
return;
|
||||
@@ -447,7 +470,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
atmosphere.State = AtmosphereProcessingState.HighPressureDelta;
|
||||
continue;
|
||||
case AtmosphereProcessingState.HighPressureDelta:
|
||||
if (!ProcessHighPressureDelta(atmosphere))
|
||||
if (!ProcessHighPressureDelta(ent))
|
||||
{
|
||||
atmosphere.ProcessingPaused = true;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user