Fix component removal / PVS bugs (#3275)

This commit is contained in:
Leon Friedrich
2022-10-08 15:22:32 +13:00
committed by GitHub
parent 2898e1413b
commit 7b0c4dd7fb
16 changed files with 138 additions and 175 deletions

View File

@@ -2,6 +2,7 @@ using Robust.Shared.Serialization;
using System;
using NetSerializer;
using Robust.Shared.Timing;
using System.Collections.Generic;
namespace Robust.Shared.GameObjects
{
@@ -16,11 +17,18 @@ namespace Robust.Shared.GameObjects
public readonly GameTick EntityLastModified;
public EntityState(EntityUid uid, NetListAsArray<ComponentChange> changedComponents, GameTick lastModified)
/// <summary>
/// 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.
/// </summary>
public HashSet<ushort>? NetComponents;
public EntityState(EntityUid uid, NetListAsArray<ComponentChange> changedComponents, GameTick lastModified, HashSet<ushort>? netComps = null)
{
Uid = uid;
ComponentChanges = changedComponents;
EntityLastModified = lastModified;
NetComponents = netComps;
}
}
@@ -29,20 +37,9 @@ namespace Robust.Shared.GameObjects
{
// 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;
public readonly ComponentState State;
/// <summary>
/// The Network ID of the component to remove.
@@ -51,33 +48,16 @@ namespace Robust.Shared.GameObjects
public readonly GameTick LastModifiedTick;
public ComponentChange(ushort netId, bool created, bool deleted, ComponentState? state, GameTick lastModifiedTick)
public ComponentChange(ushort netId, ComponentState state, GameTick lastModifiedTick)
{
Deleted = deleted;
State = state;
NetID = netId;
Created = created;
LastModifiedTick = lastModifiedTick;
}
public override string ToString()
{
return $"{(Deleted ? "D" : "C")} {NetID} {State?.GetType().Name}";
}
public static ComponentChange Added(ushort netId, ComponentState? state, GameTick lastModifiedTick)
{
return new(netId, true, false, state, lastModifiedTick);
}
public static ComponentChange Changed(ushort netId, ComponentState state, GameTick lastModifiedTick)
{
return new(netId, false, false, state, lastModifiedTick);
}
public static ComponentChange Removed(ushort netId)
{
return new(netId, false, true, null, default);
return $"{NetID} {State?.GetType().Name}";
}
}
}