#if defined _timers_included
methodmap SMTimer < Handle {
/*
* Creates a basic timer. Calling .Kill() on a timer will kill the timer. Do not .Kill(), .Close(),
* or delete in a callback! Make sure to null timer in callback if global!
*
* @param interval Interval from the current game time to execute the given function.
* @param func Function to execute once the given interval has elapsed.
* @param data Handle or value to pass through to the timer callback function.
* @param flags Flags to set (such as repeatability or auto-Handle closing).
* @return Handle to the timer object. You do not need to call CloseHandle().
* If the timer could not be created, null will be returned.
*/
public SMTimer(float interval, Timer func, any data = INVALID_HANDLE, int flags = 0) {
return view_as<SMTimer>( CreateTimer( interval, func, data, flags ) );
}
/*
* Kills a timer. Use this instead of delete if you need more options. Do not use in a timer's callback!
*
* @param autoClose If autoClose is true, the data that was passed to CreateTimer() will
* be closed as a handle if TIMER_DATA_HNDL_CLOSE was not specified.
* @error Invalid handles will cause a run time error.
*/
public void Kill(bool autoClose = false) {
KillTimer( this, autoClose );
delete this;
}
/*
* Closes a timer. Do not use in a timer's callback!
*
* @error Invalid handles will cause a run time error.
*/
public void Close() {
delete this;
}
public bool Clear(bool autoClose = false) {
if ( this == null )
return false;
this.Kill( autoClose );
return true;
}
/*
* Manually triggers a timer so its function will be called.
*
* @param reset If reset is true, the elapsed time counter is reset
* so the full interval must pass again.
*/
public void Trigger(bool reset=false) {
TriggerTimer( this, reset );
}
}
#endif