mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 23:02:34 +02:00
NetSerializer does not handle these well and sends the entire backing array instead of a more compact representation. This can then cause it to start sending lists of length 1 with a *capacity* of 4096 resulting in 250 KiB/s down to send updates for a single entity. As it just did on the public server...
69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using Robust.Shared.Serialization;
|
|
using System;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Robust.Shared.GameObjects
|
|
{
|
|
[Serializable, NetSerializable]
|
|
public sealed class EntityState
|
|
{
|
|
public EntityUid Uid { get; }
|
|
[CanBeNull]
|
|
public ComponentChanged[] ComponentChanges { get; }
|
|
[CanBeNull]
|
|
public ComponentState[] ComponentStates { get; }
|
|
|
|
public EntityState(EntityUid uid, ComponentChanged[] changedComponents, ComponentState[] componentStates)
|
|
{
|
|
Uid = uid;
|
|
|
|
// empty lists are 5 bytes each
|
|
ComponentChanges = changedComponents == null || changedComponents.Length == 0 ? null : changedComponents;
|
|
ComponentStates = componentStates == null || componentStates.Length == 0 ? null : componentStates;
|
|
}
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public readonly struct ComponentChanged
|
|
{
|
|
// 15ish bytes to create a component (strings are big), 5 bytes to remove one
|
|
|
|
/// <summary>
|
|
/// Was the component added or removed from the entity.
|
|
/// </summary>
|
|
public readonly bool Deleted;
|
|
|
|
/// <summary>
|
|
/// The Network ID of the component to remove.
|
|
/// </summary>
|
|
public readonly uint NetID;
|
|
|
|
/// <summary>
|
|
/// The prototype name of the component to add.
|
|
/// </summary>
|
|
public readonly string ComponentName;
|
|
|
|
public ComponentChanged(bool deleted, uint netId, string componentName)
|
|
{
|
|
Deleted = deleted;
|
|
NetID = netId;
|
|
ComponentName = componentName;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{(Deleted ? "D" : "C")} {NetID} {ComponentName}";
|
|
}
|
|
|
|
public static ComponentChanged Added(uint netId, string componentName)
|
|
{
|
|
return new ComponentChanged(false, netId, componentName);
|
|
}
|
|
|
|
public static ComponentChanged Removed(uint netId)
|
|
{
|
|
return new ComponentChanged(true, netId, null);
|
|
}
|
|
}
|
|
}
|