Files
RobustToolbox/Robust.Shared/GameObjects/EntityState.cs
T
AcruidandGitHub dadd7b4cc3 Remove Static Component NetIds (#1842)
* ComponentNames are not sent over the network when components are created.

* Removed ComponentStates array from EntityState, now the state is stored directly inside the CompChange struct.

* Remove the unnecessary NetID property from ComponentState.

* Remove Component.NetworkSynchronizeExistence.

* Change GetNetComponents to return both the component and the component NetId.

* Remove public usages of the Component.NetID property.

* Adds the NetIDAttribute that can be applied to components.

* Removed Component.NetID.

* Revert changes to GetComponentState and how prediction works.

* Adds component netID automatic generation.

* Modifies ClientConsoleHost so that commands can be called before Initialize().

* Completely remove static NetIds.

* Renamed NetIDAttribute to NetworkedComponentAttribute.

* Fixing unit tests.
2021-07-12 10:23:13 +02:00

78 lines
2.1 KiB
C#

using Robust.Shared.Serialization;
using System;
namespace Robust.Shared.GameObjects
{
[Serializable, NetSerializable]
public sealed class EntityState
{
public EntityUid Uid { get; }
public ComponentChange[]? ComponentChanges { get; }
public bool Empty => ComponentChanges is null;
public EntityState(EntityUid uid, ComponentChange[]? changedComponents)
{
Uid = uid;
// empty lists are 5 bytes each
ComponentChanges = changedComponents == null || changedComponents.Length == 0 ? null : changedComponents;
}
}
[Serializable, NetSerializable]
public readonly struct ComponentChange
{
// 15ish bytes to create a component (strings are big), 5 bytes to remove one
/// <summary>
/// Was the component removed from the entity.
/// </summary>
public readonly bool Deleted;
/// <summary>
/// Was the component added to the entity.
/// </summary>
public readonly bool Created;
/// <summary>
/// State data for the created/modified component, if any.
/// </summary>
public readonly ComponentState? State;
/// <summary>
/// The Network ID of the component to remove.
/// </summary>
public readonly ushort NetID;
public ComponentChange(ushort netId, bool created, bool deleted, ComponentState? state)
{
Deleted = deleted;
State = state;
NetID = netId;
Created = created;
}
public override string ToString()
{
return $"{(Deleted ? "D" : "C")} {NetID} {State?.GetType().Name}";
}
public static ComponentChange Added(ushort netId, ComponentState? state)
{
return new(netId, true, false, state);
}
public static ComponentChange Changed(ushort netId, ComponentState state)
{
return new(netId, false, false, state);
}
public static ComponentChange Removed(ushort netId)
{
return new(netId, false, true, null);
}
}
}