Makes a lot of entity systems unsubscribe from events on shutdown.

This commit is contained in:
Vera Aguilera Puerto
2021-04-09 16:08:12 +02:00
parent c28f22ebff
commit 03cd390478
15 changed files with 119 additions and 28 deletions

View File

@@ -51,8 +51,12 @@ namespace Content.Client.GameObjects.EntitySystems
/// <inheritdoc /> /// <inheritdoc />
public override void Shutdown() public override void Shutdown()
{ {
CommandBinds.Unregister<ConstructionSystem>();
base.Shutdown(); base.Shutdown();
UnsubscribeLocalEvent<PlayerAttachSysMessage>();
UnsubscribeNetworkEvent<AckStructureConstructionMessage>();
CommandBinds.Unregister<ConstructionSystem>();
} }
public event EventHandler<CraftingAvailabilityChangedArgs>? CraftingAvailabilityChanged; public event EventHandler<CraftingAvailabilityChangedArgs>? CraftingAvailabilityChanged;

View File

@@ -40,6 +40,12 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
SubscribeLocalEvent<PlayerAttachSysMessage>(HandlePlayerAttached); SubscribeLocalEvent<PlayerAttachSysMessage>(HandlePlayerAttached);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<PlayerAttachSysMessage>();
}
private void HandlePlayerAttached(PlayerAttachSysMessage message) private void HandlePlayerAttached(PlayerAttachSysMessage message)
{ {
_attachedEntity = message.AttachedEntity; _attachedEntity = message.AttachedEntity;

View File

@@ -46,6 +46,13 @@ namespace Content.Client.GameObjects.EntitySystems.HealthOverlay
SubscribeLocalEvent<PlayerAttachSysMessage>(HandlePlayerAttached); SubscribeLocalEvent<PlayerAttachSysMessage>(HandlePlayerAttached);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<PlayerAttachSysMessage>();
}
public void Reset() public void Reset()
{ {
foreach (var gui in _guis.Values) foreach (var gui in _guis.Values)

View File

@@ -24,9 +24,16 @@ namespace Content.Client.GameObjects.EntitySystems
/// <inheritdoc /> /// <inheritdoc />
public override void Initialize() public override void Initialize()
{ {
SubscribeLocalEvent<IconSmoothDirtyEvent>(HandleDirtyEvent); base.Initialize();
IoCManager.InjectDependencies(this); SubscribeLocalEvent<IconSmoothDirtyEvent>(HandleDirtyEvent);
}
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<IconSmoothDirtyEvent>();
} }
public override void FrameUpdate(float frameTime) public override void FrameUpdate(float frameTime)

View File

@@ -46,7 +46,6 @@ namespace Content.Client.GameObjects.EntitySystems
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
IoCManager.InjectDependencies(this);
SubscribeNetworkEvent<VerbSystemMessages.VerbsResponseMessage>(FillEntityPopup); SubscribeNetworkEvent<VerbSystemMessages.VerbsResponseMessage>(FillEntityPopup);
SubscribeNetworkEvent<PlayerContainerVisibilityMessage>(HandleContainerVisibilityMessage); SubscribeNetworkEvent<PlayerContainerVisibilityMessage>(HandleContainerVisibilityMessage);
@@ -62,11 +61,14 @@ namespace Content.Client.GameObjects.EntitySystems
public override void Shutdown() public override void Shutdown()
{ {
base.Shutdown();
UnsubscribeNetworkEvent<VerbSystemMessages.VerbsResponseMessage>();
UnsubscribeNetworkEvent<PlayerContainerVisibilityMessage>();
UnsubscribeLocalEvent<MoveEvent>(); UnsubscribeLocalEvent<MoveEvent>();
_contextMenuPresenter?.Dispose(); _contextMenuPresenter?.Dispose();
CommandBinds.Unregister<VerbSystem>(); CommandBinds.Unregister<VerbSystem>();
base.Shutdown();
} }
public void Reset() public void Reset()

View File

@@ -17,6 +17,13 @@ namespace Content.Client.GameObjects.EntitySystems
SubscribeLocalEvent<WindowSmoothDirtyEvent>(HandleDirtyEvent); SubscribeLocalEvent<WindowSmoothDirtyEvent>(HandleDirtyEvent);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<WindowSmoothDirtyEvent>();
}
private void HandleDirtyEvent(WindowSmoothDirtyEvent ev) private void HandleDirtyEvent(WindowSmoothDirtyEvent ev)
{ {
if (ev.Sender.HasComponent<WindowComponent>()) if (ev.Sender.HasComponent<WindowComponent>())

View File

@@ -454,6 +454,13 @@ namespace Content.IntegrationTests.Tests.Networking
SubscribeLocalEvent<SetFooMessage>(HandleMessage); SubscribeLocalEvent<SetFooMessage>(HandleMessage);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeNetworkEvent<SetFooMessage>();
UnsubscribeLocalEvent<SetFooMessage>();
}
private void HandleMessage(SetFooMessage message, EntitySessionEventArgs args) private void HandleMessage(SetFooMessage message, EntitySessionEventArgs args)
{ {
var entity = EntityManager.GetEntity(message.Uid); var entity = EntityManager.GetEntity(message.Uid);

View File

@@ -45,6 +45,13 @@ namespace Content.Server.GameObjects.EntitySystems.AI
SubscribeLocalEvent<MobStateChangedMessage>(MobStateChanged); SubscribeLocalEvent<MobStateChangedMessage>(MobStateChanged);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<SleepAiMessage>();
UnsubscribeLocalEvent<MobStateChangedMessage>();
}
/// <inheritdoc /> /// <inheritdoc />
public override void Update(float frameTime) public override void Update(float frameTime)
{ {

View File

@@ -90,6 +90,22 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
_mapManager.OnGridRemoved += GridRemoved; _mapManager.OnGridRemoved += GridRemoved;
} }
public override void Shutdown()
{
base.Shutdown();
_queuedUpdates.Clear();
_regions.Clear();
_cachedAccessible.Clear();
_queuedCacheDeletions.Clear();
_mapManager.OnGridRemoved -= GridRemoved;
UnsubscribeLocalEvent<PathfindingChunkUpdateMessage>();
UnsubscribeNetworkEvent<SharedAiDebug.SubscribeReachableMessage>();
UnsubscribeNetworkEvent<SharedAiDebug.UnsubscribeReachableMessage>();
}
private void GridRemoved(MapId mapId, GridId gridId) private void GridRemoved(MapId mapId, GridId gridId)
{ {
_regions.Remove(gridId); _regions.Remove(gridId);
@@ -126,20 +142,6 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
_queuedCacheDeletions.Clear(); _queuedCacheDeletions.Clear();
} }
public override void Shutdown()
{
base.Shutdown();
_queuedUpdates.Clear();
_regions.Clear();
_cachedAccessible.Clear();
_queuedCacheDeletions.Clear();
_mapManager.OnGridRemoved -= GridRemoved;
UnsubscribeLocalEvent<PathfindingChunkUpdateMessage>();
UnsubscribeLocalEvent<PlayerAttachSystemMessage>();
UnsubscribeNetworkEvent<SharedAiDebug.SubscribeReachableMessage>();
UnsubscribeNetworkEvent<SharedAiDebug.UnsubscribeReachableMessage>();
}
#if DEBUG #if DEBUG
private void HandleSubscription(SharedAiDebug.SubscribeReachableMessage message, EntitySessionEventArgs eventArgs) private void HandleSubscription(SharedAiDebug.SubscribeReachableMessage message, EntitySessionEventArgs eventArgs)
{ {

View File

@@ -22,6 +22,14 @@ namespace Content.Server.GameObjects.EntitySystems.Body.Surgery
SubscribeLocalEvent<SurgeryWindowCloseMessage>(OnSurgeryWindowClose); SubscribeLocalEvent<SurgeryWindowCloseMessage>(OnSurgeryWindowClose);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<SurgeryWindowOpenMessage>();
UnsubscribeLocalEvent<SurgeryWindowCloseMessage>();
}
public void Reset() public void Reset()
{ {
_openSurgeryUIs.Clear(); _openSurgeryUIs.Clear();

View File

@@ -27,6 +27,17 @@ namespace Content.Server.GameObjects.EntitySystems
SubscribeLocalEvent<BuckleComponent, AttackHandMessage>(HandleAttackHand); SubscribeLocalEvent<BuckleComponent, AttackHandMessage>(HandleAttackHand);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<MoveEvent>();
UnsubscribeLocalEvent<EntInsertedIntoContainerMessage>();
UnsubscribeLocalEvent<EntRemovedFromContainerMessage>();
UnsubscribeLocalEvent<BuckleComponent, AttackHandMessage>(HandleAttackHand);
}
private void HandleAttackHand(EntityUid uid, BuckleComponent component, AttackHandMessage args) private void HandleAttackHand(EntityUid uid, BuckleComponent component, AttackHandMessage args)
{ {
args.Handled = component.TryUnbuckle(args.User); args.Handled = component.TryUnbuckle(args.User);
@@ -40,14 +51,6 @@ namespace Content.Server.GameObjects.EntitySystems
} }
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<MoveEvent>();
UnsubscribeLocalEvent<BuckleComponent, AttackHandMessage>(HandleAttackHand);
}
private void MoveEvent(MoveEvent ev) private void MoveEvent(MoveEvent ev)
{ {
if (!ev.Sender.TryGetComponent(out BuckleComponent? buckle)) if (!ev.Sender.TryGetComponent(out BuckleComponent? buckle))

View File

@@ -30,9 +30,18 @@ namespace Content.Server.GameObjects.EntitySystems
public override void Initialize() public override void Initialize()
{ {
base.Initialize();
SubscribeLocalEvent<PlayerAttachSystemMessage>(OnPlayerAttached); SubscribeLocalEvent<PlayerAttachSystemMessage>(OnPlayerAttached);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<PlayerAttachSystemMessage>();
}
private uint GetNextRoleIdentifier() private uint GetNextRoleIdentifier()
{ {
return unchecked(_nextRoleIdentifier++); return unchecked(_nextRoleIdentifier++);

View File

@@ -51,8 +51,12 @@ namespace Content.Server.GameObjects.EntitySystems
/// <inheritdoc /> /// <inheritdoc />
public override void Shutdown() public override void Shutdown()
{ {
CommandBinds.Unregister<HandsSystem>();
base.Shutdown(); base.Shutdown();
UnsubscribeLocalEvent<EntRemovedFromContainerMessage>();
UnsubscribeLocalEvent<EntInsertedIntoContainerMessage>();
CommandBinds.Unregister<HandsSystem>();
} }
private static void HandleContainerModified(ContainerModifiedMessage args) private static void HandleContainerModified(ContainerModifiedMessage args)

View File

@@ -16,10 +16,20 @@ namespace Content.Server.GameObjects.EntitySystems
/// <inheritdoc /> /// <inheritdoc />
public override void Initialize() public override void Initialize()
{ {
base.Initialize();
SubscribeLocalEvent<EntRemovedFromContainerMessage>(HandleEntityRemovedFromContainer); SubscribeLocalEvent<EntRemovedFromContainerMessage>(HandleEntityRemovedFromContainer);
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleEntityInsertedIntoContainer); SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleEntityInsertedIntoContainer);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<EntRemovedFromContainerMessage>();
UnsubscribeLocalEvent<EntInsertedIntoContainerMessage>();
}
/// <inheritdoc /> /// <inheritdoc />
public override void Update(float frameTime) public override void Update(float frameTime)
{ {

View File

@@ -26,6 +26,14 @@ namespace Content.Server.GameObjects.EntitySystems
SubscribeLocalEvent<EntParentChangedMessage>(EntParentChanged); SubscribeLocalEvent<EntParentChangedMessage>(EntParentChanged);
} }
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<GravityChangedMessage>();
UnsubscribeLocalEvent<EntParentChangedMessage>();
}
public void Reset() public void Reset()
{ {
_alerts.Clear(); _alerts.Clear();