mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Actually disable PlayerWatcher if it is unused, and stop iterations on Clear().
This commit is contained in:
parent
9666909e87
commit
557d03861f
2 changed files with 48 additions and 13 deletions
|
|
@ -19,16 +19,19 @@ namespace Penumbra.PlayerWatch
|
|||
private readonly Dictionary< string, (ActorEquipment, HashSet< PlayerWatcher >) > _equip = new();
|
||||
private int _frameTicker;
|
||||
private bool _inGPose = false;
|
||||
private bool _enabled = false;
|
||||
private bool _cancel = false;
|
||||
|
||||
internal PlayerWatchBase( DalamudPluginInterface pi )
|
||||
{
|
||||
_pi = pi;
|
||||
EnableActorWatch();
|
||||
}
|
||||
=> _pi = pi;
|
||||
|
||||
internal void RegisterWatcher( PlayerWatcher watcher )
|
||||
{
|
||||
RegisteredWatchers.Add( watcher );
|
||||
if( watcher.Active )
|
||||
{
|
||||
EnableActorWatch();
|
||||
}
|
||||
}
|
||||
|
||||
internal void UnregisterWatcher( PlayerWatcher watcher )
|
||||
|
|
@ -40,6 +43,20 @@ namespace Penumbra.PlayerWatch
|
|||
items.Item2.Remove( watcher );
|
||||
}
|
||||
}
|
||||
|
||||
CheckActiveStatus();
|
||||
}
|
||||
|
||||
internal void CheckActiveStatus()
|
||||
{
|
||||
if( RegisteredWatchers.Any( w => w.Active ) )
|
||||
{
|
||||
EnableActorWatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableActorWatch();
|
||||
}
|
||||
}
|
||||
|
||||
internal ActorEquipment UpdateActorWithoutEvent( Actor actor )
|
||||
|
|
@ -79,16 +96,24 @@ namespace Penumbra.PlayerWatch
|
|||
|
||||
internal void EnableActorWatch()
|
||||
{
|
||||
_pi.Framework.OnUpdateEvent += OnFrameworkUpdate;
|
||||
_pi.ClientState.TerritoryChanged += OnTerritoryChange;
|
||||
_pi.ClientState.OnLogout += OnLogout;
|
||||
if( !_enabled )
|
||||
{
|
||||
_enabled = true;
|
||||
_pi.Framework.OnUpdateEvent += OnFrameworkUpdate;
|
||||
_pi.ClientState.TerritoryChanged += OnTerritoryChange;
|
||||
_pi.ClientState.OnLogout += OnLogout;
|
||||
}
|
||||
}
|
||||
|
||||
internal void DisableActorWatch()
|
||||
{
|
||||
_pi.Framework.OnUpdateEvent -= OnFrameworkUpdate;
|
||||
_pi.ClientState.TerritoryChanged -= OnTerritoryChange;
|
||||
_pi.ClientState.OnLogout -= OnLogout;
|
||||
if( _enabled )
|
||||
{
|
||||
_enabled = false;
|
||||
_pi.Framework.OnUpdateEvent -= OnFrameworkUpdate;
|
||||
_pi.ClientState.TerritoryChanged -= OnTerritoryChange;
|
||||
_pi.ClientState.OnLogout -= OnLogout;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
@ -102,6 +127,7 @@ namespace Penumbra.PlayerWatch
|
|||
|
||||
internal void Clear()
|
||||
{
|
||||
_cancel = true;
|
||||
foreach( var kvp in _equip )
|
||||
{
|
||||
kvp.Value.Item1.Clear();
|
||||
|
|
@ -193,6 +219,12 @@ namespace Penumbra.PlayerWatch
|
|||
|
||||
actor = CheckGPoseActor( actor );
|
||||
|
||||
if( _cancel )
|
||||
{
|
||||
_cancel = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !equip.Item1.CompareAndUpdate( actor ) )
|
||||
{
|
||||
TriggerEvents( equip.Item2, actor );
|
||||
|
|
|
|||
|
|
@ -25,13 +25,16 @@ namespace Penumbra.PlayerWatch
|
|||
}
|
||||
|
||||
public void Enable()
|
||||
=> Active = Valid;
|
||||
=> SetStatus( true );
|
||||
|
||||
public void Disable()
|
||||
=> Active = false;
|
||||
=> SetStatus( false );
|
||||
|
||||
public void SetStatus( bool enabled )
|
||||
=> Active = enabled && Valid;
|
||||
{
|
||||
Active = enabled && Valid;
|
||||
_playerWatch?.CheckActiveStatus();
|
||||
}
|
||||
|
||||
internal void Trigger( Actor actor )
|
||||
=> ActorChanged?.Invoke( actor );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue