NSTimer: add method StopTimer() and invalidate any thinks during OnRemoveEntity()

This commit is contained in:
Marco Cawthorne 2023-01-22 20:00:36 -08:00
parent 0078d83d80
commit baadd35ffd
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
2 changed files with 21 additions and 0 deletions

View File

@ -42,4 +42,9 @@ public:
/** When called, sets up a timer that has to be run manually later. */
static NSTimer SetupTimer(entity, void(), float, bool);
/** Invalidates the timer when called. */
nonvirtual void StopTimer(void);
virtual void OnRemoveEntity(void);
};

View File

@ -125,4 +125,20 @@ NSTimer::SetupTimer(entity receiver, void() call, float interval, bool repeats)
ret.m_vFunc = call;
ret.m_bRepeats = repeats;
return ret;
}
void
NSTimer::OnRemoveEntity(void)
{
nextthink = 0.0f;
think = __NULL__;
}
void
NSTimer::StopTimer(void)
{
if (this) {
nextthink = 0.0f;
think = __NULL__;
}
}