changed scene loading flow

This commit is contained in:
2023-07-30 21:46:42 +03:00
parent 92062cd708
commit fb58dedfaf
5 changed files with 32 additions and 24 deletions
+4 -7
View File
@@ -49,8 +49,8 @@ namespace Ragon.Client
private RagonPayload _spawnPayload; private RagonPayload _spawnPayload;
private RagonPayload _destroyPayload; private RagonPayload _destroyPayload;
private Dictionary<int, OnEventDelegate> _events = new(); private readonly Dictionary<int, OnEventDelegate> _events = new Dictionary<int, OnEventDelegate>();
private Dictionary<int, Action<RagonPlayer, IRagonEvent>> _localEvents = new(); private readonly Dictionary<int, Action<RagonPlayer, IRagonEvent>> _localEvents = new Dictionary<int, Action<RagonPlayer, IRagonEvent>>();
public RagonEntity(ushort type = 0, ushort sceneId = 0) public RagonEntity(ushort type = 0, ushort sceneId = 0)
{ {
@@ -150,29 +150,26 @@ namespace Ragon.Client
return; return;
} }
var eventCode = _client.Event.GetEventCode(evnt);
if (target != RagonTarget.ExceptOwner) if (target != RagonTarget.ExceptOwner)
{ {
if (replicationMode == RagonReplicationMode.Local) if (replicationMode == RagonReplicationMode.Local)
{ {
var eventCode = _client.Event.GetEventCode(evnt);
_localEvents[eventCode].Invoke(_client.Room.Local, evnt); _localEvents[eventCode].Invoke(_client.Room.Local, evnt);
return; return;
} }
if (replicationMode == RagonReplicationMode.LocalAndServer) if (replicationMode == RagonReplicationMode.LocalAndServer)
{ {
var eventCode = _client.Event.GetEventCode(evnt);
_localEvents[eventCode].Invoke(_client.Room.Local, evnt); _localEvents[eventCode].Invoke(_client.Room.Local, evnt);
} }
} }
var evntId = _client.Event.GetEventCode(evnt);
var buffer = _client.Buffer; var buffer = _client.Buffer;
buffer.Clear(); buffer.Clear();
buffer.WriteOperation(RagonOperation.REPLICATE_ENTITY_EVENT); buffer.WriteOperation(RagonOperation.REPLICATE_ENTITY_EVENT);
buffer.WriteUShort(Id); buffer.WriteUShort(Id);
buffer.WriteUShort(evntId); buffer.WriteUShort(eventCode);
buffer.WriteByte((byte)replicationMode); buffer.WriteByte((byte)replicationMode);
buffer.WriteByte((byte)target); buffer.WriteByte((byte)target);
@@ -22,9 +22,13 @@ namespace Ragon.Client;
internal class AuthorizeSuccessHandler: Handler internal class AuthorizeSuccessHandler: Handler
{ {
private readonly RagonListenerList _listenerList; private readonly RagonListenerList _listenerList;
private readonly RagonClient _client;
public AuthorizeSuccessHandler(RagonListenerList listenerList) public AuthorizeSuccessHandler(
RagonClient client,
RagonListenerList listenerList)
{ {
_client = client;
_listenerList = listenerList; _listenerList = listenerList;
} }
@@ -34,6 +38,7 @@ internal class AuthorizeSuccessHandler: Handler
var playerName = buffer.ReadString(); var playerName = buffer.ReadString();
var playerPayload = buffer.ReadString(); var playerPayload = buffer.ReadString();
_client.SetStatus(RagonStatus.LOBBY);
_listenerList.OnAuthorizationSuccess(playerId, playerName, playerPayload); _listenerList.OnAuthorizationSuccess(playerId, playerName, playerPayload);
} }
} }
@@ -43,7 +43,6 @@ internal class JoinSuccessHandler : Handler
private readonly RagonPlayerCache _playerCache; private readonly RagonPlayerCache _playerCache;
private readonly RagonEntityCache _entityCache; private readonly RagonEntityCache _entityCache;
private readonly RagonClient _client; private readonly RagonClient _client;
private readonly RagonBuffer _buffer;
public JoinSuccessHandler( public JoinSuccessHandler(
RagonClient client, RagonClient client,
@@ -53,7 +52,6 @@ internal class JoinSuccessHandler : Handler
RagonEntityCache entityCache RagonEntityCache entityCache
) )
{ {
_buffer = buffer;
_client = client; _client = client;
_listenerList = listenerList; _listenerList = listenerList;
_entityCache = entityCache; _entityCache = entityCache;
@@ -117,8 +117,12 @@ internal class SnapshotHandler : Handler
entity.Attach(_client, entityId, entityType, hasAuthority, player); entity.Attach(_client, entityId, entityType, hasAuthority, player);
} }
if (_client.Status != RagonStatus.ROOM) if (_client.Status == RagonStatus.LOBBY)
{
_client.SetStatus(RagonStatus.ROOM);
_listenerList.OnJoined(); _listenerList.OnJoined();
}
_listenerList.OnSceneLoaded(); _listenerList.OnSceneLoaded();
} }
+6 -2
View File
@@ -102,7 +102,7 @@ namespace Ragon.Client
_entityCache = new RagonEntityCache(this, _playerCache, _sceneCollector); _entityCache = new RagonEntityCache(this, _playerCache, _sceneCollector);
_handlers = new Handler[byte.MaxValue]; _handlers = new Handler[byte.MaxValue];
_handlers[(byte)RagonOperation.AUTHORIZED_SUCCESS] = new AuthorizeSuccessHandler(listeners); _handlers[(byte)RagonOperation.AUTHORIZED_SUCCESS] = new AuthorizeSuccessHandler(this, listeners);
_handlers[(byte)RagonOperation.AUTHORIZED_FAILED] = new AuthorizeFailedHandler(listeners); _handlers[(byte)RagonOperation.AUTHORIZED_FAILED] = new AuthorizeFailedHandler(listeners);
_handlers[(byte)RagonOperation.JOIN_SUCCESS] = new JoinSuccessHandler(this, _readBuffer, listeners, _playerCache, _entityCache); _handlers[(byte)RagonOperation.JOIN_SUCCESS] = new JoinSuccessHandler(this, _readBuffer, listeners, _playerCache, _entityCache);
_handlers[(byte)RagonOperation.JOIN_FAILED] = new JoinFailedHandler(listeners); _handlers[(byte)RagonOperation.JOIN_FAILED] = new JoinFailedHandler(listeners);
@@ -187,7 +187,11 @@ namespace Ragon.Client
internal void AssignRoom(RagonRoom room) internal void AssignRoom(RagonRoom room)
{ {
_room = room; _room = room;
_status = RagonStatus.ROOM; }
internal void SetStatus(RagonStatus status)
{
_status = status;
} }
#endregion #endregion