🐛 Remove listener inside callback
This commit is contained in:
@@ -12,11 +12,11 @@
|
|||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<DebugType>none</DebugType>
|
<DebugType>none</DebugType>
|
||||||
<OutputPath>/Users/edmand46/RagonProjects/ragon-oss-sdk/Assets/Ragon/Plugins/</OutputPath>
|
<OutputPath>/Users/edmand46/RagonProjects/ragon-oss-examples/Assets/Ragon/Plugins/</OutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
<OutputPath>/Users/edmand46/RagonProjects/ragon-unity-sdk/Assets/Ragon/Runtime/Plugins</OutputPath>
|
<OutputPath>/Users/edmand46/RagonProjects/ragon-oss-examples/Assets/Ragon/Plugins/</OutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ namespace Ragon.Client
|
|||||||
{
|
{
|
||||||
State = new RagonEntityState(this);
|
State = new RagonEntityState(this);
|
||||||
Type = type;
|
Type = type;
|
||||||
|
|
||||||
|
_spawnPayload = new RagonPayload(0);
|
||||||
|
_destroyPayload = new RagonPayload(0);
|
||||||
_sceneId = sceneId;
|
_sceneId = sceneId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ internal class SnapshotHandler : Handler
|
|||||||
RagonListenerList listenerList,
|
RagonListenerList listenerList,
|
||||||
RagonEntityCache entityCache,
|
RagonEntityCache entityCache,
|
||||||
RagonPlayerCache playerCache,
|
RagonPlayerCache playerCache,
|
||||||
IRagonEntityListener entityListener
|
IRagonEntityListener entityListener
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_client = ragonClient;
|
_client = ragonClient;
|
||||||
@@ -52,9 +52,9 @@ internal class SnapshotHandler : Handler
|
|||||||
var playerPeerId = buffer.ReadUShort();
|
var playerPeerId = buffer.ReadUShort();
|
||||||
var playerId = buffer.ReadString();
|
var playerId = buffer.ReadString();
|
||||||
var playerName = buffer.ReadString();
|
var playerName = buffer.ReadString();
|
||||||
|
|
||||||
_playerCache.AddPlayer(playerPeerId, playerId, playerName);
|
_playerCache.AddPlayer(playerPeerId, playerId, playerName);
|
||||||
|
|
||||||
RagonLog.Trace($"Player {playerPeerId} - {playerId} - {playerName}");
|
RagonLog.Trace($"Player {playerPeerId} - {playerId} - {playerName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,10 +66,7 @@ internal class SnapshotHandler : Handler
|
|||||||
var entityId = buffer.ReadUShort();
|
var entityId = buffer.ReadUShort();
|
||||||
var ownerPeerId = buffer.ReadUShort();
|
var ownerPeerId = buffer.ReadUShort();
|
||||||
var payloadSize = buffer.ReadUShort();
|
var payloadSize = buffer.ReadUShort();
|
||||||
var payload = new RagonPayload(payloadSize);
|
RagonLog.Trace("Read offset: " + buffer.ReadOffset);
|
||||||
payload.Read(buffer);
|
|
||||||
|
|
||||||
RagonLog.Trace($"Entity {entityType} - {entityId} - {ownerPeerId} - {payloadSize}");
|
|
||||||
|
|
||||||
var player = _playerCache.GetPlayerByPeer(ownerPeerId);
|
var player = _playerCache.GetPlayerByPeer(ownerPeerId);
|
||||||
if (player == null)
|
if (player == null)
|
||||||
@@ -81,11 +78,17 @@ internal class SnapshotHandler : Handler
|
|||||||
var hasAuthority = _playerCache.Local.Id == player.Id;
|
var hasAuthority = _playerCache.Local.Id == player.Id;
|
||||||
var entity = _entityCache.TryGetEntity(0, entityType, 0, entityId, hasAuthority, out _);
|
var entity = _entityCache.TryGetEntity(0, entityType, 0, entityId, hasAuthority, out _);
|
||||||
|
|
||||||
entity.Read(buffer);
|
if (payloadSize > 0)
|
||||||
entity.AttachPayload(payload);
|
{
|
||||||
|
var payload = new RagonPayload(payloadSize);
|
||||||
|
payload.Read(buffer);
|
||||||
|
|
||||||
|
entity.AttachPayload(payload);
|
||||||
|
}
|
||||||
|
|
||||||
_entityListener.OnEntityCreated(entity);
|
_entityListener.OnEntityCreated(entity);
|
||||||
|
|
||||||
|
entity.Read(buffer);
|
||||||
entity.Attach(_client, entityId, entityType, hasAuthority, player);
|
entity.Attach(_client, entityId, entityType, hasAuthority, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,26 +101,20 @@ internal class SnapshotHandler : Handler
|
|||||||
var staticId = buffer.ReadUShort();
|
var staticId = buffer.ReadUShort();
|
||||||
var ownerPeerId = buffer.ReadUShort();
|
var ownerPeerId = buffer.ReadUShort();
|
||||||
var payloadSize = buffer.ReadUShort();
|
var payloadSize = buffer.ReadUShort();
|
||||||
var payload = new RagonPayload(payloadSize);
|
|
||||||
payload.Read(buffer);
|
|
||||||
|
|
||||||
RagonLog.Trace($"Entity {entityType} - {entityId} - {ownerPeerId} - {payloadSize}");
|
|
||||||
|
|
||||||
var player = _playerCache.GetPlayerByPeer(ownerPeerId);
|
var player = _playerCache.GetPlayerByPeer(ownerPeerId);
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
RagonLog.Error($"Player not found with peerId: ${ownerPeerId}");
|
RagonLog.Error($"Player not found with peerId: ${ownerPeerId}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasAuthority = _playerCache.Local.Id == player.Id;
|
var hasAuthority = _playerCache.Local.Id == player.Id;
|
||||||
var entity = _entityCache.TryGetEntity(0, entityType, staticId, entityId, hasAuthority, out _);
|
var entity = _entityCache.TryGetEntity(0, entityType, staticId, entityId, hasAuthority, out _);
|
||||||
|
|
||||||
entity.Read(buffer);
|
|
||||||
entity.AttachPayload(payload);
|
|
||||||
|
|
||||||
_entityListener.OnEntityCreated(entity);
|
_entityListener.OnEntityCreated(entity);
|
||||||
|
|
||||||
|
entity.Read(buffer);
|
||||||
entity.Attach(_client, entityId, entityType, hasAuthority, player);
|
entity.Attach(_client, entityId, entityType, hasAuthority, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,8 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
_stats.Update(_connection.BytesSent, _connection.BytesReceived, _connection.Ping, dt);
|
_stats.Update(_connection.BytesSent, _connection.BytesReceived, _connection.Ping, dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_listenerList.Update();
|
||||||
_connection.Update();
|
_connection.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public sealed class RagonEntityCache
|
|||||||
|
|
||||||
entity.State.WriteInfo(buffer);
|
entity.State.WriteInfo(buffer);
|
||||||
|
|
||||||
spawnPayload.Write(buffer);
|
spawnPayload?.Write(buffer);
|
||||||
|
|
||||||
_pendingEntities.Add(attachId, entity);
|
_pendingEntities.Add(attachId, entity);
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ public sealed class RagonEntityCache
|
|||||||
buffer.WriteOperation(RagonOperation.REMOVE_ENTITY);
|
buffer.WriteOperation(RagonOperation.REMOVE_ENTITY);
|
||||||
buffer.WriteUShort(entity.Id);
|
buffer.WriteUShort(entity.Id);
|
||||||
|
|
||||||
destroyPayload.Write(buffer);
|
destroyPayload?.Write(buffer);
|
||||||
|
|
||||||
var sendData = buffer.ToArray();
|
var sendData = buffer.ToArray();
|
||||||
_client.Reliable.Send(sendData);
|
_client.Reliable.Send(sendData);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace Ragon.Client
|
|||||||
private readonly List<IRagonOwnershipChangedListener> _ownershipChangedListeners = new();
|
private readonly List<IRagonOwnershipChangedListener> _ownershipChangedListeners = new();
|
||||||
private readonly List<IRagonPlayerJoinListener> _playerJoinListeners = new();
|
private readonly List<IRagonPlayerJoinListener> _playerJoinListeners = new();
|
||||||
private readonly List<IRagonPlayerLeftListener> _playerLeftListeners = new();
|
private readonly List<IRagonPlayerLeftListener> _playerLeftListeners = new();
|
||||||
|
private readonly List<Action> _delayedActions = new();
|
||||||
|
|
||||||
public RagonListenerList(RagonClient client)
|
public RagonListenerList(RagonClient client)
|
||||||
{
|
{
|
||||||
@@ -51,16 +52,28 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
public void Remove(IRagonListener listener)
|
public void Remove(IRagonListener listener)
|
||||||
{
|
{
|
||||||
_authorizationListeners.Remove(listener);
|
_delayedActions.Add(() =>
|
||||||
_connectionListeners.Remove(listener);
|
{
|
||||||
_failedListeners.Remove(listener);
|
_authorizationListeners.Remove(listener);
|
||||||
_joinListeners.Remove(listener);
|
_connectionListeners.Remove(listener);
|
||||||
_leftListeners.Remove(listener);
|
_failedListeners.Remove(listener);
|
||||||
_levelListeners.Remove(listener);
|
_joinListeners.Remove(listener);
|
||||||
_ownershipChangedListeners.Remove(listener);
|
_leftListeners.Remove(listener);
|
||||||
_playerJoinListeners.Remove(listener);
|
_levelListeners.Remove(listener);
|
||||||
_playerLeftListeners.Remove(listener);
|
_ownershipChangedListeners.Remove(listener);
|
||||||
|
_playerJoinListeners.Remove(listener);
|
||||||
|
_playerLeftListeners.Remove(listener);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
foreach (var action in _delayedActions)
|
||||||
|
action.Invoke();
|
||||||
|
|
||||||
|
_delayedActions.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Add(IRagonAuthorizationListener listener)
|
public void Add(IRagonAuthorizationListener listener)
|
||||||
{
|
{
|
||||||
@@ -109,47 +122,48 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
public void Remove(IRagonAuthorizationListener listener)
|
public void Remove(IRagonAuthorizationListener listener)
|
||||||
{
|
{
|
||||||
_authorizationListeners.Remove(listener);
|
_delayedActions.Add(() => _authorizationListeners.Remove(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(IRagonConnectionListener listener)
|
public void Remove(IRagonConnectionListener listener)
|
||||||
{
|
{
|
||||||
_connectionListeners.Remove(listener);
|
|
||||||
|
_delayedActions.Add(() => _connectionListeners.Remove(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(IRagonFailedListener listener)
|
public void Remove(IRagonFailedListener listener)
|
||||||
{
|
{
|
||||||
_failedListeners.Remove(listener);
|
_delayedActions.Add(() => _failedListeners.Remove(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(IRagonJoinListener listener)
|
public void Remove(IRagonJoinListener listener)
|
||||||
{
|
{
|
||||||
_joinListeners.Remove(listener);
|
_delayedActions.Add(() => _joinListeners.Remove(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(IRagonLeftListener listener)
|
public void Remove(IRagonLeftListener listener)
|
||||||
{
|
{
|
||||||
_leftListeners.Remove(listener);
|
_delayedActions.Add(() => _leftListeners.Remove(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(IRagonLevelListener listener)
|
public void Remove(IRagonLevelListener listener)
|
||||||
{
|
{
|
||||||
_levelListeners.Remove(listener);
|
_delayedActions.Add(() => _levelListeners.Remove(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(IRagonOwnershipChangedListener listener)
|
public void Remove(IRagonOwnershipChangedListener listener)
|
||||||
{
|
{
|
||||||
_ownershipChangedListeners.Remove(listener);
|
_delayedActions.Add(() => _ownershipChangedListeners.Remove(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(IRagonPlayerJoinListener listener)
|
public void Remove(IRagonPlayerJoinListener listener)
|
||||||
{
|
{
|
||||||
_playerJoinListeners.Remove(listener);
|
_delayedActions.Add(() => _playerJoinListeners.Remove(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(IRagonPlayerLeftListener listener)
|
public void Remove(IRagonPlayerLeftListener listener)
|
||||||
{
|
{
|
||||||
_playerLeftListeners.Remove(listener);
|
_delayedActions.Add(() => _playerLeftListeners.Remove(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAuthorizationSuccess(string playerId, string playerName, string payload)
|
public void OnAuthorizationSuccess(string playerId, string playerName, string payload)
|
||||||
|
|||||||
@@ -117,13 +117,15 @@ public class RagonEntity : IRagonEntity
|
|||||||
{
|
{
|
||||||
buffer.WriteUShort(Type);
|
buffer.WriteUShort(Type);
|
||||||
buffer.WriteUShort(Id);
|
buffer.WriteUShort(Id);
|
||||||
|
|
||||||
if (StaticId != 0)
|
if (StaticId != 0)
|
||||||
buffer.WriteUShort(StaticId);
|
buffer.WriteUShort(StaticId);
|
||||||
|
|
||||||
buffer.WriteUShort(Owner.Connection.Id);
|
buffer.WriteUShort(Owner.Connection.Id);
|
||||||
|
|
||||||
buffer.WriteUShort(Payload.Size);
|
buffer.WriteUShort(Payload.Size);
|
||||||
|
|
||||||
Payload.Write(buffer);
|
Payload.Write(buffer);
|
||||||
|
|
||||||
_state.Snapshot(buffer);
|
_state.Snapshot(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public sealed class SceneLoadedOperation : IRagonOperation
|
|||||||
var playerInfo = $"Player {context.Connection.Id}|{context.LobbyPlayer.Name}";
|
var playerInfo = $"Player {context.Connection.Id}|{context.LobbyPlayer.Name}";
|
||||||
var entityInfo = $"{entity.Id}:{entity.Type}";
|
var entityInfo = $"{entity.Id}:{entity.Type}";
|
||||||
|
|
||||||
_logger.Trace($"{playerInfo} created entity {entityInfo}");
|
_logger.Trace($"{playerInfo} created static entity {entityInfo}");
|
||||||
|
|
||||||
entity.Attach(player);
|
entity.Attach(player);
|
||||||
room.AttachEntity(entity);
|
room.AttachEntity(entity);
|
||||||
|
|||||||
Reference in New Issue
Block a user