\(hopefully\) improved fps counter
This commit is contained in:
parent
f417c3e109
commit
038a287e96
19
index.js
19
index.js
@ -690,17 +690,20 @@ window.onload = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let lastTime = Date.now()
|
let lastTime = Date.now()
|
||||||
|
let now
|
||||||
|
let fpsRes = 50
|
||||||
|
|
||||||
function gameLoop () {
|
function gameLoop () {
|
||||||
requestAnimationFrame(gameLoop)
|
update()
|
||||||
|
|
||||||
let delta = (Date.now() - lastTime) / 1000
|
|
||||||
|
|
||||||
fps = 1 / (delta === 0 ? 1 : delta)
|
|
||||||
|
|
||||||
update(delta)
|
|
||||||
render()
|
render()
|
||||||
|
|
||||||
lastTime = Date.now()
|
let cfps = 1000 / ((now = new Date) - lastTime)
|
||||||
|
if (now != lastTime) {
|
||||||
|
fps += (cfps - fps) / fpsRes
|
||||||
|
lastTime = now
|
||||||
|
}
|
||||||
|
|
||||||
|
requestAnimationFrame(gameLoop)
|
||||||
}
|
}
|
||||||
|
|
||||||
function initialize () {
|
function initialize () {
|
||||||
|
Loading…
Reference in New Issue
Block a user