chore: tidy

This commit is contained in:
cha0s 2019-04-13 17:23:42 -05:00
parent 47f4aca0c9
commit c38f570028

View File

@ -188,7 +188,27 @@ const predictionHandle = setInterval(() => {
state = synchronizer.state;
// Render timing.
renderTicker.tick(elapsed);
// Apply environmental lighting.
}, 1000 / 60);
// State updates.
const unpacker = new Unpacker();
function onPacket(packet) {
if (packet instanceof KeysPacket) {
unpacker.registerKeys(packet.data);
}
if (packet instanceof StatePacket) {
const patch = unpacker.unpack(packet.data);
for (const step of patch) {
const {op, path, value} = step;
if ('add' === op && '/selfEntity' === path) {
selfEntity = value;
}
}
synchronizer.patchState(patch);
}
}
socket.on('packet', onPacket);
// Apply stage lighting.
function applyStageLighting() {
let intensity = 0;
if (worldTime.hour >= 21 || worldTime.hour < 4) {
intensity = 0.8;
@ -211,26 +231,7 @@ const predictionHandle = setInterval(() => {
lastIntensity = intensity;
lastIsFocused = isFocused;
}
}, 1000 / 60);
// State updates.
const unpacker = new Unpacker();
function onPacket(packet) {
if (packet instanceof KeysPacket) {
unpacker.registerKeys(packet.data);
}
if (packet instanceof StatePacket) {
const patch = unpacker.unpack(packet.data);
for (const step of patch) {
const {op, path, value} = step;
if ('add' === op && '/selfEntity' === path) {
selfEntity = value;
}
}
synchronizer.patchState(patch);
}
}
socket.on('packet', onPacket);
// Render.
function render() {
stage.tick();
@ -238,6 +239,8 @@ function render() {
return false;
}
mayRender = false;
// Lighting.
applyStageLighting();
stage.render();
}
const renderHandle = setAnimation(render);