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 {ActionRegistry, InputNormalizer, InputPacket} from '@avocado/input';
import {Vector} from '@avocado/math'; import {Vector} from '@avocado/math';
import {SocketClient} from '@avocado/net/client/socket'; import {SocketClient} from '@avocado/net/client/socket';
import {SocketIoParser} from '@avocado/net'; import {BundlePacket, SocketIoParser} from '@avocado/net';
import {Synchronizer} from '@avocado/state'; import {Synchronizer} from '@avocado/state';
import {clearAnimation, setAnimation} from '@avocado/timing'; import {clearAnimation, setAnimation} from '@avocado/timing';
import {World} from '@avocado/physics/matter/world'; import {World} from '@avocado/physics/matter/world';
@ -251,6 +251,11 @@ export class App extends decorate(class {}) {
this.startRendering(); this.startRendering();
this.hasReceivedState = true; 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) { if (packet instanceof SelfEntityPacket) {
this.selfEntityUuid = packet.data; this.selfEntityUuid = packet.data;
} }

View File

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