refactor: add IDisposable to AgentTracker

This commit is contained in:
alexiscatnip
2022-08-06 02:43:06 +08:00
committed by alexiscatnip
parent a1ae85d21e
commit eb5f2be103
2 changed files with 18 additions and 1 deletions
+12 -1
View File
@@ -9,7 +9,7 @@ namespace Raindrop
// in particular, it tracks :
// region handle
//
public class AgentsTracker
public class AgentsTracker : IDisposable
{
//hashtable of agents, and the sim they are last known to reside in.
public readonly Dictionary<UUID, NearbyAvatar> agentInfos = new Dictionary<UUID, NearbyAvatar>();
@@ -45,6 +45,10 @@ namespace Raindrop
RegisterClientEvents(instance.Client);
}
public void Dispose()
{
UnregisterClientEvents(instance.Client);
}
private void RegisterClientEvents(GridClient client)
{
@@ -52,6 +56,13 @@ namespace Raindrop
// client.Self.TeleportProgress += new EventHandler<TeleportEventArgs>(Self_TeleportProgress);
client.Network.SimDisconnected += new EventHandler<SimDisconnectedEventArgs>(Network_SimDisconnected);
}
private void UnregisterClientEvents(GridClient client)
{
client.Grid.CoarseLocationUpdate -= new EventHandler<CoarseLocationUpdateEventArgs>(Grid_CoarseLocationUpdate);
// client.Self.TeleportProgress -= new EventHandler<TeleportEventArgs>(Self_TeleportProgress);
client.Network.SimDisconnected -= new EventHandler<SimDisconnectedEventArgs>(Network_SimDisconnected);
}
#region eventHandlers
void Grid_CoarseLocationUpdate(object sender, CoarseLocationUpdateEventArgs e)
+6
View File
@@ -452,6 +452,12 @@ namespace Raindrop
{
MarkEndExecution();
if (_agentsTracker != null)
{
_agentsTracker.Dispose();
_agentsTracker = null;
}
if (Cof != null)
{
Cof.Dispose();