mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
WIP NOT GOOD
This commit is contained in:
parent
9688422d52
commit
f704ca7f42
@ -946,14 +946,20 @@ internal static bool IsDirty(ulong mask, int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// serialize components into writer on the server.
|
// serialize components into writer on the server.
|
||||||
// check ownerWritten/observersWritten to know if anything was written
|
// check ownerWritten/observersWritten to know if anything was written.
|
||||||
// We pass dirtyComponentsMask into this function so that we can check
|
//
|
||||||
// if any Components are dirty before creating writers
|
// here's how it works:
|
||||||
// -> SyncMethod: Serialize handles all the magic internally depending
|
// Spawn():
|
||||||
// on SyncMethod, so that the user API (OnSerialize) remains the same.
|
// SerializeServer(initial=true, method=Reliable):
|
||||||
// -> unreliableFullSendIntervalElapsed: indicates that unreliable sync components need a reliable baseline sync this time.
|
// serializes both RELIABLE and UNRELIABLE components with initial=true.
|
||||||
// for reliable components, it just means sync as usual.
|
//
|
||||||
internal void SerializeServer(bool initialState, SyncMethod method, NetworkWriter ownerWriter, NetworkWriter observersWriter, bool unreliableFullSendIntervalElapsed)
|
// Broadcast():
|
||||||
|
// Reliable components:
|
||||||
|
// synced @ syncInterval with initial=false.
|
||||||
|
// Unreliable components:
|
||||||
|
// synced @ 1 Hz with initial=true for baseline.
|
||||||
|
// synced @ N Hz with initial=false for deltas.
|
||||||
|
internal void SerializeServer(bool initialState, SyncMethod method, NetworkWriter ownerWriter, NetworkWriter observersWriter)
|
||||||
{
|
{
|
||||||
// ensure NetworkBehaviours are valid before usage
|
// ensure NetworkBehaviours are valid before usage
|
||||||
ValidateComponents();
|
ValidateComponents();
|
||||||
@ -968,12 +974,9 @@ internal void SerializeServer(bool initialState, SyncMethod method, NetworkWrite
|
|||||||
// the ulong is also varint compressed for minimum bandwidth.
|
// the ulong is also varint compressed for minimum bandwidth.
|
||||||
(ulong ownerMask, ulong observerMask) =
|
(ulong ownerMask, ulong observerMask) =
|
||||||
// initialState: if true, flags all dirty bits.
|
// initialState: if true, flags all dirty bits.
|
||||||
// Reliable: initialState is true once, and then false on subsequent serializations.
|
// Reliable: Spawn serializes with initial=true, Broadcast with initial=false.
|
||||||
// Unreliable: spawn message is Reliable with initialState=true. and for subsequent serializations:
|
// Unreliable: Spawn serializes with initial=true. Broadcast with 1 Hz initial=true and 60 Hz initial=false.
|
||||||
// initialState is alwasy false because we only want to send reliable baseline (or unreliable deltas)
|
ServerDirtyMasks(initialState, method);
|
||||||
// while dirty bits are set.
|
|
||||||
// bits are reset after every reliable baseline send.
|
|
||||||
ServerDirtyMasks(method == SyncMethod.Reliable ? initialState : false, method);
|
|
||||||
|
|
||||||
// if nothing dirty, then don't even write the mask.
|
// if nothing dirty, then don't even write the mask.
|
||||||
// otherwise, every unchanged object would send a 1 byte dirty mask!
|
// otherwise, every unchanged object would send a 1 byte dirty mask!
|
||||||
@ -1007,7 +1010,7 @@ internal void SerializeServer(bool initialState, SyncMethod method, NetworkWrite
|
|||||||
// serialize into helper writer
|
// serialize into helper writer
|
||||||
using (NetworkWriterPooled temp = NetworkWriterPool.Get())
|
using (NetworkWriterPooled temp = NetworkWriterPool.Get())
|
||||||
{
|
{
|
||||||
comp.Serialize(temp, method == SyncMethod.Reliable ? initialState : unreliableFullSendIntervalElapsed);
|
comp.Serialize(temp, initialState);
|
||||||
ArraySegment<byte> segment = temp.ToArraySegment();
|
ArraySegment<byte> segment = temp.ToArraySegment();
|
||||||
|
|
||||||
// copy to owner / observers as needed
|
// copy to owner / observers as needed
|
||||||
@ -1031,16 +1034,10 @@ internal void SerializeServer(bool initialState, SyncMethod method, NetworkWrite
|
|||||||
}
|
}
|
||||||
else if (method == SyncMethod.Unreliable)
|
else if (method == SyncMethod.Unreliable)
|
||||||
{
|
{
|
||||||
// for unreliable: only clear for delta, not for full (spawn messages).
|
// for unreliable: only clear dirty bits on full sync.
|
||||||
// otherwise if a player joins, we serialize monster,
|
// delta sync isn't guaranteed to be delivered so no point in clearing dirty bits.
|
||||||
// and shouldn't clear dirty bits not yet synced to
|
// TODO what about the situation from reliable above?
|
||||||
// other players.
|
if (initialState) comp.ClearAllDirtyBits();
|
||||||
//
|
|
||||||
// for delta: only clear for full syncs.
|
|
||||||
// delta syncs over unreliable may not be delivered,
|
|
||||||
// so we can only clear dirty bits for guaranteed to
|
|
||||||
// be delivered full syncs.
|
|
||||||
if (!initialState && unreliableFullSendIntervalElapsed) comp.ClearAllDirtyBits();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1216,19 +1213,22 @@ internal NetworkIdentitySerialization GetServerSerializationAtTick(int tick, boo
|
|||||||
// reset
|
// reset
|
||||||
lastSerialization.ResetWriters();
|
lastSerialization.ResetWriters();
|
||||||
|
|
||||||
// serialize - reliable
|
// serialize - reliable components:
|
||||||
|
// Spawn serializes with initial=true.
|
||||||
|
// Broadcast serializes with initial=false.
|
||||||
SerializeServer(false,
|
SerializeServer(false,
|
||||||
SyncMethod.Reliable,
|
SyncMethod.Reliable,
|
||||||
lastSerialization.ownerWriterReliable,
|
lastSerialization.ownerWriterReliable,
|
||||||
lastSerialization.observersWriterReliable,
|
lastSerialization.observersWriterReliable);
|
||||||
unreliableFullSendIntervalElapsed);
|
|
||||||
|
|
||||||
// serialize - unreliable
|
// serialize - unreliable components:
|
||||||
SerializeServer(false,
|
// Spawn serializes Reliable with initial=true.
|
||||||
|
// Braodcast serializes @ 1 Hz with initial=true for baseline.
|
||||||
|
// @ 60 Hz with initial=false for deltas.
|
||||||
|
SerializeServer(unreliableFullSendIntervalElapsed,
|
||||||
SyncMethod.Unreliable,
|
SyncMethod.Unreliable,
|
||||||
lastSerialization.ownerWriterFastPaced,
|
lastSerialization.ownerWriterFastPaced,
|
||||||
lastSerialization.observersWriterFastPaced,
|
lastSerialization.observersWriterFastPaced);
|
||||||
unreliableFullSendIntervalElapsed);
|
|
||||||
|
|
||||||
// set tick
|
// set tick
|
||||||
lastSerialization.tick = tick;
|
lastSerialization.tick = tick;
|
||||||
|
@ -1469,10 +1469,11 @@ static ArraySegment<byte> CreateSpawnMessagePayload(bool isOwner, NetworkIdentit
|
|||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spawn: serialize with initial=true to include both RELIABLE and UNRELIABLE components.
|
||||||
// serialize all components with initialState = true
|
// serialize all components with initialState = true
|
||||||
// (can be null if has none)
|
// (can be null if has none)
|
||||||
// SyncMethod doesn't matter for initialState, since everything is included
|
// SyncMethod doesn't matter for initialState, since everything is included
|
||||||
identity.SerializeServer(true, SyncMethod.Reliable, ownerWriter, observersWriter, false);
|
identity.SerializeServer(true, SyncMethod.Reliable, ownerWriter, observersWriter);
|
||||||
|
|
||||||
// convert to ArraySegment to avoid reader allocations
|
// convert to ArraySegment to avoid reader allocations
|
||||||
// if nothing was written, .ToArraySegment returns an empty segment.
|
// if nothing was written, .ToArraySegment returns an empty segment.
|
||||||
|
Loading…
Reference in New Issue
Block a user