Stop emitting SPRITE_INFO_REPORT

Instead, set the `_refreshTargets` flag, and emit a full target list at the end of the step.
This commit is contained in:
Ray Schamp 2017-05-12 11:42:22 -04:00
parent 312e15932e
commit 20337b53f2
3 changed files with 48 additions and 40 deletions
src/engine

View file

@ -104,6 +104,13 @@ class Runtime extends EventEmitter {
*/
this._cloneCounter = 0;
/**
* Flag to emit a targets update at the end of a step. When target data
* changes, this flag is set to true.
* @type {boolean}
*/
this._refreshTargets = false;
/**
* Whether the project is in "turbo mode."
* @type {Boolean}
@ -226,11 +233,11 @@ class Runtime extends EventEmitter {
}
/**
* Event name for sprite info report.
* Event name for targets update report.
* @const {string}
*/
static get SPRITE_INFO_REPORT () {
return 'SPRITE_INFO_REPORT';
static get TARGETS_UPDATE () {
return 'TARGETS_UPDATE';
}
/**
@ -638,6 +645,7 @@ class Runtime extends EventEmitter {
* inactive threads after each iteration.
*/
_step () {
this._refreshTargets = false;
// Find all edge-activated hats, and add them to threads to be evaluated.
for (const hatType in this._hats) {
if (!this._hats.hasOwnProperty(hatType)) continue;
@ -655,6 +663,7 @@ class Runtime extends EventEmitter {
// @todo: Only render when this.redrawRequested or clones rendered.
this.renderer.draw();
}
if (this._refreshTargets) this.emit(Runtime.TARGETS_UPDATE);
}
/**
@ -673,7 +682,7 @@ class Runtime extends EventEmitter {
// Script glows must be cleared.
this._scriptGlowsPreviousFrame = [];
this._updateGlows();
this.spriteInfoReport(editingTarget);
this.requestTargetsUpdate(editingTarget);
}
/**
@ -809,16 +818,6 @@ class Runtime extends EventEmitter {
this.emit(Runtime.VISUAL_REPORT, {id: blockId, value: String(value)});
}
/**
* Emit a sprite info report if the provided target is the original sprite
* @param {!Target} target Target to report sprite info for.
*/
spriteInfoReport (target) {
if (!target.isOriginal) return;
this.emit(Runtime.SPRITE_INFO_REPORT, target.toJSON());
}
/**
* Get a target by its id.
* @param {string} targetId Id of target to find.
@ -896,6 +895,16 @@ class Runtime extends EventEmitter {
this.redrawRequested = true;
}
/**
* Emit a targets update at the end of the step if the provided target is
* the original sprite
* @param {!Target} target Target requesting the targets update
*/
requestTargetsUpdate (target) {
if (!target.isOriginal) return;
this._refreshTargets = true;
}
/**
* Set up timers to repeatedly step in a browser.
*/