Exemple #1
0
        private void ParseGamestate(Q3HuffmanStream stream)
        {
            this.gameState.Clear();
            this.incomingCommandSequence = stream.ReadInt32();
            EntityState nullstate = new EntityState();

            ServerCommandType cmd;

            entityBaselinesEvent.WaitOne();

            while (ServerCommandType.EOF != (cmd = ( ServerCommandType )stream.ReadByte()))
            {
                switch (cmd)
                {
                case ServerCommandType.ConfigString:
                    int i = stream.ReadInt16();
                    gameState [i] = stream.ReadString();
                    break;

                case ServerCommandType.BaseLine:
                    int newnum = stream.ReadBits(10);

                    ReadDeltaEntity(stream, nullstate, ref entityBaselines [newnum], newnum);
                    break;

                default:
                    // Unknown command
                    break;
                }
            }

            entityBaselinesEvent.Set();

            this.clientNum    = stream.ReadInt32();
            this.checksumFeed = stream.ReadInt32();

            SystemInfoChanged();
            this.connState = ConnectionState.Primed;

            //SendPureChecksums ();
        }
Exemple #2
0
        private void ReadDeltaPlayerstate(Q3HuffmanStream stream, PlayerState from, ref PlayerState to)
        {
            int i;

            if (from == null)
            {
                from = new PlayerState();
            }

            from.CopyTo(to);

            int      lc = stream.ReadByte();
            NetField field;
            int      trunc;

            for (i = 0, field = PlayerState.fields [i]; i < lc; i++)
            {
                field = PlayerState.fields [i];

                if (stream.ReadBits(1) == 0)
                {
                    // no change
                    KeyValueCoder.TrySetFieldValue(to, field.name,
                                                   KeyValueCoder.TryGetFieldValue(from, field.name));
                }
                else
                {
                    if (field.bits == 0)
                    {
                        // float
                        if (stream.ReadBits(1) == 0)
                        {
                            // integral float
                            trunc = stream.ReadBits(NetField.FLOAT_INT_BITS);
                            // bias to allow equal parts positive and negative
                            trunc -= NetField.FLOAT_INT_BIAS;
                            KeyValueCoder.TrySetFieldValue(to, field.name, trunc);
                        }
                        else
                        {
                            // full floating point value
                            // FIXIT: wrong conversion from 32 bits to floating point value
                            KeyValueCoder.TrySetFieldValue(to, field.name, stream.ReadInt32());
                        }
                    }
                    else
                    {
                        // integer
                        KeyValueCoder.TrySetFieldValue(to, field.name, stream.ReadBits(( int )field.bits));
                    }
                }
            }

            for (i = lc, field = PlayerState.fields [lc]; i < PlayerState.fields.Length; i++)
            {
                field = PlayerState.fields [i];

                // no change
                KeyValueCoder.TrySetFieldValue(to, field.name,
                                               KeyValueCoder.TryGetFieldValue(from, field.name));
            }

            short bits;

            // read the arrays
            if (0 != stream.ReadBits(1))
            {
                // parse stats
                if (0 != stream.ReadBits(1))
                {
                    bits = stream.ReadInt16();

                    for (i = 0; i < 16; i++)
                    {
                        if (0 != (bits & (1 << i)))
                        {
                            to.stats [i] = stream.ReadInt16();
                        }
                    }
                }

                // parse persistant stats
                if (0 != stream.ReadBits(1))
                {
                    bits = stream.ReadInt16();

                    for (i = 0; i < 16; i++)
                    {
                        if (0 != (bits & (1 << i)))
                        {
                            to.persistant [i] = stream.ReadInt16();
                        }
                    }
                }

                // parse ammo
                if (0 != stream.ReadBits(1))
                {
                    bits = stream.ReadInt16();

                    for (i = 0; i < 16; i++)
                    {
                        if (0 != (bits & (1 << i)))
                        {
                            to.ammo [i] = stream.ReadInt16();
                        }
                    }
                }

                // parse powerups
                if (0 != stream.ReadBits(1))
                {
                    bits = stream.ReadInt16();

                    for (i = 0; i < 16; i++)
                    {
                        if (0 != (bits & (1 << i)))
                        {
                            to.powerups [i] = stream.ReadInt32();
                        }
                    }
                }
            }
        }