NSTimer: Add SetupTimer(entity, void(), float, bool) and RunTimer() methods.

This commit is contained in:
Marco Cawthorne 2022-08-27 11:21:11 -07:00
parent 267a956ec9
commit 27529eb3a6
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
2 changed files with 33 additions and 0 deletions

View File

@ -26,6 +26,13 @@ NSTimer:NSEntity
virtual void(void) _TimerThink;
virtual void(void) _TempTimerThink;
/* creates and sets up a new timer, starts immediately */
static NSTimer(entity, void(), float, bool) ScheduleTimer;
/* self garbage collecting version of the above */
static NSTimer(entity, void(), float, bool) TemporaryTimer;
/* when you want to set up a timer ahead of time, but only run it manually */
virtual void(void) RunTimer;
static NSTimer(entity, void(), float, bool) SetupTimer;
};

View File

@ -99,4 +99,30 @@ NSTimer::TemporaryTimer(entity receiver, void() call, float interval, bool repea
ret.think = NSTimer::_TempTimerThink;
ret.nextthink = time + interval;
return ret;
}
void
NSTimer::RunTimer(void)
{
think = NSTimer::_TimerThink;
nextthink = time + m_flTime;
}
NSTimer
NSTimer::SetupTimer(entity receiver, void() call, float interval, bool repeats)
{
NSTimer ret;
if (this)
ret = this;
else {
ret = spawn(NSTimer);
this = ret;
}
ret.m_eReceiver = receiver;
ret.m_flTime = interval;
ret.m_vFunc = call;
ret.m_bRepeats = repeats;
return ret;
}