refactor: flushed packet return

This commit is contained in:
cha0s 2019-05-04 12:43:11 -05:00
parent 911843561c
commit 771220982e
2 changed files with 18 additions and 9 deletions

View File

@ -533,12 +533,16 @@ export class App extends decorate(class {}) {
this.synchronizer.tick(elapsed); this.synchronizer.tick(elapsed);
this.state = this.synchronizer.state; this.state = this.synchronizer.state;
// Emit packets. // Emit packets.
this.entityPacketSynchronizer.flushPackets((packetEntity, packets) => { const flushed = this.entityPacketSynchronizer.flushPackets();
for (let i = 0; i < packets.length; i++) { const it = flushed.values();
const packet = packets[i]; for (let value = it.next(); !value.done; value = it.next()) {
const packets = value.value;
const it2 = packets.values();
for (let value2 = it2.next(); !value2.done; value2 = it2.next()) {
const packet = value2.value;
this.socket.send(packet); this.socket.send(packet);
} }
}); }
// Sample. // Sample.
this.tps.sample(elapsed); this.tps.sample(elapsed);
}, 1000 * config.simulationFrequency); }, 1000 * config.simulationFrequency);

View File

@ -52,17 +52,22 @@ export default class Game {
bundleEntityPackets() { bundleEntityPackets() {
const bundledEntityPackets = new Map(); const bundledEntityPackets = new Map();
this.entityPacketSynchronizer.flushPackets((packetEntity, packets) => { const flushed = this.entityPacketSynchronizer.flushPackets();
const it = flushed.entries();
for (let value = it.next(); !value.done; value = it.next()) {
const packetEntity = value.value[0];
const packets = value.value[1];
for (let i = 0; i < this.informables.length; ++i) { for (let i = 0; i < this.informables.length; ++i) {
const entity = this.informables[i]; const entity = this.informables[i];
if (!entity.seesEntity(packetEntity)) { if (!entity.seesEntity(packetEntity)) {
return; continue;
} }
if (!bundledEntityPackets.has(entity)) { if (!bundledEntityPackets.has(entity)) {
bundledEntityPackets.set(entity, new Map()); bundledEntityPackets.set(entity, new Map());
} }
for (let j = 0; j < packets.length; j++) { const it2 = packets.values();
const packet = packets[j]; for (let value2 = it2.next(); !value2.done; value2 = it2.next()) {
const packet = value2.value;
const Packet = packet.constructor; const Packet = packet.constructor;
if (!bundledEntityPackets.get(entity).has(Packet)) { if (!bundledEntityPackets.get(entity).has(Packet)) {
bundledEntityPackets.get(entity).set(Packet, packet); bundledEntityPackets.get(entity).set(Packet, packet);
@ -72,7 +77,7 @@ export default class Game {
} }
} }
} }
}); }
return bundledEntityPackets; return bundledEntityPackets;
} }