コード例 #1
0
        public static void ProcessPacket(FastList <byte> packet)
        {
            if (packet == null || packet.Count < 4)
            {
                throw new System.Exception("Packet is null or not valid length");
            }
            int frameCount = BitConverter.ToInt32(packet.innerArray, 0);
            int index      = 4;

            if (FrameManager.HasFrame(frameCount) == false)
            {
                Frame frame = new Frame();

                if (packet.Count > 4)
                {
                    RecordedBytes.AddRange(BitConverter.GetBytes((ushort)packet.Count));
                    RecordedBytes.AddRange(packet);
                    while (index < packet.Count)
                    {
                        Command com = new Command();
                        index += com.Reconstruct(packet.innerArray, index);
                        frame.AddCommand(com);
                    }
                    if (frameCount > LastCommandedFrameCount)
                    {
                        LastCommandedFrameCount = frameCount;
                    }
                }
                FrameManager.AddFrame(frameCount, frame);
            }
            else
            {
            }
        }
コード例 #2
0
        public static void Simulate()
        {
            if (IterationCount == 0)
            {
                switch (sendState)
                {
                case SendState.Autosend:
                    ReceivedBytes.AddRange(BitConverter.GetBytes(LockstepManager.FrameCount));
                    for (i = 0; i < OutCommands.Count; i++)
                    {
                        ReceivedBytes.AddRange(OutCommands [i].Serialized);
                    }
                    break;
                }

                if (ReceivedBytes.Count < 4)
                {
                    return;
                }



                int frameCount = BitConverter.ToInt32(ReceivedBytes.innerArray, 0);
                Index = 4;

                FrameManager.EnsureCapacity(frameCount + 1);

                Frame frame;
                if (!FrameManager.HasFrame [frameCount])
                {
                    ReceivedFrameCount++;
                    if (ReceivedBytes.Count > 4)
                    {
                        RecordedBytes.AddRange(BitConverter.GetBytes((ushort)ReceivedBytes.Count));
                        RecordedBytes.AddRange(ReceivedBytes);
                        LastRecordedFrame = ReceivedFrameCount;
                    }

                    frame = new Frame();
                    FrameManager.AddFrame(frameCount, frame);

                    while (Index < ReceivedBytes.Count)
                    {
                        Command com = new Command();
                        Index += com.Reconstruct(ReceivedBytes.innerArray, Index);
                        frame.AddCommand(com);
                    }
                }

                ReceivedBytes.FastClear();
                OutCommands.FastClear();

                IterationCount = LockstepManager.NetworkingIterationSpread - 1;
            }
            else
            {
                IterationCount--;
                FrameManager.AddFrame(LockstepManager.FrameCount, new Frame());
            }
        }
コード例 #3
0
 public static void Simulate()
 {
     if (GameStarted == false)
     {
     }
     else
     {
         bufferBytes.FastClear();
         bufferBytes.AddRange(BitConverter.GetBytes(InfluenceFrameCount));
         bufferBytes.AddRange(receivedBytes);
         receivedBytes.FastClear();
         ClientManager.NetworkHelper.SendMessageToAll(MessageType.Frame, bufferBytes.ToArray());
         InfluenceFrameCount++;
     }
 }
コード例 #4
0
 static IEnumerator Tick()
 {
     while (true)
     {
         if (IsSimulating && LockstepManager.GameStarted)
         {
             bufferBytes.FastClear();
             bufferBytes.AddRange(BitConverter.GetBytes(InfluenceFrameCount));
             InfluenceFrameCount++;
             bufferBytes.AddRange(receivedBytes);
             receivedBytes.FastClear();
             Send(bufferBytes.ToArray());
         }
         yield return(LSUtility.WaitRealTime(LockstepManager.BaseDeltaTime * LockstepManager.InfluenceResolution));
     }
 }
コード例 #5
0
        public byte[] GetBytes()
        {
            this.Serialize();

            bufferBites.FastClear();
            //Serialize header
            int headerLength    = Header.Length;
            int headerArraySize = (headerLength - 1) / 8 + 1;

            bufferBites.Add((byte)headerArraySize);
            byte[] headerBytes = new byte[headerArraySize];

            Header.CopyTo(headerBytes, 0);

            bufferBites.AddRange(headerBytes);

            //Serializing the good stuff
            for (int i = 0; i < Header.Length; i++)
            {
                if (Header.Get(i))
                {
                    bufferBites.Add(Data[i]);
                }
            }
            return(bufferBites.ToArray());
        }
コード例 #6
0
        static IEnumerator receive(byte[] data)
        {
            yield return(LSUtility.WaitRealTime(UnityEngine.Random.Range(Latency, Latency + Jitter)));

            receivedBytes.AddRange(data);
            yield break;
        }
コード例 #7
0
 public void AddCommands(Command[] coms, int startIndex, int count)
 {
     if (Commands == null)
     {
         Commands = new FastList <Command> ();
     }
     Commands.AddRange(coms, startIndex, count);
 }
コード例 #8
0
        //static FastList<Command> asdf = new FastList<Command>();
        public static void SendCommand(Command com)
        {
            if (com == null)
            {
                return;
            }

            bufferedBytes.AddRange(com.Serialized);
        }
コード例 #9
0
        public static void Simulate()
        {
            if (Offline)
            {
                ReceivedBytes.AddRange(BitConverter.GetBytes(LockstepManager.FrameCount));
                for (i = 0; i < OutCommands.Count; i++)
                {
                    ReceivedBytes.AddRange(OutCommands [i].Serialized);
                }
                AllReceivedBytes.AddRange(BitConverter.GetBytes(ReceivedBytes.Count));
                AllReceivedBytes.AddRange(ReceivedBytes);
            }
            else
            {
            }



            int frameCount = BitConverter.ToInt32(ReceivedBytes.innerArray, 0);

            Index = 4;

            FrameManager.EnsureCapacity(frameCount + 1);

            Frame frame;

            if (!FrameManager.HasFrame [frameCount])
            {
                frame = new Frame();
                FrameManager.AddFrame(frameCount, frame);

                while (Index < ReceivedBytes.Count)
                {
                    Command com = new Command();
                    Index += com.Reconstruct(ReceivedBytes.innerArray, Index);
                    frame.AddCommand(com);
                }
            }

            ReceivedBytes.FastClear();
            OutCommands.FastClear();
        }
コード例 #10
0
        public static void Simulate()
        {
            if (sendType == SendState.None)
            {
                return;
            }

            {
                bufferedBytes.FastClear();

                switch (sendType)
                {
                case SendState.Network:
                    if (SendAggregated)
                    {
                        for (int i = 0; i < outCommands.Count; i++)
                        {
                            bufferedBytes.AddRange(outCommands [i].Serialized);
                        }
                        if (bufferedBytes.Count > 0)
                        {
                            ClientManager.Distribute(bufferedBytes.ToArray());
                        }
                    }
                    break;

                case SendState.Offline:
                    bufferedBytes.AddRange(BitConverter.GetBytes(LockstepManager.InfluenceFrameCount));
                    for (int i = 0; i < outCommands.Count; i++)
                    {
                        bufferedBytes.AddRange(outCommands [i].Serialized);
                    }
                    ProcessPacket(bufferedBytes.ToArray());
                    break;
                }
                outCommands.FastClear();
                NextFrameCount++;
            }
        }
コード例 #11
0
ファイル: CommandManager.cs プロジェクト: fqkw6/AStartTest
        /// <summary>
        /// Sends out all Commands
        /// </summary>
        public static void SendOut()
        {
            if (outCommands.Count > 0)
            {
                bufferedBytes.FastClear();

                for (int i = 0; i < outCommands.Count; i++)
                {
                    bufferedBytes.AddRange(outCommands [i].Serialized);
                }
                if (bufferedBytes.Count > 0)
                {
                    ClientManager.Distribute(bufferedBytes.ToArray());
                }

                outCommands.FastClear();
            }
        }
コード例 #12
0
        public static IEnumerator StreamPlayback(Replay playbackReplay)
        {
            int lastFrameByteCount = 0;
            int playbackPosition   = 0;

            byte[] playbackBytes = playbackReplay.Content;

            bool getNextStream = true;
            int  frameCount    = 0;
            int  nextFrame     = -1;


            yield return(null);

            FrameManager.EndFrame = playbackReplay.LastCommandedFrameCount;

            while (playbackPosition < playbackBytes.Length || frameCount <= nextFrame)
            {
                if (getNextStream == true)
                {
                    bufferBytes.FastClear();
                    lastFrameByteCount = (int)BitConverter.ToUInt16(playbackBytes, playbackPosition);
                    playbackPosition  += 2;
                    nextFrame          = BitConverter.ToInt32(playbackBytes, playbackPosition);
                    bufferBytes.AddRange(playbackBytes, playbackPosition, lastFrameByteCount);
                    playbackPosition += lastFrameByteCount;
                    getNextStream     = false;
                }

                if (nextFrame == frameCount)
                {
                    getNextStream = true;
                    CommandManager.ProcessPacket(bufferBytes);
                }
                else
                {
                    CommandManager.ProcessPacket(BitConverter.GetBytes(frameCount));
                }
                frameCount++;
            }
            yield break;
        }
コード例 #13
0
ファイル: Writer.cs プロジェクト: zhu1987/Lockstep-Framework
 public void Write(byte[] values)
 {
     canvas.AddRange(values);
 }
コード例 #14
0
 public void Enumerate(FastList <T> output)
 {
     output.FastClear();
     output.AddRange(this);
 }