public SerializationFlags OnNetSerialize(int frameId, byte[] buffer, ref int bitposition, SerializationFlags writeFlags) { /// Don't transmit data if this component is disabled. Allows for muting components /// Simply by disabling them at the authority side. if (!isActiveAndEnabled) { buffer.WriteBool(false, ref bitposition); return(SerializationFlags.None); } Frame frame = frames[frameId]; bool isKeyframe = IsKeyframe(frameId); bool forceForNewConn = keyframeRate == 0 && (writeFlags & SerializationFlags.NewConnection) != 0; /// Only check for changes if we aren't forced to send by a keyframe. if (!forceForNewConn && !isKeyframe) { bool hascontent = useDeltas && (prevSentFrame == null || !frame.cm.Equals(prevSentFrame.cm)); if (!hascontent) { buffer.WriteBool(false, ref bitposition); prevSentFrame = frame; //Debug.LogError("Skipping " + frameId); return(SerializationFlags.None); } } //Debug.LogError("OUT " + frameId + " " + frame.m.position); /// has content bool buffer.WriteBool(true, ref bitposition); ///Teleport handling bool _hasTeleported = frame.hasTeleported; buffer.WriteBool(_hasTeleported, ref bitposition); if (_hasTeleported) { //Debug.LogError(Time.time + " " + name + " " + frameId + " <b>SER TELE</b>"); transformCrusher.Write(frame.telecm, buffer, ref bitposition); } /// TRS handling transformCrusher.Write(frame.cm, buffer, ref bitposition); transformCrusher.Decompress(frame.m, frame.cm); prevSentFrame = frame; //if (GetComponent<SyncPickup>()) // Debug.Log(Time.time + " " + name + " " + frameId + " <b>ST SER </b>" + frame.m.position + " -> " + frame.telem.position); //if (_hasTeleported) // return SerializationFlags.HasChanged | SerializationFlags.ForceReliable; //else return(SerializationFlags.HasChanged); }
/// <summary> /// Decompress this CompressedMatrix into the supplied nonalloc Matrix class. /// </summary> /// <param name="nonalloc">The target for the uncompressed TRS.</param> public void Decompress(Matrix nonalloc) { if (crusher != null) { crusher.Decompress(nonalloc, this); } else { nonalloc.Clear(); } }
public SerializationFlags OnNetSerialize(int frameId, byte[] buffer, ref int bitposition, SerializationFlags writeFlags) { Frame frame = frames[frameId]; bool hasTeleported = frame.hasTeleported; bool mustSend = hasTeleported || (writeFlags & SerializationFlags.NewConnection) != 0; /// Don't transmit data non-critical updates if this component is disabled. Allows for muting components /// Simply by disabling them at the authority side. /// Currently teleports and new connections still send even if disabled, but normal keyframes and changes are not sent. if (!mustSend && !isActiveAndEnabled) { buffer.WriteBool(false, ref bitposition); return(SerializationFlags.None); } bool isKeyframe = IsKeyframe(frameId); /// Only check for changes if we aren't forced to send by a keyframe. if (!mustSend && !isKeyframe) { bool hascontent = useDeltas && (prevSentFrame == null || !frame.cm.Equals(prevSentFrame.cm)); if (!hascontent) { buffer.WriteBool(false, ref bitposition); prevSentFrame = frame; //Debug.LogError("Skipping " + frameId); return(SerializationFlags.None); } } SerializationFlags flags = SerializationFlags.HasContent; //Debug.LogError("OUT " + frameId + " " + frame.m.position); /// has content bool buffer.WriteBool(true, ref bitposition); ///Teleport handling buffer.WriteBool(hasTeleported, ref bitposition); if (hasTeleported) { //Debug.LogError(Time.time + " " + name + " " + frameId + " <b>SER TELE</b>"); transformCrusher.Write(frame.telecm, buffer, ref bitposition); if (teleportReliable) { flags |= SerializationFlags.ForceReliable; } } /// TRS handling transformCrusher.Write(frame.cm, buffer, ref bitposition); transformCrusher.Decompress(frame.m, frame.cm); prevSentFrame = frame; //if (frame.hasTeleported) //if (GetComponent<SyncPickup>()) // Debug.LogError(Time.time + " " + frame.frameId + ":" + frameId + " <b> TELE </b>" + frame.m.position + " -> " + frame.telem.position); //if (_hasTeleported) // return SerializationFlags.HasChanged | SerializationFlags.ForceReliable; //else return(flags); }