Example #1
0
        public void CalculateDelta(NetStream state0, NetStream state1, NetStream delta)
        {
            bool          flag           = false;
            NetVector3    netVector      = default(NetVector3);
            NetVector3    netVector2     = default(NetVector3);
            NetQuaternion netQuaternion  = default(NetQuaternion);
            NetQuaternion netQuaternion2 = default(NetQuaternion);

            if (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World || syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
            {
                if (syncPosition != 0)
                {
                    netVector  = ((state0 != null) ? NetVector3.Read(state0, posfull) : zero);
                    netVector2 = NetVector3.Read(state1, posfull);
                    flag      |= (netVector2 != netVector);
                }
                if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
                {
                    netQuaternion  = ((state0 != null) ? NetQuaternion.Read(state0, rotfull) : identity);
                    netQuaternion2 = NetQuaternion.Read(state1, rotfull);
                    flag          |= (netQuaternion2 != netQuaternion);
                }
                if (flag)
                {
                    delta.Write(v: true);
                    if (syncPosition != 0)
                    {
                        NetVector3.Delta(netVector, netVector2, poslarge).Write(delta, possmall, poslarge, posfull);
                    }
                    if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
                    {
                        NetQuaternion.Delta(netQuaternion, netQuaternion2, rotlarge).Write(delta, rotsmall, rotlarge, rotfull);
                    }
                }
                else
                {
                    delta.Write(v: false);
                }
            }
            if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
            {
                eulerEncoder.CalculateDelta(state0, state1, delta);
            }
            if (syncLocalScale)
            {
                NetVector3 netVector3 = default(NetVector3);
                NetVector3 netVector4 = default(NetVector3);
                netVector3 = ((state0 != null) ? NetVector3.Read(state0, posfull) : zero);
                netVector4 = NetVector3.Read(state1, posfull);
                if (netVector4 != netVector3)
                {
                    delta.Write(v: true);
                    NetVector3.Delta(netVector3, netVector4, poslarge).Write(delta, possmall, poslarge, posfull);
                }
                else
                {
                    delta.Write(v: false);
                }
            }
        }
Example #2
0
 public void ApplyState(NetStream state)
 {
     if (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World)
     {
         Vector3 target = NetVector3.Read(state, posfull).Dequantize(posRange);
         ApplyPositionState(target);
     }
     if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
     {
         NetQuaternion netQuaternion = appliedRot = NetQuaternion.Read(state, rotfull);
         Quaternion    target2       = netQuaternion.Dequantize();
         ApplyQuaternionState(target2);
     }
     else if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
     {
         float diff = eulerEncoder.ApplyState(state);
         ApplyEulerState(diff);
     }
     if (body != null)
     {
         Rigidbody rigidbody = body;
         Vector3   vector    = Vector3.zero;
         body.velocity             = vector;
         rigidbody.angularVelocity = vector;
     }
     if (syncLocalScale)
     {
         Vector3 localScale = NetVector3.Read(state, posfull).Dequantize(posRange);
         base.transform.localScale = localScale;
     }
 }
Example #3
0
        public void ApplySnapshot(NetStream stream)
        {
            NetVector3    netVector     = NetVector3.Read(stream, 18);
            NetQuaternion netQuaternion = NetQuaternion.Read(stream, 9);

            netPos = netVector.Dequantize(500f);
            netRot = netQuaternion.Dequantize();
            base.transform.localPosition = netPos;
            base.transform.localRotation = netRot;
        }
Example #4
0
        public Vector3 ApplyLerpedState(NetStream state0, NetStream state1, float mix)
        {
            Vector3 a      = NetVector3.Read(state0, fullBits).Dequantize(range);
            Vector3 vector = NetVector3.Read(state1, fullBits).Dequantize(range);

            if ((a - vector).sqrMagnitude > 15f)
            {
                a = vector;
            }
            return(Vector3.Lerp(a, vector, mix));
        }
Example #5
0
        public bool CalculateWorstCaseDelta(NetStream state0, NetStream state1, NetStream delta, bool writeChanged = true)
        {
            NetVector3 from = (state0 != null) ? NetVector3.Read(state0, fullBits) : NetVector3.Quantize(startPos, range, fullBits);
            NetVector3 to   = (state1 != null) ? NetVector3.Read(state1, fullBits) : NetVector3.Quantize(startPos, range, fullBits);

            if (writeChanged)
            {
                delta.Write(v: true);
            }
            NetVector3.WorstCaseDelta(from, to).Write(delta, deltaSmall, deltaLarge, fullBits);
            return(true);
        }
Example #6
0
        public void AddDelta(NetStream state0, NetStream delta, NetStream result, bool readChanged = true)
        {
            NetVector3 from = (state0 != null) ? NetVector3.Read(state0, fullBits) : NetVector3.Quantize(startPos, range, fullBits);

            if (delta == null || (readChanged && !delta.ReadBool()))
            {
                from.Write(result);
                return;
            }
            NetVector3Delta delta2 = NetVector3Delta.Read(delta, deltaSmall, deltaLarge, fullBits);

            NetVector3.AddDelta(from, delta2).Write(result);
        }
Example #7
0
 public void AddDelta(NetStream state0, NetStream delta, NetStream result)
 {
     if (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World || syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
     {
         if (delta.ReadBool())
         {
             if (syncPosition != 0)
             {
                 NetVector3      from   = (state0 != null) ? NetVector3.Read(state0, posfull) : zero;
                 NetVector3Delta delta2 = NetVector3Delta.Read(delta, possmall, poslarge, posfull);
                 NetVector3.AddDelta(from, delta2).Write(result);
             }
             if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
             {
                 NetQuaternion      from2  = (state0 != null) ? NetQuaternion.Read(state0, rotfull) : identity;
                 NetQuaternionDelta delta3 = NetQuaternionDelta.Read(delta, rotsmall, rotlarge, rotfull);
                 NetQuaternion.AddDelta(from2, delta3).Write(result);
             }
         }
         else
         {
             if (syncPosition != 0)
             {
                 ((state0 != null) ? NetVector3.Read(state0, posfull) : zero).Write(result);
             }
             if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
             {
                 ((state0 != null) ? NetQuaternion.Read(state0, rotfull) : identity).Write(result);
             }
         }
     }
     if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
     {
         eulerEncoder.AddDelta(state0, delta, result);
     }
     if (syncLocalScale)
     {
         if (delta.ReadBool())
         {
             NetVector3      from3  = (state0 != null) ? NetVector3.Read(state0, posfull) : zero;
             NetVector3Delta delta4 = NetVector3Delta.Read(delta, possmall, poslarge, posfull);
             NetVector3.AddDelta(from3, delta4).Write(result);
         }
         else
         {
             ((state0 != null) ? NetVector3.Read(state0, posfull) : zero).Write(result);
         }
     }
 }
Example #8
0
        public bool CalculateDelta(NetStream state0, NetStream state1, NetStream delta, bool writeChanged = true)
        {
            NetVector3 netVector  = (state0 != null) ? NetVector3.Read(state0, fullBits) : NetVector3.Quantize(startPos, range, fullBits);
            NetVector3 netVector2 = NetVector3.Read(state1, fullBits);

            if (netVector == netVector2)
            {
                if (writeChanged)
                {
                    delta.Write(v: false);
                }
                return(false);
            }
            if (writeChanged)
            {
                delta.Write(v: true);
            }
            NetVector3.Delta(netVector, netVector2, deltaLarge).Write(delta, deltaSmall, deltaLarge, fullBits);
            return(true);
        }
Example #9
0
 public void ApplyLerpedState(NetStream state0, NetStream state1, float mix)
 {
     if (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World)
     {
         Vector3 a      = NetVector3.Read(state0, posfull).Dequantize(posRange);
         Vector3 vector = NetVector3.Read(state1, posfull).Dequantize(posRange);
         if ((a - vector).sqrMagnitude > 15f)
         {
             a = vector;
         }
         Vector3 target = Vector3.Lerp(a, vector, mix);
         ApplyPositionState(target);
     }
     if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
     {
         Quaternion    a2            = NetQuaternion.Read(state0, rotfull).Dequantize();
         NetQuaternion netQuaternion = appliedRot = NetQuaternion.Read(state1, rotfull);
         Quaternion    b             = netQuaternion.Dequantize();
         Quaternion    target2       = Quaternion.Slerp(a2, b, mix);
         ApplyQuaternionState(target2);
     }
     else if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
     {
         float diff = eulerEncoder.ApplyLerpedState(state0, state1, mix);
         ApplyEulerState(diff);
     }
     if (body != null)
     {
         Rigidbody rigidbody = body;
         Vector3   vector2   = Vector3.zero;
         body.velocity             = vector2;
         rigidbody.angularVelocity = vector2;
     }
     if (syncLocalScale && (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World))
     {
         Vector3 a3         = NetVector3.Read(state0, posfull).Dequantize(posRange);
         Vector3 b2         = NetVector3.Read(state1, posfull).Dequantize(posRange);
         Vector3 localScale = Vector3.Lerp(a3, b2, mix);
         base.transform.localScale = localScale;
     }
 }
Example #10
0
        public void ReadDelta(NetStream stream, NetStream reference, NetStream fullStream)
        {
            bool          flag          = stream.ReadBool();
            NetVector3    netVector     = (reference != null) ? NetVector3.Read(reference, 18) : default(NetVector3);
            NetQuaternion netQuaternion = (reference != null) ? NetQuaternion.Read(reference, 9) : default(NetQuaternion);
            NetVector3    netVector2;
            NetQuaternion netQuaternion2;

            if (flag)
            {
                NetVector3Delta delta = NetVector3Delta.Read(stream, 5, 9, 18);
                netVector2 = NetVector3.AddDelta(netVector, delta);
                NetQuaternionDelta delta2 = NetQuaternionDelta.Read(stream, 5, 8, 9);
                netQuaternion2 = NetQuaternion.AddDelta(netQuaternion, delta2);
            }
            else
            {
                netVector2     = netVector;
                netQuaternion2 = netQuaternion;
            }
            netVector2.Write(fullStream);
            netQuaternion2.Write(fullStream);
        }
Example #11
0
        public void WriteDelta(NetStream stream, NetStream reference, NetStream fullStream)
        {
            netPos = base.transform.localPosition;
            NetVector3 netVector  = NetVector3.Quantize(netPos, 500f, 18);
            NetVector3 netVector2 = (reference != null) ? NetVector3.Read(reference, 18) : default(NetVector3);

            netRot = base.transform.localRotation;
            NetQuaternion netQuaternion  = NetQuaternion.Quantize(netRot, 9);
            NetQuaternion netQuaternion2 = (reference != null) ? NetQuaternion.Read(reference, 9) : default(NetQuaternion);

            if (netVector != netVector2 || netQuaternion != netQuaternion2)
            {
                stream.Write(v: true);
                NetVector3.Delta(netVector2, netVector, 9).Write(stream, 5, 9, 18);
                NetQuaternion.Delta(netQuaternion2, netQuaternion, 8).Write(stream, 5, 8, 9);
            }
            else
            {
                stream.Write(v: false);
            }
            netVector.Write(fullStream);
            netQuaternion.Write(fullStream);
        }
Example #12
0
 public Vector3 ApplyState(NetStream state)
 {
     return(NetVector3.Read(state, fullBits).Dequantize(range));
 }