Exemple #1
0
        static sfx_t RegisterSexedSound(entity_state_t ent, String base_renamed)
        {
            sfx_t sfx   = null;
            var   model = "male";
            var   n     = CS_PLAYERSKINS + ent.number - 1;

            if (cl.configstrings[n] != null)
            {
                var p = cl.configstrings[n].IndexOf('\\');
                if (p >= 0)
                {
                    p++;
                    model = cl.configstrings[n].Substring(p);
                    p     = model.IndexOf('/');
                    if (p > 0)
                    {
                        model = model.Substring(0, p - 1);
                    }
                }
            }

            if (model == null || model.Length == 0)
            {
                model = "male";
            }
            var sexedFilename = "#players/" + model + "/" + base_renamed.Substring(1);

            sfx = FindName(sexedFilename, false);
            if (sfx == null)
            {
                FileStream f = null;
                try
                {
                    f = FS.FOpenFile(sexedFilename.Substring(1));
                }
                catch (Exception e)
                {
                }

                if (f != null)
                {
                    try
                    {
                        FS.FCloseFile(f);
                    }
                    catch (Exception e1)
                    {
                    }

                    sfx = RegisterSound(sexedFilename);
                }
                else
                {
                    var maleFilename = "player/male/" + base_renamed.Substring(1);
                    sfx = AliasName(sexedFilename, maleFilename);
                }
            }

            return(sfx);
        }
Exemple #2
0
        public static void ParseBaseline( )
        {
            entity_state_t nullstate = new entity_state_t(null);

            Int32[]        bits   = new[] { 0 };
            var            newnum = CL_ents.ParseEntityBits(bits);
            entity_state_t es     = Globals.cl_entities[newnum].baseline;

            CL_ents.ParseDelta(nullstate, es, newnum, bits[0]);
        }
Exemple #3
0
 public server_t( )
 {
     models = new cmodel_t[Defines.MAX_MODELS];
     for (var n = 0; n < Defines.MAX_MODELS; n++)
     {
         models[n] = new cmodel_t();
     }
     for (var n = 0; n < Defines.MAX_EDICTS; n++)
     {
         baselines[n] = new entity_state_t(null);
     }
 }
Exemple #4
0
        sfx_t RegisterSexedSound(entity_state_t ent, string base_renamed)
        {
            sfx_t  sfx   = null;
            string model = null;
            int    n     = Globals.CS_PLAYERSKINS + ent.number - 1;

            if (Globals.cl.configstrings[n] != null)
            {
                int p = Globals.cl.configstrings[n].IndexOf('\\');
                if (p >= 0)
                {
                    p++;
                    model = Globals.cl.configstrings[n].Substring(p);
                    p     = model.IndexOf('/');
                    if (p > 0)
                    {
                        model = model.Substring(0, p);
                    }
                }
            }

            if (model == null || model.Length == 0)
            {
                model = "male";
            }
            string sexedFilename = "#players/" + model + "/" + base_renamed.Substring(1);

            sfx = FindName(sexedFilename, false);
            if (sfx != null)
            {
                return(sfx);
            }
            if (FS.FileLength(sexedFilename.Substring(1)) > 0)
            {
                return(RegisterSound(sexedFilename));
            }

            if (model.EqualsIgnoreCase("female"))
            {
                string femaleFilename = "player/female/" + base_renamed.Substring(1);
                if (FS.FileLength("sound/" + femaleFilename) > 0)
                {
                    return(AliasName(sexedFilename, femaleFilename));
                }
            }

            string maleFilename = "player/male/" + base_renamed.Substring(1);

            return(AliasName(sexedFilename, maleFilename));
        }
        private sfx_t RegisterSexedSound(entity_state_t ent, string @base)
        {
            sfx_t sfx = null;

            // determine what model the client is using
            string model = null;
            var    n     = Defines.CS_PLAYERSKINS + ent.number - 1;

            if (Globals.cl.configstrings[n] != null)
            {
                var p = Globals.cl.configstrings[n].IndexOf('\\');

                if (p >= 0)
                {
                    p++;
                    model = Globals.cl.configstrings[n][p..];
Exemple #6
0
        static Globals( )
        {
            for (var i = 0; i < cl_entities.Length; i++)
            {
                cl_entities[i] = new centity_t();
            }

            for (var i = 0; i < cl_parse_entities.Length; i++)
            {
                cl_parse_entities[i] = new entity_state_t(null);
            }

            for (var i = 0; i < key_lines.Length; i++)
            {
                key_lines[i] = new Byte[Defines.MAXCMDLINE];
            }
        }
Exemple #7
0
        public static void SV_Baselines_f( )
        {
            Int32          start;
            entity_state_t nullstate;
            entity_state_t base_renamed;

            Com.DPrintf("Baselines() from " + SV_MAIN.sv_client.name + "\\n");
            if (SV_MAIN.sv_client.state != Defines.cs_connected)
            {
                Com.Printf("baselines not valid -- already spawned\\n");
                return;
            }

            if (Lib.Atoi(Cmd.Argv(1)) != SV_INIT.svs.spawncount)
            {
                Com.Printf("SV_Baselines_f from different level\\n");
                SV_New_f();
                return;
            }

            start     = Lib.Atoi(Cmd.Argv(2));
            nullstate = new entity_state_t(null);
            while (SV_MAIN.sv_client.netchan.message.cursize < Defines.MAX_MSGLEN / 2 && start < Defines.MAX_EDICTS)
            {
                base_renamed = SV_INIT.sv.baselines[start];
                if (base_renamed.modelindex != 0 || base_renamed.sound != 0 || base_renamed.effects != 0)
                {
                    MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_spawnbaseline);
                    MSG.WriteDeltaEntity(nullstate, base_renamed, SV_MAIN.sv_client.netchan.message, true, true);
                }

                start++;
            }

            if (start == Defines.MAX_EDICTS)
            {
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext);
                MSG.WriteString(SV_MAIN.sv_client.netchan.message, "precache " + SV_INIT.svs.spawncount + "\\n");
            }
            else
            {
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext);
                MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd baselines " + SV_INIT.svs.spawncount + " " + start + "\\n");
            }
        }
Exemple #8
0
        public static void SV_RecordDemoMessage( )
        {
            if (SV_INIT.svs.demofile == null)
            {
                return;
            }
            entity_state_t nostate = new entity_state_t(null);
            sizebuf_t      buf     = new sizebuf_t();

            SZ.Init(buf, buf_data, buf_data.Length);
            MSG.WriteByte(buf, Defines.svc_frame);
            MSG.WriteLong(buf, SV_INIT.sv.framenum);
            MSG.WriteByte(buf, Defines.svc_packetentities);
            var     e   = 1;
            edict_t ent = GameBase.g_edicts[e];

            while (e < GameBase.num_edicts)
            {
                if (ent.inuse && ent.s.number != 0 && (ent.s.modelindex != 0 || ent.s.effects != 0 || ent.s.sound != 0 || ent.s.event_renamed != 0) && 0 == (ent.svflags & Defines.SVF_NOCLIENT))
                {
                    MSG.WriteDeltaEntity(nostate, ent.s, buf, false, true);
                }
                e++;
                ent = GameBase.g_edicts[e];
            }

            MSG.WriteShort(buf, 0);
            SZ.Write(buf, SV_INIT.svs.demo_multicast.data, SV_INIT.svs.demo_multicast.cursize);
            SZ.Clear(SV_INIT.svs.demo_multicast);
            var len = EndianHandler.SwapInt(buf.cursize);

            try
            {
                SV_INIT.svs.demofile.Write(len);
                SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize);
            }
            catch (Exception e1)
            {
                Com.Printf("Error writing demo file:" + e);
            }
        }
Exemple #9
0
        public static void DeltaEntity(frame_t frame, Int32 newnum, entity_state_t old, Int32 bits)
        {
            centity_t      ent;
            entity_state_t state;

            ent   = Globals.cl_entities[newnum];
            state = Globals.cl_parse_entities[Globals.cl.parse_entities & (Defines.MAX_PARSE_ENTITIES - 1)];
            Globals.cl.parse_entities++;
            frame.num_entities++;
            ParseDelta(old, state, newnum, bits);
            if (state.modelindex != ent.current.modelindex || state.modelindex2 != ent.current.modelindex2 || state.modelindex3 != ent.current.modelindex3 || state.modelindex4 != ent.current.modelindex4 || Math.Abs(state.origin[0] - ent.current.origin[0]) > 512 || Math.Abs(state.origin[1] - ent.current.origin[1]) > 512 || Math.Abs(state.origin[2] - ent.current.origin[2]) > 512 || state.event_renamed == Defines.EV_PLAYER_TELEPORT || state.event_renamed == Defines.EV_OTHER_TELEPORT)
            {
                ent.serverframe = -99;
            }

            if (ent.serverframe != Globals.cl.frame.serverframe - 1)
            {
                ent.trailcount = 1024;
                ent.prev.Set(state);
                if (state.event_renamed == Defines.EV_OTHER_TELEPORT)
                {
                    Math3D.VectorCopy(state.origin, ent.prev.origin);
                    Math3D.VectorCopy(state.origin, ent.lerp_origin);
                }
                else
                {
                    Math3D.VectorCopy(state.old_origin, ent.prev.origin);
                    Math3D.VectorCopy(state.old_origin, ent.lerp_origin);
                }
            }
            else
            {
                ent.prev.Set(ent.current);
            }

            ent.serverframe = Globals.cl.frame.serverframe;
            ent.current.Set(state);
        }
Exemple #10
0
        static void SV_EmitPacketEntities(client_frame_t from, client_frame_t to, sizebuf_t msg)
        {
            entity_state_t oldent = null, newent = null;
            Int32          oldindex, newindex;
            Int32          oldnum, newnum;
            Int32          from_num_entities;
            Int32          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)
                {
                    MSG.WriteDeltaEntity(oldent, newent, msg, false, newent.number <= SV_MAIN.maxclients.value);
                    oldindex++;
                    newindex++;
                    continue;
                }

                if (newnum < oldnum)
                {
                    MSG.WriteDeltaEntity(SV_INIT.sv.baselines[newnum], newent, msg, true, true);
                    newindex++;
                    continue;
                }

                if (newnum > oldnum)
                {
                    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);
        }
Exemple #11
0
        /*
         * ================== WriteDeltaEntity
         *
         * Writes part of a packetentities message. Can delta from either a baseline
         * or a previous packet_entity ==================
         */
        public static void WriteDeltaEntity(entity_state_t from, entity_state_t to, sizebuf_t msg, bool force, bool newentity)
        {
            int bits;

            if (0 == to.number)
            {
                Com.Error(Defines.ERR_FATAL, "Unset entity number");
            }

            if (to.number >= Defines.MAX_EDICTS)
            {
                Com.Error(Defines.ERR_FATAL, "Entity number >= MAX_EDICTS");
            }

            // send an update
            bits = 0;

            if (to.number >= 256)
            {
                bits |= Defines.U_NUMBER16;                 // number8 is implicit otherwise
            }
            if (to.origin[0] != from.origin[0])
            {
                bits |= Defines.U_ORIGIN1;
            }

            if (to.origin[1] != from.origin[1])
            {
                bits |= Defines.U_ORIGIN2;
            }

            if (to.origin[2] != from.origin[2])
            {
                bits |= Defines.U_ORIGIN3;
            }

            if (to.angles[0] != from.angles[0])
            {
                bits |= Defines.U_ANGLE1;
            }

            if (to.angles[1] != from.angles[1])
            {
                bits |= Defines.U_ANGLE2;
            }

            if (to.angles[2] != from.angles[2])
            {
                bits |= Defines.U_ANGLE3;
            }

            if (to.skinnum != from.skinnum)
            {
                if (to.skinnum < 256)
                {
                    bits |= Defines.U_SKIN8;
                }
                else if (to.skinnum < 0x10000)
                {
                    bits |= Defines.U_SKIN16;
                }
                else
                {
                    bits |= Defines.U_SKIN8 | Defines.U_SKIN16;
                }
            }

            if (to.frame != from.frame)
            {
                if (to.frame < 256)
                {
                    bits |= Defines.U_FRAME8;
                }
                else
                {
                    bits |= Defines.U_FRAME16;
                }
            }

            if (to.effects != from.effects)
            {
                if (to.effects < 256)
                {
                    bits |= Defines.U_EFFECTS8;
                }
                else if (to.effects < 0x8000)
                {
                    bits |= Defines.U_EFFECTS16;
                }
                else
                {
                    bits |= Defines.U_EFFECTS8 | Defines.U_EFFECTS16;
                }
            }

            if (to.renderfx != from.renderfx)
            {
                if (to.renderfx < 256)
                {
                    bits |= Defines.U_RENDERFX8;
                }
                else if (to.renderfx < 0x8000)
                {
                    bits |= Defines.U_RENDERFX16;
                }
                else
                {
                    bits |= Defines.U_RENDERFX8 | Defines.U_RENDERFX16;
                }
            }

            if (to.solid != from.solid)
            {
                bits |= Defines.U_SOLID;
            }

            // event is not delta compressed, just 0 compressed
            if (to.@event != 0)
            {
                bits |= Defines.U_EVENT;
            }

            if (to.modelindex != from.modelindex)
            {
                bits |= Defines.U_MODEL;
            }

            if (to.modelindex2 != from.modelindex2)
            {
                bits |= Defines.U_MODEL2;
            }

            if (to.modelindex3 != from.modelindex3)
            {
                bits |= Defines.U_MODEL3;
            }

            if (to.modelindex4 != from.modelindex4)
            {
                bits |= Defines.U_MODEL4;
            }

            if (to.sound != from.sound)
            {
                bits |= Defines.U_SOUND;
            }

            if (newentity || (to.renderfx & Defines.RF_BEAM) != 0)
            {
                bits |= Defines.U_OLDORIGIN;
            }

            //
            // write the message
            //
            if (bits == 0 && !force)
            {
                return;                 // nothing to send!
            }
            //----------

            if ((bits & 0xff000000) != 0)
            {
                bits |= Defines.U_MOREBITS3 | Defines.U_MOREBITS2 | Defines.U_MOREBITS1;
            }
            else if ((bits & 0x00ff0000) != 0)
            {
                bits |= Defines.U_MOREBITS2 | Defines.U_MOREBITS1;
            }
            else if ((bits & 0x0000ff00) != 0)
            {
                bits |= Defines.U_MOREBITS1;
            }

            MSG.WriteByte(msg, bits & 255);

            if ((bits & 0xff000000) != 0)
            {
                MSG.WriteByte(msg, ((uint)bits >> 8) & 255);
                MSG.WriteByte(msg, ((uint)bits >> 16) & 255);
                MSG.WriteByte(msg, ((uint)bits >> 24) & 255);
            }
            else if ((bits & 0x00ff0000) != 0)
            {
                MSG.WriteByte(msg, ((uint)bits >> 8) & 255);
                MSG.WriteByte(msg, ((uint)bits >> 16) & 255);
            }
            else if ((bits & 0x0000ff00) != 0)
            {
                MSG.WriteByte(msg, ((uint)bits >> 8) & 255);
            }

            //----------

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

            if ((bits & Defines.U_MODEL) != 0)
            {
                MSG.WriteByte(msg, to.modelindex);
            }

            if ((bits & Defines.U_MODEL2) != 0)
            {
                MSG.WriteByte(msg, to.modelindex2);
            }

            if ((bits & Defines.U_MODEL3) != 0)
            {
                MSG.WriteByte(msg, to.modelindex3);
            }

            if ((bits & Defines.U_MODEL4) != 0)
            {
                MSG.WriteByte(msg, to.modelindex4);
            }

            if ((bits & Defines.U_FRAME8) != 0)
            {
                MSG.WriteByte(msg, to.frame);
            }

            if ((bits & Defines.U_FRAME16) != 0)
            {
                MSG.WriteShort(msg, to.frame);
            }

            if ((bits & Defines.U_SKIN8) != 0 && (bits & Defines.U_SKIN16) != 0)             //used for laser
            // colors
            {
                MSG.WriteInt(msg, to.skinnum);
            }
            else if ((bits & Defines.U_SKIN8) != 0)
            {
                MSG.WriteByte(msg, to.skinnum);
            }
            else if ((bits & Defines.U_SKIN16) != 0)
            {
                MSG.WriteShort(msg, to.skinnum);
            }

            if ((bits & (Defines.U_EFFECTS8 | Defines.U_EFFECTS16)) == (Defines.U_EFFECTS8 | Defines.U_EFFECTS16))
            {
                MSG.WriteInt(msg, to.effects);
            }
            else if ((bits & Defines.U_EFFECTS8) != 0)
            {
                MSG.WriteByte(msg, to.effects);
            }
            else if ((bits & Defines.U_EFFECTS16) != 0)
            {
                MSG.WriteShort(msg, to.effects);
            }

            if ((bits & (Defines.U_RENDERFX8 | Defines.U_RENDERFX16)) == (Defines.U_RENDERFX8 | Defines.U_RENDERFX16))
            {
                MSG.WriteInt(msg, to.renderfx);
            }
            else if ((bits & Defines.U_RENDERFX8) != 0)
            {
                MSG.WriteByte(msg, to.renderfx);
            }
            else if ((bits & Defines.U_RENDERFX16) != 0)
            {
                MSG.WriteShort(msg, to.renderfx);
            }

            if ((bits & Defines.U_ORIGIN1) != 0)
            {
                MSG.WriteCoord(msg, to.origin[0]);
            }

            if ((bits & Defines.U_ORIGIN2) != 0)
            {
                MSG.WriteCoord(msg, to.origin[1]);
            }

            if ((bits & Defines.U_ORIGIN3) != 0)
            {
                MSG.WriteCoord(msg, to.origin[2]);
            }

            if ((bits & Defines.U_ANGLE1) != 0)
            {
                MSG.WriteAngle(msg, to.angles[0]);
            }

            if ((bits & Defines.U_ANGLE2) != 0)
            {
                MSG.WriteAngle(msg, to.angles[1]);
            }

            if ((bits & Defines.U_ANGLE3) != 0)
            {
                MSG.WriteAngle(msg, to.angles[2]);
            }

            if ((bits & Defines.U_OLDORIGIN) != 0)
            {
                MSG.WriteCoord(msg, to.old_origin[0]);
                MSG.WriteCoord(msg, to.old_origin[1]);
                MSG.WriteCoord(msg, to.old_origin[2]);
            }

            if ((bits & Defines.U_SOUND) != 0)
            {
                MSG.WriteByte(msg, to.sound);
            }

            if ((bits & Defines.U_EVENT) != 0)
            {
                MSG.WriteByte(msg, to.@event);
            }

            if ((bits & Defines.U_SOLID) != 0)
            {
                MSG.WriteShort(msg, to.solid);
            }
        }
Exemple #12
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 #13
0
 public static void ParseDelta(entity_state_t from, entity_state_t to, Int32 number, Int32 bits)
 {
     to.Set(from);
     Math3D.VectorCopy(from.origin, to.old_origin);
     to.number = number;
     if ((bits & Defines.U_MODEL) != 0)
     {
         to.modelindex = MSG.ReadByte(Globals.net_message);
     }
     if ((bits & Defines.U_MODEL2) != 0)
     {
         to.modelindex2 = MSG.ReadByte(Globals.net_message);
     }
     if ((bits & Defines.U_MODEL3) != 0)
     {
         to.modelindex3 = MSG.ReadByte(Globals.net_message);
     }
     if ((bits & Defines.U_MODEL4) != 0)
     {
         to.modelindex4 = MSG.ReadByte(Globals.net_message);
     }
     if ((bits & Defines.U_FRAME8) != 0)
     {
         to.frame = MSG.ReadByte(Globals.net_message);
     }
     if ((bits & Defines.U_FRAME16) != 0)
     {
         to.frame = MSG.ReadShort(Globals.net_message);
     }
     if ((bits & Defines.U_SKIN8) != 0 && (bits & Defines.U_SKIN16) != 0)
     {
         to.skinnum = MSG.ReadLong(Globals.net_message);
     }
     else if ((bits & Defines.U_SKIN8) != 0)
     {
         to.skinnum = MSG.ReadByte(Globals.net_message);
     }
     else if ((bits & Defines.U_SKIN16) != 0)
     {
         to.skinnum = MSG.ReadShort(Globals.net_message);
     }
     if ((bits & (Defines.U_EFFECTS8 | Defines.U_EFFECTS16)) == (Defines.U_EFFECTS8 | Defines.U_EFFECTS16))
     {
         to.effects = MSG.ReadLong(Globals.net_message);
     }
     else if ((bits & Defines.U_EFFECTS8) != 0)
     {
         to.effects = MSG.ReadByte(Globals.net_message);
     }
     else if ((bits & Defines.U_EFFECTS16) != 0)
     {
         to.effects = MSG.ReadShort(Globals.net_message);
     }
     if ((bits & (Defines.U_RENDERFX8 | Defines.U_RENDERFX16)) == (Defines.U_RENDERFX8 | Defines.U_RENDERFX16))
     {
         to.renderfx = MSG.ReadLong(Globals.net_message);
     }
     else if ((bits & Defines.U_RENDERFX8) != 0)
     {
         to.renderfx = MSG.ReadByte(Globals.net_message);
     }
     else if ((bits & Defines.U_RENDERFX16) != 0)
     {
         to.renderfx = MSG.ReadShort(Globals.net_message);
     }
     if ((bits & Defines.U_ORIGIN1) != 0)
     {
         to.origin[0] = MSG.ReadCoord(Globals.net_message);
     }
     if ((bits & Defines.U_ORIGIN2) != 0)
     {
         to.origin[1] = MSG.ReadCoord(Globals.net_message);
     }
     if ((bits & Defines.U_ORIGIN3) != 0)
     {
         to.origin[2] = MSG.ReadCoord(Globals.net_message);
     }
     if ((bits & Defines.U_ANGLE1) != 0)
     {
         to.angles[0] = MSG.ReadAngle(Globals.net_message);
     }
     if ((bits & Defines.U_ANGLE2) != 0)
     {
         to.angles[1] = MSG.ReadAngle(Globals.net_message);
     }
     if ((bits & Defines.U_ANGLE3) != 0)
     {
         to.angles[2] = MSG.ReadAngle(Globals.net_message);
     }
     if ((bits & Defines.U_OLDORIGIN) != 0)
     {
         MSG.ReadPos(Globals.net_message, to.old_origin);
     }
     if ((bits & Defines.U_SOUND) != 0)
     {
         to.sound = MSG.ReadByte(Globals.net_message);
     }
     if ((bits & Defines.U_EVENT) != 0)
     {
         to.event_renamed = MSG.ReadByte(Globals.net_message);
     }
     else
     {
         to.event_renamed = 0;
     }
     if ((bits & Defines.U_SOLID) != 0)
     {
         to.solid = MSG.ReadShort(Globals.net_message);
     }
 }
Exemple #14
0
        public static void ParsePacketEntities(frame_t oldframe, frame_t newframe)
        {
            Int32          newnum;
            var            bits     = 0;
            entity_state_t oldstate = null;
            Int32          oldnum;

            newframe.parse_entities = Globals.cl.parse_entities;
            newframe.num_entities   = 0;
            var oldindex = 0;

            if (oldframe == null)
            {
                oldnum = 99999;
            }
            else
            {
                oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];
                oldnum   = oldstate.number;
            }

            while (true)
            {
                iw[0]  = bits;
                newnum = ParseEntityBits(iw);
                bits   = iw[0];
                if (newnum >= Defines.MAX_EDICTS)
                {
                    Com.Error(Defines.ERR_DROP, "CL_ParsePacketEntities: bad number:" + newnum);
                }
                if (Globals.net_message.readcount > Globals.net_message.cursize)
                {
                    Com.Error(Defines.ERR_DROP, "CL_ParsePacketEntities: end of message");
                }
                if (0 == newnum)
                {
                    break;
                }
                while (oldnum < newnum)
                {
                    if (Globals.cl_shownet.value == 3)
                    {
                        Com.Printf("   unchanged: " + oldnum + "\\n");
                    }
                    DeltaEntity(newframe, oldnum, oldstate, 0);
                    oldindex++;
                    if (oldindex >= oldframe.num_entities)
                    {
                        oldnum = 99999;
                    }
                    else
                    {
                        oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];
                        oldnum   = oldstate.number;
                    }
                }

                if ((bits & Defines.U_REMOVE) != 0)
                {
                    if (Globals.cl_shownet.value == 3)
                    {
                        Com.Printf("   remove: " + newnum + "\\n");
                    }
                    if (oldnum != newnum)
                    {
                        Com.Printf("U_REMOVE: oldnum != newnum\\n");
                    }
                    oldindex++;
                    if (oldindex >= oldframe.num_entities)
                    {
                        oldnum = 99999;
                    }
                    else
                    {
                        oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];
                        oldnum   = oldstate.number;
                    }

                    continue;
                }

                if (oldnum == newnum)
                {
                    if (Globals.cl_shownet.value == 3)
                    {
                        Com.Printf("   delta: " + newnum + "\\n");
                    }
                    DeltaEntity(newframe, newnum, oldstate, bits);
                    oldindex++;
                    if (oldindex >= oldframe.num_entities)
                    {
                        oldnum = 99999;
                    }
                    else
                    {
                        oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];
                        oldnum   = oldstate.number;
                    }

                    continue;
                }

                if (oldnum > newnum)
                {
                    if (Globals.cl_shownet.value == 3)
                    {
                        Com.Printf("   baseline: " + newnum + "\\n");
                    }
                    DeltaEntity(newframe, newnum, Globals.cl_entities[newnum].baseline, bits);
                    continue;
                }
            }

            while (oldnum != 99999)
            {
                if (Globals.cl_shownet.value == 3)
                {
                    Com.Printf("   unchanged: " + oldnum + "\\n");
                }
                DeltaEntity(newframe, oldnum, oldstate, 0);
                oldindex++;
                if (oldindex >= oldframe.num_entities)
                {
                    oldnum = 99999;
                }
                else
                {
                    oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];
                    oldnum   = oldstate.number;
                }
            }
        }
Exemple #15
0
        public static void WriteDeltaEntity(entity_state_t from, entity_state_t to, sizebuf_t msg, Boolean force, Boolean newentity)
        {
            Int32 bits;

            if (0 == to.number)
            {
                Com.Error(ERR_FATAL, "Unset entity number");
            }
            if (to.number >= MAX_EDICTS)
            {
                Com.Error(ERR_FATAL, "Entity number >= MAX_EDICTS");
            }
            bits = 0;
            if (to.number >= 256)
            {
                bits |= U_NUMBER16;
            }
            if (to.origin[0] != from.origin[0])
            {
                bits |= U_ORIGIN1;
            }
            if (to.origin[1] != from.origin[1])
            {
                bits |= U_ORIGIN2;
            }
            if (to.origin[2] != from.origin[2])
            {
                bits |= U_ORIGIN3;
            }
            if (to.angles[0] != from.angles[0])
            {
                bits |= U_ANGLE1;
            }
            if (to.angles[1] != from.angles[1])
            {
                bits |= U_ANGLE2;
            }
            if (to.angles[2] != from.angles[2])
            {
                bits |= U_ANGLE3;
            }
            if (to.skinnum != from.skinnum)
            {
                if (to.skinnum < 256)
                {
                    bits |= U_SKIN8;
                }
                else if (to.skinnum < 0x10000)
                {
                    bits |= U_SKIN16;
                }
                else
                {
                    bits |= (U_SKIN8 | U_SKIN16);
                }
            }

            if (to.frame != from.frame)
            {
                if (to.frame < 256)
                {
                    bits |= U_FRAME8;
                }
                else
                {
                    bits |= U_FRAME16;
                }
            }

            if (to.effects != from.effects)
            {
                if (to.effects < 256)
                {
                    bits |= U_EFFECTS8;
                }
                else if (to.effects < 0x8000)
                {
                    bits |= U_EFFECTS16;
                }
                else
                {
                    bits |= U_EFFECTS8 | U_EFFECTS16;
                }
            }

            if (to.renderfx != from.renderfx)
            {
                if (to.renderfx < 256)
                {
                    bits |= U_RENDERFX8;
                }
                else if (to.renderfx < 0x8000)
                {
                    bits |= U_RENDERFX16;
                }
                else
                {
                    bits |= U_RENDERFX8 | U_RENDERFX16;
                }
            }

            if (to.solid != from.solid)
            {
                bits |= U_SOLID;
            }
            if (to.event_renamed != 0)
            {
                bits |= U_EVENT;
            }
            if (to.modelindex != from.modelindex)
            {
                bits |= U_MODEL;
            }
            if (to.modelindex2 != from.modelindex2)
            {
                bits |= U_MODEL2;
            }
            if (to.modelindex3 != from.modelindex3)
            {
                bits |= U_MODEL3;
            }
            if (to.modelindex4 != from.modelindex4)
            {
                bits |= U_MODEL4;
            }
            if (to.sound != from.sound)
            {
                bits |= U_SOUND;
            }
            if (newentity || (to.renderfx & RF_BEAM) != 0)
            {
                bits |= U_OLDORIGIN;
            }
            if (bits == 0 && !force)
            {
                return;
            }
            if ((bits & 0xff000000) != 0)
            {
                bits |= U_MOREBITS3 | U_MOREBITS2 | U_MOREBITS1;
            }
            else if ((bits & 0x00ff0000) != 0)
            {
                bits |= U_MOREBITS2 | U_MOREBITS1;
            }
            else if ((bits & 0x0000ff00) != 0)
            {
                bits |= U_MOREBITS1;
            }
            WriteByte(msg, bits & 255);
            if ((bits & 0xff000000) != 0)
            {
                WriteByte(msg, (bits >> 8) & 255);
                WriteByte(msg, (bits >> 16) & 255);
                WriteByte(msg, (bits >> 24) & 255);
            }
            else if ((bits & 0x00ff0000) != 0)
            {
                WriteByte(msg, (bits >> 8) & 255);
                WriteByte(msg, (bits >> 16) & 255);
            }
            else if ((bits & 0x0000ff00) != 0)
            {
                WriteByte(msg, (bits >> 8) & 255);
            }

            if ((bits & U_NUMBER16) != 0)
            {
                WriteShort(msg, to.number);
            }
            else
            {
                WriteByte(msg, to.number);
            }
            if ((bits & U_MODEL) != 0)
            {
                WriteByte(msg, to.modelindex);
            }
            if ((bits & U_MODEL2) != 0)
            {
                WriteByte(msg, to.modelindex2);
            }
            if ((bits & U_MODEL3) != 0)
            {
                WriteByte(msg, to.modelindex3);
            }
            if ((bits & U_MODEL4) != 0)
            {
                WriteByte(msg, to.modelindex4);
            }
            if ((bits & U_FRAME8) != 0)
            {
                WriteByte(msg, to.frame);
            }
            if ((bits & U_FRAME16) != 0)
            {
                WriteShort(msg, to.frame);
            }
            if ((bits & U_SKIN8) != 0 && (bits & U_SKIN16) != 0)
            {
                WriteInt(msg, to.skinnum);
            }
            else if ((bits & U_SKIN8) != 0)
            {
                WriteByte(msg, to.skinnum);
            }
            else if ((bits & U_SKIN16) != 0)
            {
                WriteShort(msg, to.skinnum);
            }
            if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
            {
                WriteInt(msg, to.effects);
            }
            else if ((bits & U_EFFECTS8) != 0)
            {
                WriteByte(msg, to.effects);
            }
            else if ((bits & U_EFFECTS16) != 0)
            {
                WriteShort(msg, to.effects);
            }
            if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
            {
                WriteInt(msg, to.renderfx);
            }
            else if ((bits & U_RENDERFX8) != 0)
            {
                WriteByte(msg, to.renderfx);
            }
            else if ((bits & U_RENDERFX16) != 0)
            {
                WriteShort(msg, to.renderfx);
            }
            if ((bits & U_ORIGIN1) != 0)
            {
                WriteCoord(msg, to.origin[0]);
            }
            if ((bits & U_ORIGIN2) != 0)
            {
                WriteCoord(msg, to.origin[1]);
            }
            if ((bits & U_ORIGIN3) != 0)
            {
                WriteCoord(msg, to.origin[2]);
            }
            if ((bits & U_ANGLE1) != 0)
            {
                WriteAngle(msg, to.angles[0]);
            }
            if ((bits & U_ANGLE2) != 0)
            {
                WriteAngle(msg, to.angles[1]);
            }
            if ((bits & U_ANGLE3) != 0)
            {
                WriteAngle(msg, to.angles[2]);
            }
            if ((bits & U_OLDORIGIN) != 0)
            {
                WriteCoord(msg, to.old_origin[0]);
                WriteCoord(msg, to.old_origin[1]);
                WriteCoord(msg, to.old_origin[2]);
            }

            if ((bits & U_SOUND) != 0)
            {
                WriteByte(msg, to.sound);
            }
            if ((bits & U_EVENT) != 0)
            {
                WriteByte(msg, to.event_renamed);
            }
            if ((bits & U_SOLID) != 0)
            {
                WriteShort(msg, to.solid);
            }
        }