Skip to main content

apply_derivations

Function apply_derivations 

Source
pub fn apply_derivations<H: ScriptHost + Resource<Mutability = Mutable>>(
    host: ResMut<'_, H>,
    store: ResMut<'_, PropertyStore>,
    arrays: Option<Res<'_, ArraySignals>>,
    out: MessageWriter<'_, ScriptCommandEvent>,
)
Expand description

Re-evaluate every computed signal whose deps changed this tick.

Reads the per-tick PropertyStore::dirty_global_names set together with the arrays ArraySignals::changed names, snapshots every derivation whose declared deps intersect that set (plus the pending-initial set), evaluates each via ScriptHost::eval_derivation, and commits the result directly into the store (marking it dirty) so binding readers ordered .after this system observe the fresh derived value on the same tick the dep changed.

Cascades (derived-of-derived) resolve within the tick: after each evaluation wave, names whose stored value actually changed form the dirty set for the next wave, looping to a fixed point (bounded by 32 passes; a self-referential cycle logs and stops). Pending-initial names all run in wave 1 regardless of dirt; an erroring derivation stays pending and retries next tick. Equal writes don’t propagate (set_global_str skips the dirty push).

A panicking evaluation is contained the same way: caught, reported through the same failed-derivation log line an Err gets, and left pending so it retries next tick. See the catch_unwind call below.

Each write is also mirrored as a ScriptCommand::SetSignal event so bare-plugin embedders that drain ScriptCommandEvent keep observing derived values; under lumenc that replay is a next-tick equal-value no-op.