MaskedPixel

Simulate irregular fps

Recommended Posts

The situation:  I have an update loop where I "fixed the timestep".  Physics is running at ta fixed 30fps and my render loop is completely independent.  However, on a mobile device with a framerate that jumps around between 20-35 fps, there seems to be stuttering with the camera.  Now, I know how to approach the issue, I'm just trying to figure out how to do it off the mobile device.

What I want to do:  I would like to simulate the irregular fps within the browser on desktop.  Is there a way to do that via debug tools or with an extension on any browser?

Does anyone know of a solution here?

Fix your timestep: http://gafferongames.com/game-physics/fix-your-timestep/

Share this post


Link to post
Share on other sites

You could be a bit more specific about chewing up cycles by timing it:

function work (frames) {
  let start = performance.now(); 
  let flag = true
  let time = 1000 / frames
  while (flag) {
    if (performance.now() - start > time) {
      flag = false
    }
  }
}

There might be a few edge-cases with this, for example, make sure you test that current execution time is greater than the time you want because something could cause a couple of cycles to run longer than a frame and you don't want this function to hang your code, at least by checking greater than it should do very little work if you're already over. You might need to pass in the start time to coincide with the actual start of your update/render, rather than when this function gets called. Slightly more reliable/usable than something like counting down from 1e8 though or rendering loads of sprites in one go.

Share this post


Link to post
Share on other sites

So, @mattstyles your goal is to reproduce the unstable framerate of a mobile device on your desktop computer. Why don't you spin up a small Virtual Machine and then adjust the memory/CPU to get the desired behaviour? At the end, your goal is to fix the problem on lower-end systems (regardless of it being mobile or desktop) and modifying your code just to reproduce this might actually introduce other problems and not solve your first issue.

What do you think?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.