Jump to content

[solved] Avoiding "fake" fps drops


aWeirdo
 Share

Recommended Posts

Hey all,

I'm working on a fps correction multiplier for movement speed.

it is working, but when "fake" fps drops happens it goes nuts :D 

With "fake" fps drops, i mean if you tab out of the game page, wait a few seconds, then tab back on the game page,
because javascript basicly pauses on non-active pages, the fps drops to 0 very shortly and takes a few seconds to work it's way back up to being stable, which in turn increase the fpsCorrection value and suddenly you're half way across the map :) 

(note that even though the fps says 10 or something after tabbing out/in, it still acts as if it was running 60 fps when moving without the fpsCorrection, where if it was actually running at 10 fps it would move much slower, thus i call it "fake" fps drop)


Is there any good ideas to avoid this drop?

cheers.
 

Update;

This is the (so far) final result.


var updateSpeed = 1000 / engine.fpsRange; // Target 60 fps
var deltaCorrection = 1; // Speed correction



// registerBeforeRender

var delta_time = engine.getDeltaTime();

// Correction for 'real' low fps, support down to 10 fps.
if (delta_time < updateSpeed * 6)
  deltaCorrection = delta_time / updateSpeed;

// Handle script pauses by executing processUpdates * delta_time/updateSpeed to catch up with missing frames.
if (delta_time >= updateSpeed * 6) {
  deltaCorrection = 1; //Reset correction to 1.
  for (var delta = delta_time; delta > 0; delta -= updateSpeed) processUpdates();


} else { //Regular frame
  processUpdates();
}

// processUpdates, this is where the movement happens.
var speed = currentMesh.speed * deltaCorrection;

// etc etc..

 

Link to comment
Share on other sites

as BoG, I would suggest multiplying your delta time with the movement speed, so whenever you get 'real' FPS drops, the speed will be consistent.

If you run at 60FPS, you'll get a delta time of ~17ms(0.017), so if your delta time is more than some threshold, you know that the tab is either paused, or something causes the engine to hang, so you shouldn't move anyways.

Link to comment
Share on other sites

@BitOfGold & @Raggar 

Thanks for the suggestions :)

Update;

It was a bit triggy to do, it's a multiplayer game so i can't simply "pause" the movement (thats what i was trying to avoid in the first place), i needed it to catch up, and i wanted to avoid having the server interfere.

I updated and marked the original post as solved.

Thanks again

Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...