refactor: inform guards
This commit is contained in:
parent
4fe9c45ee8
commit
d60247b751
|
@ -27,17 +27,8 @@ export default class Game {
|
||||||
room: this.room,
|
room: this.room,
|
||||||
worldTime: this.worldTime,
|
worldTime: this.worldTime,
|
||||||
});
|
});
|
||||||
this.informTicker = new Ticker(1 / 40);
|
this.informTicker = new Ticker(config.informInterval);
|
||||||
this.informTicker.on('tick', () => {
|
this.informTicker.on('tick', this.inform, this);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Simulation.
|
// Simulation.
|
||||||
this.mainLoopHandle = setInterval(
|
this.mainLoopHandle = setInterval(
|
||||||
this.createMainLoop(),
|
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() {
|
readConfig() {
|
||||||
return {
|
return {
|
||||||
|
informInterval: 1 / 40,
|
||||||
simulationInterval: 1 / 80,
|
simulationInterval: 1 / 80,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,6 +211,9 @@ export class Informed extends decorate(Trait) {
|
||||||
return {
|
return {
|
||||||
|
|
||||||
inform: (state) => {
|
inform: (state) => {
|
||||||
|
if (!this._socket) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Reduce state.
|
// Reduce state.
|
||||||
const reducedState = this.reduceState(state);
|
const reducedState = this.reduceState(state);
|
||||||
// Take a pure JS diff.
|
// Take a pure JS diff.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user