chore: physics and predictions back

This commit is contained in:
cha0s 2019-03-23 23:38:14 -05:00
parent ff07ef86c8
commit e2d9151c02

View File

@ -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}) {