Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
 public void Write(NetStream stream)
 {
     stream.Write(sel, 2);
     stream.Write(x, bits);
     stream.Write(y, bits);
     stream.Write(z, bits);
 }
Ejemplo n.º 3
0
        public void AddDelta(NetStream state0, NetStream delta, NetStream result)
        {
            int num = state0?.ReadInt32(fullBits) ?? Quantize(0f, range, fullBits);

            if (!delta.ReadBool())
            {
                result.Write(num, fullBits);
                return;
            }
            int x;

            if (deltaSmall == fullBits)
            {
                x = delta.ReadInt32(fullBits);
            }
            else if (!delta.ReadBool())
            {
                x = delta.ReadInt32(fullBits);
            }
            else
            {
                int num2 = (deltaSmall != deltaLarge) ? delta.ReadInt32(deltaSmall, deltaLarge) : delta.ReadInt32(deltaLarge);
                x = num + num2;
            }
            result.Write(x, fullBits);
        }
Ejemplo n.º 4
0
		public void SendMove(float walkForward, float walkRight, float cameraPitch, float cameraYaw, float leftExtend, float rightExtend, bool jump, bool playDead, bool shooting)
		{
			if (host != null && host.isReady)
			{
				NetStream netStream = NetGame.BeginMessage(NetMsgId.Move);
				try
				{
					netStream.WriteNetId(netId);
					netStream.Write(NetFloat.Quantize(walkForward, 1f, 8), 8);
					netStream.Write(NetFloat.Quantize(walkRight, 1f, 8), 8);
					netStream.Write(NetFloat.Quantize(Math2d.NormalizeAngleDeg(cameraPitch), 180f, 9), 9);
					netStream.Write(NetFloat.Quantize(Math2d.NormalizeAngleDeg(cameraYaw), 180f, 9), 9);
					netStream.Write(NetFloat.Quantize(leftExtend, 1f, 5), 5);
					netStream.Write(NetFloat.Quantize(rightExtend, 1f, 5), 5);
					netStream.Write(jump);
					netStream.Write(playDead);
					netStream.Write(shooting);
					NetGame.instance.SendUnreliableToServer(netStream, -1);
				}
				finally
				{
					if (netStream != null)
					{
						netStream = netStream.Release();
					}
				}
			}
		}
Ejemplo n.º 5
0
 public static void ResetLevel(int checkpoint, int subObjectives)
 {
     if ((bool)instance)
     {
         NetStream netStream = instance.identity.BeginEvent(instance.evtResetLevel);
         netStream.Write((uint)checkpoint, 6);
         netStream.Write((uint)subObjectives, 6);
         instance.identity.EndEvent();
         Debug.Log("Send Reset Level Message");
     }
 }
Ejemplo n.º 6
0
 public static void EnterCheckpoint(int number, int subObjectives)
 {
     if ((bool)instance)
     {
         NetStream netStream = instance.identity.BeginEvent(instance.evtCheckpoint);
         netStream.Write((uint)number, 6);
         netStream.Write((uint)subObjectives, 6);
         instance.identity.EndEvent();
         Debug.Log("Send Enter Checkpoint Message");
     }
 }
Ejemplo n.º 7
0
        public void CalculateDelta(NetStream state0, NetStream state1, NetStream delta)
        {
            int num  = state0?.ReadInt32(fullBits) ?? Quantize(0f, range, fullBits);
            int num2 = state1.ReadInt32(fullBits);

            if (num == num2)
            {
                delta.Write(v: false);
                return;
            }
            delta.Write(v: true);
            if (deltaSmall == fullBits)
            {
                delta.Write(num2, fullBits);
                return;
            }
            int num3 = num2 - num;
            int num4 = 1 << deltaLarge - 1;

            if (num3 < -num4 || num3 >= num4)
            {
                delta.Write(v: false);
                delta.Write(num2, fullBits);
                return;
            }
            delta.Write(v: true);
            if (deltaSmall == deltaLarge)
            {
                delta.Write(num3, deltaLarge);
            }
            else
            {
                delta.Write(num3, deltaSmall, deltaLarge);
            }
        }
Ejemplo n.º 8
0
 public void Buffer(NetStream stream, NetTransport transport, int expectedContainerId)
 {
     lock (unreliableStreamLock)
     {
         if (!CanBuffer(stream, expectedContainerId))
         {
             FlushBuffer(transport);
         }
         if (unreliableStream.position == 0)
         {
             unreliableStream.WriteMsgId(NetMsgId.Container);
             unreliableStream.Write(NetGame.currentLevelInstanceID, 4);
             currentBufferTag = NetGame.currentLevelInstanceID;
             unreliableStream.Write((uint)writeFrameId, 22);
         }
         unreliableStream.WriteStream(stream);
     }
 }
Ejemplo n.º 9
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);
        }
        public bool CalculateDelta(NetStream state0, NetStream state1, NetStream delta, bool writeChanged = true)
        {
            NetQuaternion netQuaternion  = (state0 != null) ? NetQuaternion.Read(state0, fullBits) : NetQuaternion.Quantize(startRot, fullBits);
            NetQuaternion netQuaternion2 = NetQuaternion.Read(state1, fullBits);

            if (netQuaternion == netQuaternion2)
            {
                if (writeChanged)
                {
                    delta.Write(v: false);
                }
                return(false);
            }
            if (writeChanged)
            {
                delta.Write(v: true);
            }
            NetQuaternion.Delta(netQuaternion, netQuaternion2, deltaLarge).Write(delta, deltaSmall, deltaLarge, fullBits);
            return(true);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
 public void Write(NetStream stream, ushort bitsmall, ushort bitlarge, ushort bitfull)
 {
     stream.Write(isRelative);
     stream.Write(sel, 2);
     if (isRelative)
     {
         stream.Write(x, bitsmall, bitlarge);
         stream.Write(y, bitsmall, bitlarge);
         stream.Write(z, bitsmall, bitlarge);
     }
     else
     {
         stream.Write(x, bitfull);
         stream.Write(y, bitfull);
         stream.Write(z, bitfull);
     }
 }
Ejemplo n.º 14
0
		public void ReceiveMove(NetStream stream)
		{
			float b = NetFloat.Dequantize(stream.ReadInt32(8), 1f, 8);
			float b2 = NetFloat.Dequantize(stream.ReadInt32(8), 1f, 8);
			lock (moveLock)
			{
				moveFrames++;
				walkForward = Mathf.Lerp(walkForward, b, 1f / (float)moveFrames);
				walkRight = Mathf.Lerp(walkRight, b2, 1f / (float)moveFrames);
				cameraPitch = NetFloat.Dequantize(stream.ReadInt32(9), 180f, 9);
				cameraYaw = NetFloat.Dequantize(stream.ReadInt32(9), 180f, 9);
				if (moveFrames == 1)
				{
					leftExtend = (rightExtend = 0f);
					jump = (playDead = false);
					shooting = false;
				}
				leftExtend = Mathf.Max(leftExtend, NetFloat.Dequantize(stream.ReadInt32(5), 1f, 5));
				rightExtend = Mathf.Max(rightExtend, NetFloat.Dequantize(stream.ReadInt32(5), 1f, 5));
				jump |= stream.ReadBool();
				playDead |= stream.ReadBool();
				shooting |= stream.ReadBool();
				if (shooting)
				{
					Debug.LogError("shooting = true in NetPlayer.cs:357");
				}
				NetStream netStream = NetGame.BeginMessage(NetMsgId.Move);
				try
				{
					netStream.WriteNetId(netId);
					netStream.Write(holding);
					NetGame.instance.SendUnreliable(host, netStream, -1);
				}
				finally
				{
					if (netStream != null)
					{
						netStream = netStream.Release();
					}
				}
			}
		}
Ejemplo n.º 15
0
 public void Write(NetStream stream, ushort bitsShort)
 {
     stream.Write(x, bitsShort, bits);
     stream.Write(y, bitsShort, bits);
     stream.Write(z, bitsShort, bits);
 }
Ejemplo n.º 16
0
        public void CollectState(NetStream stream, float value)
        {
            int x = Quantize(value, range, fullBits);

            stream.Write(x, fullBits);
        }