コード例 #1
0
        /**
         * Save everything in the world out without deltas. Used for recording
         * footage for merged or assembled demos.
         */
        public static void SV_RecordDemoMessage()
        {
            if (SV_INIT.svs.demofile == null)
            {
                return;
            }

            //memset (nostate, 0, sizeof(nostate));
            entity_state_t nostate = new(null);
            sizebuf_t      buf     = new();

            SZ.Init(buf, SV_ENTS.buf_data, SV_ENTS.buf_data.Length);

            // write a frame message that doesn't contain a player_state_t
            MSG.WriteByte(buf, Defines.svc_frame);
            MSG.WriteLong(buf, SV_INIT.sv.framenum);

            MSG.WriteByte(buf, Defines.svc_packetentities);

            var e   = 1;
            var ent = GameBase.g_edicts[e];

            while (e < GameBase.num_edicts)
            {
                // ignore ents without visible models unless they have an effect
                if (ent.inuse &&
                    ent.s.number != 0 &&
                    (ent.s.modelindex != 0 || ent.s.effects != 0 || ent.s.sound != 0 || ent.s.@event != 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);             // end of packetentities

            // now add the accumulated multicast information
            SZ.Write(buf, SV_INIT.svs.demo_multicast.data, SV_INIT.svs.demo_multicast.cursize);
            SZ.Clear(SV_INIT.svs.demo_multicast);

            // now write the entire message to the file, prefixed by the length
            var len = EndianHandler.swapInt(buf.cursize);

            try
            {
                //fwrite (len, 4, 1, svs.demofile);
                SV_INIT.svs.demofile.Write(len);

                //fwrite (buf.data, buf.cursize, 1, svs.demofile);
                SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize);
            }
            catch (Exception)
            {
                Com.Printf("Error writing demo file:" + e);
            }
        }
コード例 #2
0
ファイル: SV_USER.cs プロジェクト: optimus-code/Q2Sharp
        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");
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
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);
        }
コード例 #5
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
        }