mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkServer/Client Broadcast: consistent syntax
This commit is contained in:
parent
0c213fbce4
commit
da12015aca
@ -1512,24 +1512,10 @@ static void BootstrapIdentity(NetworkIdentity identity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// broadcast ///////////////////////////////////////////////////////////
|
// broadcast ///////////////////////////////////////////////////////////
|
||||||
static void BroadcastTimeSnapshot()
|
// NetworkServer has BroadcastToConnection.
|
||||||
|
// NetworkClient has BroadcastToServer.
|
||||||
|
static void BroadcastToServer()
|
||||||
{
|
{
|
||||||
Send(new TimeSnapshotMessage(), Channels.Unreliable);
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure Broadcast() is only called every sendInterval.
|
|
||||||
// calling it every update() would require too much bandwidth.
|
|
||||||
static void Broadcast()
|
|
||||||
{
|
|
||||||
// joined the world yet?
|
|
||||||
if (!connection.isReady) return;
|
|
||||||
|
|
||||||
// nothing to do in host mode. server already knows the state.
|
|
||||||
if (NetworkServer.active) return;
|
|
||||||
|
|
||||||
// send time snapshot every sendInterval.
|
|
||||||
BroadcastTimeSnapshot();
|
|
||||||
|
|
||||||
// for each entity that the client owns
|
// for each entity that the client owns
|
||||||
foreach (NetworkIdentity identity in connection.owned)
|
foreach (NetworkIdentity identity in connection.owned)
|
||||||
{
|
{
|
||||||
@ -1563,6 +1549,23 @@ static void Broadcast()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure Broadcast() is only called every sendInterval.
|
||||||
|
// calling it every update() would require too much bandwidth.
|
||||||
|
static void Broadcast()
|
||||||
|
{
|
||||||
|
// joined the world yet?
|
||||||
|
if (!connection.isReady) return;
|
||||||
|
|
||||||
|
// nothing to do in host mode. server already knows the state.
|
||||||
|
if (NetworkServer.active) return;
|
||||||
|
|
||||||
|
// send time snapshot every sendInterval.
|
||||||
|
Send(new TimeSnapshotMessage(), Channels.Unreliable);
|
||||||
|
|
||||||
|
// broadcast client state to server
|
||||||
|
BroadcastToServer();
|
||||||
|
}
|
||||||
|
|
||||||
// update //////////////////////////////////////////////////////////////
|
// update //////////////////////////////////////////////////////////////
|
||||||
// NetworkEarlyUpdate called before any Update/FixedUpdate
|
// NetworkEarlyUpdate called before any Update/FixedUpdate
|
||||||
// (we add this to the UnityEngine in NetworkLoop)
|
// (we add this to the UnityEngine in NetworkLoop)
|
||||||
|
@ -1963,30 +1963,6 @@ static void Broadcast()
|
|||||||
// update connection to flush out batched messages
|
// update connection to flush out batched messages
|
||||||
connection.Update();
|
connection.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is way too slow because we iterate ALL spawned :/
|
|
||||||
// TODO this is way too complicated :/
|
|
||||||
// to understand what this tries to prevent, consider this example:
|
|
||||||
// monster has health=100
|
|
||||||
// we change health=200, dirty bit is set
|
|
||||||
// player comes in range, gets full serialization spawn packet.
|
|
||||||
// next Broadcast(), player gets the health=200 change because dirty bit was set.
|
|
||||||
//
|
|
||||||
// this code clears all dirty bits if no players are around to prevent it.
|
|
||||||
// BUT there are two issues:
|
|
||||||
// 1. what if a playerB was around the whole time?
|
|
||||||
// 2. why don't we handle broadcast and spawn packets both HERE?
|
|
||||||
// handling spawn separately is why we need this complex magic
|
|
||||||
//
|
|
||||||
// see test: DirtyBitsAreClearedForSpawnedWithoutObservers()
|
|
||||||
// see test: SyncObjectChanges_DontGrowWithoutObservers()
|
|
||||||
//
|
|
||||||
// PAUL: we also do this to avoid ever growing SyncList .changes
|
|
||||||
//ClearSpawnedDirtyBits();
|
|
||||||
//
|
|
||||||
// this was moved to NetworkIdentity.AddObserver!
|
|
||||||
// same result, but no more O(N) loop in here!
|
|
||||||
// TODO remove this comment after moving spawning into Broadcast()!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update //////////////////////////////////////////////////////////////
|
// update //////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user