Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Engine frame step debugging feature #1170

Closed
eonarheim opened this issue Jun 15, 2019 · 1 comment · Fixed by #2122
Closed

Add Engine frame step debugging feature #1170

eonarheim opened this issue Jun 15, 2019 · 1 comment · Fixed by #2122
Assignees
Labels
core team This issue should be done by an Excalibur core member feature Label applied to new feature requests stale This issue or PR has not had any activity recently
Milestone

Comments

@eonarheim
Copy link
Member

Context

Currently it can be difficult to debug complex interactions in Excalibur, some guess work and experience is required. It can also be difficult to simulate issues that only occur at high speed.

Proposal

Add a new frame stepping API on the ex.Engine.debug component. This can be accomplished by providing new implementations of the frameStep() and now() which is currently provided by window.requestAnimationFrame and Date.now.

Something like this

// Drops the engine into frame step mode
engine.debug.toggleFrameStep();

// number of frames and the fps to simulate
// Will step the engine 10 frames, at simulated 60fps
engine.debug.frameStep(10, 60);

singleframestep2

@eonarheim eonarheim self-assigned this Jun 15, 2019
@eonarheim eonarheim added core team This issue should be done by an Excalibur core member feature Label applied to new feature requests labels Jun 15, 2019
@github-actions
Copy link

This issue hasn't had any recent activity lately and is being marked as stale automatically.

@github-actions github-actions bot added the stale This issue or PR has not had any activity recently label Dec 27, 2020
@jedeen jedeen added this to the vNext milestone Oct 9, 2021
eonarheim added a commit that referenced this issue Nov 28, 2021
Closes: #1170 
Closes: #577 

This PR implements a new Clock api to manage the core main loop. Clocks hide the implementation detail of how the mainloop runs, users just knows that it ticks somehow. Clocks additionally encapsulate any related browser timing, like `performance.now()`

1. `StandardClock` encapsulates the existing `requestAnimationFrame` api logic
2. `TestClock` allows a user to manually step the mainloop, this can be useful for frame by frame debugging #1170 
3. The base abstract clock implements the specifics of elapsed time 

* The new `maxFps` option is added to the engine constructor options. This is achieved by exiting the mainloop early in clock if the current elapsed time does not match the desired fps. This can be useful when you want to deliver a consistent experience across devices.

## Some fixed bugs that were illuminated as part of this
- Excalibur's initialize flow was flawed, this PR refactors the start() to mean "ready for game code to run", before it actually meant resources loaded and player clicked play
- Play button wasn't positioned until first update, now positioned on init
- Systems were not initialized until first update, now initialized with the scene

## Current game start flow

### After this PR (consolidate init before start resolves)

1. game.start(loader)
2. clock started
3. load resources
4. compute resolution 
5. run engine/scene/ecs system initialize
6. emit ready
7. start the game

### Before

1. game.start(loader);
2. mainloop raf started
3. load resources
4. run some initialize logic
5. compute resolution
4. start game
5. run initialize logic

## Changes:

- New Clock API for managing the mainloop
- Added `maxFps` engine option to constrain to a maximum fps 
- Updated fps sampling to be more useful
- Updates the tests to use the new TestClock (fun side-effect tests are ~20 seconds faster in CI!)
- Some small bug fixes that are related to clock timings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core team This issue should be done by an Excalibur core member feature Label applied to new feature requests stale This issue or PR has not had any activity recently
Projects
None yet
2 participants