From e195064210dda705fc7cf7b22a6962c27390042c Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 23 Mar 2019 18:31:59 -0500 Subject: [PATCH] refactor: more accurate tick --- client/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/index.js b/client/index.js index d934cee..840029b 100644 --- a/client/index.js +++ b/client/index.js @@ -72,12 +72,16 @@ const messageHandle = setInterval(() => { } }, 1000 / 60); // Prediction. +let lastTime = performance.now(); const predictionHandle = setInterval(() => { + const now = performance.now(); + const elapsed = (now - lastTime) / 1000; + lastTime = now; if (hasSelfEntity()) { selfEntity.inputState = actionState.toJS(); } - entityList.tick(1 / 60); -}, 1000 / 60); + entityList.tick(elapsed); +}, 1000 / 80); // State updates. let dirty = false; function onMessage({type, payload}) {