Dojo - Live Reloading
Dojo is the primary development tool for Clayground projects. It monitors your source files and automatically reloads the sandbox when changes are detected.
Basic Usage
# Run a single sandbox
./build/bin/claydojo --sbx examples/platformer/Sandbox.qml
# Run multiple sandboxes (switch with Ctrl+1-5)
./build/bin/claydojo \
--sbx examples/platformer/Sandbox.qml \
--sbx examples/topdown/Sandbox.qml \
--sbx examples/visualfx/Sandbox.qml
Command-Line Options
| Option | Description |
|---|---|
--sbx <path> |
QML sandbox file to load (can be used multiple times) |
--sbxindex <n> |
Which sandbox to load initially (0-based) |
--dynplugin <src,bin> |
Watch plugin source and binary directories |
--import <dir> |
Add QML import directory |
--guistyle <style> |
Set Qt Quick GUI style |
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Ctrl+G |
Toggle guide overlay |
Ctrl+L |
Toggle logging overlay |
Ctrl+F |
Flag a moment — screenshot + annotation |
Ctrl+T |
Toggle trace recording |
Ctrl+1 to Ctrl+5 |
Switch between loaded sandboxes |
How Live-Reloading Works
At the heart of Dojo is a sophisticated hot-reload system. When you save a QML file, changes appear within milliseconds.
The reload process:
- A recursive file watcher monitors your sandbox directory
- A fresh QML engine is created for each reload
- Changes fade in with a brief loading indicator
- Session statistics persist across reloads
The 50ms debounce window catches rapid file changes from editor auto-saves.
A Sandbox’s Own Shaders
A ShaderEffect only takes compiled .qsb files. The Dojo compiles a
sandbox’s shaders for you: every *.frag and *.vert under the sandbox
directory is baked with Qt’s qsb into <name>.frag.qsb right beside it —
when the Dojo starts (only sources newer than their .qsb) and again each
time you save one, before the reload. clayrender does the same before it
loads a sandbox.
ShaderEffect {
fragmentShader: "shaders/floor.frag.qsb" // baked from shaders/floor.frag
}
A shader that does not compile does not reload silently into an effect that
stopped drawing: qsb’s message, with file and line, shows up in the Dojo and
in the inspector log. The targets are the ones qt_add_shaders() uses by
default (GLSL 100 es/120/150, HLSL 50, MSL 12) plus GLSL 300 es, which the
browser runtime needs: WebGL2 refuses to link a fragment shader of another
version than its 300 es vertex shaders. So the same .qsb files work when
the game is served to the web runtime. For the shipped app, bake the same
files into the resources at the same relative path, with 300 es added to
qt_add_shaders()’ GLSL list — without it the app works on the desktop and
draws nothing of that effect in the browser:
qt_add_shaders(my_game "my_game_shaders" PREFIX "/"
GLSL "100 es,120,150,300 es"
FILES src/shaders/floor.frag)
Keep *.qsb out of version control — they are build output. Set CLAY_QSB
to use a qsb other than the one shipped with your Qt.
Ignoring Files — .dojoignore
Dojo watches the sandbox directory recursively, so any file change in
that tree (including data files your sandbox edits live, song sources,
generated caches, etc.) triggers a full scene reload. For files that your
sandbox handles itself at runtime — e.g. a song file being hot-reloaded
by SongPlayer — that full reload is counter-productive: it drags the
playhead back to zero and throws away the live state you were tuning.
Editor and tool noise is filtered out by default, with no configuration:
*~, .#*, #*#, *.swp/*.swo/*.swx, 4913, .DS_Store,
Thumbs.db, *.tmp, *.temp, *.bak, *.orig, *.rej, __pycache__/,
*.pyc and .git/. A vim swap file or a rejected patch landing next to
your sandbox used to restart the running scene, which reads as a random
reset. Sources and assets are never on that list — a .qml, .png or
shader change still reloads, as it should.
Drop a .dojoignore file next to your Sandbox.qml to exclude paths
from the reload trigger. Same spirit as .gitignore:
# ignore a single file, anywhere under the sandbox dir
notes.txt
# ignore all song sources
*.song.json
# ignore an entire subdirectory and its contents
songs/
# anchor to the sandbox dir (exact path)
data/level1.json
Semantics:
| Pattern | Matches |
|---|---|
name |
any file/dir named name under the sandbox tree |
*.ext |
basename wildcard, matches in any subdirectory |
name/ |
the directory and everything beneath it |
sub/file.txt |
path-anchored (no match on other/sub/file.txt) |
/file.txt |
path-anchored (leading / optional; same meaning as above) |
** |
any number of path segments |
!pattern |
un-ignores; last matching rule wins, as in .gitignore |
Comments start with #; blank lines are ignored. The file is re-read
automatically when you save it, so you can add/remove patterns without
restarting the dojo.
Use ! when a built-in default gets in your way — !*.bak makes the dojo
reload on .bak files again. A literal leading ! is escaped as \!.
.dojoignore only ever subtracts from the watched set — it cannot make
the dojo watch files it would otherwise miss (except for un-ignoring a
built-in default, which is what ! is for).
Dynamic Plugin Development
Beyond QML hot-reloading, Dojo supports live development of C++ plugins:
./build/bin/claydojo \
--sbx examples/pluginlive/Sandbox.qml \
--dynplugin examples/pluginlive/plugin,build/examples/pluginlive/plugin
The format is --dynplugin <source_dir>,<binary_dir>. Dojo detects when your plugin binary is rebuilt and automatically restarts with the updated code.
Tips
- Keep the sandbox visible while editing for immediate feedback
- Use multiple sandboxes to quickly switch between different test scenarios
- Watch the console for QML errors during reload
- Use the guide overlay (
Ctrl+G) when learning the shortcuts
Next Steps
- Use the Inspector for structured state snapshots and flagging moments
- Learn about the Logging Overlay
- Create your own plugins