feat: pack it real good
This commit is contained in:
parent
a618ebd9cb
commit
7b68f9397e
|
@ -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);
|
||||
|
|
|
@ -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});
|
||||
},
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user