AllocEdict() public static method

ED_Alloc Either finds a free edict, or allocates a new one. Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.
public static AllocEdict ( ) : edict_t
return edict_t
示例#1
0
        /// <summary>
        /// ED_LoadFromFile
        /// The entities are directly placed in the array, rather than allocated with
        /// ED_Alloc, because otherwise an error loading the map would have entity
        /// number references out of order.
        ///
        /// Creates a server's entity / program execution context by
        /// parsing textual entity definitions out of an ent file.
        ///
        /// Used for both fresh maps and savegame loads.  A fresh map would also need
        /// to call ED_CallSpawnFunctions () to let the objects initialize themselves.
        /// </summary>
        public static void LoadFromFile(string data)
        {
            edict_t ent     = null;
            int     inhibit = 0;

            Progs.GlobalStruct.time = (float)Server.sv.time;

            // parse ents
            while (true)
            {
                // parse the opening brace
                data = Common.Parse(data);
                if (data == null)
                {
                    break;
                }

                if (Common.Token != "{")
                {
                    Sys.Error("ED_LoadFromFile: found {0} when expecting {", Common.Token);
                }

                if (ent == null)
                {
                    ent = Server.EdictNum(0);
                }
                else
                {
                    ent = Server.AllocEdict();
                }

                data = ParseEdict(data, ent);

                // remove things from different skill levels or deathmatch
                if (Host.Deathmatch != 0)
                {
                    if (((int)ent.v.spawnflags & SpawnFlags.SPAWNFLAG_NOT_DEATHMATCH) != 0)
                    {
                        Server.FreeEdict(ent);
                        inhibit++;
                        continue;
                    }
                }
                else if ((Host.CurrentSkill == 0 && ((int)ent.v.spawnflags & SpawnFlags.SPAWNFLAG_NOT_EASY) != 0) ||
                         (Host.CurrentSkill == 1 && ((int)ent.v.spawnflags & SpawnFlags.SPAWNFLAG_NOT_MEDIUM) != 0) ||
                         (Host.CurrentSkill >= 2 && ((int)ent.v.spawnflags & SpawnFlags.SPAWNFLAG_NOT_HARD) != 0))
                {
                    Server.FreeEdict(ent);
                    inhibit++;
                    continue;
                }

                //
                // immediately call spawn function
                //
                if (ent.v.classname == 0)
                {
                    Con.Print("No classname for:\n");
                    Print(ent);
                    Server.FreeEdict(ent);
                    continue;
                }

                // look for the spawn function
                int func = IndexOfFunction(GetString(ent.v.classname));
                if (func == -1)
                {
                    Con.Print("No spawn function for:\n");
                    Print(ent);
                    Server.FreeEdict(ent);
                    continue;
                }

                Progs.GlobalStruct.self = Server.EdictToProg(ent);
                Execute(func);
            }

            Con.DPrint("{0} entities inhibited\n", inhibit);
        }
示例#2
0
        static void PF_Spawn()
        {
            edict_t ed = Server.AllocEdict();

            ReturnEdict(ed);
        }