UpdateVarsMessage renamed to EntityStateMessage so it's more obvious. NetworkClient.OnEntityStateMessage can be reused for WorldState easier later.

This commit is contained in:
vis2k 2021-05-26 18:16:51 +08:00
parent 0a6cd15bbd
commit a43837e0d8
4 changed files with 7 additions and 7 deletions

View File

@ -87,7 +87,7 @@ public struct ObjectHideMessage : NetworkMessage
public uint netId; public uint netId;
} }
public struct UpdateVarsMessage : NetworkMessage public struct EntityStateMessage : NetworkMessage
{ {
public uint netId; public uint netId;
// the serialized component data // the serialized component data

View File

@ -109,7 +109,7 @@ internal static void RegisterSystemHandlers(bool hostMode)
// host mode doesn't need spawning // host mode doesn't need spawning
RegisterHandler<ObjectSpawnFinishedMessage>(msg => {}); RegisterHandler<ObjectSpawnFinishedMessage>(msg => {});
// host mode doesn't need state updates // host mode doesn't need state updates
RegisterHandler<UpdateVarsMessage>(msg => {}); RegisterHandler<EntityStateMessage>(msg => {});
} }
else else
{ {
@ -119,7 +119,7 @@ internal static void RegisterSystemHandlers(bool hostMode)
RegisterHandler<SpawnMessage>(OnSpawn); RegisterHandler<SpawnMessage>(OnSpawn);
RegisterHandler<ObjectSpawnStartedMessage>(OnObjectSpawnStarted); RegisterHandler<ObjectSpawnStartedMessage>(OnObjectSpawnStarted);
RegisterHandler<ObjectSpawnFinishedMessage>(OnObjectSpawnFinished); RegisterHandler<ObjectSpawnFinishedMessage>(OnObjectSpawnFinished);
RegisterHandler<UpdateVarsMessage>(OnUpdateVarsMessage); RegisterHandler<EntityStateMessage>(OnEntityStateMessage);
} }
RegisterHandler<RpcMessage>(OnRPCMessage); RegisterHandler<RpcMessage>(OnRPCMessage);
} }
@ -1145,7 +1145,7 @@ internal static void OnHostClientSpawn(SpawnMessage message)
} }
// client-only mode callbacks ////////////////////////////////////////// // client-only mode callbacks //////////////////////////////////////////
static void OnUpdateVarsMessage(UpdateVarsMessage message) static void OnEntityStateMessage(EntityStateMessage message)
{ {
// Debug.Log("NetworkClient.OnUpdateVarsMessage " + msg.netId); // Debug.Log("NetworkClient.OnUpdateVarsMessage " + msg.netId);
if (NetworkIdentity.spawned.TryGetValue(message.netId, out NetworkIdentity localObject) && localObject != null) if (NetworkIdentity.spawned.TryGetValue(message.netId, out NetworkIdentity localObject) && localObject != null)

View File

@ -1510,7 +1510,7 @@ static void BroadcastToConnection(NetworkConnectionToClient connection)
NetworkWriter serialization = GetEntitySerializationForConnection(identity, connection); NetworkWriter serialization = GetEntitySerializationForConnection(identity, connection);
if (serialization != null) if (serialization != null)
{ {
UpdateVarsMessage message = new UpdateVarsMessage EntityStateMessage message = new EntityStateMessage
{ {
netId = identity.netId, netId = identity.netId,
payload = serialization.ToArraySegment() payload = serialization.ToArraySegment()

View File

@ -182,13 +182,13 @@ void DoTest(ulong testSceneId)
public void UpdateVarsMessage() public void UpdateVarsMessage()
{ {
// try setting value with constructor // try setting value with constructor
UpdateVarsMessage message = new UpdateVarsMessage EntityStateMessage message = new EntityStateMessage
{ {
netId = 42, netId = 42,
payload = new ArraySegment<byte>(new byte[] { 0x01, 0x02 }) payload = new ArraySegment<byte>(new byte[] { 0x01, 0x02 })
}; };
byte[] arr = MessagePackingTest.PackToByteArray(message); byte[] arr = MessagePackingTest.PackToByteArray(message);
UpdateVarsMessage fresh = MessagePackingTest.UnpackFromByteArray<UpdateVarsMessage>(arr); EntityStateMessage fresh = MessagePackingTest.UnpackFromByteArray<EntityStateMessage>(arr);
Assert.That(fresh.netId, Is.EqualTo(message.netId)); Assert.That(fresh.netId, Is.EqualTo(message.netId));
Assert.That(fresh.payload.Count, Is.EqualTo(message.payload.Count)); Assert.That(fresh.payload.Count, Is.EqualTo(message.payload.Count));
for (int i = 0; i < fresh.payload.Count; ++i) for (int i = 0; i < fresh.payload.Count; ++i)