feat: pack it real good

This commit is contained in:
cha0s 2019-04-08 08:31:13 -04:00
parent a618ebd9cb
commit 7b68f9397e
2 changed files with 12 additions and 17 deletions

View File

@ -183,20 +183,18 @@ const predictionHandle = setInterval(() => {
}
}, 1000 / 80);
// State updates.
function onMessage({type, payload}) {
switch (type) {
case 'state-update':
const patch = unpacker.unpack(payload);
for (const step of patch) {
const {op, path, value} = step;
if ('add' === op && '/selfEntity' === path) {
selfEntity = value;
}
function onMessage(message) {
if ('s' in message) {
const patch = unpacker.unpack(message.s);
for (const step of patch) {
const {op, path, value} = step;
if ('add' === op && '/selfEntity' === path) {
selfEntity = value;
}
synchronizer.patchState(patch);
dirty = true;
break;
default:
}
synchronizer.patchState(patch);
dirty = true;
return;
}
}
socket.on('message', onMessage);

View File

@ -70,10 +70,7 @@ export class Informed extends decorate(Trait) {
}
// Emit!
const packed = this._packer.pack(steps);
this._socket.send({
type: 'state-update',
payload: packed,
});
this._socket.send({s: packed});
},
};