diff --git a/client/app.js b/client/app.js index 8648d00..1d3de13 100644 --- a/client/app.js +++ b/client/app.js @@ -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; } diff --git a/server/traits/informed.trait.js b/server/traits/informed.trait.js index cd085c3..6665490 100644 --- a/server/traits/informed.trait.js +++ b/server/traits/informed.trait.js @@ -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)); } },