feat: bundle packets over the wire

This commit is contained in:
cha0s 2019-05-16 00:57:28 -05:00
parent fdf68f50ce
commit 6047a61906
2 changed files with 10 additions and 8 deletions

View File

@ -7,7 +7,7 @@ import {Stage} from '@avocado/graphics';
import {ActionRegistry, InputNormalizer, InputPacket} from '@avocado/input';
import {Vector} from '@avocado/math';
import {SocketClient} from '@avocado/net/client/socket';
import {SocketIoParser} from '@avocado/net';
import {BundlePacket, SocketIoParser} from '@avocado/net';
import {Synchronizer} from '@avocado/state';
import {clearAnimation, setAnimation} from '@avocado/timing';
import {World} from '@avocado/physics/matter/world';
@ -251,6 +251,11 @@ export class App extends decorate(class {}) {
this.startRendering();
this.hasReceivedState = true;
}
if (packet instanceof BundlePacket) {
for (let i = 0; i < packet.data.length; i++) {
this.onPacket(packet.data[i]);
}
}
if (packet instanceof SelfEntityPacket) {
this.selfEntityUuid = packet.data;
}

View File

@ -6,6 +6,7 @@ import immutablediff from 'immutablediff';
import {compose} from '@avocado/core';
import {EntityCreatePacket, EntityPacket, EntityRemovePacket, Trait} from '@avocado/entity';
import {Rectangle, Vector} from '@avocado/math';
import {BundlePacket} from '@avocado/net';
import {Synchronizer} from '@avocado/state';
const decorate = compose(
@ -267,13 +268,9 @@ export class Informed extends decorate(Trait) {
this.markEntitiesSeen(visibleEntities);
// Unsee any removed entities.
this.markEntitiesUnseen(packets);
// Ship it! TODO: bundle.
for (let i = 0; i < packets.length; i++) {
// This can actually happen during a send. Yikes.
if (!this._socket) {
break;
}
this._socket.send(packets[i]);
// Ship it!
if (this._socket) {
this._socket.send(new BundlePacket(packets));
}
},