refactor: msgpack input packets

This commit is contained in:
cha0s 2019-04-13 18:42:53 -05:00
parent afbaccb581
commit 7470d4ae5c
3 changed files with 6 additions and 4 deletions

View File

@ -1,4 +1,5 @@
// 3rd party.
import msgpack from 'msgpack-lite';
import React from 'react';
import ReactDOM from 'react-dom';
// 2nd party.
@ -154,7 +155,7 @@ const pointerMovementHandle = setInterval(() => {
const inputHandle = setInterval(() => {
if (actionState !== actionRegistry.state) {
actionState = actionRegistry.state;
socket.send(new InputPacket(JSON.stringify(actionRegistry.state.toJS())));
socket.send(new InputPacket(msgpack.encode(actionRegistry.state.toJS())));
}
}, 1000 / 60);
// Prediction.

View File

@ -5,8 +5,8 @@ export class InputPacket extends Packet {
static get schema() {
return {
...super.schema,
// TODO we can do better than JSON.
data: 'string',
data: 'buffer',
};
}
}

View File

@ -1,4 +1,5 @@
// Node.
import msgpack from 'msgpack-lite';
import {performance} from 'perf_hooks';
// 3rd party.
// 2nd party.
@ -52,7 +53,7 @@ function createPacketListener(socket) {
const {entity} = socket;
return (packet) => {
if (packet instanceof InputPacket) {
entity.inputState = JSON.parse(packet.data);
entity.inputState = msgpack.decode(packet.data);
}
};
}