mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Merge pull request #1723 from mzgoddard/blocks-monitored-cache
Cache the set of actively monitored blocks
This commit is contained in:
commit
8aa88fa2a2
1 changed files with 26 additions and 7 deletions
|
@ -64,7 +64,14 @@ class Blocks {
|
||||||
* execute.
|
* execute.
|
||||||
* @type {object.<string, object>}
|
* @type {object.<string, object>}
|
||||||
*/
|
*/
|
||||||
_executeCached: {}
|
_executeCached: {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A cache of block IDs and targets to start threads on as they are
|
||||||
|
* actively monitored.
|
||||||
|
* @type {Array<{blockId: string, target: Target}>}
|
||||||
|
*/
|
||||||
|
_monitored: null
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -492,6 +499,7 @@ class Blocks {
|
||||||
this._cache.procedureParamNames = {};
|
this._cache.procedureParamNames = {};
|
||||||
this._cache.procedureDefinitions = {};
|
this._cache.procedureDefinitions = {};
|
||||||
this._cache._executeCached = {};
|
this._cache._executeCached = {};
|
||||||
|
this._cache._monitored = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -702,12 +710,23 @@ class Blocks {
|
||||||
* @param {!object} runtime Runtime to run all blocks in.
|
* @param {!object} runtime Runtime to run all blocks in.
|
||||||
*/
|
*/
|
||||||
runAllMonitored (runtime) {
|
runAllMonitored (runtime) {
|
||||||
Object.keys(this._blocks).forEach(blockId => {
|
if (this._cache._monitored === null) {
|
||||||
if (this.getBlock(blockId).isMonitored) {
|
this._cache._monitored = Object.keys(this._blocks)
|
||||||
const targetId = this.getBlock(blockId).targetId;
|
.filter(blockId => this.getBlock(blockId).isMonitored)
|
||||||
runtime.addMonitorScript(blockId, targetId ? runtime.getTargetById(targetId) : null);
|
.map(blockId => {
|
||||||
}
|
const targetId = this.getBlock(blockId).targetId;
|
||||||
});
|
return {
|
||||||
|
blockId,
|
||||||
|
target: targetId ? runtime.getTargetById(targetId) : null
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const monitored = this._cache._monitored;
|
||||||
|
for (let i = 0; i < monitored.length; i++) {
|
||||||
|
const {blockId, target} = monitored[i];
|
||||||
|
runtime.addMonitorScript(blockId, target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue