Skip to content

Add entity cloning and prefabs, an inspector edit mode, and asset hot reload - #7

Merged
RohanFredriksson merged 1 commit into
masterfrom
claude/gameplay-api-batch5
Oct 16, 2026
Merged

RohanFredriksson merged 1 commit into
masterfrom
claude/gameplay-api-batch5

Conversation

@RohanFredriksson

Copy link
Copy Markdown
Owner

Batch 5 of ROADMAP.md, the last one. Batches 1–4 are already on master, so this targets master directly and contains one commit.

Changes

  • Cloning: Entity::clone() and Entity::instantiate(json) copy an entity's saved state with new entity and component ids. Components that aren't serialisable are left out. Entity::load(json) still keeps the ids in the json, as scene loading needs.
  • Prefabs (core/prefab.hpp): Prefab::save, load and spawn, and Pancake::spawn(file, position).
    • Files are cached and read again when their modified time changes.
    • Missing or malformed files print ERROR::PREFAB::... and return nullptr.
    • Prefabs don't include assets, so sprites they use must already be loaded (noted in the README).
  • Inspector edit mode:
    • Dragging moves the selected entity and stops its body while held.
    • Duplicate and Delete buttons, with Ctrl+D and Delete shortcuts.
    • A toolbar to pause, step, save and load. Load adds the file's entities to the current scene, like the load command.
    • The actions are public as Inspector::duplicateSelected, deleteSelected and moveSelected.
  • Hot reload:
    • TexturePool and AudioPool record each file's modified time, and AssetPool::reloadChanged() reloads changed files in place.
    • With Pancake::hotReload(true), the main loop checks twice a second of real time, so it also works while paused.
    • Texture::reload keeps the GL texture id, so sprites and spritesheets pick up the new image untouched. It also sets the unpack alignment for 3-channel rows that aren't 4-byte aligned.
  • Console: clone <id|name> [x y], prefab <file> <x> <y>, saveprefab <id|name> <file>, hotreload [on|off] and reload.
  • Demo: D no longer toggles physics debug drawing while Ctrl is held, since Ctrl+D duplicates in the inspector.
  • Docs: README gets a "Prefabs and Hot Reload" section, CLAUDE.md gets "Prefabs and copies" and "Hot reload", and all ROADMAP.md items are ticked.

Testing

  • New unit test tests/test_prefab.cpp covers:
    • clones getting new entity and component ids and dropping unsaved components;
    • load versus instantiate ids;
    • prefab save and load, with each load a new copy;
    • re-reading a changed prefab file;
    • missing, malformed and invalid prefab files.
  • New engine test tests/test_editor_engine.cpp covers:
    • inspector duplicate, move (stopping the body) and delete;
    • prefabs from code and from the console, and clone;
    • hot reload of a PNG and a WAV that the test writes and then changes, checking the texture keeps its GL id;
    • reload with hot reload off.
  • Not covered: real mouse dragging and button clicks in the inspector, since a mouse can't be driven in this environment. The tests call the same functions the drag and buttons use.
  • All 14 tests pass locally in the ASan build and the Release build.

🤖 Generated with Claude Code

https://claude.ai/code/session_015cNAkNqoDWA5gFReD1AsqV


Generated by Claude Code

… reload

Batch 5 of ROADMAP.md, the last one.

- Entity::clone() and Entity::instantiate(json) copy an entity's saved
  state with new entity and component ids. Entity::load(json) still keeps
  the ids, as scene loading needs.
- Prefab::save, load and spawn, and Pancake::spawn(file, position).
  Prefab files are cached and read again when they change on disk.
  Missing or malformed files print an error and return nullptr.
- The inspector can edit: dragging moves the selected entity (stopping its
  body), Duplicate and Delete buttons with Ctrl+D and Delete shortcuts, and
  a toolbar to pause, step, save and load. The actions are public as
  Inspector::duplicateSelected, deleteSelected and moveSelected.
- Hot reload: TexturePool and AudioPool record each file's modified time.
  AssetPool::reloadChanged reloads changed files in place, and with
  Pancake::hotReload(true) the main loop checks twice a second of real
  time. Texture::reload keeps the GL texture id, so sprites and
  spritesheets pick up the new image without being touched, and handles 3
  channel rows that aren't 4 byte aligned.
- Console commands clone, prefab, saveprefab, hotreload and reload.
- The demo's D key no longer toggles physics debug drawing when Ctrl is
  held, since Ctrl+D duplicates in the inspector.

Tests: new unit test test_prefab for clones, instantiate, prefab save,
load, refresh on change, and bad files. New engine test
test_editor_engine for the inspector actions, prefabs from code and the
console, and hot reload of a PNG and a WAV the test writes and changes,
checking the texture keeps its GL id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015cNAkNqoDWA5gFReD1AsqV
@RohanFredriksson
RohanFredriksson merged commit f7c485e into master Oct 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants