I have been working on the Jams_Mapper plugin and most of the processing is done when you move between maps (I call them sectors since they are a sector of the $dataMap that gets updated).
I noticed that most of my processing is triggered when I cross from one sector to another in order to refresh the other sectors and there is a visible stutter in the application when you cross this line. In order to combat this issue I was going to implement throttling in my event bus to spread the load across multiple engine ticks and that has improved the issue significantly, but I wanted to know if there were any other tips to spread processing across game engines frames or other solutions in general.
Jams_EventBus.js
the ticks are coming from SceneManager.updateFrameCount.
I noticed that most of my processing is triggered when I cross from one sector to another in order to refresh the other sectors and there is a visible stutter in the application when you cross this line. In order to combat this issue I was going to implement throttling in my event bus to spread the load across multiple engine ticks and that has improved the issue significantly, but I wanted to know if there were any other tips to spread processing across game engines frames or other solutions in general.
Jams_EventBus.js
JavaScript:
JamsEventBus.prototype.execute = function () {
if (this.backlog.length > 0) {
const { eventType, id, arg } = this.backlog[0];
this.subscriptions[eventType][id](arg);
this.backlog.shift();
}
};
JamsEventBus.prototype.execution = function (eventType, arg) {
var d = Date.now();
var len = this.backlog.length;
var interval = 10;
var loop = 0;
if (len > 10) {
loop = Math.ceil(len / 5);
interval = 0;
}
for (let i = 0; i <= loop; i++) {
if (d - this.tick > interval) {
this.execute();
this.tick = d;
}
}
};
the ticks are coming from SceneManager.updateFrameCount.
JavaScript:
let _updateFrameCount = SceneManager.updateFrameCount;
SceneManager.updateFrameCount = function () {
...
Jams.EventBus.execution();
_updateFrameCount();
};