mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 18:17:09 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
using Robust.Client.Timing;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Utility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Robust.Client.GameStates;
|
|
|
|
/// <summary>
|
|
/// Tracks dirty entities on the client for the purposes of gamestatemanager.
|
|
/// </summary>
|
|
public sealed partial class ClientDirtySystem : EntitySystem
|
|
{
|
|
[Dependency] private IClientGameTiming _timing = default!;
|
|
[Dependency] private IComponentFactory _compFact = default!;
|
|
|
|
// Entities that have removed networked components
|
|
// could pool the ushort sets, but predicted component changes are rare... soo...
|
|
internal readonly Dictionary<EntityUid, HashSet<ushort>> RemovedComponents = new();
|
|
|
|
internal readonly HashSet<EntityUid> DirtyEntities = new(256);
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<EntityTerminatingEvent>(OnTerminate);
|
|
EntityManager.EntityDirtied += OnEntityDirty;
|
|
EntityManager.ComponentRemoved += OnCompRemoved;
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
EntityManager.EntityDirtied -= OnEntityDirty;
|
|
EntityManager.ComponentRemoved -= OnCompRemoved;
|
|
Reset();
|
|
}
|
|
|
|
private void OnTerminate(ref EntityTerminatingEvent ev)
|
|
{
|
|
if (!_timing.InPrediction || IsClientSide(ev.Entity))
|
|
return;
|
|
|
|
// Client-side entity deletion is not supported and will cause errors.
|
|
Log.Error($"Predicting the deletion of a networked entity: {ToPrettyString(ev.Entity.Owner, ev.Entity.Comp)}. Trace: {Environment.StackTrace}");
|
|
}
|
|
|
|
private void OnCompRemoved(RemovedComponentEventArgs args)
|
|
{
|
|
if (args.Terminating)
|
|
return;
|
|
|
|
var uid = args.BaseArgs.Owner;
|
|
var comp = args.BaseArgs.Component;
|
|
if (!_timing.InPrediction || !comp.NetSyncEnabled || IsClientSide(uid, args.Meta))
|
|
return;
|
|
|
|
// Was this component added during prediction? If yes, then there is no need to re-add it when resetting.
|
|
if (comp.CreationTick > _timing.LastRealTick)
|
|
return;
|
|
|
|
var netId = _compFact.GetRegistration(comp).NetID;
|
|
if (netId != null)
|
|
RemovedComponents.GetOrNew(uid).Add(netId.Value);
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
DirtyEntities.Clear();
|
|
RemovedComponents.Clear();
|
|
}
|
|
|
|
private void OnEntityDirty(Entity<MetaDataComponent> e)
|
|
{
|
|
if (_timing.InPrediction && !IsClientSide(e, e))
|
|
DirtyEntities.Add(e);
|
|
}
|
|
}
|