ISource2ModScheduler

Interface for scheduling tasks and managing timers.

Provides functionality for:

  • Scheduling callbacks for next frame
  • Creating repeating or delayed timers
  • Managing timer lifecycle

Interface for scheduling tasks and timers.

Interface id ISource2ModScheduler002 (SOURCE2MOD_SCHEDULER_INTERFACE) · Global g_pSource2ModScheduler · Header source2mod/ISource2ModScheduler.h

Types

TimerCallback

using TimerCallback = Source2ModCallback<void()>;

Callback executed by timers A timer's or a next-frame task's callback: a function, an object and a method, or a lambda (Source2ModCallback) -- whose it is, the core reads off it.

Methods

NextFrame

virtual void NextFrame(TimerCallback task) = 0;

Executes a task on the next frame.

Runs once on the next game frame
Dropped if the owning plugin unloads before the frame arrives
ParameterTypeDescription
taskTimerCallbackCallback function; the plugin whose code it is owns it

AddTimer

virtual Timer* AddTimer(float interval, TimerCallback callback, int flags = 0) = 0;

Adds a timer.

Killed automatically when the owning plugin unloads
ParameterTypeDefaultDescription
intervalfloatTime in seconds between executions
callbackTimerCallbackFunction to execute
flagsint0Timer behavior flags

Returns Timer* — Pointer to created Timer

KillTimer

virtual void KillTimer(Timer* timer) = 0;

Removes a timer.

ParameterTypeDescription
timerTimer*Timer instance

Timer

Represents a scheduled timer.

Contains execution data and state for scheduled callbacks.

Fields

FieldTypeDescription
OwnerPluginIdPlugin that created the timer, 0 for Source2Mod itself. The callback holds code inside that plugin's library, so the scheduler has to drop the timer before the library is closed -- destroying the std::function afterwards calls into unmapped memory.
IntervalfloatInterval between executions (seconds)
ExecTimedoubleNext execution time (engine time)
CallbackTimerCallbackCallback function
FlagsintTimer flags (TimerFlags)
InExecboolTrue while callback is executing
KillMeboolMarks timer for deletion

Constructors

Timer(PluginId owner, float interval, double execTime, TimerCallback callback, int flags);

Constructs a timer.

Enums

TimerFlags

enum TimerFlags

Timer behavior flags.

NameValueDescription
TIMER_FLAG_REPEAT1 << 0Repeats timer indefinitely
TIMER_FLAG_NO_MAPCHANGE1 << 1Automatically stops timer on map change

Macros

MacroExpands to
NEXT_FRAME(task)g_pSource2ModScheduler->NextFrame(task)
ADD_TIMER(interval, cb, ...)g_pSource2ModScheduler->AddTimer(interval, cb, ##__VA_ARGS__)
KILL_TIMER(timer)g_pSource2ModScheduler->KillTimer(timer)

On this page