From e2d9151c026ef747aeb8a3950f9dfa48155ef651 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 23 Mar 2019 23:38:14 -0500 Subject: [PATCH] chore: physics and predictions back --- client/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/client/index.js b/client/index.js index 0946691..c141961 100644 --- a/client/index.js +++ b/client/index.js @@ -3,12 +3,14 @@ import {EntityList} from '@avocado/entity'; import {ActionRegistry} from '@avocado/input'; import {Container, Renderer, ShapeView} from '@avocado/graphics'; import {shapeFromJSON} from '@avocado/physics'; +import {World} from '@avocado/physics/dummy'; import {StateSynchronizer} from '@avocado/state'; import {Animation} from '@avocado/timing'; const stage = new Container(); const entityList = new EntityList(); +entityList.world = new World(); const stateSynchronizer = new StateSynchronizer({ entityList, }); @@ -67,16 +69,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(elapsed); -// }, 1000 / 80); +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(elapsed); +}, 1000 / 80); // State updates. let dirty = false; function onMessage({type, payload}) {