refactor: do dirty checks later
This commit is contained in:
parent
6b2f392794
commit
2dca6509fb
|
@ -24,7 +24,6 @@ appNode.addEventListener('touchmove', (event) => {
|
|||
event.preventDefault();
|
||||
});
|
||||
// Graphics stage.
|
||||
let dirty = false;
|
||||
const visibleSize = [320, 180];
|
||||
const halfVisibleSize = Vector.scale(visibleSize, 0.5);
|
||||
const visibleScale = [2, 2];
|
||||
|
@ -93,7 +92,6 @@ room.on('entityAdded', (entity) => {
|
|||
camera.on('realPositionChanged', () => {
|
||||
const offset = Vector.sub(halfVisibleSize, camera.realPosition);
|
||||
roomView.position = offset;
|
||||
dirty = true;
|
||||
});
|
||||
// Avoid the initial 'lerp.
|
||||
camera.realPosition = camera.position;
|
||||
|
@ -207,7 +205,6 @@ const predictionHandle = setInterval(() => {
|
|||
}
|
||||
// Tick synchronized.
|
||||
synchronizer.tick(elapsed);
|
||||
dirty = dirty || synchronizer.state !== state;
|
||||
state = synchronizer.state;
|
||||
// Render timing.
|
||||
renderTicker.tick(elapsed);
|
||||
|
@ -254,22 +251,17 @@ function onPacket(packet) {
|
|||
}
|
||||
}
|
||||
synchronizer.patchState(patch);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
socket.on('packet', onPacket);
|
||||
// Render.
|
||||
function render() {
|
||||
stage.tick();
|
||||
if (!dirty) {
|
||||
return;
|
||||
}
|
||||
if (!mayRender) {
|
||||
return false;
|
||||
}
|
||||
mayRender = false;
|
||||
stage.render();
|
||||
dirty = false;
|
||||
}
|
||||
const renderHandle = setAnimation(render);
|
||||
// UI.
|
||||
|
|
Loading…
Reference in New Issue
Block a user