mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix broadcast and ignore for owned
This commit is contained in:
parent
7e1446b40c
commit
51412fb651
@ -445,16 +445,24 @@ protected virtual void OnClientToServerDeltaSync(byte baselineTick, Vector3? pos
|
|||||||
[ClientRpc(channel = Channels.Reliable)] // reliable baseline
|
[ClientRpc(channel = Channels.Reliable)] // reliable baseline
|
||||||
void RpcServerToClientBaselineSync(ArraySegment<byte> message)
|
void RpcServerToClientBaselineSync(ArraySegment<byte> message)
|
||||||
{
|
{
|
||||||
|
// baseline is broadcast to all clients.
|
||||||
|
// ignore if this object is owned by this client.
|
||||||
|
if (IsClientWithAuthority) return;
|
||||||
|
|
||||||
using (NetworkReaderPooled reader = NetworkReaderPool.Get(message))
|
using (NetworkReaderPooled reader = NetworkReaderPool.Get(message))
|
||||||
{
|
{
|
||||||
DeserializeBaseline(reader);
|
DeserializeBaseline(reader);
|
||||||
// Debug.Log($"[{name}] client received baseline #{lastDeserializedBaselineTick}");
|
Debug.Log($"[{name}] client received baseline #{lastDeserializedBaselineTick} for {name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ClientRpc(channel = Channels.Unreliable)] // unreliable delta
|
[ClientRpc(channel = Channels.Unreliable)] // unreliable delta
|
||||||
void RpcServerToClientDeltaSync(ArraySegment<byte> message)
|
void RpcServerToClientDeltaSync(ArraySegment<byte> message)
|
||||||
{
|
{
|
||||||
|
// delta is broadcast to all clients.
|
||||||
|
// ignore if this object is owned by this client.
|
||||||
|
if (IsClientWithAuthority) return;
|
||||||
|
|
||||||
using (NetworkReaderPooled reader = NetworkReaderPool.Get(message))
|
using (NetworkReaderPooled reader = NetworkReaderPool.Get(message))
|
||||||
{
|
{
|
||||||
if (DeserializeDelta(reader, out byte baselineTick, out Vector3 position, out Quaternion rotation, out Vector3 scale))
|
if (DeserializeDelta(reader, out byte baselineTick, out Vector3 position, out Quaternion rotation, out Vector3 scale))
|
||||||
@ -519,6 +527,8 @@ void UpdateServerBaseline(double localTime)
|
|||||||
// send a reliable baseline every 1 Hz
|
// send a reliable baseline every 1 Hz
|
||||||
if (localTime >= lastBaselineTime + baselineInterval)
|
if (localTime >= lastBaselineTime + baselineInterval)
|
||||||
{
|
{
|
||||||
|
Debug.Log($"UpdateServerBaseline for {name}");
|
||||||
|
|
||||||
// perf: get position/rotation directly. TransformSnapshot is too expensive.
|
// perf: get position/rotation directly. TransformSnapshot is too expensive.
|
||||||
// TransformSnapshot snapshot = ConstructSnapshot();
|
// TransformSnapshot snapshot = ConstructSnapshot();
|
||||||
target.GetLocalPositionAndRotation(out Vector3 position, out Quaternion rotation);
|
target.GetLocalPositionAndRotation(out Vector3 position, out Quaternion rotation);
|
||||||
@ -647,14 +657,13 @@ void UpdateServerInterpolation()
|
|||||||
|
|
||||||
void UpdateServer()
|
void UpdateServer()
|
||||||
{
|
{
|
||||||
// broadcasting
|
// server broadcasts all objects all the time.
|
||||||
if (syncDirection == SyncDirection.ServerToClient || IsClientWithAuthority)
|
// -> not just ServerToClient: ClientToServer need to be broadcast to others too
|
||||||
{
|
|
||||||
// perf: only grab NetworkTime.localTime property once.
|
// perf: only grab NetworkTime.localTime property once.
|
||||||
double localTime = NetworkTime.localTime;
|
double localTime = NetworkTime.localTime;
|
||||||
UpdateServerBaseline(localTime);
|
UpdateServerBaseline(localTime);
|
||||||
UpdateServerDelta(localTime);
|
UpdateServerDelta(localTime);
|
||||||
}
|
|
||||||
|
|
||||||
// interpolate remote clients
|
// interpolate remote clients
|
||||||
UpdateServerInterpolation();
|
UpdateServerInterpolation();
|
||||||
|
Loading…
Reference in New Issue
Block a user