|
| 1 | +Toolbox Aid |
| 2 | +David Quesenberry |
| 3 | +04/05/2026 |
| 4 | +APPLY_PR_RUNTIME_SCENE_LOADER_AND_HOT_RELOAD.md |
| 5 | + |
| 6 | +# APPLY_PR_RUNTIME_SCENE_LOADER_AND_HOT_RELOAD |
| 7 | + |
| 8 | +## Purpose |
| 9 | +Apply the approved runtime scene loader and hot reload design as a focused implementation PR that wires composition-driven scene loading into the existing engine without breaking engine-layer boundaries. |
| 10 | + |
| 11 | +## Scope |
| 12 | +Implement only the approved runtime scene loader + hot reload flow. |
| 13 | + |
| 14 | +In scope: |
| 15 | +- Add a runtime scene loader above engine systems |
| 16 | +- Add hot reload coordinator for development workflows |
| 17 | +- Consume the previously defined composition contract and per-tool asset contracts |
| 18 | +- Preserve deterministic render ordering already approved in the render pipeline contract work |
| 19 | +- Add validation-aware reload behavior |
| 20 | +- Add focused automated test coverage |
| 21 | +- Add minimal sample/dev wiring needed to verify the pipeline |
| 22 | + |
| 23 | +Out of scope: |
| 24 | +- No engine rewrite |
| 25 | +- No new editor features |
| 26 | +- No new asset schema invention beyond approved contract docs |
| 27 | +- No production packaging system |
| 28 | +- No multiplayer/network sync |
| 29 | +- No destructive public API changes unless required and documented |
| 30 | + |
| 31 | +## Implementation Intent |
| 32 | +Codex should implement a thin orchestration layer that: |
| 33 | +1. Reads a composition document |
| 34 | +2. Validates referenced tool outputs |
| 35 | +3. Loads/parses tool outputs into runtime-ready models |
| 36 | +4. Applies deterministic stage ordering |
| 37 | +5. Swaps the active scene safely in dev workflows on reload |
| 38 | +6. Surfaces structured validation/runtime errors without silent failure |
| 39 | + |
| 40 | +## Required Deliverables |
| 41 | +### Runtime loading |
| 42 | +- Runtime scene loader module |
| 43 | +- Composition resolver |
| 44 | +- Contract validation bridge |
| 45 | +- Tool asset loader adapters only where needed by the approved contracts |
| 46 | +- Deterministic stage assembly |
| 47 | + |
| 48 | +### Hot reload |
| 49 | +- Development-only hot reload coordinator |
| 50 | +- Safe disposal + replacement flow |
| 51 | +- Reload debouncing/coalescing if file-watch events can burst |
| 52 | +- Reload failure fallback that preserves last known good scene |
| 53 | + |
| 54 | +### Tests |
| 55 | +- Composition load success path |
| 56 | +- Missing asset / invalid contract rejection |
| 57 | +- Render order preservation after reload |
| 58 | +- Scene disposal occurs before replacement |
| 59 | +- Last-known-good fallback behavior |
| 60 | +- No duplicate runtime entities/systems after repeated reloads |
| 61 | + |
| 62 | +## Architecture Constraints |
| 63 | +- Loader/orchestrator stays above engine core |
| 64 | +- Engine remains reusable and tool-agnostic |
| 65 | +- Samples consume public runtime contracts only |
| 66 | +- Games are not introduced as a dependency |
| 67 | +- Tool-specific quirks are not embedded into engine systems |
| 68 | +- Existing engine APIs remain stable unless absolutely necessary and documented |
| 69 | + |
| 70 | +## Suggested File Targets |
| 71 | +These are guidance targets. Codex may adjust exact paths if the repo requires better placement while keeping architecture boundaries intact. |
| 72 | + |
| 73 | +- engine/scene/RuntimeSceneLoader.js |
| 74 | +- engine/scene/SceneCompositionResolver.js |
| 75 | +- engine/validation/RuntimeContractValidator.js |
| 76 | +- engine/debug/HotReloadCoordinator.js |
| 77 | +- samples/<target-sample>/ or tools/dev harness wiring as appropriate |
| 78 | +- tests/scene/RuntimeSceneLoader.test.mjs |
| 79 | +- tests/debug/HotReloadCoordinator.test.mjs |
| 80 | + |
| 81 | +## Safe Reload Rules |
| 82 | +- Validate before swap |
| 83 | +- Build next runtime state before tearing down current scene when possible |
| 84 | +- Dispose current scene exactly once before replacement |
| 85 | +- Preserve last known good scene if reload fails |
| 86 | +- Log structured error output for invalid composition or invalid referenced assets |
| 87 | +- Do not leak timers, handlers, subscriptions, or duplicate entities across reload cycles |
| 88 | + |
| 89 | +## Render Ordering |
| 90 | +Preserve previously approved stage order: |
| 91 | + |
| 92 | +1. Parallax background |
| 93 | +2. Tilemap world |
| 94 | +3. Runtime entities / gameplay visuals |
| 95 | +4. Sprite effects / foreground sprite layers as approved by contract |
| 96 | +5. Vector overlays / debug / UI overlays |
| 97 | + |
| 98 | +If the implementation needs internal sub-stages, document them in code comments/tests while preserving public ordering. |
| 99 | + |
| 100 | +## Acceptance Criteria |
| 101 | +- A composition document can load a mixed scene from approved tool outputs |
| 102 | +- Hot reload refreshes changed assets/scenes without full restart in dev workflow |
| 103 | +- Invalid changes do not crash the running last-known-good scene |
| 104 | +- Render order remains deterministic before and after reload |
| 105 | +- Repeated reloads do not duplicate objects or corrupt state |
| 106 | +- Tests pass |
| 107 | +- A repo-structured implementation ZIP is produced at: |
| 108 | + - <project folder>/tmp/APPLY_PR_RUNTIME_SCENE_LOADER_AND_HOT_RELOAD_delta.zip |
| 109 | + |
| 110 | +## Validation Checklist |
| 111 | +- [ ] Runtime scene loader created |
| 112 | +- [ ] Composition-driven scene assembly works |
| 113 | +- [ ] Validation blocks malformed inputs |
| 114 | +- [ ] Safe dispose/replace behavior confirmed |
| 115 | +- [ ] Last-known-good fallback confirmed |
| 116 | +- [ ] Deterministic render ordering confirmed |
| 117 | +- [ ] Tests added and passing |
| 118 | +- [ ] No engine-layer pollution from tool-specific logic |
0 commit comments