Skip to content

Commit

Permalink
Game loop timing: More tests suggest 144 hz monitors like 0.33 for 30…
Browse files Browse the repository at this point in the history
… FPS.
  • Loading branch information
scottschiller committed Mar 31, 2023
1 parent b214aad commit 01f9f43
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions script/core/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ const ua = navigator.userAgent;
const FPS = 30;
const FRAMERATE = 1000 / FPS;

// skip frame(s) as needed, prevent the game from running too fast.
const FRAME_MIN_TIME = (1000 / 60) * (60 / FPS) - (1000 / 60) * 0.5;
/**
* Skip frame(s) as needed, prevent the game from running too fast.
*
* Note: 144 hz monitors (maybe on Windows?) may need 0.33 or less,
* or else the loop may run at 35+ FPS. This may be a 144 hz
* monitor thing, not necessarily tied to Windows. TBD.
*
* It may be this value needs to be made dynamic, starting at 0.5
* and trickling down to 0.33 or so if the frame rate is > 30FPS.
*
*/
const frameOffset = parseFloat(searchParams.get('frameOffset')) || 0.33;

const FRAME_MIN_TIME = (1000 / 60) * (60 / FPS) - (1000 / 60) * frameOffset;

/**
*
Expand Down

0 comments on commit 01f9f43

Please sign in to comment.