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.
keel.App is the single entry point for every Keel game. It wires together the ECS World, the Scheduler, the GLFW Window, the ModernGL rendering context, and the InputState into one object you configure at startup. After setup, a single call to app.run() blocks until the window closes, driving the fixed-timestep loop for you.
Creating an App
App.__init__ performs four things in order:
Creates the ECS World
app.world is a fresh World instance containing the archetype registry, the command buffer, the event bus, and the scheduler.Opens the GLFW Window
app.window is a Window object that creates the GLFW window and a ModernGL context. The context is available immediately as app.ctx.Wires input callbacks
app.input is an InputState registered as a world resource so systems can receive it via type injection. GLFW keyboard, mouse, and window-resize callbacks are connected and emit events into the world’s event bus.App Properties
| Property | Type | Description |
|---|---|---|
app.world | World | The ECS world — spawn entities, run queries, emit events. |
app.input | InputState | Keyboard, mouse, and window state with held and edge-detected helpers. |
app.ctx | moderngl.Context | The ModernGL GL context — pass to renderer and shader setup functions. |
app.scheduler | Scheduler | The phase-ordered system scheduler. |
Registering Systems
Use@app.system(phase) to register a plain function as a system. The phase argument controls when the system runs relative to physics, rendering, and other systems within the same frame.
after parameter:
Resources
Resources are singleton objects stored in the world and injected into systems by type annotation.app.insert_resource is a convenience forward to world.insert_resource:
Asset Hot Reload
app.setup_assets(watch_dirs) creates the AssetRegistry, registers default loaders for JSON and images, and starts the watchdog file watcher so textures and data files reload automatically when changed on disk.
watch_dirs=None (or omit the argument) to skip the file watcher. The registry is also returned for direct use.
Shutdown Hooks
Register cleanup callbacks withapp.add_shutdown_hook. Hooks run after the loop exits and before GLFW is torn down, in registration order. Exceptions inside individual hooks are swallowed so all hooks always run.
Running the Loop
app.run() blocks until the window is closed. On exit it calls every registered shutdown hook, destroys the window, and shuts down GLFW.
The Fixed-Timestep Loop
The loop insiderun_loop separates simulation from rendering.
FIXED_DT is 1.0 / 60.0 seconds — the constant timestep passed to every simulation system. Render systems receive the real elapsed wall time for the visual frame.
The accumulator is capped at 10 × FIXED_DT to prevent the “spiral of death” if the host machine stalls. Any excess elapsed time beyond that cap is discarded rather than scheduling an unbounded burst of catch-up ticks.
Event queues are cleared once per visual frame, not once per simulation tick. This means a
KeyEvent emitted during GLFW polling is visible to all simulation ticks within that frame, and to the render phase.Exported Loop Constants and Types
These are re-exported fromkeel for convenience:
| Name | Value / Type | Description |
|---|---|---|
keel.FIXED_DT | 1/60 s | Fixed simulation timestep. |
keel.PRESS | GLFW constant | Action value in KeyEvent when a key is pressed. |
keel.RELEASE | GLFW constant | Action value when a key is released. |
keel.REPEAT | GLFW constant | Action value for a held-key repeat event. |
keel.FixedStepDriver | class | The accumulator logic; useful for writing headless test drivers. |
keel.RenderState | class | Per-frame resource holding alpha (interpolation progress) and frame_dt. |
