This is basically what I do:
extern CBaseEntity *g_pLastSpawn;
void CHL2MPRules::CleanMap()
{
// Get rid of all entities except players.
CBaseEntity *entity = gEntList.FirstEnt();
while ( entity )
{
if ( entity->bAllowRoundReset() && entity->IsMapCreated())
{
entity->CustomReset();
entity->Remove();
}
entity = gEntList.NextEnt( entity );
}
gEntList.CleanupDeleteList();
HL2MPMapEntityFilter entFilter;
//this will only respawn MAP entities, so we need to make sure that
entities not created by the map itself aren't deleted above!!!
MapEntity_ParseAllEntities( engine->GetMapEntitiesString(),
&entFilter, true);
g_pLastSpawn = NULL; //get rid of it
Activate(); //omega; need to call activate again so that the capture
point list can be regenerated.
}
My customreset function is for anything that creates other entities at
spawn, etc.
Anyway, for the entity->IsMapCreated() part, I have a Boolean that's
defaulted to false and after the entity has been created _And_ spawned
through parseallentities, I do:
if ( pEntity )
{
pEntity->SetMapCreatedEntity(); //omega; mark the entity as
being created by the mapper, for round reset
}
And entity->bAllowRoundReset() is just a Boolean returning function stuck
inside cbaseentity that can be overridden by any child to return false
(defaults true)
Ie: I have info_frontline return false, for example (a map entity that
shouldn't restart)
Also: in my mapentity filter itself:
class HL2MPMapEntityFilter : public IMapEntityFilter
{
public:
virtual bool ShouldCreateEntity( const char *pClassname )
{
//omega; we don't want to re-create world or info_frontline
entities
//if info_frontline is re-created, then gamerules will
re-initialize and
//get all skrewed up.
if ( (Q_stricmp( pClassname, "worldspawn" ) == 0) ||
(Q_stricmp( pClassname, "info_frontline" ) == 0) ||
(Q_stricmp( pClassname, "team_manager" ) == 0))
{
return false;
}
else
{
return true;
}
}
virtual CBaseEntity* CreateNextEntity( const char *pClassname )
{
if (ShouldCreateEntity(pClassname))
return CreateEntityByName( pClassname );
else
return NULL; //don't create it then.
}
};
-----Original Message-----
From: Tim Jones [mailto:[EMAIL PROTECTED]
Sent: June 24, 2005 7:54 AM
To: [email protected]
Subject: Re: [hlcoders] Resetting entites on round restart.
So if I'm already calling CleanupDeleteList() prior to reinstantiating
all my entities and I'm still getting the "no free edicts" error do you
have any suggestions? After calling UTIL_Remove on all the unnecessary
entities and making the call to CleanupDeleteList() I'm left with about
50 entities according to gEntList.NumberOfEdicts(). I realize that this
may not reflect the number of free edicts but I don't know of any way to
get that number. Any suggestions?
-Tim
Jay Stelly wrote:
>>My first thought was that UTIL_Remove wasn't actually
>>clearing stuff out until the next frame so I tried waiting to
>>call Map...Entities() but no luck. I've also tried calling
>>SetFree() on every edict that's deleted.
>>Does anyone have any insight?
>>
>>
>
>
>I haven't followed this discussion, but yes, UTIL_Remove is not
>immediately freeing the entities.
>
>After you've marked them all for delete by calling UTIL_Remove() you can
>call this:
> gEntList.CleanupDeleteList();
>
>which will flush all of the queued deletes.
>
>Jay
>
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.8.0/27 - Release Date: 23/06/2005
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders