Content update for NetEntities (#18935)

This commit is contained in:
metalgearsloth
2023-09-11 09:42:41 +10:00
committed by GitHub
parent 389c8d1a2c
commit 5a0fc68be2
526 changed files with 3058 additions and 2215 deletions

View File

@@ -161,7 +161,7 @@ namespace Content.Server.Atmos.EntitySystems
}
}
RaiseNetworkEvent(new AtmosDebugOverlayMessage(grid.Owner, baseTile, debugOverlayContent), session.ConnectedClient);
RaiseNetworkEvent(new AtmosDebugOverlayMessage(GetNetEntity(grid.Owner), baseTile, debugOverlayContent), session.ConnectedClient);
}
}
}

View File

@@ -67,7 +67,7 @@ public sealed partial class AtmosphereSystem
foreach (var arg in args)
{
if(!EntityUid.TryParse(arg, out var euid))
if (!NetEntity.TryParse(arg, out var netEntity) || !TryGetEntity(netEntity, out var euid))
{
shell.WriteError($"Failed to parse euid '{arg}'.");
return;
@@ -85,7 +85,7 @@ public sealed partial class AtmosphereSystem
continue;
}
var transform = Transform(euid);
var transform = Transform(euid.Value);
foreach (var (indices, tileMain) in gridAtmosphere.Tiles)
{

View File

@@ -229,7 +229,7 @@ namespace Content.Server.Atmos.EntitySystems
_userInterface.TrySendUiMessage(uid, GasAnalyzerUiKey.Key,
new GasAnalyzerUserMessage(gasMixList.ToArray(),
component.Target != null ? Name(component.Target.Value) : string.Empty,
component.Target ?? EntityUid.Invalid,
GetNetEntity(component.Target) ?? NetEntity.Invalid,
deviceFlipped));
return true;
}

View File

@@ -77,7 +77,6 @@ namespace Content.Server.Atmos.EntitySystems
public void UpdateUserInterface(GasTankComponent component, bool initialUpdate = false)
{
var internals = GetInternalsComponent(component);
_ui.TrySetUiState(component.Owner, SharedGasTankUiKey.Key,
new GasTankBoundUserInterfaceState
{

View File

@@ -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();