dao::timers
The scripts’ delayed events: hold them, deliver them on a clock of your own, trace them.
Declared in dao/Timers.h.
Functions
Advance()
void Advance(float seconds)
Moves time on for the held events of every object that is not on its own clock.
The events that fall due are delivered in order at the event queue’s next update. When a script sends its event again, the new delay counts from the time the old one came due, so four seconds give a 1.5-second tick at 1.5 and at 3.0. Does nothing while the timers are not held.
| Parameter | |
|---|---|
seconds |
the time to add, in game seconds |
AdvanceObject()
void AdvanceObject(ObjectId object, float seconds)
Moves time on for one object’s held events, whether or not it is on its own clock.
Does nothing while the timers are not held.
| Parameter | |
|---|---|
seconds |
the time to add, in game seconds; fractions carry over |
Held()
bool Held()
Returns whether the timers are held.
Hold()
void Hold(bool held)
Holds delayed script events of the held kinds, or lets them run again.
Call it on the game thread. Only events of the held kinds (see HoldKind and HoldFrom) that were sent with a delay are held. The rest of the world’s time, such as commands, the AI and animation, still runs. Held events are not written to a save, so release them before the game saves.
| Parameter | |
|---|---|
held |
true to hold them; false to put the waiting events back in the game’s queue, each with the time it had left |
HoldFrom()
void HoldFrom(float seconds)
Also holds every script event sent with a delay of at least seconds, whatever its kind.
Plot timers wait for seconds at a time, while the scripts also chain steps with delays of 0 to 0.01 seconds that must not wait. A value of 1 holds the first and not the second. Kinds excluded with HoldKind(type, false) stay excluded.
| Parameter | |
|---|---|
seconds |
the shortest delay to hold; 0 or less to hold none by delay (the default) |
HoldKind()
void HoldKind(script::EventType type, bool held=true)
Sets whether script events of one kind are held, whatever their delay.
By default EventType::DotTick and AoeHeartbeat are held, and DelayedGmChange, which the scripts use to end a fight, is never held. A plugin may add the kinds its own timers use. The change applies to events sent after the call, and to those already queued when a hold begins.
| Parameter | |
|---|---|
held |
true to hold the kind; false never to hold it, either by kind or by HoldFrom’s delay |
OwnClock()
void OwnClock(ObjectId object, bool own=true)
Puts an object’s held events on a clock of their own, or back on the shared one.
Does nothing while the timers are not held. Hold(false) returns every object to the shared clock.
| Parameter | |
|---|---|
own |
true for its own clock, which Advance leaves out; false for the shared one |
Trace()
void Trace(bool on)
Starts or stops logging every script event the game queues with a delay, held or not.
Each event is logged at info level when it is queued, with its type, target, sender, delay and the world clock, and again when it is delivered. Use it to find out what a script times with DelayEvent before deciding whether to hold that kind.
| Parameter | |
|---|---|
on |
true to start, false to stop |
Waiting()
std::size_t Waiting()
Returns how many events are held in all.
WaitingFor()
std::size_t WaitingFor(ObjectId object)
Returns how many events are held for one object.