Example #1
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 #2
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 #3
0
        public void CollectState(NetStream stream)
        {
            if (syncPosition == NetBodySyncPosition.Relative)
            {
                NetVector3.Quantize(base.transform.position - relativeTo.position - basePos, posRange, posfull).Write(stream);
            }
            else if (syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World)
            {
                NetVector3.Quantize(((syncPosition != NetBodySyncPosition.Local) ? base.transform.position : base.transform.localPosition) - basePos, posRange, posfull).Write(stream);
            }
            if (syncRotation == NetBodySyncRotation.Relative)
            {
                NetQuaternion netQuaternion = collectedRot = NetQuaternion.Quantize(baseRotInv * Quaternion.Inverse(relativeTo.rotation) * base.transform.rotation, rotfull);
                netQuaternion.Write(stream);
            }
            else if (syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
            {
                NetQuaternion netQuaternion2 = collectedRot = NetQuaternion.Quantize(baseRotInv * ((syncRotation != NetBodySyncRotation.Local) ? base.transform.rotation : base.transform.localRotation), rotfull);
                netQuaternion2.Write(stream);
            }
            else if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
            {
                float value;
                switch (syncRotation)
                {
                case NetBodySyncRotation.EulerX:
                    value = 0f - Math3d.SignedVectorAngle(baseRotInv * base.transform.localRotation * Vector3.up, Vector3.up, Vector3.right);
                    break;

                case NetBodySyncRotation.EulerY:
                    value = 0f - Math3d.SignedVectorAngle(baseRotInv * base.transform.localRotation * Vector3.forward, Vector3.forward, Vector3.up);
                    break;

                case NetBodySyncRotation.EulerZ:
                    value = 0f - Math3d.SignedVectorAngle(baseRotInv * base.transform.localRotation * Vector3.right, Vector3.right, Vector3.forward);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                collectedEuler = value;
                eulerEncoder.CollectState(stream, value);
            }
            if (syncLocalScale)
            {
                NetVector3.Quantize(base.transform.localScale, posRange, posfull).Write(stream);
            }
        }
Example #4
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 #5
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 #6
0
 public void CollectState(NetStream stream, Vector3 value)
 {
     NetVector3.Quantize(value, range, fullBits).Write(stream);
 }
Example #7
0
 public NetVector3 Quantize(Vector3 value)
 {
     return(NetVector3.Quantize(value, range, fullBits));
 }
Example #8
0
 public void Start()
 {
     if (!isStarted)
     {
         isStarted = true;
         if (NetGame.isClient)
         {
             hasNetSetActive = (GetComponent <NetSetActive>() != null);
         }
         NetBodyResetOverride component = GetComponent <NetBodyResetOverride>();
         if ((bool)component)
         {
             mResetFramesAdditionalDelay = component.FramesDelay;
         }
         body        = GetComponent <Rigidbody>();
         isKinematic = body.isKinematic;
         if (syncPosition == NetBodySyncPosition.Relative)
         {
             posRange = 10f;
             posfull -= 6;
         }
         if (syncPosition == NetBodySyncPosition.Local)
         {
             posRange = 10f;
             posfull -= 6;
         }
         if (posRangeOverride != 0f)
         {
             posRange = posRangeOverride;
         }
         eulerEncoder.fullBits   = (ushort)(eulerEncoder.fullBits + rotPrecision);
         eulerEncoder.deltaSmall = (ushort)(eulerEncoder.deltaSmall + rotPrecision);
         eulerEncoder.deltaLarge = (ushort)(eulerEncoder.deltaLarge + rotPrecision);
         possmall        = (ushort)(possmall + posPrecision);
         poslarge        = (ushort)(poslarge + posPrecision);
         posfull         = (ushort)(posfull + posPrecision);
         rotfull         = (ushort)(rotfull + rotPrecision);
         rotsmall        = (ushort)(rotsmall + rotPrecision);
         rotlarge        = (ushort)(rotlarge + rotPrecision);
         startPos        = base.transform.position;
         startRot        = base.transform.rotation;
         startLocalScale = base.transform.localScale;
         if (syncPosition == NetBodySyncPosition.Relative)
         {
             basePos = base.transform.position - relativeTo.position;
         }
         else if (syncPosition == NetBodySyncPosition.Absolute)
         {
             basePos = Vector3.zero;
         }
         else
         {
             basePos = ((syncPosition != NetBodySyncPosition.Local) ? base.transform.position : base.transform.localPosition);
         }
         if (syncRotation == NetBodySyncRotation.Relative)
         {
             baseRot = Quaternion.Inverse(relativeTo.rotation) * base.transform.rotation;
         }
         else if (syncRotation == NetBodySyncRotation.Absolute)
         {
             baseRot = Quaternion.identity;
         }
         else
         {
             baseRot = ((syncRotation != NetBodySyncRotation.Local && syncRotation != NetBodySyncRotation.EulerX && syncRotation != NetBodySyncRotation.EulerY && syncRotation != NetBodySyncRotation.EulerZ) ? base.transform.rotation : base.transform.localRotation);
         }
         baseRotInv = Quaternion.Inverse(baseRot);
         zero       = NetVector3.Quantize(Vector3.zero, posRange, posfull);
         identity   = NetQuaternion.Quantize(Quaternion.identity, rotfull);
         if (!disableSleep)
         {
             sleep = new NetBodySleep(body);
         }
     }
 }