> ## Documentation Index
> Fetch the complete documentation index at: https://torqpy.itsdote.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# SimClock

> Fixed-timestep sim ticks: step, frame, set_dt, hooks, pause, timescale, reset, lerp, and % grids.

Subclass of `Clock` for games / animation-style ticks. Same shred wake order; advances in exact multiples of a fixed `Dur`. Dual update/render cadence via an accumulator (`frame`). No audio required.

```python theme={null}
from torq import SimClock, second, spork, now, lerp, tick
```

## Members

| Member | Meaning |
| - | - |
| `SimClock(dt, sample_rate=48000)` | `dt` must be a positive `Dur` |
| `.dt` / `.set_dt(dur)` | Fixed timestep; writable — retunes later `step` / `frame` (keeps accumulator residual) |
| `.tick` | Completed steps (with constant `dt`, `now == tick * dt` under `step`) |
| `.grid(n)` | `TickGrid` for `%` quantize (same as `tick(n)`; does not collide with `.tick`) |
| `.accumulator` | Leftover `Dur` toward the next fixed step (`frame` only) |
| `.alpha` | `accumulator / dt` (usually `[0, 1)`; may be `>= 1` after `set_dt`) |
| `.on_step(fn, *, priority=0)` / `@sim.on_step` | Fixed-update hook; after shreds; ascending `priority`, then registration order |
| `.on_update` | Alias for `on_step` |
| `.on_render(fn, *, priority=0)` / `@sim.on_render` | Render hook; once per `frame` after updates (not on bare `step`) |
| `.clear_hooks` / `.off_step` / `.off_update` / `.off_render` | Drop registrations |
| `.paused` / `.pause()` / `.resume()` | Freeze `step` / `frame` / `run_ticks` as no-ops |
| `.timescale` | Scale `frame(elapsed)` only (default `1.0`, `>= 0`); `step` ignores it |
| `.step(n=1)` / `.run_ticks(n)` | Advance `n` fixed steps by current `dt` |
| `.frame(elapsed, *, max_steps=None)` | Bank `elapsed * timescale`, drain updates, then render once |
| `.reset()` | Back to origin; hooks stay; pending shreds cancelled; pause/timescale/`dt` unchanged |
| `.lerp(a, b, t=None)` | `a + (b - a) * t`; omit `t` to use this clock’s `alpha` |
| `lerp(a, b, t=None)` | Module helper; omit `t` to use current `SimClock.alpha` |

## Pause a chase

junnu freezes the chase mid-frame so Laddu can inspect the last drawn `alpha`:

```python theme={null}
sim = SimClock(second / 60)
log = []

def junnu_chase():
    while True:
        log.append(("junnu", sim.now, sim.tick))
        yield sim.dt

@sim.on_update
def physics():
    log.append(("update", sim.tick))

@sim.on_render
def laddu_draw():
    log.append(("draw", float(sim.alpha)))

with sim:
    spork(junnu_chase)

sim.frame(sim.dt)          # one fixed update + render
sim.pause()
sim.frame(sim.dt)          # no-op
sim.resume()
sim.frame(sim.dt)
```

## Grid quantize

```python theme={null}
from torq import Node, tick

impulse = Node("collision") % tick(4)   # or % sim.grid(4)
# impulse.due(sim) when tick in {4, 8, 12, …}
```

At each fixed boundary: shreds at that `now` (creation order), then update hooks in ascending `priority` (default `0`), with registration order for ties. Replay-stable for the same sporks, hooks, and `step`/`frame` sequence.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.