mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-13 23:10:56 -04:00
Merge branch 'develop' of https://github.com/LLK/scratch-vm into sound
# Conflicts: # playground/index.html
This commit is contained in:
commit
7bd0142deb
25 changed files with 828 additions and 831 deletions
src/engine
|
@ -1,5 +1,6 @@
|
|||
var EventEmitter = require('events');
|
||||
var Sequencer = require('./sequencer');
|
||||
var Blocks = require('./blocks');
|
||||
var Thread = require('./thread');
|
||||
var util = require('util');
|
||||
|
||||
|
@ -45,6 +46,8 @@ function Runtime () {
|
|||
/** @type {!Sequencer} */
|
||||
this.sequencer = new Sequencer(this);
|
||||
|
||||
this.flyoutBlocks = new Blocks();
|
||||
|
||||
/**
|
||||
* Map to look up a block primitive's implementation function by its opcode.
|
||||
* This is a two-step lookup: package name first, then primitive name.
|
||||
|
@ -244,6 +247,9 @@ Runtime.prototype._pushThread = function (id, target) {
|
|||
* @param {?Thread} thread Thread object to remove from actives
|
||||
*/
|
||||
Runtime.prototype._removeThread = function (thread) {
|
||||
// Inform sequencer to stop executing that thread.
|
||||
this.sequencer.retireThread(thread);
|
||||
// Remove from the list.
|
||||
var i = this.threads.indexOf(thread);
|
||||
if (i > -1) {
|
||||
this.threads.splice(i, 1);
|
||||
|
@ -342,7 +348,7 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
|
|||
// any existing threads starting with the top block.
|
||||
for (var i = 0; i < instance.threads.length; i++) {
|
||||
if (instance.threads[i].topBlock === topBlockId &&
|
||||
(!opt_target || instance.threads[i].target == opt_target)) {
|
||||
instance.threads[i].target == target) {
|
||||
instance._removeThread(instance.threads[i]);
|
||||
}
|
||||
}
|
||||
|
@ -351,7 +357,7 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
|
|||
// give up if any threads with the top block are running.
|
||||
for (var j = 0; j < instance.threads.length; j++) {
|
||||
if (instance.threads[j].topBlock === topBlockId &&
|
||||
(!opt_target || instance.threads[j].target == opt_target)) {
|
||||
instance.threads[j].target == target) {
|
||||
// Some thread is already running.
|
||||
return;
|
||||
}
|
||||
|
@ -364,26 +370,38 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
|
|||
};
|
||||
|
||||
/**
|
||||
* Dispose of a target.
|
||||
* @param {!Target} target Target to dispose of.
|
||||
* Dispose all targets. Return to clean state.
|
||||
*/
|
||||
Runtime.prototype.disposeTarget = function (target) {
|
||||
// Allow target to do dispose actions.
|
||||
target.dispose();
|
||||
// Remove from list of targets.
|
||||
var index = this.targets.indexOf(target);
|
||||
if (index > -1) {
|
||||
this.targets.splice(index, 1);
|
||||
}
|
||||
Runtime.prototype.dispose = function () {
|
||||
this.stopAll();
|
||||
this.targets.map(this.disposeTarget, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispose of a target.
|
||||
* @param {!Target} disposingTarget Target to dispose of.
|
||||
*/
|
||||
Runtime.prototype.disposeTarget = function (disposingTarget) {
|
||||
this.targets = this.targets.filter(function (target) {
|
||||
if (disposingTarget !== target) return true;
|
||||
// Allow target to do dispose actions.
|
||||
target.dispose();
|
||||
// Remove from list of targets.
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop any threads acting on the target.
|
||||
* @param {!Target} target Target to stop threads for.
|
||||
* @param {Thread=} opt_threadException Optional thread to skip.
|
||||
*/
|
||||
Runtime.prototype.stopForTarget = function (target) {
|
||||
Runtime.prototype.stopForTarget = function (target, opt_threadException) {
|
||||
// Stop any threads on the target.
|
||||
for (var i = 0; i < this.threads.length; i++) {
|
||||
if (this.threads[i] === opt_threadException) {
|
||||
continue;
|
||||
}
|
||||
if (this.threads[i].target == target) {
|
||||
this._removeThread(this.threads[i]);
|
||||
}
|
||||
|
@ -464,6 +482,10 @@ Runtime.prototype._updateScriptGlows = function () {
|
|||
if (thread.requestScriptGlowInFrame && target == this._editingTarget) {
|
||||
var blockForThread = thread.peekStack() || thread.topBlock;
|
||||
var script = target.blocks.getTopLevelScript(blockForThread);
|
||||
if (!script) {
|
||||
// Attempt to find in flyout blocks.
|
||||
script = this.flyoutBlocks.getTopLevelScript(blockForThread);
|
||||
}
|
||||
if (script) {
|
||||
requestedGlowsThisFrame.push(script);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue