NetworkClient.RegisterSystemHandlers: OnHostClientObjectDestroy/OnObjectDestroy merged to prepare for WorldState

This commit is contained in:
vis2k 2021-05-26 18:27:50 +08:00
parent f97a09e255
commit b640523f9b

View File

@ -103,7 +103,6 @@ internal static void RegisterSystemHandlers(bool hostMode)
// 'message id not found' errors.
if (hostMode)
{
RegisterHandler<ObjectDestroyMessage>(OnHostClientObjectDestroy);
RegisterHandler<NetworkPongMessage>(msg => {}, false);
RegisterHandler<SpawnMessage>(OnHostClientSpawn);
// host mode doesn't need spawning
@ -115,13 +114,13 @@ internal static void RegisterSystemHandlers(bool hostMode)
}
else
{
RegisterHandler<ObjectDestroyMessage>(OnObjectDestroy);
RegisterHandler<NetworkPongMessage>(NetworkTime.OnClientPong, false);
RegisterHandler<SpawnMessage>(OnSpawn);
RegisterHandler<ObjectSpawnStartedMessage>(OnObjectSpawnStarted);
RegisterHandler<ObjectSpawnFinishedMessage>(OnObjectSpawnFinished);
RegisterHandler<EntityStateMessage>(OnEntityStateMessage);
}
RegisterHandler<ObjectDestroyMessage>(OnObjectDestroy);
RegisterHandler<ObjectHideMessage>(OnObjectHide);
RegisterHandler<RpcMessage>(OnRPCMessage);
}
@ -1109,17 +1108,6 @@ static void ClearNullFromSpawned()
}
// host mode callbacks /////////////////////////////////////////////////
static void OnHostClientObjectDestroy(ObjectDestroyMessage message)
{
// Debug.Log("NetworkClient.OnLocalObjectObjDestroy netId:" + msg.netId);
// TODO why do we do this?
// in host mode, .spawned is shared between server and client.
// removing it on client would remove it on server.
// huh.
NetworkIdentity.spawned.Remove(message.netId);
}
internal static void OnHostClientSpawn(SpawnMessage message)
{
if (NetworkIdentity.spawned.TryGetValue(message.netId, out NetworkIdentity localObject) &&
@ -1178,7 +1166,25 @@ static void OnObjectHide(ObjectHideMessage message)
}
}
internal static void OnObjectDestroy(ObjectDestroyMessage message) => DestroyObject(message.netId);
internal static void OnObjectDestroy(ObjectDestroyMessage message)
{
// Debug.Log("NetworkClient.OnObjectDestroy netId:" + msg.netId);
// host mode
if (isHostClient)
{
// TODO why do we do this?
// in host mode, .spawned is shared between server and client.
// removing it on client would remove it on server.
// huh.
NetworkIdentity.spawned.Remove(message.netId);
}
// client only
else
{
DestroyObject(message.netId);
}
}
internal static void OnSpawn(SpawnMessage message)
{