mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
OnObjectSpawnFinished message split into OnObjectSpawnStarted + OnObjectSpawnFinished. Saves 2 bytes of bandwidth per client spawn, and makes the code more obvious.
This commit is contained in:
parent
7e9ed33448
commit
4ece68d053
@ -220,6 +220,7 @@ internal static void RegisterSystemHandlers(NetworkClient client, bool localClie
|
||||
// LocalClient shares the sim/scene with the server, no need for these events
|
||||
client.RegisterHandler(MsgType.SpawnPrefab, OnSpawnPrefab);
|
||||
client.RegisterHandler(MsgType.SpawnSceneObject, OnSpawnSceneObject);
|
||||
client.RegisterHandler(MsgType.SpawnStarted, OnObjectSpawnStarted);
|
||||
client.RegisterHandler(MsgType.SpawnFinished, OnObjectSpawnFinished);
|
||||
client.RegisterHandler(MsgType.ObjectDestroy, OnObjectDestroy);
|
||||
client.RegisterHandler(MsgType.ObjectHide, OnObjectDestroy);
|
||||
@ -511,17 +512,17 @@ static void OnSpawnSceneObject(NetworkMessage netMsg)
|
||||
ApplySpawnPayload(spawnedId, msg.position, msg.rotation, msg.payload, msg.netId);
|
||||
}
|
||||
|
||||
static void OnObjectSpawnStarted(NetworkMessage netMsg)
|
||||
{
|
||||
if (LogFilter.Debug) { Debug.Log("SpawnStarted"); }
|
||||
|
||||
PrepareToSpawnSceneObjects();
|
||||
s_IsSpawnFinished = false;
|
||||
}
|
||||
|
||||
static void OnObjectSpawnFinished(NetworkMessage netMsg)
|
||||
{
|
||||
ObjectSpawnFinishedMessage msg = netMsg.ReadMessage<ObjectSpawnFinishedMessage>();
|
||||
if (LogFilter.Debug) { Debug.Log("SpawnFinished:" + msg.state); }
|
||||
|
||||
if (msg.state == 0)
|
||||
{
|
||||
PrepareToSpawnSceneObjects();
|
||||
s_IsSpawnFinished = false;
|
||||
return;
|
||||
}
|
||||
if (LogFilter.Debug) { Debug.Log("SpawnFinished"); }
|
||||
|
||||
// paul: Initialize the objects in the same order as they were initialized
|
||||
// in the server. This is important if spawned objects
|
||||
|
@ -249,21 +249,9 @@ public override void Serialize(NetworkWriter writer)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO use ByteMessage or use a SpawnStarted/Finished message.
|
||||
class ObjectSpawnFinishedMessage : MessageBase
|
||||
{
|
||||
public byte state; // byte because it's always 0 or 1
|
||||
class ObjectSpawnStartedMessage : EmptyMessage {}
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
state = reader.ReadByte();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(state);
|
||||
}
|
||||
}
|
||||
class ObjectSpawnFinishedMessage : EmptyMessage {}
|
||||
|
||||
class ObjectDestroyMessage : MessageBase
|
||||
{
|
||||
|
@ -717,9 +717,7 @@ public static void SetClientReady(NetworkConnection conn)
|
||||
// Spawn/update all current server objects
|
||||
if (LogFilter.Debug) { Debug.Log("Spawning " + NetworkIdentity.spawned.Count + " objects for conn " + conn.connectionId); }
|
||||
|
||||
ObjectSpawnFinishedMessage msg = new ObjectSpawnFinishedMessage();
|
||||
msg.state = 0;
|
||||
conn.Send((short)MsgType.SpawnFinished, msg);
|
||||
conn.Send((short)MsgType.SpawnStarted, new ObjectSpawnStartedMessage());
|
||||
|
||||
foreach (NetworkIdentity identity in NetworkIdentity.spawned.Values)
|
||||
{
|
||||
@ -742,8 +740,7 @@ public static void SetClientReady(NetworkConnection conn)
|
||||
}
|
||||
}
|
||||
|
||||
msg.state = 1;
|
||||
conn.Send((short)MsgType.SpawnFinished, msg);
|
||||
conn.Send((short)MsgType.SpawnFinished, new ObjectSpawnFinishedMessage());
|
||||
}
|
||||
|
||||
internal static void ShowForConnection(NetworkIdentity identity, NetworkConnection conn)
|
||||
|
@ -35,6 +35,7 @@ public enum MsgType : short
|
||||
UpdateVars = 8,
|
||||
SpawnPrefab = 3,
|
||||
SpawnSceneObject = 10,
|
||||
SpawnStarted = 11,
|
||||
SpawnFinished = 12,
|
||||
ObjectHide = 13,
|
||||
LocalClientAuthority = 15,
|
||||
|
Loading…
Reference in New Issue
Block a user