Skip to content

Add time scale, pause and stepping, more console commands, and timers and tweens - #3

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

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

Conversation

@RohanFredriksson

Copy link
Copy Markdown
Owner

Batch 2 of ROADMAP.md. This is stacked on #2 (batch 1), so it targets that branch and the diff shows only batch 2. Merge #2 first. GitHub then retargets this PR to master if the batch 1 branch is deleted on merge; otherwise change the base to master by hand.

Changes

  • Time: Pancake::timeScale, pause(bool) / pause(), step(n), getFps and getUnscaledDeltaTime.
    • The scene gets the frame time × time scale, zero while paused, or exactly one physics step per step() while paused.
    • Components keep updating while paused, with a dt of 0, so a pause menu can still read input.
  • Display: Pancake::vsync and fullscreen, applied by the main loop. Both can be set before start().
  • Console commands:
    • pause, step [n] and timescale [x].
    • spawn <x> <y> [w h] creates a dynamic box.
    • kill <id|name> and tp <id|name> <x> <y>. tp also stops the body.
    • fps toggles an overlay with frame rate, pause state and time scale.
    • vsync and fullscreen.
  • Timers: Scene::after, every, cancel and hasTimer.
    • They advance with the scene's dt, run after entity updates, fire at most once a frame, and are cancelled when their owner entity dies.
    • Callbacks can add and cancel timers safely. Timers aren't serialised.
  • Tweens: a non-serialised Tween component (components/tween.hpp) for position, size, rotation, sprite colour and custom values (Tween::value).
    • 12 Ease functions, plus delays and begin/complete callbacks.
    • Start values are read after the delay, so tweens chain.
    • Colour tweens look the sprite up by id, so removing the sprite first is safe.
  • Behaviour change: Entity::update only updates the components it had when the frame began.
    • Before, a component added during an update ran in the same frame. For example, a tween chained from onComplete used up the whole frame's time at once.
    • This is noted in the README's upgrade section.
  • Demo: P (pause), N (step) and F (fps) keys, and spawned boxes pop in with a size tween.
  • Docs: README gets a "Time, Timers and Tweens" section. CLAUDE.md and ROADMAP.md are updated.

Testing

  • New unit test tests/test_time.cpp covers one-shot and repeating timers, zero dt, adding and cancelling from callbacks, owner death, easing endpoints, and position, chained, rotation, size and value tweens.
  • New engine test tests/test_time_engine.cpp covers:
    • pause freezing physics and timers, and step advancing exactly one physics step;
    • time scale 0, and a negative scale being rejected;
    • spawn, tp and kill by id and by name;
    • fps and vsync;
    • colour tweens, including one whose sprite is removed mid-tween;
    • fullscreen on and off under Xvfb.
  • For the removed-sprite case, I checked that the test catches the bug: a version of the colour tween that keeps the raw pointer fails with heap-use-after-free under ASan.
  • All 9 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

… and tweens

Batch 2 of ROADMAP.md.

- Time: Pancake::timeScale, pause, step, getFps and getUnscaledDeltaTime.
  The scene gets the frame time times the time scale, zero while paused,
  or exactly one physics step per step() while paused. Components keep
  updating while paused, so a pause menu can still read input.
- Display: Pancake::vsync and fullscreen, applied by the main loop.
- Console commands: pause, step, timescale, spawn, kill and tp (by id or
  name), fps (an overlay showing frame rate, pause and time scale), vsync
  and fullscreen.
- Timers: Scene::after, every, cancel and hasTimer. They advance with the
  scene's delta time, run after entity updates, fire at most once a frame,
  and are cancelled when their owner entity dies. Callbacks can add and
  cancel timers safely.
- Tweens: a non-serialised Tween component for position, size, rotation,
  sprite colour and custom values, with Ease functions, delays, and begin
  and complete callbacks. Start values are read after the delay, so tweens
  chain. Colour tweens look the sprite up by id, so removing the sprite
  first is safe.
- Entity::update only updates the components it had when the frame began.
  A component added during an update, like a tween chained from
  onComplete, used to run in the same frame and consume its time.
- The demo gets P (pause), N (step) and F (fps) keys, and spawned boxes
  pop in with a size tween.

Tests: new unit test test_time for timers, easing and tweens, and engine
test test_time_engine for pause, step, time scale, the console commands,
colour tweens (including a removed sprite, which ASan checks) and
fullscreen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015cNAkNqoDWA5gFReD1AsqV
@RohanFredriksson
RohanFredriksson changed the base branch from claude/gameplay-api-batch1 to master October 16, 2026 02:13
@RohanFredriksson
RohanFredriksson merged commit 56ea4df 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