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

@@ -24,29 +24,27 @@ namespace Content.Server.Atmos.Commands
return;
}
var entMan = IoCManager.Resolve<IEntityManager>();
if (!EntityUid.TryParse(args[0], out var euid))
if (!NetEntity.TryParse(args[0], out var eNet) || !_entities.TryGetEntity(eNet, out var euid))
{
shell.WriteError($"Failed to parse euid '{args[0]}'.");
return;
}
if (!entMan.HasComponent<MapGridComponent>(euid))
if (!_entities.HasComponent<MapGridComponent>(euid))
{
shell.WriteError($"Euid '{euid}' does not exist or is not a grid.");
return;
}
var atmos = entMan.EntitySysManager.GetEntitySystem<AtmosphereSystem>();
var atmos = _entities.EntitySysManager.GetEntitySystem<AtmosphereSystem>();
if (atmos.HasAtmosphere(euid))
if (atmos.HasAtmosphere(euid.Value))
{
shell.WriteLine("Grid already has an atmosphere.");
return;
}
_entities.AddComponent<GridAtmosphereComponent>(euid);
_entities.AddComponent<GridAtmosphereComponent>(euid.Value);
shell.WriteLine($"Added atmosphere to grid {euid}.");
}

View File

@@ -11,28 +11,34 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class AddGasCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
public string Command => "addgas";
public string Description => "Adds gas at a certain position.";
public string Help => "addgas <X> <Y> <GridEid> <Gas> <moles>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 5) return;
if (args.Length < 5)
return;
if(!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !EntityUid.TryParse(args[2], out var euid)
|| !(AtmosCommandUtils.TryParseGasID(args[3], out var gasId))
|| !float.TryParse(args[4], out var moles)) return;
if (!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !NetEntity.TryParse(args[2], out var netEnt)
|| !_entManager.TryGetEntity(netEnt, out var euid)
|| !(AtmosCommandUtils.TryParseGasID(args[3], out var gasId))
|| !float.TryParse(args[4], out var moles))
{
return;
}
var entMan = IoCManager.Resolve<IEntityManager>();
if (!entMan.HasComponent<MapGridComponent>(euid))
if (!_entManager.HasComponent<MapGridComponent>(euid))
{
shell.WriteError($"Euid '{euid}' does not exist or is not a grid.");
return;
}
var atmosphereSystem = entMan.EntitySysManager.GetEntitySystem<AtmosphereSystem>();
var atmosphereSystem = _entManager.EntitySysManager.GetEntitySystem<AtmosphereSystem>();
var indices = new Vector2i(x, y);
var tile = atmosphereSystem.GetTileMixture(euid, null, indices, true);

View File

@@ -11,6 +11,9 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class DeleteGasCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
public string Command => "deletegas";
public string Description => "Removes all gases from a grid, or just of one type if specified.";
public string Help => $"Usage: {Command} <GridId> <Gas> / {Command} <GridId> / {Command} <Gas> / {Command}";
@@ -21,8 +24,6 @@ namespace Content.Server.Atmos.Commands
EntityUid? gridId;
Gas? gas = null;
var entMan = IoCManager.Resolve<IEntityManager>();
switch (args.Length)
{
case 0:
@@ -39,7 +40,7 @@ namespace Content.Server.Atmos.Commands
return;
}
gridId = entMan.GetComponent<TransformComponent>(playerEntity).GridUid;
gridId = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid;
if (gridId == null)
{
@@ -51,7 +52,7 @@ namespace Content.Server.Atmos.Commands
}
case 1:
{
if (!EntityUid.TryParse(args[0], out var number))
if (!NetEntity.TryParse(args[0], out var numberEnt) || !_entManager.TryGetEntity(numberEnt, out var number))
{
// Argument is a gas
if (player == null)
@@ -66,7 +67,7 @@ namespace Content.Server.Atmos.Commands
return;
}
gridId = entMan.GetComponent<TransformComponent>(playerEntity).GridUid;
gridId = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid;
if (gridId == null)
{
@@ -90,7 +91,7 @@ namespace Content.Server.Atmos.Commands
}
case 2:
{
if (!EntityUid.TryParse(args[0], out var first))
if (!NetEntity.TryParse(args[0], out var firstNet) || !_entManager.TryGetEntity(firstNet, out var first))
{
shell.WriteLine($"{args[0]} is not a valid integer for a grid id.");
return;
@@ -119,15 +120,13 @@ namespace Content.Server.Atmos.Commands
return;
}
var mapManager = IoCManager.Resolve<IMapManager>();
if (!mapManager.TryGetGrid(gridId, out _))
if (!_mapManager.TryGetGrid(gridId, out _))
{
shell.WriteLine($"No grid exists with id {gridId}");
return;
}
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var atmosphereSystem = _entManager.System<AtmosphereSystem>();
var tiles = 0;
var moles = 0f;
@@ -136,7 +135,8 @@ namespace Content.Server.Atmos.Commands
{
foreach (var tile in atmosphereSystem.GetAllMixtures(gridId.Value, true))
{
if (tile.Immutable) continue;
if (tile.Immutable)
continue;
tiles++;
moles += tile.TotalMoles;
@@ -148,7 +148,8 @@ namespace Content.Server.Atmos.Commands
{
foreach (var tile in atmosphereSystem.GetAllMixtures(gridId.Value, true))
{
if (tile.Immutable) continue;
if (tile.Immutable)
continue;
tiles++;
moles += tile.TotalMoles;

View File

@@ -10,26 +10,33 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class FillGas : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
public string Command => "fillgas";
public string Description => "Adds gas to all tiles in a grid.";
public string Help => "fillgas <GridEid> <Gas> <moles>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 3) return;
if(!EntityUid.TryParse(args[0], out var gridId)
|| !(AtmosCommandUtils.TryParseGasID(args[1], out var gasId))
|| !float.TryParse(args[2], out var moles)) return;
if (args.Length < 3)
return;
var mapMan = IoCManager.Resolve<IMapManager>();
if (!NetEntity.TryParse(args[0], out var gridIdNet)
|| !_entManager.TryGetEntity(gridIdNet, out var gridId)
|| !(AtmosCommandUtils.TryParseGasID(args[1], out var gasId))
|| !float.TryParse(args[2], out var moles))
{
return;
}
if (!mapMan.TryGetGrid(gridId, out var grid))
if (!_mapManager.TryGetGrid(gridId, out var grid))
{
shell.WriteLine("Invalid grid ID.");
return;
}
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var atmosphereSystem = _entManager.System<AtmosphereSystem>();
foreach (var tile in atmosphereSystem.GetAllMixtures(grid.Owner, true))
{

View File

@@ -9,20 +9,28 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class RemoveGasCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
public string Command => "removegas";
public string Description => "Removes an amount of gases.";
public string Help => "removegas <X> <Y> <GridId> <amount> <ratio>\nIf <ratio> is true, amount will be treated as the ratio of gas to be removed.";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 5) return;
if(!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !EntityUid.TryParse(args[2], out var id)
|| !float.TryParse(args[3], out var amount)
|| !bool.TryParse(args[4], out var ratio)) return;
if (args.Length < 5)
return;
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
if (!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !NetEntity.TryParse(args[2], out var idNet)
|| !_entManager.TryGetEntity(idNet, out var id)
|| !float.TryParse(args[3], out var amount)
|| !bool.TryParse(args[4], out var ratio))
{
return;
}
var atmosphereSystem = _entManager.System<AtmosphereSystem>();
var indices = new Vector2i(x, y);
var tile = atmosphereSystem.GetTileMixture(id, null, indices, true);

View File

@@ -10,17 +10,23 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class SetAtmosTemperatureCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
public string Command => "setatmostemp";
public string Description => "Sets a grid's temperature (in kelvin).";
public string Help => "Usage: setatmostemp <GridId> <Temperature>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 2) return;
if(!EntityUid.TryParse(args[0], out var gridId)
|| !float.TryParse(args[1], out var temperature)) return;
if (args.Length < 2)
return;
var mapMan = IoCManager.Resolve<IMapManager>();
if (!_entManager.TryParseNetEntity(args[0], out var gridId)
|| !float.TryParse(args[1], out var temperature))
{
return;
}
if (temperature < Atmospherics.TCMB)
{
@@ -28,13 +34,13 @@ namespace Content.Server.Atmos.Commands
return;
}
if (!gridId.IsValid() || !mapMan.TryGetGrid(gridId, out var gridComp))
if (!gridId.Value.IsValid() || !_mapManager.TryGetGrid(gridId, out var gridComp))
{
shell.WriteLine("Invalid grid ID.");
return;
}
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var atmosphereSystem = _entManager.System<AtmosphereSystem>();
var tiles = 0;
foreach (var tile in atmosphereSystem.GetAllMixtures(gridComp.Owner, true))

View File

@@ -22,11 +22,17 @@ namespace Content.Server.Atmos.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 4) return;
if(!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !EntityUid.TryParse(args[2], out var gridId)
|| !float.TryParse(args[3], out var temperature)) return;
if (args.Length < 4)
return;
if (!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !NetEntity.TryParse(args[2], out var gridIdNet)
|| !_entities.TryGetEntity(gridIdNet, out var gridId)
|| !float.TryParse(args[3], out var temperature))
{
return;
}
if (temperature < Atmospherics.TCMB)
{

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