refactor: inform guards
This commit is contained in:
parent
4fe9c45ee8
commit
d60247b751
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user