refactor: msgpack input packets
This commit is contained in:
parent
afbaccb581
commit
7470d4ae5c
|
@ -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.
|
||||
|
|
|
@ -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',
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user