Partial atmos refactor (#22521)
* Reduce atmos component queries * Remove method events * Cache airtight data * Make MolesArchived nullable * Fix airtight cache * only get tile def once * Immutable mixtures * firelock queries * misc * misc cleanup * Trim disconnected tiles * Fix merge issues and bugs * Why does the PR keep increasing in scope * debug overlay * Fix bugs * Fix test, remove unused events * Add setmapatmos command * Fix overlays * Add map check * A * Resolve conflicts with #26102 * Remove some obsolete methods
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Shared.Atmos.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Atmos.EntitySystems;
|
||||
|
||||
@@ -8,10 +10,25 @@ public partial class AtmosphereSystem
|
||||
{
|
||||
private void InitializeMap()
|
||||
{
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, ComponentInit>(OnMapStartup);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, ComponentRemove>(OnMapRemove);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, IsTileSpaceMethodEvent>(MapIsTileSpace);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, GetTileMixtureMethodEvent>(MapGetTileMixture);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, GetTileMixturesMethodEvent>(MapGetTileMixtures);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, ComponentGetState>(OnMapGetState);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, EntParentChangedMessage>(OnGridParentChanged);
|
||||
}
|
||||
|
||||
private void OnMapStartup(EntityUid uid, MapAtmosphereComponent component, ComponentInit args)
|
||||
{
|
||||
component.Mixture.MarkImmutable();
|
||||
component.Overlay = _gasTileOverlaySystem.GetOverlayData(component.Mixture);
|
||||
}
|
||||
|
||||
private void OnMapRemove(EntityUid uid, MapAtmosphereComponent component, ComponentRemove args)
|
||||
{
|
||||
if (!TerminatingOrDeleted(uid))
|
||||
RefreshAllGridMapAtmospheres(uid);
|
||||
}
|
||||
|
||||
private void MapIsTileSpace(EntityUid uid, MapAtmosphereComponent component, ref IsTileSpaceMethodEvent args)
|
||||
@@ -28,54 +45,115 @@ public partial class AtmosphereSystem
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
// Clone the mixture, if possible.
|
||||
args.Mixture = component.Mixture?.Clone();
|
||||
args.Mixture = component.Mixture;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void MapGetTileMixtures(EntityUid uid, MapAtmosphereComponent component, ref GetTileMixturesMethodEvent args)
|
||||
{
|
||||
if (args.Handled || component.Mixture == null)
|
||||
if (args.Handled)
|
||||
return;
|
||||
args.Handled = true;
|
||||
args.Mixtures ??= new GasMixture?[args.Tiles.Count];
|
||||
|
||||
for (var i = 0; i < args.Tiles.Count; i++)
|
||||
{
|
||||
args.Mixtures[i] ??= component.Mixture.Clone();
|
||||
args.Mixtures[i] ??= component.Mixture;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMapGetState(EntityUid uid, MapAtmosphereComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new MapAtmosphereComponentState(_gasTileOverlaySystem.GetOverlayData(component.Mixture));
|
||||
args.State = new MapAtmosphereComponentState(component.Overlay);
|
||||
}
|
||||
|
||||
public void SetMapAtmosphere(EntityUid uid, bool space, GasMixture mixture, MapAtmosphereComponent? component = null)
|
||||
public void SetMapAtmosphere(EntityUid uid, bool space, GasMixture mixture)
|
||||
{
|
||||
DebugTools.Assert(HasComp<MapComponent>(uid));
|
||||
var component = EnsureComp<MapAtmosphereComponent>(uid);
|
||||
SetMapGasMixture(uid, mixture, component, false);
|
||||
SetMapSpace(uid, space, component, false);
|
||||
RefreshAllGridMapAtmospheres(uid);
|
||||
}
|
||||
|
||||
public void SetMapGasMixture(EntityUid uid, GasMixture mixture, MapAtmosphereComponent? component = null, bool updateTiles = true)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
if (!mixture.Immutable)
|
||||
{
|
||||
mixture = mixture.Clone();
|
||||
mixture.MarkImmutable();
|
||||
}
|
||||
|
||||
component.Mixture = mixture;
|
||||
component.Overlay = _gasTileOverlaySystem.GetOverlayData(component.Mixture);
|
||||
Dirty(uid, component);
|
||||
if (updateTiles)
|
||||
RefreshAllGridMapAtmospheres(uid);
|
||||
}
|
||||
|
||||
public void SetMapSpace(EntityUid uid, bool space, MapAtmosphereComponent? component = null, bool updateTiles = true)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
if (component.Space == space)
|
||||
return;
|
||||
|
||||
component.Space = space;
|
||||
component.Mixture = mixture;
|
||||
Dirty(uid, component);
|
||||
|
||||
if (updateTiles)
|
||||
RefreshAllGridMapAtmospheres(uid);
|
||||
}
|
||||
|
||||
public void SetMapGasMixture(EntityUid uid, GasMixture? mixture, MapAtmosphereComponent? component = null)
|
||||
/// <summary>
|
||||
/// Forces a refresh of all MapAtmosphere tiles on every grid on a map.
|
||||
/// </summary>
|
||||
public void RefreshAllGridMapAtmospheres(EntityUid map)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
component.Mixture = mixture;
|
||||
Dirty(uid, component);
|
||||
DebugTools.Assert(HasComp<MapComponent>(map));
|
||||
var enumerator = AllEntityQuery<GridAtmosphereComponent, TransformComponent>();
|
||||
while (enumerator.MoveNext(out var grid, out var atmos, out var xform))
|
||||
{
|
||||
if (xform.MapUid == map)
|
||||
RefreshMapAtmosphereTiles((grid, atmos));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMapSpace(EntityUid uid, bool space, MapAtmosphereComponent? component = null)
|
||||
/// <summary>
|
||||
/// Forces a refresh of all MapAtmosphere tiles on a given grid.
|
||||
/// </summary>
|
||||
private void RefreshMapAtmosphereTiles(Entity<GridAtmosphereComponent?> grid)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
if (!Resolve(grid.Owner, ref grid.Comp))
|
||||
return;
|
||||
|
||||
component.Space = space;
|
||||
Dirty(uid, component);
|
||||
var atmos = grid.Comp;
|
||||
foreach (var tile in atmos.MapTiles)
|
||||
{
|
||||
RemoveMapAtmos(atmos, tile);
|
||||
atmos.InvalidatedCoords.Add(tile.GridIndices);
|
||||
}
|
||||
atmos.MapTiles.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles updating map-atmospheres when grids move across maps.
|
||||
/// </summary>
|
||||
private void OnGridParentChanged(Entity<GridAtmosphereComponent> grid, ref EntParentChangedMessage args)
|
||||
{
|
||||
// Do nothing if detaching to nullspace
|
||||
if (!args.Transform.ParentUid.IsValid())
|
||||
return;
|
||||
|
||||
// Avoid doing work if moving from a space-map to another space-map.
|
||||
if (args.OldParent == null
|
||||
|| HasComp<MapAtmosphereComponent>(args.OldParent)
|
||||
|| HasComp<MapAtmosphereComponent>(args.Transform.ParentUid))
|
||||
{
|
||||
RefreshMapAtmosphereTiles((grid, grid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user