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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.