chore: throttle packets for now

This commit is contained in:
cha0s 2019-04-09 10:55:25 -04:00
parent a2295ed038
commit 5e0a9665aa

View File

@ -4,6 +4,7 @@ import {performance} from 'perf_hooks';
import immutablediff from 'immutablediff';
// 2nd party.
import {Synchronizer} from '@avocado/state';
import {Ticker} from '@avocado/timing';
// 1st party.
import {WorldTime} from '../common/world-time';
import {createEntityForConnection} from './create-entity-for-connection';
@ -66,6 +67,13 @@ function createDisconnectionListener(socket) {
}
// Main loop.
let lastTime = performance.now();
const informTicker = new Ticker(1/40);
informTicker.on('tick', () => {
// Inform entities of the new state.
for (const entity of informables) {
entity.inform(synchronizer.state);
}
});
function createMainLoop() {
return () => {
const now = performance.now();
@ -73,9 +81,7 @@ function createMainLoop() {
lastTime = now;
// Tick synchronized.
synchronizer.tick(elapsed);
// Inform entities of the new state.
for (const entity of informables) {
entity.inform(synchronizer.state);
}
// Tick informer.
informTicker.tick(elapsed);
}
}