using Robust.Shared.Serialization; using System; using NetSerializer; using Robust.Shared.Timing; using System.Collections.Generic; namespace Robust.Shared.GameObjects { [Serializable, NetSerializable] public sealed class EntityState { /// /// Network identifier for the entity. /// public NetEntity NetEntity; public NetListAsArray ComponentChanges { get; } public bool Empty => (ComponentChanges.Value is null or { Count: 0 }) && NetComponents == null; public readonly GameTick EntityLastModified; /// /// Set of all networked component ids. Only sent to clients if a component has been removed sometime since the /// entity was last sent to a player. /// public HashSet? NetComponents; public EntityState(NetEntity netEntity, NetListAsArray changedComponents, GameTick lastModified, HashSet? netComps = null) { NetEntity = netEntity; ComponentChanges = changedComponents; EntityLastModified = lastModified; NetComponents = netComps; } } [Serializable, NetSerializable] public readonly struct ComponentChange { // 15ish bytes to create a component (strings are big), 5 bytes to remove one /// State data for the created/modified component, if any. /// public readonly ComponentState State; /// /// The Network ID of the component to remove. /// public readonly ushort NetID; public readonly GameTick LastModifiedTick; public ComponentChange(ushort netId, ComponentState state, GameTick lastModifiedTick) { State = state; NetID = netId; LastModifiedTick = lastModifiedTick; } public override string ToString() { return $"{NetID} {State?.GetType().Name}"; } } }