diff --git a/client/index.js b/client/index.js index a1131b4..2fc948e 100644 --- a/client/index.js +++ b/client/index.js @@ -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. diff --git a/common/packet/input.js b/common/packet/input.js index 7f697e6..8bbdff9 100644 --- a/common/packet/input.js +++ b/common/packet/input.js @@ -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', }; } + } diff --git a/server/game.js b/server/game.js index 0480154..877abcb 100644 --- a/server/game.js +++ b/server/game.js @@ -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); } }; }