tecs.ecs.runif
Provides timer, state and logical predicates for system dispatch.
Module contents
Functions
| Function | Kind | Description |
|---|---|---|
after | function | Allows one dispatch after a delay and removes the system before its body runs. |
both | function | Allows dispatch only when both predicates allow it, evaluating left first. |
cooldown | function | Allows the first dispatch immediately, then waits a cooldown between runs. |
either | function | Allows dispatch when either predicate allows it, evaluating left first. |
every | function | Allows repeated dispatches separated by an interval, retaining elapsed overshoot. |
inState | function | Allows dispatch only while the named state is on top of the world stack. |
negate | function | Inverts whether a predicate allows dispatch. |
Functions#
afterfunction#
function after(delay: number): world.RunIfAllows one dispatch after a delay and removes the system before its body runs.
Arguments
| Name | Type | Description |
|---|---|---|
delay | number | The non-negative finite delay in seconds; zero fires on the first call. |
Returns
| Type | Description |
|---|---|
world.RunIf | Returns a new stateful system predicate. |
Raises
Raises when delay is negative or non-finite.
bothfunction#
Allows dispatch only when both predicates allow it, evaluating left first.
Arguments
| Name | Type | Description |
|---|---|---|
lhs | world.RunIf | The predicate that always receives the dispatch delta. |
rhs | world.RunIf | The predicate evaluated only when lhs returns true. |
Returns
| Type | Description |
|---|---|
world.RunIf | Returns a short-circuiting conjunction. |
cooldownfunction#
function cooldown(duration: number): world.RunIfAllows the first dispatch immediately, then waits a cooldown between runs.
Arguments
| Name | Type | Description |
|---|---|---|
duration | number | The non-negative finite cooldown in seconds; zero always allows a run. |
Returns
| Type | Description |
|---|---|
world.RunIf | Returns a new timer that discards elapsed overshoot after each run. |
Raises
Raises when duration is negative or non-finite.
eitherfunction#
Allows dispatch when either predicate allows it, evaluating left first.
Arguments
| Name | Type | Description |
|---|---|---|
lhs | world.RunIf | The predicate that always receives the dispatch delta. |
rhs | world.RunIf | The predicate evaluated only when lhs returns false. |
Returns
| Type | Description |
|---|---|
world.RunIf | Returns a short-circuiting disjunction. |
everyfunction#
function every(interval: number, jitter: number?, generator: random.Random?): world.RunIfAllows repeated dispatches separated by an interval, retaining elapsed overshoot.
Arguments
| Name | Type | Description |
|---|---|---|
interval | number | The positive finite base interval in seconds. |
jitter | number? | The non-negative finite variance in seconds, defaulting to zero. |
generator | random.Random? | The caller-owned random generator, required for nonzero jitter. |
Returns
| Type | Description |
|---|---|
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#
Allows dispatch only while the named state is on top of the world stack.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | The state name to match; it need not be registered yet. |
Returns
| Type | Description |
|---|---|
world.RunIf | Returns a predicate that reads the current state on each call. |
negatefunction#
Inverts whether a predicate allows dispatch.
Arguments
| Name | Type | Description |
|---|---|---|
predicate | world.RunIf | The predicate to evaluate once per call. |
Returns
| Type | Description |
|---|---|
world.RunIf | Returns its logical negation, preserving its timer and other side effects. |