glemy/stopwatch

A plain accumulate-while-a-condition-holds timer – a genre-agnostic Core utility, not part of glemy/physics, matching how every engine surveyed (Bevy, Godot, LÖVE2D) keeps timer utilities separate from physics. bevy::time::Stopwatch is the closest direct precedent for this exact shape: count-up, no built-in duration or “finished” concept of its own.

Deliberately no threshold/“exceeded” concept here – a specific game’s own trigger threshold (e.g. glemy/games/tiers’s danger_timer_threshold) is that game’s tuning constant, compared directly by the caller, not something this Core utility should own (matching glemy/physics.Model’s own doc comment: no score, no win/lose state – “a specific game wraps this… rather than this type growing a field per game”). See decision 0049.

Values

pub fn tick(elapsed: Float, dt: Float, holding: Bool) -> Float

Advances elapsed (seconds) by dt while holding is True; resets to 0.0 the instant it’s False. dt is assumed non-negative (a real per-frame value); not specially guarded against if negative while holding is True, in which case elapsed decreases rather than increases.

tick(1.0, 0.5, True)
// -> 1.5
tick(1.0, 0.5, False)
// -> 0.0
Search Document