NSEntity: Add Destroy() which makes sure a sub-class is cleanly removed

from the game when possible.
This commit is contained in:
Marco Cawthorne 2022-01-10 13:17:36 -08:00
parent f42263dbfe
commit e4b7d55b3c
Signed by: eukara
GPG key ID: C196CD8BA993248A
8 changed files with 30 additions and 14 deletions

View file

@ -53,8 +53,7 @@ env_soundscape::SpawnKey(string strField, string strKey)
m_iShader = Sound_Precache(strKey); m_iShader = Sound_Precache(strKey);
if (m_iShader == -1) { if (m_iShader == -1) {
think = Util_Destroy; Destroy();
nextthink = time;
} }
break; break;

View file

@ -93,10 +93,9 @@ game_counter::Trigger(entity act, int state)
if (m_iCounted < m_iMaxCount) if (m_iCounted < m_iMaxCount)
return; return;
if (spawnflags & GMCNT_REMOVE) { if (spawnflags & GMCNT_REMOVE)
think = Util_Destroy; Destroy();
nextthink = time; else if (spawnflags & GMCNT_RESET)
} else if (spawnflags & GMCNT_RESET)
Respawn(); Respawn();
else else
m_iValue = 1; m_iValue = 1;

View file

@ -81,4 +81,5 @@ class NSEntity:NSTrigger
virtual void(vector) SetOrigin; virtual void(vector) SetOrigin;
virtual void(vector, vector) SetSize; virtual void(vector, vector) SetSize;
virtual void(string, string) SpawnKey; virtual void(string, string) SpawnKey;
nonvirtual void(void) Destroy;
}; };

View file

@ -508,6 +508,27 @@ NSEntity::SpawnKey(string strKey, string strValue)
} }
} }
/*
============
NSEntity::Destroy
Call if the entity is to be removed the next possible frame.
If you want an entity to be purged immediately, you'll have to jump
through your own hoops. This however will be sufficient 99,99% of the time.
============
*/
void
NSEntity::Destroy(void)
{
think = Util_Destroy;
if (!time)
nextthink = time + 0.01;
else
nextthink = time;
};
/* /*
============ ============
NSEntity::NSEntity NSEntity::NSEntity

View file

@ -115,8 +115,7 @@ func_illusionary::Init(void)
/* this entity is being controlled by the server, remove it */ /* this entity is being controlled by the server, remove it */
if (targetname) { if (targetname) {
think = Util_Destroy; Destroy();
nextthink = time + 0.01f; /* time may be 0.0 */
return; return;
} }

View file

@ -112,8 +112,7 @@ func_ladder::Init(void)
/* this entity is being controlled by the server, remove it */ /* this entity is being controlled by the server, remove it */
if (targetname) { if (targetname) {
think = Util_Destroy; Destroy();
nextthink = time + 0.01f; /* time may be 0.0 */
return; return;
} }

View file

@ -110,8 +110,7 @@ func_wall::Init(void)
/* this entity is being controlled by the server, remove it */ /* this entity is being controlled by the server, remove it */
if (targetname) { if (targetname) {
think = Util_Destroy; Destroy();
nextthink = time + 0.01f; /* time may be 0.0 */
return; return;
} }

View file

@ -173,8 +173,7 @@ light_dynamic::Initialized(void)
{ {
/* we're meant to be a server controlled entity. cancel out and kill us ASAP */ /* we're meant to be a server controlled entity. cancel out and kill us ASAP */
if (targetname) { if (targetname) {
think = Util_Destroy; Destroy();
nextthink = time + 0.1f;
return; return;
} }