class Network {
constructor(iops = 10, jitter = 0.5) {
this.ticks = 0
this.nodes = []
this.packets = []
this.packetLog = []
setSemiRandomTimer(this.run.bind(this), 1000 / iops, jitter);
}
run() {
++this.ticks;
let packet = this.packets.shift()
if(!packet) {
return;
}
for(let node of this.nodes) {
node.receive(packet);
}
this.packetLog.push(new PacketLogEntry(Date.now(), packet));
while(this.packetLog[0].timestamp < Date.now() - 30000) {
this.packetLog.shift();
}
}
enqueue(packet) {
this.packets.push(packet)
}
}