Content update for NetEntities (#18935)
This commit is contained in:
@@ -12,6 +12,10 @@ namespace Content.Server.Decals.Commands
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
public sealed class AddDecalCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
|
||||
public string Command => "adddecal";
|
||||
public string Description => "Creates a decal on the map";
|
||||
public string Help => $"{Command} <id> <x position> <y position> <gridId> [angle=<angle> zIndex=<zIndex> color=<color>]";
|
||||
@@ -23,7 +27,7 @@ namespace Content.Server.Decals.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IPrototypeManager>().HasIndex<DecalPrototype>(args[0]))
|
||||
if (!_protoManager.HasIndex<DecalPrototype>(args[0]))
|
||||
{
|
||||
shell.WriteError($"Cannot find decalprototype '{args[0]}'.");
|
||||
}
|
||||
@@ -40,8 +44,9 @@ namespace Content.Server.Decals.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
if (!EntityUid.TryParse(args[3], out var gridIdRaw) || !mapManager.TryGetGrid(gridIdRaw, out var grid))
|
||||
if (!NetEntity.TryParse(args[3], out var gridIdNet) ||
|
||||
!_entManager.TryGetEntity(gridIdNet, out var gridIdRaw) ||
|
||||
!_mapManager.TryGetGrid(gridIdRaw, out var grid))
|
||||
{
|
||||
shell.WriteError($"Failed parsing gridId '{args[3]}'.");
|
||||
return;
|
||||
@@ -101,7 +106,7 @@ namespace Content.Server.Decals.Commands
|
||||
}
|
||||
}
|
||||
|
||||
if(EntitySystem.Get<DecalSystem>().TryAddDecal(args[0], coordinates, out var uid, color, rotation, zIndex))
|
||||
if (_entManager.System<DecalSystem>().TryAddDecal(args[0], coordinates, out var uid, color, rotation, zIndex))
|
||||
{
|
||||
shell.WriteLine($"Successfully created decal {uid}.");
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace Content.Server.Decals;
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
public sealed class EditDecalCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public string Command => "editdecal";
|
||||
public string Description => "Edits a decal.";
|
||||
public string Help => $@"{Command} <gridId> <uid> <mode>\n
|
||||
@@ -28,7 +31,7 @@ Possible modes are:\n
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EntityUid.TryParse(args[0], out var gridId))
|
||||
if (!NetEntity.TryParse(args[0], out var gridIdNet) || !_entManager.TryGetEntity(gridIdNet, out var gridId))
|
||||
{
|
||||
shell.WriteError($"Failed parsing gridId '{args[3]}'.");
|
||||
return;
|
||||
@@ -40,13 +43,13 @@ Possible modes are:\n
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IMapManager>().GridExists(gridId))
|
||||
if (!_mapManager.GridExists(gridId))
|
||||
{
|
||||
shell.WriteError($"No grid with gridId {gridId} exists.");
|
||||
return;
|
||||
}
|
||||
|
||||
var decalSystem = EntitySystem.Get<DecalSystem>();
|
||||
var decalSystem = _entManager.System<DecalSystem>();
|
||||
switch (args[2].ToLower())
|
||||
{
|
||||
case "position":
|
||||
@@ -62,7 +65,7 @@ Possible modes are:\n
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalPosition(gridId, uid, new(gridId, new Vector2(x, y))))
|
||||
if (!decalSystem.SetDecalPosition(gridId.Value, uid, new(gridId.Value, new Vector2(x, y))))
|
||||
{
|
||||
shell.WriteError("Failed changing decalposition.");
|
||||
}
|
||||
@@ -80,7 +83,7 @@ Possible modes are:\n
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalColor(gridId, uid, color))
|
||||
if (!decalSystem.SetDecalColor(gridId.Value, uid, color))
|
||||
{
|
||||
shell.WriteError("Failed changing decal color.");
|
||||
}
|
||||
@@ -92,7 +95,7 @@ Possible modes are:\n
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalId(gridId, uid, args[3]))
|
||||
if (!decalSystem.SetDecalId(gridId.Value, uid, args[3]))
|
||||
{
|
||||
shell.WriteError("Failed changing decal id.");
|
||||
}
|
||||
@@ -110,7 +113,7 @@ Possible modes are:\n
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalRotation(gridId, uid, Angle.FromDegrees(degrees)))
|
||||
if (!decalSystem.SetDecalRotation(gridId.Value, uid, Angle.FromDegrees(degrees)))
|
||||
{
|
||||
shell.WriteError("Failed changing decal rotation.");
|
||||
}
|
||||
@@ -128,7 +131,7 @@ Possible modes are:\n
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalZIndex(gridId, uid, zIndex))
|
||||
if (!decalSystem.SetDecalZIndex(gridId.Value, uid, zIndex))
|
||||
{
|
||||
shell.WriteError("Failed changing decal zIndex.");
|
||||
}
|
||||
@@ -146,7 +149,7 @@ Possible modes are:\n
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalCleanable(gridId, uid, cleanable))
|
||||
if (!decalSystem.SetDecalCleanable(gridId.Value, uid, cleanable))
|
||||
{
|
||||
shell.WriteError("Failed changing decal cleanable flag.");
|
||||
}
|
||||
|
||||
@@ -2,12 +2,16 @@ using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Map;
|
||||
using SQLitePCL;
|
||||
|
||||
namespace Content.Server.Decals.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
public sealed class RemoveDecalCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public string Command => "rmdecal";
|
||||
public string Description => "removes a decal";
|
||||
public string Help => $"{Command} <uid> <gridId>";
|
||||
@@ -25,14 +29,16 @@ namespace Content.Server.Decals.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EntityUid.TryParse(args[1], out var rawGridId) ||
|
||||
!IoCManager.Resolve<IMapManager>().GridExists(rawGridId))
|
||||
if (!NetEntity.TryParse(args[1], out var rawGridIdNet) ||
|
||||
!_entManager.TryGetEntity(rawGridIdNet, out var rawGridId) ||
|
||||
!_mapManager.GridExists(rawGridId))
|
||||
{
|
||||
shell.WriteError("Failed parsing gridId.");
|
||||
return;
|
||||
}
|
||||
|
||||
var decalSystem = EntitySystem.Get<DecalSystem>();
|
||||
if (decalSystem.RemoveDecal(rawGridId, uid))
|
||||
var decalSystem = _entManager.System<DecalSystem>();
|
||||
if (decalSystem.RemoveDecal(rawGridId.Value, uid))
|
||||
{
|
||||
shell.WriteLine($"Successfully removed decal {uid}.");
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
@@ -14,7 +13,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;
|
||||
@@ -34,8 +32,8 @@ namespace Content.Server.Decals
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
|
||||
private readonly Dictionary<EntityUid, HashSet<Vector2i>> _dirtyChunks = new();
|
||||
private readonly Dictionary<IPlayerSession, Dictionary<EntityUid, HashSet<Vector2i>>> _previousSentChunks = new();
|
||||
private readonly Dictionary<NetEntity, HashSet<Vector2i>> _dirtyChunks = new();
|
||||
private readonly Dictionary<IPlayerSession, Dictionary<NetEntity, HashSet<Vector2i>>> _previousSentChunks = new();
|
||||
private static readonly Vector2 _boundsMinExpansion = new(0.01f, 0.01f);
|
||||
private static readonly Vector2 _boundsMaxExpansion = new(1.01f, 1.01f);
|
||||
|
||||
@@ -44,9 +42,9 @@ namespace Content.Server.Decals
|
||||
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);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -203,10 +201,12 @@ namespace Content.Server.Decals
|
||||
if (!_adminManager.HasAdminFlag(session, AdminFlags.Spawn))
|
||||
return;
|
||||
|
||||
if (!ev.Coordinates.IsValid(EntityManager))
|
||||
var coordinates = GetCoordinates(ev.Coordinates);
|
||||
|
||||
if (!coordinates.IsValid(EntityManager))
|
||||
return;
|
||||
|
||||
if (!TryAddDecal(ev.Decal, ev.Coordinates, out _))
|
||||
if (!TryAddDecal(ev.Decal, coordinates, out _))
|
||||
return;
|
||||
|
||||
if (eventArgs.SenderSession.AttachedEntity != null)
|
||||
@@ -230,10 +230,12 @@ namespace Content.Server.Decals
|
||||
if (!_adminManager.HasAdminFlag(session, AdminFlags.Spawn))
|
||||
return;
|
||||
|
||||
if (!ev.Coordinates.IsValid(EntityManager))
|
||||
var coordinates = GetCoordinates(ev.Coordinates);
|
||||
|
||||
if (!coordinates.IsValid(EntityManager))
|
||||
return;
|
||||
|
||||
var gridId = ev.Coordinates.GetGridUid(EntityManager);
|
||||
var gridId = coordinates.GetGridUid(EntityManager);
|
||||
|
||||
if (gridId == null)
|
||||
return;
|
||||
@@ -256,8 +258,9 @@ namespace Content.Server.Decals
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DirtyChunk(EntityUid id, Vector2i chunkIndices, DecalChunk chunk)
|
||||
protected override void DirtyChunk(EntityUid uid, Vector2i chunkIndices, DecalChunk chunk)
|
||||
{
|
||||
var id = GetNetEntity(uid);
|
||||
chunk.LastModified = _timing.CurTick;
|
||||
if(!_dirtyChunks.ContainsKey(id))
|
||||
_dirtyChunks[id] = new HashSet<Vector2i>();
|
||||
@@ -409,8 +412,8 @@ namespace Content.Server.Decals
|
||||
|
||||
foreach (var ent in _dirtyChunks.Keys)
|
||||
{
|
||||
if (TryComp(ent, out DecalGridComponent? decals))
|
||||
Dirty(decals);
|
||||
if (TryGetEntity(ent, out var uid) && TryComp(uid, out DecalGridComponent? decals))
|
||||
Dirty(uid.Value, decals);
|
||||
}
|
||||
|
||||
if (!PvsEnabled)
|
||||
@@ -431,8 +434,7 @@ namespace Content.Server.Decals
|
||||
|
||||
public void UpdatePlayer(IPlayerSession player)
|
||||
{
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var chunksInRange = _chunking.GetChunksForSession(player, ChunkSize, xformQuery, _chunkIndexPool, _chunkViewerPool);
|
||||
var chunksInRange = _chunking.GetChunksForSession(player, ChunkSize, _chunkIndexPool, _chunkViewerPool);
|
||||
var staleChunks = _chunkViewerPool.Get();
|
||||
var previouslySent = _previousSentChunks[player];
|
||||
|
||||
@@ -440,16 +442,16 @@ namespace Content.Server.Decals
|
||||
// Then, remove them from previousSentChunks (for stuff like grids out of range)
|
||||
// and also mark them as stale for networking.
|
||||
|
||||
foreach (var (gridId, oldIndices) in previouslySent)
|
||||
foreach (var (netGrid, oldIndices) in previouslySent)
|
||||
{
|
||||
// Mark the whole grid as stale and flag for removal.
|
||||
if (!chunksInRange.TryGetValue(gridId, out var chunks))
|
||||
if (!chunksInRange.TryGetValue(netGrid, out var chunks))
|
||||
{
|
||||
previouslySent.Remove(gridId);
|
||||
previouslySent.Remove(netGrid);
|
||||
|
||||
// Was the grid deleted?
|
||||
if (MapManager.IsGrid(gridId))
|
||||
staleChunks[gridId] = oldIndices;
|
||||
if (!TryGetEntity(netGrid, out var gridId) || !MapManager.IsGrid(gridId.Value))
|
||||
staleChunks[netGrid] = oldIndices;
|
||||
else
|
||||
{
|
||||
// If grid was deleted then don't worry about telling the client to delete the chunk.
|
||||
@@ -465,7 +467,9 @@ namespace Content.Server.Decals
|
||||
// Get individual stale chunks.
|
||||
foreach (var chunk in oldIndices)
|
||||
{
|
||||
if (chunks.Contains(chunk)) continue;
|
||||
if (chunks.Contains(chunk))
|
||||
continue;
|
||||
|
||||
elmo.Add(chunk);
|
||||
}
|
||||
|
||||
@@ -475,16 +479,16 @@ namespace Content.Server.Decals
|
||||
continue;
|
||||
}
|
||||
|
||||
staleChunks.Add(gridId, elmo);
|
||||
staleChunks.Add(netGrid, elmo);
|
||||
}
|
||||
|
||||
var updatedChunks = _chunkViewerPool.Get();
|
||||
foreach (var (gridId, gridChunks) in chunksInRange)
|
||||
foreach (var (netGrid, gridChunks) in chunksInRange)
|
||||
{
|
||||
var newChunks = _chunkIndexPool.Get();
|
||||
_dirtyChunks.TryGetValue(gridId, out var dirtyChunks);
|
||||
_dirtyChunks.TryGetValue(netGrid, out var dirtyChunks);
|
||||
|
||||
if (!previouslySent.TryGetValue(gridId, out var previousChunks))
|
||||
if (!previouslySent.TryGetValue(netGrid, out var previousChunks))
|
||||
newChunks.UnionWith(gridChunks);
|
||||
else
|
||||
{
|
||||
@@ -498,19 +502,19 @@ namespace Content.Server.Decals
|
||||
_chunkIndexPool.Return(previousChunks);
|
||||
}
|
||||
|
||||
previouslySent[gridId] = gridChunks;
|
||||
previouslySent[netGrid] = gridChunks;
|
||||
|
||||
if (newChunks.Count == 0)
|
||||
_chunkIndexPool.Return(newChunks);
|
||||
else
|
||||
updatedChunks[gridId] = newChunks;
|
||||
updatedChunks[netGrid] = newChunks;
|
||||
}
|
||||
|
||||
//send all gridChunks to client
|
||||
SendChunkUpdates(player, updatedChunks, staleChunks);
|
||||
}
|
||||
|
||||
private void ReturnToPool(Dictionary<EntityUid, HashSet<Vector2i>> chunks)
|
||||
private void ReturnToPool(Dictionary<NetEntity, HashSet<Vector2i>> chunks)
|
||||
{
|
||||
foreach (var (_, previous) in chunks)
|
||||
{
|
||||
@@ -524,12 +528,14 @@ namespace Content.Server.Decals
|
||||
|
||||
private void SendChunkUpdates(
|
||||
IPlayerSession session,
|
||||
Dictionary<EntityUid, HashSet<Vector2i>> updatedChunks,
|
||||
Dictionary<EntityUid, HashSet<Vector2i>> staleChunks)
|
||||
Dictionary<NetEntity, HashSet<Vector2i>> updatedChunks,
|
||||
Dictionary<NetEntity, HashSet<Vector2i>> staleChunks)
|
||||
{
|
||||
var updatedDecals = new Dictionary<EntityUid, Dictionary<Vector2i, DecalChunk>>();
|
||||
foreach (var (gridId, chunks) in updatedChunks)
|
||||
var updatedDecals = new Dictionary<NetEntity, Dictionary<Vector2i, DecalChunk>>();
|
||||
foreach (var (netGrid, chunks) in updatedChunks)
|
||||
{
|
||||
var gridId = GetEntity(netGrid);
|
||||
|
||||
var collection = ChunkCollection(gridId);
|
||||
if (collection == null)
|
||||
continue;
|
||||
@@ -542,7 +548,7 @@ namespace Content.Server.Decals
|
||||
? chunk
|
||||
: new());
|
||||
}
|
||||
updatedDecals[gridId] = gridChunks;
|
||||
updatedDecals[netGrid] = gridChunks;
|
||||
}
|
||||
|
||||
if (updatedDecals.Count != 0 || staleChunks.Count != 0)
|
||||
|
||||
Reference in New Issue
Block a user