VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::Scheduler Class Reference

One-shot delays and repeating timers, run on the game thread. More...

#include <Scheduler.hpp>

Public Member Functions

 Scheduler ()=default
Subscription Delay (int64_t delayMs, std::function< void()> callback)
Subscription Repeat (int64_t intervalMs, std::function< void()> callback)
Subscription NextTick (std::function< void()> callback)
Subscription EveryFrame (std::function< void()> callback)
Subscription EveryFrame (std::function< void(float seconds)> callback, float maxSeconds=MaxFrameSeconds)
void OnGameFrame ()

Static Public Attributes

static constexpr float MaxFrameSeconds = 0.1f

Detailed Description

One-shot delays and repeating timers, run on the game thread.

Dropping a registration's Subscription cancels its timer, one-shots included, so a callback never outlives the state it captured.

Definition at line 17 of file Scheduler.hpp.

Constructor & Destructor Documentation

◆ Scheduler()

VoltMod::Scheduler::Scheduler ( )
default

Member Function Documentation

◆ Delay()

Subscription VoltMod::Scheduler::Delay ( int64_t delayMs,
std::function< void()> callback )
nodiscard

Run callback once after delayMs milliseconds.

Definition at line 22 of file Scheduler.cpp.

Referenced by NextTick(), and VoltMod::TimerOn().

◆ EveryFrame() [1/2]

Subscription VoltMod::Scheduler::EveryFrame ( std::function< void()> callback)
nodiscard

Run callback every game frame.

Definition at line 37 of file Scheduler.cpp.

Referenced by EveryFrame().

◆ EveryFrame() [2/2]

Subscription VoltMod::Scheduler::EveryFrame ( std::function< void(float seconds)> callback,
float maxSeconds = MaxFrameSeconds )
nodiscard

Run callback every game frame with the seconds since its previous call, or since this call for the first. Capped at maxSeconds, so a server hitch does not jump anything moving across the map.

Definition at line 43 of file Scheduler.cpp.

References EveryFrame().

◆ NextTick()

Subscription VoltMod::Scheduler::NextTick ( std::function< void()> callback)
nodiscard

Run callback on the very next game frame.

Definition at line 32 of file Scheduler.cpp.

References Delay().

◆ OnGameFrame()

void VoltMod::Scheduler::OnGameFrame ( )

Called every frame by the runtime.

Definition at line 59 of file Scheduler.cpp.

◆ Repeat()

Subscription VoltMod::Scheduler::Repeat ( int64_t intervalMs,
std::function< void()> callback )
nodiscard

Run callback every intervalMs milliseconds.

Definition at line 27 of file Scheduler.cpp.

Member Data Documentation

◆ MaxFrameSeconds

float VoltMod::Scheduler::MaxFrameSeconds = 0.1f
staticconstexpr

The longest frame step EveryFrame reports, in seconds.

Definition at line 35 of file Scheduler.hpp.


The documentation for this class was generated from the following files: