tecs.ecs.runif

Provides timer, state and logical predicates for system dispatch.

Module contents

Functions

FunctionKindDescription
afterfunctionAllows one dispatch after a delay and removes the system before its body runs.
bothfunctionAllows dispatch only when both predicates allow it, evaluating left first.
cooldownfunctionAllows the first dispatch immediately, then waits a cooldown between runs.
eitherfunctionAllows dispatch when either predicate allows it, evaluating left first.
everyfunctionAllows repeated dispatches separated by an interval, retaining elapsed overshoot.
inStatefunctionAllows dispatch only while the named state is on top of the world stack.
negatefunctionInverts whether a predicate allows dispatch.

Functions#

afterfunction#

function after(delay: number): world.RunIf

Allows one dispatch after a delay and removes the system before its body runs.

Arguments

NameTypeDescription
delaynumber

The non-negative finite delay in seconds; zero fires on the first call.

Returns

TypeDescription
world.RunIf

Returns a new stateful system predicate.

Raises

  • Raises when delay is negative or non-finite.

bothfunction#

function both(lhs: world.RunIf, rhs: world.RunIf): world.RunIf

Allows dispatch only when both predicates allow it, evaluating left first.

Arguments

NameTypeDescription
lhsworld.RunIf

The predicate that always receives the dispatch delta.

rhsworld.RunIf

The predicate evaluated only when lhs returns true.

Returns

TypeDescription
world.RunIf

Returns a short-circuiting conjunction.

cooldownfunction#

function cooldown(duration: number): world.RunIf

Allows the first dispatch immediately, then waits a cooldown between runs.

Arguments

NameTypeDescription
durationnumber

The non-negative finite cooldown in seconds; zero always allows a run.

Returns

TypeDescription
world.RunIf

Returns a new timer that discards elapsed overshoot after each run.

Raises

  • Raises when duration is negative or non-finite.

eitherfunction#

function either(lhs: world.RunIf, rhs: world.RunIf): world.RunIf

Allows dispatch when either predicate allows it, evaluating left first.

Arguments

NameTypeDescription
lhsworld.RunIf

The predicate that always receives the dispatch delta.

rhsworld.RunIf

The predicate evaluated only when lhs returns false.

Returns

TypeDescription
world.RunIf

Returns a short-circuiting disjunction.

everyfunction#

function every(interval: number, jitter: number?, generator: random.Random?): world.RunIf

Allows repeated dispatches separated by an interval, retaining elapsed overshoot.

Arguments

NameTypeDescription
intervalnumber

The positive finite base interval in seconds.

jitternumber?

The non-negative finite variance in seconds, defaulting to zero.

generatorrandom.Random?

The caller-owned random generator, required for nonzero jitter.

Returns

TypeDescription
world.RunIf

Returns a new timer, firing at most once per call. The first interval is unjittered; later intervals clamp to at least one percent of the base interval.

Raises

  • Raises for invalid durations or nonzero jitter without a generator.

inStatefunction#

function inState(name: string): world.RunIf

Allows dispatch only while the named state is on top of the world stack.

Arguments

NameTypeDescription
namestring

The state name to match; it need not be registered yet.

Returns

TypeDescription
world.RunIf

Returns a predicate that reads the current state on each call.

negatefunction#

function negate(predicate: world.RunIf): world.RunIf

Inverts whether a predicate allows dispatch.

Arguments

NameTypeDescription
predicateworld.RunIf

The predicate to evaluate once per call.

Returns

TypeDescription
world.RunIf

Returns its logical negation, preserving its timer and other side effects.