aWeirdo Posted January 28, 2017 Share Posted January 28, 2017 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 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.. Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted January 28, 2017 Share Posted January 28, 2017 One solution is measuring delta time between frames, not FPS. If delta time is bigger than, say 0.33s (that is 3FPS), you know it is not a regular frame but a pause. Then you can skip moving or anything, waiting for a regular frame. aWeirdo 1 Quote Link to comment Share on other sites More sharing options...
Raggar Posted January 28, 2017 Share Posted January 28, 2017 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. aWeirdo 1 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted January 29, 2017 Author Share Posted January 29, 2017 @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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.