removes beforeserialization hook (#12319)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Atmos.Piping.Components;
|
||||
using Content.Server.Atmos.Serialization;
|
||||
using Content.Server.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.Atmos.Components
|
||||
{
|
||||
@@ -10,7 +10,7 @@ namespace Content.Server.Atmos.Components
|
||||
/// </summary>
|
||||
[RegisterComponent, Serializable,
|
||||
Access(typeof(AtmosphereSystem), typeof(GasTileOverlaySystem), typeof(AtmosDebugOverlaySystem))]
|
||||
public sealed class GridAtmosphereComponent : Component, ISerializationHooks
|
||||
public sealed class GridAtmosphereComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Simulated { get; set; } = true;
|
||||
@@ -24,13 +24,8 @@ namespace Content.Server.Atmos.Components
|
||||
[ViewVariables]
|
||||
public int UpdateCounter { get; set; } = 1; // DO NOT SET TO ZERO BY DEFAULT! It will break roundstart atmos...
|
||||
|
||||
[DataField("uniqueMixes")]
|
||||
public List<GasMixture>? UniqueMixes;
|
||||
|
||||
[DataField("tiles")]
|
||||
public Dictionary<Vector2i, int>? TilesUniqueMixes;
|
||||
|
||||
[ViewVariables]
|
||||
[IncludeDataField(customTypeSerializer:typeof(TileAtmosCollectionSerializer))]
|
||||
public readonly Dictionary<Vector2i, TileAtmosphere> Tiles = new(1000);
|
||||
|
||||
[ViewVariables]
|
||||
@@ -95,34 +90,5 @@ namespace Content.Server.Atmos.Components
|
||||
|
||||
[ViewVariables]
|
||||
public AtmosphereProcessingState State { get; set; } = AtmosphereProcessingState.Revalidate;
|
||||
|
||||
void ISerializationHooks.BeforeSerialization()
|
||||
{
|
||||
var uniqueMixes = new List<GasMixture>();
|
||||
var uniqueMixHash = new Dictionary<GasMixture, int>();
|
||||
var tiles = new Dictionary<Vector2i, int>();
|
||||
|
||||
foreach (var (indices, tile) in Tiles)
|
||||
{
|
||||
if (tile.Air == null) continue;
|
||||
|
||||
if (uniqueMixHash.TryGetValue(tile.Air, out var index))
|
||||
{
|
||||
tiles[indices] = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
uniqueMixes.Add(tile.Air);
|
||||
var newIndex = uniqueMixes.Count - 1;
|
||||
uniqueMixHash[tile.Air] = newIndex;
|
||||
tiles[indices] = newIndex;
|
||||
}
|
||||
|
||||
if (uniqueMixes.Count == 0) uniqueMixes = null;
|
||||
if (tiles.Count == 0) tiles = null;
|
||||
|
||||
UniqueMixes = uniqueMixes;
|
||||
TilesUniqueMixes = tiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ using System.Linq;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.Reactions;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -44,29 +43,13 @@ public sealed partial class AtmosphereSystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
gridAtmosphere.Tiles.Clear();
|
||||
|
||||
if (!TryComp(uid, out IMapGridComponent? mapGrid))
|
||||
return;
|
||||
|
||||
if (gridAtmosphere.TilesUniqueMixes != null)
|
||||
foreach (var (indices, tile) in gridAtmosphere.Tiles)
|
||||
{
|
||||
foreach (var (indices, mix) in gridAtmosphere.TilesUniqueMixes)
|
||||
{
|
||||
try
|
||||
{
|
||||
gridAtmosphere.Tiles.Add(indices, new TileAtmosphere(mapGrid.Owner, indices,
|
||||
gridAtmosphere.UniqueMixes![mix].Clone()));
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
Logger.Error(
|
||||
$"Error during atmos serialization! Tile at {indices} points to an unique mix ({mix}) out of range!");
|
||||
throw;
|
||||
}
|
||||
|
||||
gridAtmosphere.InvalidatedCoords.Add(indices);
|
||||
}
|
||||
gridAtmosphere.InvalidatedCoords.Add(indices);
|
||||
tile.GridIndex = uid;
|
||||
}
|
||||
|
||||
GridRepopulateTiles(mapGrid.Grid, gridAtmosphere);
|
||||
@@ -334,7 +317,7 @@ public sealed partial class AtmosphereSystem
|
||||
{
|
||||
adjacent = new TileAtmosphere(tile.GridIndex, otherIndices,
|
||||
GetTileMixture(null, mapUid, otherIndices),
|
||||
space:IsTileSpace(null, mapUid, otherIndices, mapGridComp));
|
||||
space: IsTileSpace(null, mapUid, otherIndices, mapGridComp));
|
||||
}
|
||||
|
||||
var oppositeDirection = direction.GetOpposite();
|
||||
@@ -531,7 +514,7 @@ public sealed partial class AtmosphereSystem
|
||||
{
|
||||
if (!gridAtmosphere.Tiles.ContainsKey(tile.GridIndices))
|
||||
gridAtmosphere.Tiles[tile.GridIndices] = new TileAtmosphere(tile.GridUid, tile.GridIndices,
|
||||
new GasMixture(volume) {Temperature = Atmospherics.T20C});
|
||||
new GasMixture(volume) { Temperature = Atmospherics.T20C });
|
||||
|
||||
gridAtmosphere.InvalidatedCoords.Add(tile.GridIndices);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using Content.Server.Atmos.Piping.Components;
|
||||
using Content.Server.NodeContainer.NodeGroups;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -59,7 +58,8 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
if (!atmosphere.Tiles.TryGetValue(indices, out var tile))
|
||||
{
|
||||
tile = new TileAtmosphere(mapGrid.GridEntityId, indices, new GasMixture(volume){Temperature = Atmospherics.T20C});
|
||||
tile = new TileAtmosphere(mapGrid.GridEntityId, indices,
|
||||
new GasMixture(volume) { Temperature = Atmospherics.T20C });
|
||||
atmosphere.Tiles[indices] = tile;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
using Robust.Shared.Serialization.Markdown.Validation;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
|
||||
|
||||
namespace Content.Server.Atmos.Serialization;
|
||||
|
||||
public sealed class TileAtmosCollectionSerializer : ITypeSerializer<Dictionary<Vector2i, TileAtmosphere>, MappingDataNode>
|
||||
{
|
||||
public ValidationNode Validate(ISerializationManager serializationManager, MappingDataNode node,
|
||||
IDependencyCollection dependencies, ISerializationContext? context = null)
|
||||
{
|
||||
return serializationManager.ValidateNode<TileAtmosData>(node, context);
|
||||
}
|
||||
|
||||
public Dictionary<Vector2i, TileAtmosphere> Read(ISerializationManager serializationManager, MappingDataNode node, IDependencyCollection dependencies,
|
||||
bool skipHook, ISerializationContext? context = null, Dictionary<Vector2i, TileAtmosphere>? value = default)
|
||||
{
|
||||
var data = serializationManager.Read<TileAtmosData>(node, context, skipHook);
|
||||
var tiles = new Dictionary<Vector2i, TileAtmosphere>();
|
||||
if (data.TilesUniqueMixes != null)
|
||||
{
|
||||
foreach (var (indices, mix) in data.TilesUniqueMixes)
|
||||
{
|
||||
try
|
||||
{
|
||||
tiles.Add(indices, new TileAtmosphere(EntityUid.Invalid, indices,
|
||||
data.UniqueMixes![mix].Clone()));
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
Logger.Error(
|
||||
$"Error during atmos serialization! Tile at {indices} points to an unique mix ({mix}) out of range!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
public DataNode Write(ISerializationManager serializationManager, Dictionary<Vector2i, TileAtmosphere> value, IDependencyCollection dependencies,
|
||||
bool alwaysWrite = false, ISerializationContext? context = null)
|
||||
{
|
||||
var uniqueMixes = new List<GasMixture>();
|
||||
var uniqueMixHash = new Dictionary<GasMixture, int>();
|
||||
var tiles = new Dictionary<Vector2i, int>();
|
||||
|
||||
foreach (var (indices, tile) in value)
|
||||
{
|
||||
if (tile.Air == null) continue;
|
||||
|
||||
if (uniqueMixHash.TryGetValue(tile.Air, out var index))
|
||||
{
|
||||
tiles[indices] = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
uniqueMixes.Add(tile.Air);
|
||||
var newIndex = uniqueMixes.Count - 1;
|
||||
uniqueMixHash[tile.Air] = newIndex;
|
||||
tiles[indices] = newIndex;
|
||||
}
|
||||
|
||||
if (uniqueMixes.Count == 0) uniqueMixes = null;
|
||||
if (tiles.Count == 0) tiles = null;
|
||||
|
||||
return serializationManager.WriteValue(new TileAtmosData
|
||||
{
|
||||
UniqueMixes = uniqueMixes,
|
||||
TilesUniqueMixes = tiles
|
||||
}, alwaysWrite, context);
|
||||
}
|
||||
|
||||
public Dictionary<Vector2i, TileAtmosphere> Copy(ISerializationManager serializationManager, Dictionary<Vector2i, TileAtmosphere> source, Dictionary<Vector2i, TileAtmosphere> target, bool skipHook,
|
||||
ISerializationContext? context = null)
|
||||
{
|
||||
serializationManager.Copy(source, ref target, context, skipHook);
|
||||
return target;
|
||||
}
|
||||
|
||||
[DataDefinition]
|
||||
private struct TileAtmosData
|
||||
{
|
||||
[DataField("uniqueMixes")] public List<GasMixture>? UniqueMixes;
|
||||
|
||||
[DataField("tiles")] public Dictionary<Vector2i, int>? TilesUniqueMixes;
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,8 @@ namespace Content.Server.Atmos
|
||||
public AtmosDirection LastPressureDirection;
|
||||
|
||||
[ViewVariables]
|
||||
public EntityUid GridIndex { get; }
|
||||
[Access(typeof(AtmosphereSystem))]
|
||||
public EntityUid GridIndex { get; set; }
|
||||
|
||||
[ViewVariables]
|
||||
public TileRef? Tile => GridIndices.GetTileRef(GridIndex);
|
||||
|
||||
Reference in New Issue
Block a user