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.state = this.synchronizer.state;
// Emit packets.
this.entityPacketSynchronizer.flushPackets((packetEntity, packets) => {
for (let i = 0; i < packets.length; i++) {
const packet = packets[i];
const flushed = this.entityPacketSynchronizer.flushPackets();
const it = flushed.values();
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);
}
});
}
// Sample.
this.tps.sample(elapsed);
}, 1000 * config.simulationFrequency);

View File

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