Skip to content

Add typed component access, entity names, release events and lambda loads - #2

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

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

Conversation

@RohanFredriksson

Copy link
Copy Markdown
Owner

Batch 1 of the new ROADMAP.md, which queues the planned engine improvements in batches of related work.

Changes

  • Typed component access: Entity::getComponent<T>(), getComponents<T>(), hasComponent<T>() and addComponent<T>(args...). They match subclasses (getComponent<ForceGenerator>() finds a Gravity) and skip dead components. The demo now uses them instead of dynamic_cast on a type-name string.
  • Entity names and lookup:
    • Entities have an optional name. It is serialised only when set, so older save files load unchanged, and a non-string name is rejected as malformed.
    • New lookups: Scene::findEntity(name), findEntities(name) and getEntitiesWith<T>().
    • Names can be edited in the inspector and show in the entities console command.
  • Release events: KeyListener::isKeyEndDown and MouseListener::isMouseEndDown are true for the frame a key or button is released.
    • Behaviour change: a key pressed and released within one frame now reports begin down for that frame too. Before, the release cleared it and the tap was lost.
    • MouseListener skips the world-coordinate update when no scene exists, so endFrame is safe before start.
  • load takes any callable: Pancake::load and Window::load take std::function<void(Scene*)>, so capturing lambdas work. Existing calls with plain functions still compile.
    • The main loop now moves the load queue out before running it. Otherwise, a load function that queues another load could resize the vector holding the function that is running, which is a use-after-free once functions capture variables. Queued loads still run in the same frame.
  • Docs: README gets a "Working with Entities" section and upgrade notes. CLAUDE.md points at the roadmap.

Testing

  • New unit test tests/test_entity.cpp covers typed components, names round-tripping through JSON, and key and mouse press/release, including a tap within one frame.
  • tests/test_engine.cpp now checks that names survive a save and reload, that getEntitiesWith<Rigidbody>() works, and that a capturing load lambda that queues a second one runs both in the same frame.
  • All 7 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

…oads

Batch 1 of ROADMAP.md, the queue of planned engine improvements.

- Entity::getComponent<T>(), getComponents<T>(), hasComponent<T>() and
  addComponent<T>(args...). They match subclasses and skip dead components.
- Entities have an optional name, serialised only when set so older save
  files load unchanged. Scene::findEntity, findEntities and
  getEntitiesWith<T>() look entities up. Names show in the inspector, where
  they can be edited, and in the entities console command.
- KeyListener::isKeyEndDown and MouseListener::isMouseEndDown report a
  release for one frame. A press and release within one frame now still
  reports begin down. Mouse world coordinates are skipped when no scene
  exists, so MouseListener::endFrame is safe before start.
- Pancake::load and Window::load take std::function, so capturing lambdas
  work. The load queue is moved out before running, so a load function that
  queues another can't reallocate the vector holding the running function.

Tests: new unit test test_entity, and test_engine now covers name lookup
across a save and reload, getEntitiesWith, and capturing and nested loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015cNAkNqoDWA5gFReD1AsqV
@RohanFredriksson
RohanFredriksson merged commit 55fb1ff into master Oct 16, 2026
6 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