Content update for NetEntities (#18935)
This commit is contained in:
@@ -15,7 +15,6 @@ using Robust.Server.Player;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Threading;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -36,15 +35,15 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
[Robust.Shared.IoC.Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||
[Robust.Shared.IoC.Dependency] private readonly ChunkingSystem _chunkingSys = default!;
|
||||
|
||||
private readonly Dictionary<IPlayerSession, Dictionary<EntityUid, HashSet<Vector2i>>> _lastSentChunks = new();
|
||||
private readonly Dictionary<IPlayerSession, Dictionary<NetEntity, HashSet<Vector2i>>> _lastSentChunks = new();
|
||||
|
||||
// Oh look its more duplicated decal system code!
|
||||
private ObjectPool<HashSet<Vector2i>> _chunkIndexPool =
|
||||
new DefaultObjectPool<HashSet<Vector2i>>(
|
||||
new DefaultPooledObjectPolicy<HashSet<Vector2i>>(), 64);
|
||||
private ObjectPool<Dictionary<EntityUid, HashSet<Vector2i>>> _chunkViewerPool =
|
||||
new DefaultObjectPool<Dictionary<EntityUid, HashSet<Vector2i>>>(
|
||||
new DefaultPooledObjectPolicy<Dictionary<EntityUid, HashSet<Vector2i>>>(), 64);
|
||||
private ObjectPool<Dictionary<NetEntity, HashSet<Vector2i>>> _chunkViewerPool =
|
||||
new DefaultObjectPool<Dictionary<NetEntity, HashSet<Vector2i>>>(
|
||||
new DefaultPooledObjectPolicy<Dictionary<NetEntity, HashSet<Vector2i>>>(), 64);
|
||||
|
||||
/// <summary>
|
||||
/// Overlay update interval, in seconds.
|
||||
@@ -294,22 +293,21 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
private void UpdatePlayer(IPlayerSession playerSession, GameTick curTick)
|
||||
{
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var chunksInRange = _chunkingSys.GetChunksForSession(playerSession, ChunkSize, xformQuery, _chunkIndexPool, _chunkViewerPool);
|
||||
var chunksInRange = _chunkingSys.GetChunksForSession(playerSession, ChunkSize, _chunkIndexPool, _chunkViewerPool);
|
||||
var previouslySent = _lastSentChunks[playerSession];
|
||||
|
||||
var ev = new GasOverlayUpdateEvent();
|
||||
|
||||
foreach (var (grid, oldIndices) in previouslySent)
|
||||
foreach (var (netGrid, oldIndices) in previouslySent)
|
||||
{
|
||||
// Mark the whole grid as stale and flag for removal.
|
||||
if (!chunksInRange.TryGetValue(grid, out var chunks))
|
||||
if (!chunksInRange.TryGetValue(netGrid, out var chunks))
|
||||
{
|
||||
previouslySent.Remove(grid);
|
||||
previouslySent.Remove(netGrid);
|
||||
|
||||
// If grid was deleted then don't worry about sending it to the client.
|
||||
if (_mapManager.IsGrid(grid))
|
||||
ev.RemovedChunks[grid] = oldIndices;
|
||||
if (!TryGetEntity(netGrid, out var gridId) || !_mapManager.IsGrid(gridId.Value))
|
||||
ev.RemovedChunks[netGrid] = oldIndices;
|
||||
else
|
||||
{
|
||||
oldIndices.Clear();
|
||||
@@ -330,19 +328,19 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
if (old.Count == 0)
|
||||
_chunkIndexPool.Return(old);
|
||||
else
|
||||
ev.RemovedChunks.Add(grid, old);
|
||||
ev.RemovedChunks.Add(netGrid, old);
|
||||
}
|
||||
|
||||
foreach (var (grid, gridChunks) in chunksInRange)
|
||||
foreach (var (netGrid, gridChunks) in chunksInRange)
|
||||
{
|
||||
// Not all grids have atmospheres.
|
||||
if (!TryComp(grid, out GasTileOverlayComponent? overlay))
|
||||
if (!TryGetEntity(netGrid, out var grid) || !TryComp(grid, out GasTileOverlayComponent? overlay))
|
||||
continue;
|
||||
|
||||
List<GasOverlayChunk> dataToSend = new();
|
||||
ev.UpdatedChunks[grid] = dataToSend;
|
||||
ev.UpdatedChunks[netGrid] = dataToSend;
|
||||
|
||||
previouslySent.TryGetValue(grid, out var previousChunks);
|
||||
previouslySent.TryGetValue(netGrid, out var previousChunks);
|
||||
|
||||
foreach (var index in gridChunks)
|
||||
{
|
||||
@@ -359,7 +357,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
dataToSend.Add(value);
|
||||
}
|
||||
|
||||
previouslySent[grid] = gridChunks;
|
||||
previouslySent[netGrid] = gridChunks;
|
||||
if (previousChunks != null)
|
||||
{
|
||||
previousChunks.Clear();
|
||||
|
||||
Reference in New Issue
Block a user