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());
            }
        }
        public static void ProcessPacket(FastList <byte> packet)
        {
            if (ReplayManager.IsPlayingBack)
            {
                return;
            }
            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;

            Frame frame = new Frame();

            // packet.Count > 6 is a guard for random extra bytes bug with DarkRift implementation
            if (packet.Count > 4 && packet.Count > 6)
            {
                while (index < packet.Count)
                {
                    Command com = new Command();
                    index += com.Reconstruct(packet.innerArray, index);
                    frame.AddCommand(com);
                }
            }
            ProcessFrame(frameCount, frame);
        }
        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
            {
            }
        }
        public static Frame[] Deserialize(Reader reader)
        {
            bufferFrames.Clear();

            int length         = reader.ReadInt();
            int lastSavedFrame = -1;

            while (reader.Position < reader.Length)
            {
                int    frameCount   = reader.ReadInt();
                ushort commandCount = reader.ReadUShort();
                Frame  frame        = new Frame();
                for (int i = 0; i < commandCount; i++)
                {
                    Command com = new Command();
                    int     reconstructionCount = (com.Reconstruct(reader.Source, reader.Position));
                    reader.MovePosition(reconstructionCount);
                    frame.AddCommand(com);
                }
                for (int i = lastSavedFrame + 1; i < frameCount; i++)
                {
                    bufferFrames.Add(new Frame());
                }
                bufferFrames.Add(frame);
                lastSavedFrame = frameCount;
            }
            for (int i = lastSavedFrame + 1; i < length; i++)
            {
                bufferFrames.Add(new Frame());
            }
            return(bufferFrames.ToArray());
        }
        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 {

            }
        }
        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 ();
        }
        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();
        }
Example #8
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;

            Frame frame = new Frame();

            if (packet.Count > 4)
            {
                while (index < packet.Count)
                {
                    Command com = new Command();
                    index += com.Reconstruct(packet.innerArray, index);
                    frame.AddCommand(com);
                }
            }
            ProcessFrame(frameCount, frame);
        }
        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 ());
            }
        }