Skip to content

Commit

Permalink
Add lastTileModifiedTick to MapGridComponentDeltaState
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr committed May 25, 2024
1 parent 5da7eaf commit 615e106
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Robust.Shared/GameObjects/Systems/SharedMapSystem.Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ private void OnGridHandleState(EntityUid uid, MapGridComponent component, ref Co
ApplyChunkData(uid, component, chunkData, modifiedChunks);
}

component.LastTileModifiedTick = delta.LastTileModifiedTick;
break;
}
case MapGridComponentState state:
Expand Down Expand Up @@ -419,7 +420,7 @@ private void OnGridGetState(EntityUid uid, MapGridComponent component, ref Compo
}
}

args.State = new MapGridComponentDeltaState(component.ChunkSize, chunkData);
args.State = new MapGridComponentDeltaState(component.ChunkSize, chunkData, component.LastTileModifiedTick);

#if DEBUG
if (chunkData == null)
Expand Down
13 changes: 10 additions & 3 deletions Robust.Shared/Map/Components/MapGridComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ internal sealed class MapGridComponentState(ushort chunkSize, Dictionary<Vector2
/// Networked chunk data containing the full grid state.
/// </summary>
public Dictionary<Vector2i, Tile[]> FullGridData = fullGridData;

/// <summary>
/// Last game tick that the tile on the grid was modified.
/// </summary>
Expand All @@ -357,7 +357,7 @@ internal sealed class MapGridComponentState(ushort chunkSize, Dictionary<Vector2
/// Serialized state of a <see cref="MapGridComponentState"/>.
/// </summary>
[Serializable, NetSerializable]
internal sealed class MapGridComponentDeltaState(ushort chunkSize, List<ChunkDatum>? chunkData)
internal sealed class MapGridComponentDeltaState(ushort chunkSize, List<ChunkDatum>? chunkData, GameTick lastTileModifiedTick)
: ComponentState, IComponentDeltaState<MapGridComponentState>
{
/// <summary>
Expand All @@ -370,6 +370,11 @@ internal sealed class MapGridComponentDeltaState(ushort chunkSize, List<ChunkDat
/// </summary>
public readonly List<ChunkDatum>? ChunkData = chunkData;

/// <summary>
/// Last game tick that the tile on the grid was modified.
/// </summary>
public GameTick LastTileModifiedTick = lastTileModifiedTick;

public void ApplyToFullState(MapGridComponentState state)
{
state.ChunkSize = ChunkSize;
Expand All @@ -384,6 +389,8 @@ public void ApplyToFullState(MapGridComponentState state)
else
state.FullGridData![data.Index] = data.TileData;
}

state.LastTileModifiedTick = LastTileModifiedTick;
}

public MapGridComponentState CreateNewFullState(MapGridComponentState state)
Expand All @@ -396,7 +403,7 @@ public MapGridComponentState CreateNewFullState(MapGridComponentState state)
Array.Copy(value, arr, value.Length);
}

var newState = new MapGridComponentState(ChunkSize, fullGridData, state.LastTileModifiedTick);
var newState = new MapGridComponentState(ChunkSize, fullGridData, LastTileModifiedTick);
ApplyToFullState(newState);
return newState;
}
Expand Down

0 comments on commit 615e106

Please sign in to comment.