mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +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 readonly Dictionary< string, (ActorEquipment, HashSet< PlayerWatcher >) > _equip = new();
|
||||||
private int _frameTicker;
|
private int _frameTicker;
|
||||||
private bool _inGPose = false;
|
private bool _inGPose = false;
|
||||||
|
private bool _enabled = false;
|
||||||
|
private bool _cancel = false;
|
||||||
|
|
||||||
internal PlayerWatchBase( DalamudPluginInterface pi )
|
internal PlayerWatchBase( DalamudPluginInterface pi )
|
||||||
{
|
=> _pi = pi;
|
||||||
_pi = pi;
|
|
||||||
EnableActorWatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void RegisterWatcher( PlayerWatcher watcher )
|
internal void RegisterWatcher( PlayerWatcher watcher )
|
||||||
{
|
{
|
||||||
RegisteredWatchers.Add( watcher );
|
RegisteredWatchers.Add( watcher );
|
||||||
|
if( watcher.Active )
|
||||||
|
{
|
||||||
|
EnableActorWatch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void UnregisterWatcher( PlayerWatcher watcher )
|
internal void UnregisterWatcher( PlayerWatcher watcher )
|
||||||
|
|
@ -40,6 +43,20 @@ namespace Penumbra.PlayerWatch
|
||||||
items.Item2.Remove( watcher );
|
items.Item2.Remove( watcher );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckActiveStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void CheckActiveStatus()
|
||||||
|
{
|
||||||
|
if( RegisteredWatchers.Any( w => w.Active ) )
|
||||||
|
{
|
||||||
|
EnableActorWatch();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DisableActorWatch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal ActorEquipment UpdateActorWithoutEvent( Actor actor )
|
internal ActorEquipment UpdateActorWithoutEvent( Actor actor )
|
||||||
|
|
@ -79,16 +96,24 @@ namespace Penumbra.PlayerWatch
|
||||||
|
|
||||||
internal void EnableActorWatch()
|
internal void EnableActorWatch()
|
||||||
{
|
{
|
||||||
_pi.Framework.OnUpdateEvent += OnFrameworkUpdate;
|
if( !_enabled )
|
||||||
_pi.ClientState.TerritoryChanged += OnTerritoryChange;
|
{
|
||||||
_pi.ClientState.OnLogout += OnLogout;
|
_enabled = true;
|
||||||
|
_pi.Framework.OnUpdateEvent += OnFrameworkUpdate;
|
||||||
|
_pi.ClientState.TerritoryChanged += OnTerritoryChange;
|
||||||
|
_pi.ClientState.OnLogout += OnLogout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void DisableActorWatch()
|
internal void DisableActorWatch()
|
||||||
{
|
{
|
||||||
_pi.Framework.OnUpdateEvent -= OnFrameworkUpdate;
|
if( _enabled )
|
||||||
_pi.ClientState.TerritoryChanged -= OnTerritoryChange;
|
{
|
||||||
_pi.ClientState.OnLogout -= OnLogout;
|
_enabled = false;
|
||||||
|
_pi.Framework.OnUpdateEvent -= OnFrameworkUpdate;
|
||||||
|
_pi.ClientState.TerritoryChanged -= OnTerritoryChange;
|
||||||
|
_pi.ClientState.OnLogout -= OnLogout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|
@ -102,6 +127,7 @@ namespace Penumbra.PlayerWatch
|
||||||
|
|
||||||
internal void Clear()
|
internal void Clear()
|
||||||
{
|
{
|
||||||
|
_cancel = true;
|
||||||
foreach( var kvp in _equip )
|
foreach( var kvp in _equip )
|
||||||
{
|
{
|
||||||
kvp.Value.Item1.Clear();
|
kvp.Value.Item1.Clear();
|
||||||
|
|
@ -193,6 +219,12 @@ namespace Penumbra.PlayerWatch
|
||||||
|
|
||||||
actor = CheckGPoseActor( actor );
|
actor = CheckGPoseActor( actor );
|
||||||
|
|
||||||
|
if( _cancel )
|
||||||
|
{
|
||||||
|
_cancel = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if( !equip.Item1.CompareAndUpdate( actor ) )
|
if( !equip.Item1.CompareAndUpdate( actor ) )
|
||||||
{
|
{
|
||||||
TriggerEvents( equip.Item2, actor );
|
TriggerEvents( equip.Item2, actor );
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,16 @@ namespace Penumbra.PlayerWatch
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Enable()
|
public void Enable()
|
||||||
=> Active = Valid;
|
=> SetStatus( true );
|
||||||
|
|
||||||
public void Disable()
|
public void Disable()
|
||||||
=> Active = false;
|
=> SetStatus( false );
|
||||||
|
|
||||||
public void SetStatus( bool enabled )
|
public void SetStatus( bool enabled )
|
||||||
=> Active = enabled && Valid;
|
{
|
||||||
|
Active = enabled && Valid;
|
||||||
|
_playerWatch?.CheckActiveStatus();
|
||||||
|
}
|
||||||
|
|
||||||
internal void Trigger( Actor actor )
|
internal void Trigger( Actor actor )
|
||||||
=> ActorChanged?.Invoke( actor );
|
=> ActorChanged?.Invoke( actor );
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue