🚧 clean up listeners

This commit is contained in:
2023-10-09 09:17:43 +03:00
parent c214b6ca7f
commit 5d812d7acc
4 changed files with 21 additions and 2 deletions
+8 -1
View File
@@ -19,7 +19,7 @@ using Ragon.Protocol;
namespace Ragon.Client namespace Ragon.Client
{ {
public sealed class RagonEntity public sealed class RagonEntity: IDisposable
{ {
private delegate void OnEventDelegate(RagonPlayer player, RagonBuffer serializer); private delegate void OnEventDelegate(RagonPlayer player, RagonBuffer serializer);
@@ -266,5 +266,12 @@ namespace Ragon.Client
OwnershipChanged?.Invoke(prevOwner, player); OwnershipChanged?.Invoke(prevOwner, player);
} }
public void Dispose()
{
_events.Clear();
_listeners.Clear();
_localListeners.Clear();
}
} }
} }
+1
View File
@@ -193,6 +193,7 @@ namespace Ragon.Client
internal void AssignRoom(RagonRoom room) internal void AssignRoom(RagonRoom room)
{ {
_room?.Dispose();
_room = room; _room = room;
} }
+2
View File
@@ -215,10 +215,12 @@ public sealed class RagonEntityCache
{ {
if (_entityMap.TryGetValue(entityId, out var entity)) if (_entityMap.TryGetValue(entityId, out var entity))
{ {
_entityMap.Remove(entityId); _entityMap.Remove(entityId);
_entityList.Remove(entity); _entityList.Remove(entity);
entity.Detach(payload); entity.Detach(payload);
entity.Dispose();
} }
} }
+10 -1
View File
@@ -18,7 +18,7 @@ using Ragon.Protocol;
namespace Ragon.Client namespace Ragon.Client
{ {
public class RagonRoom public class RagonRoom: IDisposable
{ {
private delegate void OnEventDelegate(RagonPlayer player, RagonBuffer serializer); private delegate void OnEventDelegate(RagonPlayer player, RagonBuffer serializer);
@@ -130,5 +130,14 @@ namespace Ragon.Client
public void DestroyEntity(RagonEntity entityId) => DestroyEntity(entityId, null); public void DestroyEntity(RagonEntity entityId) => DestroyEntity(entityId, null);
public void DestroyEntity(RagonEntity entityId, RagonPayload payload) => _entityCache.Destroy(entityId, payload); public void DestroyEntity(RagonEntity entityId, RagonPayload payload) => _entityCache.Destroy(entityId, payload);
public void Dispose()
{
Cleanup();
_events.Clear();
_listeners.Clear();
_localListeners.Clear();
}
} }
} }