Split GasTileOverlaySystem update over two ticks (#26542)
Split GasTileOverlaySystem update over ticks
This commit is contained in:
@@ -52,6 +52,8 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
new DefaultObjectPool<Dictionary<NetEntity, HashSet<Vector2i>>>(
|
new DefaultObjectPool<Dictionary<NetEntity, HashSet<Vector2i>>>(
|
||||||
new DefaultPooledObjectPolicy<Dictionary<NetEntity, HashSet<Vector2i>>>(), 64);
|
new DefaultPooledObjectPolicy<Dictionary<NetEntity, HashSet<Vector2i>>>(), 64);
|
||||||
|
|
||||||
|
private bool _doSessionUpdate;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Overlay update interval, in seconds.
|
/// Overlay update interval, in seconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -192,7 +194,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the visuals for a tile on some grid chunk. Returns true if the visuals have changed.
|
/// Updates the visuals for a tile on some grid chunk. Returns true if the visuals have changed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool UpdateChunkTile(GridAtmosphereComponent gridAtmosphere, GasOverlayChunk chunk, Vector2i index, GameTick curTick)
|
private bool UpdateChunkTile(GridAtmosphereComponent gridAtmosphere, GasOverlayChunk chunk, Vector2i index)
|
||||||
{
|
{
|
||||||
ref var oldData = ref chunk.TileData[chunk.GetDataIndex(index)];
|
ref var oldData = ref chunk.TileData[chunk.GetDataIndex(index)];
|
||||||
if (!gridAtmosphere.Tiles.TryGetValue(index, out var tile))
|
if (!gridAtmosphere.Tiles.TryGetValue(index, out var tile))
|
||||||
@@ -200,7 +202,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
if (oldData.Equals(default))
|
if (oldData.Equals(default))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
chunk.LastUpdate = curTick;
|
chunk.LastUpdate = _gameTiming.CurTick;
|
||||||
oldData = default;
|
oldData = default;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -258,11 +260,11 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
if (!changed)
|
if (!changed)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
chunk.LastUpdate = curTick;
|
chunk.LastUpdate = _gameTiming.CurTick;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateOverlayData(GameTick curTick)
|
private void UpdateOverlayData()
|
||||||
{
|
{
|
||||||
// TODO parallelize?
|
// TODO parallelize?
|
||||||
var query = EntityQueryEnumerator<GasTileOverlayComponent, GridAtmosphereComponent, MetaDataComponent>();
|
var query = EntityQueryEnumerator<GasTileOverlayComponent, GridAtmosphereComponent, MetaDataComponent>();
|
||||||
@@ -276,7 +278,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
if (!overlay.Chunks.TryGetValue(chunkIndex, out var chunk))
|
if (!overlay.Chunks.TryGetValue(chunkIndex, out var chunk))
|
||||||
overlay.Chunks[chunkIndex] = chunk = new GasOverlayChunk(chunkIndex);
|
overlay.Chunks[chunkIndex] = chunk = new GasOverlayChunk(chunkIndex);
|
||||||
|
|
||||||
changed |= UpdateChunkTile(gam, chunk, index, curTick);
|
changed |= UpdateChunkTile(gam, chunk, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
@@ -291,13 +293,28 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
AccumulatedFrameTime += frameTime;
|
AccumulatedFrameTime += frameTime;
|
||||||
|
|
||||||
if (AccumulatedFrameTime < _updateInterval) return;
|
if (_doSessionUpdate)
|
||||||
|
{
|
||||||
|
UpdateSessions();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AccumulatedFrameTime < _updateInterval)
|
||||||
|
return;
|
||||||
|
|
||||||
AccumulatedFrameTime -= _updateInterval;
|
AccumulatedFrameTime -= _updateInterval;
|
||||||
|
|
||||||
var curTick = _gameTiming.CurTick;
|
|
||||||
|
|
||||||
// First, update per-chunk visual data for any invalidated tiles.
|
// First, update per-chunk visual data for any invalidated tiles.
|
||||||
UpdateOverlayData(curTick);
|
UpdateOverlayData();
|
||||||
|
|
||||||
|
// Then, next tick we send the data to players.
|
||||||
|
// This is to avoid doing all the work in the same tick.
|
||||||
|
_doSessionUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateSessions()
|
||||||
|
{
|
||||||
|
_doSessionUpdate = false;
|
||||||
|
|
||||||
if (!PvsEnabled)
|
if (!PvsEnabled)
|
||||||
return;
|
return;
|
||||||
@@ -315,11 +332,11 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
_sessions.Add(player);
|
_sessions.Add(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_sessions.Count > 0)
|
if (_sessions.Count == 0)
|
||||||
{
|
return;
|
||||||
_updateJob.CurrentTick = curTick;
|
|
||||||
_parMan.ProcessNow(_updateJob, _sessions.Count);
|
_parMan.ProcessNow(_updateJob, _sessions.Count);
|
||||||
}
|
_updateJob.LastSessionUpdate = _gameTiming.CurTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset(RoundRestartCleanupEvent ev)
|
public void Reset(RoundRestartCleanupEvent ev)
|
||||||
@@ -352,7 +369,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
public ObjectPool<HashSet<Vector2i>> ChunkIndexPool;
|
public ObjectPool<HashSet<Vector2i>> ChunkIndexPool;
|
||||||
public ObjectPool<Dictionary<NetEntity, HashSet<Vector2i>>> ChunkViewerPool;
|
public ObjectPool<Dictionary<NetEntity, HashSet<Vector2i>>> ChunkViewerPool;
|
||||||
|
|
||||||
public GameTick CurrentTick;
|
public GameTick LastSessionUpdate;
|
||||||
public Dictionary<ICommonSession, Dictionary<NetEntity, HashSet<Vector2i>>> LastSentChunks;
|
public Dictionary<ICommonSession, Dictionary<NetEntity, HashSet<Vector2i>>> LastSentChunks;
|
||||||
public List<ICommonSession> Sessions;
|
public List<ICommonSession> Sessions;
|
||||||
|
|
||||||
@@ -415,7 +432,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
|
|
||||||
if (previousChunks != null &&
|
if (previousChunks != null &&
|
||||||
previousChunks.Contains(gIndex) &&
|
previousChunks.Contains(gIndex) &&
|
||||||
value.LastUpdate != CurrentTick)
|
value.LastUpdate > LastSessionUpdate)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user