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

feat: Implement Fixed timestep #2339

Merged
merged 8 commits into from
Jun 11, 2022
Merged

feat: Implement Fixed timestep #2339

merged 8 commits into from
Jun 11, 2022

Conversation

eonarheim
Copy link
Member

@eonarheim eonarheim commented Jun 5, 2022

===:clipboard: PR Checklist :clipboard:===

  • 📌 issue exists in github for these changes
  • 🔬 existing tests still pass
  • 🙈 code conforms to the style guide
  • 📐 new tests written and passing / old tests updated with new scenario(s)
  • 📄 changelog entry added (or not needed)

==================

v0.27.0 Milestone related,

This PR adds the ability to configure a fixed FPS for the update loop. One advantage of setting a fix update is that you will have a more consistent and predictable physics simulation. Excalibur graphics will be interpolated automatically to avoid any jitter in the fixed update.

  • If the fixed update FPS is greater than the display FPS, excalibur will run multiple updates in a row (at the configured update elapsed) to catch up, for example there could be X updates and 1 draw each clock step.
  • If the fixed update FPS is less than the display FPS, excalibur will skip updates until it meets the desired FPS, for example there could be no update for 1 draw each clock step.
const game = new ex.Engine({
  fixedUpdateFps: 20 // 20 fps fixed update, or a fixed update delta of 50 milliseconds
});

The graphics interpolation can be turned off on a per body basis.

// turn off interpolation on a per actor basis
const actor = new ex.Actor({...});
actor.body.enableFixedUpdateInterpolate = false;

Fixed update @ 10 fps - graphics without interpolation

no-interpolation

Fixed update @ 10 fps - graphics with interpolation

interpolation

TODOs:

  • Interpolate graphics to prevent jitter
  • Convenient way to set in constructor
  • Tests

@github-actions github-actions bot added the enhancement Label applied to enhancements or improvements to existing features label Jun 5, 2022
@eonarheim eonarheim merged commit a038743 into main Jun 11, 2022
@eonarheim eonarheim deleted the feature/fixed-timestep branch June 11, 2022 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Label applied to enhancements or improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant