🚧 clean up listeners
This commit is contained in:
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,6 +193,7 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
internal void AssignRoom(RagonRoom room)
|
internal void AssignRoom(RagonRoom room)
|
||||||
{
|
{
|
||||||
|
_room?.Dispose();
|
||||||
_room = room;
|
_room = room;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user