Files
RobustToolbox/Robust.Shared/GameObjects/EntityState.cs
Tyler Young 214f9f0323 Implement client bubble PVS. (#983)
* bubble implementation

include contained entities

fix line edit crash when clipboard contents are null somehow

use CVar for update bubble range

remove seenMovers that get NaN'd out of MaxUpdateRange - huge reduction in network traffic from bullets

cut default of MaxUpdateRange down to 12.5 for now

maybe handle teleported things

handle removing player state on disconnect

fixed positional audio errors

make UpdateEntityTree also update player's last seen ents

make net.maxupdaterange cvar tunable at runtime w/o impacting performance

back to position nan as means to hide from client

revert work pooling as the wrong player was getting the wrong game state

ffs needed to think less about *if* something is *seen* and more about *when* it must be *unseen*

clean up usings

handle parenting and sequencing issues that arise on the client

gather needed ents to update recursively

applied suggestions from code review

fix missing recursively contained ents

make assumption that client last saw things on first tick instead of tick zero, as zero would be the "from tick" and first would be he "to tick"

add First tick as constant to GameTick due to relevance above

renamed includedEnts to checkedEnts to make usage more clear

added comments

inverted some conditions to flatten parts of the pvs logic

fixed sending states when already seen (lastChange < lastSeen to lastChange <= lastSeen)

fix sending states when no actual changes (other bugs?)

local caching of currentTick, remove priorTick

* make TransformComponent's Parent setter call Dirty() to handle replicating network state if AttachParent isn't invoked

* fixed parent changed by setting Parent on Transform not updating parent's Children collection and other stuff

rotating parent entities now are visible with their orbiting children if one of their children moves into view

* break out duplicated code as GetLastSeen

* remove unused net.parallelstates

introduce net.pvs to configure enabling/disabling PVS
2020-02-23 14:42:54 +01:00

67 lines
2.0 KiB
C#

using Robust.Shared.Serialization;
using System;
using System.Collections.Generic;
namespace Robust.Shared.GameObjects
{
[Serializable, NetSerializable]
public sealed class EntityState
{
public EntityUid Uid { get; }
public List<ComponentChanged> ComponentChanges { get; }
public List<ComponentState> ComponentStates { get; }
public EntityState(EntityUid uid, List<ComponentChanged> changedComponents, List<ComponentState> componentStates)
{
Uid = uid;
// empty lists are 5 bytes each
ComponentChanges = changedComponents == null || changedComponents.Count == 0 ? null : changedComponents;
ComponentStates = componentStates == null || componentStates.Count == 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);
}
}
}