Beispiel #1
0
        public void Depacketize(IReadablePacket packet)
        {
            // Unwrap the trailing state and mirror it to all the newer ones.
            packet.ReadPacketizableInto(_simulations[_simulations.Length - 1]);
            MirrorSimulation(_simulations[_simulations.Length - 1], _simulations.Length - 2);

            // Find adds / removes / commands that our out of date now, but keep
            // newer ones (that might be locally generated).
            PrunePastEvents();

            // Continue with reading the list of removes.
            var removeCount = packet.ReadInt32();

            for (var removeIndex = 0; removeIndex < removeCount; ++removeIndex)
            {
                var key = packet.ReadInt64();
                if (!_removes.ContainsKey(key))
                {
                    _removes.Add(key, new List <int>());
                }
                var valueCount = packet.ReadInt32();
                for (var valueIndex = 0; valueIndex < valueCount; ++valueIndex)
                {
                    _removes[key].Add(packet.ReadInt32());
                }
            }

            // And finally the commands.
            var commandCount = packet.ReadInt32();

            for (var commandIndex = 0; commandIndex < commandCount; ++commandIndex)
            {
                var key = packet.ReadInt64();
                if (!_commands.ContainsKey(key))
                {
                    _commands.Add(key, new List <Command>());
                }
                _commands[key].AddRange(packet.ReadPacketizablesWithTypeInfo <Command>());
            }

            // Got a valid state.
            WaitingForSynchronization = false;
        }
Beispiel #2
0
        public void Depacketize(IReadablePacket packet)
        {
            _livingCells.Clear();
            var livingCellCount = packet.ReadInt32();

            for (var i = 0; i < livingCellCount; i++)
            {
                _livingCells.Add(packet.ReadUInt64());
            }
            _pendingCells.Clear();
            var pendingCellCount = packet.ReadInt32();

            for (var i = 0; i < pendingCellCount; i++)
            {
                var cell  = packet.ReadUInt64();
                var frame = packet.ReadInt64();
                _pendingCells.Add(cell, frame);
            }

            _livingSubCells.Clear();
            var livingSubCellCount = packet.ReadInt32();

            for (var i = 0; i < livingSubCellCount; i++)
            {
                _livingSubCells.Add(packet.ReadUInt64());
            }
            _pendingSubCells.Clear();
            var pendingSubCellCount = packet.ReadInt32();

            for (var i = 0; i < pendingSubCellCount; i++)
            {
                var cell  = packet.ReadUInt64();
                var frame = packet.ReadInt64();
                _pendingSubCells.Add(cell, frame);
            }
        }
Beispiel #3
0
 public static IReadablePacket Read(this IReadablePacket packet, out long data)
 {
     data = packet.ReadInt64();
     return(packet);
 }