refactor: inform guards

This commit is contained in:
cha0s 2019-04-22 14:06:57 -05:00
parent 4fe9c45ee8
commit d60247b751
2 changed files with 14 additions and 11 deletions

View File

@ -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,
};
}

View File

@ -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.