Documentation Index
Fetch the complete documentation index at: https://mintlify.com/VKSFY/keel/llms.txt
Use this file to discover all available pages before exploring further.
Phase is an IntEnum that controls the order in which systems execute during each tick. The run loop advances simulation phases at a fixed 60 Hz rate and render phases once per visual frame. Register every system in the phase that best matches its role so Keel’s scheduler can enforce safe execution order without manual dependency declarations.
Phase Values
PRE_UPDATE — 0
Runs before the main update. Asset hot-reload drains here: changed files are detected, assets re-loaded, and dependent entities updated before any game logic sees the new data.
UPDATE — 1
Main game logic phase. AI, player input processing, state machines, and anything that should advance the simulation each tick belong here.
POST_UPDATE — 2
Physics bridges run here. After game logic mutates velocities and positions in UPDATE, the physics engine reads those values, steps the simulation, and writes corrected transforms back.
PRE_RENDER — 3
Camera updates and culling setup. Systems that derive the view/projection matrix or compute visibility lists run here so the RENDER phase has a stable camera each frame.
RENDER — 4
Draw calls. Sprite batching, mesh submission, and particle system rendering all execute in this phase. The ModernGL context is active and the framebuffer is writable.
POST_RENDER — 5
Debug draw overlay and ImGui submission. The debug-draw system flushes GL line primitives here; the inspector panel submits its ImGui draw list on top, so the inspector always renders above scene geometry.
Simulation vs Render Phases
Keel’s run loop separates phases into two groups that run at different cadences:| Group | Phases | Rate |
|---|---|---|
| Simulation | PRE_UPDATE, UPDATE, POST_UPDATE | Fixed 1/60 s (keel.FIXED_DT) |
| Render | PRE_RENDER, RENDER, POST_RENDER | Once per visual frame (variable dt) |
dt == keel.FIXED_DT (≈ 16.67 ms). Systems in render phases receive the real elapsed wall-clock time for the frame, which may be shorter or longer depending on display refresh rate and host load. Use RenderState.alpha (available as a world resource) for sub-tick interpolation in render systems.
Because simulation phases may run multiple times per visual frame (when the machine is slow) or zero times (when the frame is very fast), render systems must not write simulation state. Only read from components; use
alpha to blend between previous and current positions for smooth visuals.Usage Examples
Registering systems to each phase
Ordering systems within a phase
Use theafter parameter to express ordering constraints within a single phase. The scheduler topologically sorts the phase list and rejects cycles or cross-phase dependencies with ValueError.
Using Phase directly
Phase is an IntEnum, so you can iterate over all phases or compare them:
Running specific phase groups manually
In headless tests or custom loops you can run only the phases you need:Phase Reference
| Constant | Value | Typical use |
|---|---|---|
keel.Phase.PRE_UPDATE | 0 | Asset hot-reload, input preprocessing |
keel.Phase.UPDATE | 1 | AI, player input, state machines, timers |
keel.Phase.POST_UPDATE | 2 | Physics bridges, collision response |
keel.Phase.PRE_RENDER | 3 | Camera, culling, shadow map updates |
keel.Phase.RENDER | 4 | Sprite/mesh/particle draw calls |
keel.Phase.POST_RENDER | 5 | Debug overlays, ImGui, profiler HUD |
