Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        // 64
        /// <summary>
        /// Serializes the CompressedMatrix into an array.
        /// <para>WARNING: The returned array is recycled - so the values are subject to change. Use contents immediately.</para>
        /// <para>If you want to store the returned value, supply a nonalloc array as an argument.</para>
        /// </summary>
        public ulong[] AsArray64(BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            int bitposition = 0;

            crusher.Write(this, reusableArray64, ref bitposition, bcl);
            reusableArray64.Zero((bitposition + 63) >> 6);
            return(reusableArray64);
        }
Exemplo n.º 3
0
        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);
        }