diff --git a/server/game.js b/server/game.js index b7f7d39..3868283 100644 --- a/server/game.js +++ b/server/game.js @@ -27,17 +27,8 @@ export default class Game { room: this.room, worldTime: this.worldTime, }); - this.informTicker = new Ticker(1 / 40); - this.informTicker.on('tick', () => { - // Inform entities of the new state. - for (let i = 0; i < this.informables.length; ++i) { - const entity = this.informables[i]; - if (!entity.socket) { - continue; - } - entity.inform(this.synchronizer.state); - } - }); + this.informTicker = new Ticker(config.informInterval); + this.informTicker.on('tick', this.inform, this); // Simulation. this.mainLoopHandle = setInterval( this.createMainLoop(), @@ -102,8 +93,17 @@ export default class Game { }; } + inform() { + // Inform entities of the new state. + for (let i = 0; i < this.informables.length; ++i) { + const entity = this.informables[i]; + entity.inform(this.synchronizer.state); + } + } + readConfig() { return { + informInterval: 1 / 40, simulationInterval: 1 / 80, }; } diff --git a/server/traits/informed.trait.js b/server/traits/informed.trait.js index 1dbb8db..230ec2d 100644 --- a/server/traits/informed.trait.js +++ b/server/traits/informed.trait.js @@ -211,6 +211,9 @@ export class Informed extends decorate(Trait) { return { inform: (state) => { + if (!this._socket) { + return; + } // Reduce state. const reducedState = this.reduceState(state); // Take a pure JS diff.