Exemple #1
0
        public static byte[] fatpvs = new byte[65536 / 8];         // 32767 is MAX_MAP_LEAFS

        /*
         * =============================================================================
         *
         * Encode a client frame onto the network channel
         *
         * =============================================================================
         */

        /**
         * Writes a delta update of an entity_state_t list to the message.
         */
        private static void SV_EmitPacketEntities(client_frame_t from, client_frame_t to, sizebuf_t msg)
        {
            entity_state_t oldent = null, newent = null;
            int            oldindex, newindex;
            int            oldnum, newnum;
            int            from_num_entities;
            int            bits;

            MSG.WriteByte(msg, Defines.svc_packetentities);

            if (from == null)
            {
                from_num_entities = 0;
            }
            else
            {
                from_num_entities = from.num_entities;
            }

            newindex = 0;
            oldindex = 0;

            while (newindex < to.num_entities || oldindex < from_num_entities)
            {
                if (newindex >= to.num_entities)
                {
                    newnum = 9999;
                }
                else
                {
                    newent = SV_INIT.svs.client_entities[(to.first_entity + newindex) % SV_INIT.svs.num_client_entities];
                    newnum = newent.number;
                }

                if (oldindex >= from_num_entities)
                {
                    oldnum = 9999;
                }
                else
                {
                    oldent = SV_INIT.svs.client_entities[(from.first_entity + oldindex) % SV_INIT.svs.num_client_entities];
                    oldnum = oldent.number;
                }

                if (newnum == oldnum)
                {
                    // delta update from old position
                    // because the force parm is false, this will not result
                    // in any bytes being emited if the entity has not changed at
                    // all note that players are always 'newentities', this updates
                    // their oldorigin always
                    // and prevents warping
                    MSG.WriteDeltaEntity(oldent, newent, msg, false, newent.number <= SV_MAIN.maxclients.value);
                    oldindex++;
                    newindex++;

                    continue;
                }

                if (newnum < oldnum)
                {
                    // this is a new entity, send it from the baseline
                    MSG.WriteDeltaEntity(SV_INIT.sv.baselines[newnum], newent, msg, true, true);
                    newindex++;

                    continue;
                }

                if (newnum > oldnum)
                {
                    // the old entity isn't present in the new message
                    bits = Defines.U_REMOVE;

                    if (oldnum >= 256)
                    {
                        bits |= Defines.U_NUMBER16 | Defines.U_MOREBITS1;
                    }

                    MSG.WriteByte(msg, bits & 255);

                    if ((bits & 0x0000ff00) != 0)
                    {
                        MSG.WriteByte(msg, (bits >> 8) & 255);
                    }

                    if ((bits & Defines.U_NUMBER16) != 0)
                    {
                        MSG.WriteShort(msg, oldnum);
                    }
                    else
                    {
                        MSG.WriteByte(msg, oldnum);
                    }

                    oldindex++;

                    continue;
                }
            }

            MSG.WriteShort(msg, 0);             // end of packetentities
        }
Exemple #2
0
        /**
         * Writes the status of a player to a client system.
         */
        private static void SV_WritePlayerstateToClient(client_frame_t from, client_frame_t to, sizebuf_t msg)
        {
            // ptr
            player_state_t ps, ops;

            // mem
            player_state_t dummy;

            ps = to.ps;

            if (from == null)
            {
                //memset (dummy, 0, sizeof(dummy));
                dummy = new();
                ops   = dummy;
            }
            else
            {
                ops = @from.ps;
            }

            // determine what needs to be sent
            var pflags = 0;

            if (ps.pmove.pm_type != ops.pmove.pm_type)
            {
                pflags |= Defines.PS_M_TYPE;
            }

            if (ps.pmove.origin[0] != ops.pmove.origin[0] || ps.pmove.origin[1] != ops.pmove.origin[1] || ps.pmove.origin[2] != ops.pmove.origin[2])
            {
                pflags |= Defines.PS_M_ORIGIN;
            }

            if (ps.pmove.velocity[0] != ops.pmove.velocity[0] || ps.pmove.velocity[1] != ops.pmove.velocity[1] || ps.pmove.velocity[2] != ops.pmove.velocity[2])
            {
                pflags |= Defines.PS_M_VELOCITY;
            }

            if (ps.pmove.pm_time != ops.pmove.pm_time)
            {
                pflags |= Defines.PS_M_TIME;
            }

            if (ps.pmove.pm_flags != ops.pmove.pm_flags)
            {
                pflags |= Defines.PS_M_FLAGS;
            }

            if (ps.pmove.gravity != ops.pmove.gravity)
            {
                pflags |= Defines.PS_M_GRAVITY;
            }

            if (ps.pmove.delta_angles[0] != ops.pmove.delta_angles[0] ||
                ps.pmove.delta_angles[1] != ops.pmove.delta_angles[1] ||
                ps.pmove.delta_angles[2] != ops.pmove.delta_angles[2])
            {
                pflags |= Defines.PS_M_DELTA_ANGLES;
            }

            if (ps.viewoffset[0] != ops.viewoffset[0] || ps.viewoffset[1] != ops.viewoffset[1] || ps.viewoffset[2] != ops.viewoffset[2])
            {
                pflags |= Defines.PS_VIEWOFFSET;
            }

            if (ps.viewangles[0] != ops.viewangles[0] || ps.viewangles[1] != ops.viewangles[1] || ps.viewangles[2] != ops.viewangles[2])
            {
                pflags |= Defines.PS_VIEWANGLES;
            }

            if (ps.kick_angles[0] != ops.kick_angles[0] || ps.kick_angles[1] != ops.kick_angles[1] || ps.kick_angles[2] != ops.kick_angles[2])
            {
                pflags |= Defines.PS_KICKANGLES;
            }

            if (ps.blend[0] != ops.blend[0] || ps.blend[1] != ops.blend[1] || ps.blend[2] != ops.blend[2] || ps.blend[3] != ops.blend[3])
            {
                pflags |= Defines.PS_BLEND;
            }

            if (ps.fov != ops.fov)
            {
                pflags |= Defines.PS_FOV;
            }

            if (ps.rdflags != ops.rdflags)
            {
                pflags |= Defines.PS_RDFLAGS;
            }

            if (ps.gunframe != ops.gunframe)
            {
                pflags |= Defines.PS_WEAPONFRAME;
            }

            pflags |= Defines.PS_WEAPONINDEX;

            // write it
            MSG.WriteByte(msg, Defines.svc_playerinfo);
            MSG.WriteShort(msg, pflags);

            // write the pmove_state_t
            if ((pflags & Defines.PS_M_TYPE) != 0)
            {
                MSG.WriteByte(msg, ps.pmove.pm_type);
            }

            if ((pflags & Defines.PS_M_ORIGIN) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.origin[0]);
                MSG.WriteShort(msg, ps.pmove.origin[1]);
                MSG.WriteShort(msg, ps.pmove.origin[2]);
            }

            if ((pflags & Defines.PS_M_VELOCITY) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.velocity[0]);
                MSG.WriteShort(msg, ps.pmove.velocity[1]);
                MSG.WriteShort(msg, ps.pmove.velocity[2]);
            }

            if ((pflags & Defines.PS_M_TIME) != 0)
            {
                MSG.WriteByte(msg, ps.pmove.pm_time);
            }

            if ((pflags & Defines.PS_M_FLAGS) != 0)
            {
                MSG.WriteByte(msg, ps.pmove.pm_flags);
            }

            if ((pflags & Defines.PS_M_GRAVITY) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.gravity);
            }

            if ((pflags & Defines.PS_M_DELTA_ANGLES) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.delta_angles[0]);
                MSG.WriteShort(msg, ps.pmove.delta_angles[1]);
                MSG.WriteShort(msg, ps.pmove.delta_angles[2]);
            }

            // write the rest of the player_state_t
            if ((pflags & Defines.PS_VIEWOFFSET) != 0)
            {
                MSG.WriteChar(msg, ps.viewoffset[0] * 4);
                MSG.WriteChar(msg, ps.viewoffset[1] * 4);
                MSG.WriteChar(msg, ps.viewoffset[2] * 4);
            }

            if ((pflags & Defines.PS_VIEWANGLES) != 0)
            {
                MSG.WriteAngle16(msg, ps.viewangles[0]);
                MSG.WriteAngle16(msg, ps.viewangles[1]);
                MSG.WriteAngle16(msg, ps.viewangles[2]);
            }

            if ((pflags & Defines.PS_KICKANGLES) != 0)
            {
                MSG.WriteChar(msg, ps.kick_angles[0] * 4);
                MSG.WriteChar(msg, ps.kick_angles[1] * 4);
                MSG.WriteChar(msg, ps.kick_angles[2] * 4);
            }

            if ((pflags & Defines.PS_WEAPONINDEX) != 0)
            {
                MSG.WriteByte(msg, ps.gunindex);
            }

            if ((pflags & Defines.PS_WEAPONFRAME) != 0)
            {
                MSG.WriteByte(msg, ps.gunframe);
                MSG.WriteChar(msg, ps.gunoffset[0] * 4);
                MSG.WriteChar(msg, ps.gunoffset[1] * 4);
                MSG.WriteChar(msg, ps.gunoffset[2] * 4);
                MSG.WriteChar(msg, ps.gunangles[0] * 4);
                MSG.WriteChar(msg, ps.gunangles[1] * 4);
                MSG.WriteChar(msg, ps.gunangles[2] * 4);
            }

            if ((pflags & Defines.PS_BLEND) != 0)
            {
                MSG.WriteByte(msg, ps.blend[0] * 255);
                MSG.WriteByte(msg, ps.blend[1] * 255);
                MSG.WriteByte(msg, ps.blend[2] * 255);
                MSG.WriteByte(msg, ps.blend[3] * 255);
            }

            if ((pflags & Defines.PS_FOV) != 0)
            {
                MSG.WriteByte(msg, ps.fov);
            }

            if ((pflags & Defines.PS_RDFLAGS) != 0)
            {
                MSG.WriteByte(msg, ps.rdflags);
            }

            // send stats
            var statbits = 0;

            for (var i = 0; i < Defines.MAX_STATS; i++)
            {
                if (ps.stats[i] != ops.stats[i])
                {
                    statbits |= 1 << i;
                }
            }

            MSG.WriteLong(msg, statbits);

            for (var i = 0; i < Defines.MAX_STATS; i++)
            {
                if ((statbits & (1 << i)) != 0)
                {
                    MSG.WriteShort(msg, ps.stats[i]);
                }
            }
        }