mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Drop single-stepping and pause modes (#294)
This commit is contained in:
parent
9af9a87cb6
commit
3d57c2e74c
5 changed files with 1 additions and 156 deletions
|
@ -18,16 +18,9 @@
|
||||||
<div>
|
<div>
|
||||||
Turbo: <input id='turbomode' type='checkbox' />
|
Turbo: <input id='turbomode' type='checkbox' />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
Pause: <input id='pausemode' type='checkbox' />
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
Compatibility (30 TPS): <input id='compatmode' type='checkbox' />
|
Compatibility (30 TPS): <input id='compatmode' type='checkbox' />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
Single stepping: <input id='singlestepmode' type='checkbox' />
|
|
||||||
<input id='singlestepspeed' type='range' min='1' max='20' value='10' />
|
|
||||||
</div>
|
|
||||||
<br />
|
<br />
|
||||||
<ul id="playgroundLinks">
|
<ul id="playgroundLinks">
|
||||||
<li><a id="renderexplorer-link" href="#">Renderer</a></li>
|
<li><a id="renderexplorer-link" href="#">Renderer</a></li>
|
||||||
|
|
|
@ -249,26 +249,11 @@ window.onload = function() {
|
||||||
var turboOn = document.getElementById('turbomode').checked;
|
var turboOn = document.getElementById('turbomode').checked;
|
||||||
vm.setTurboMode(turboOn);
|
vm.setTurboMode(turboOn);
|
||||||
});
|
});
|
||||||
document.getElementById('pausemode').addEventListener('change', function() {
|
|
||||||
var pauseOn = document.getElementById('pausemode').checked;
|
|
||||||
vm.setPauseMode(pauseOn);
|
|
||||||
});
|
|
||||||
document.getElementById('compatmode').addEventListener('change',
|
document.getElementById('compatmode').addEventListener('change',
|
||||||
function() {
|
function() {
|
||||||
var compatibilityMode = document.getElementById('compatmode').checked;
|
var compatibilityMode = document.getElementById('compatmode').checked;
|
||||||
vm.setCompatibilityMode(compatibilityMode);
|
vm.setCompatibilityMode(compatibilityMode);
|
||||||
});
|
});
|
||||||
document.getElementById('singlestepmode').addEventListener('change',
|
|
||||||
function() {
|
|
||||||
var singleStep = document.getElementById('singlestepmode').checked;
|
|
||||||
vm.setSingleSteppingMode(singleStep);
|
|
||||||
});
|
|
||||||
document.getElementById('singlestepspeed').addEventListener('input',
|
|
||||||
function() {
|
|
||||||
var speed = document.getElementById('singlestepspeed').value;
|
|
||||||
vm.setSingleSteppingSpeed(speed);
|
|
||||||
});
|
|
||||||
|
|
||||||
var tabBlockExplorer = document.getElementById('tab-blockexplorer');
|
var tabBlockExplorer = document.getElementById('tab-blockexplorer');
|
||||||
var tabThreadExplorer = document.getElementById('tab-threadexplorer');
|
var tabThreadExplorer = document.getElementById('tab-threadexplorer');
|
||||||
var tabRenderExplorer = document.getElementById('tab-renderexplorer');
|
var tabRenderExplorer = document.getElementById('tab-renderexplorer');
|
||||||
|
|
|
@ -83,12 +83,6 @@ function Runtime () {
|
||||||
*/
|
*/
|
||||||
this._scriptGlowsPreviousFrame = [];
|
this._scriptGlowsPreviousFrame = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of block IDs that were glowing during the previous frame.
|
|
||||||
* @type {!Array.<!string>}
|
|
||||||
*/
|
|
||||||
this._blockGlowsPreviousFrame = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently known number of clones, used to enforce clone limit.
|
* Currently known number of clones, used to enforce clone limit.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
|
@ -101,24 +95,12 @@ function Runtime () {
|
||||||
*/
|
*/
|
||||||
this.turboMode = false;
|
this.turboMode = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the project is in "pause mode."
|
|
||||||
* @type {Boolean}
|
|
||||||
*/
|
|
||||||
this.pauseMode = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the project is in "compatibility mode" (30 TPS).
|
* Whether the project is in "compatibility mode" (30 TPS).
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
this.compatibilityMode = false;
|
this.compatibilityMode = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the project is in "single stepping mode."
|
|
||||||
* @type {Boolean}
|
|
||||||
*/
|
|
||||||
this.singleStepping = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How fast in ms "single stepping mode" should run, in ms.
|
* How fast in ms "single stepping mode" should run, in ms.
|
||||||
* Can be updated dynamically.
|
* Can be updated dynamically.
|
||||||
|
@ -542,10 +524,6 @@ Runtime.prototype.stopAll = function () {
|
||||||
* inactive threads after each iteration.
|
* inactive threads after each iteration.
|
||||||
*/
|
*/
|
||||||
Runtime.prototype._step = function () {
|
Runtime.prototype._step = function () {
|
||||||
if (this.pauseMode) {
|
|
||||||
// Don't do any execution while in pause mode.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Find all edge-activated hats, and add them to threads to be evaluated.
|
// Find all edge-activated hats, and add them to threads to be evaluated.
|
||||||
for (var hatType in this._hats) {
|
for (var hatType in this._hats) {
|
||||||
var hat = this._hats[hatType];
|
var hat = this._hats[hatType];
|
||||||
|
@ -569,23 +547,6 @@ Runtime.prototype.setEditingTarget = function (editingTarget) {
|
||||||
this._updateGlows();
|
this._updateGlows();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether we are in pause mode.
|
|
||||||
* @param {boolean} pauseModeOn True iff in pause mode.
|
|
||||||
*/
|
|
||||||
Runtime.prototype.setPauseMode = function (pauseModeOn) {
|
|
||||||
// Inform the project clock/timer to pause/resume its time.
|
|
||||||
if (this.ioDevices.clock) {
|
|
||||||
if (pauseModeOn && !this.pauseMode) {
|
|
||||||
this.ioDevices.clock.pause();
|
|
||||||
}
|
|
||||||
if (!pauseModeOn && this.pauseMode) {
|
|
||||||
this.ioDevices.clock.resume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.pauseMode = pauseModeOn;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether we are in 30 TPS compatibility mode.
|
* Set whether we are in 30 TPS compatibility mode.
|
||||||
* @param {boolean} compatibilityModeOn True iff in compatibility mode.
|
* @param {boolean} compatibilityModeOn True iff in compatibility mode.
|
||||||
|
@ -599,31 +560,7 @@ Runtime.prototype.setCompatibilityMode = function (compatibilityModeOn) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether we are in single-stepping mode.
|
* Emit glows/glow clears for scripts after a single tick.
|
||||||
* @param {boolean} singleSteppingOn True iff in single-stepping mode.
|
|
||||||
*/
|
|
||||||
Runtime.prototype.setSingleSteppingMode = function (singleSteppingOn) {
|
|
||||||
this.singleStepping = singleSteppingOn;
|
|
||||||
if (this._steppingInterval) {
|
|
||||||
self.clearInterval(this._steppingInterval);
|
|
||||||
this.start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the speed during single-stepping mode.
|
|
||||||
* @param {number} speed Interval length to step threads, in ms.
|
|
||||||
*/
|
|
||||||
Runtime.prototype.setSingleSteppingSpeed = function (speed) {
|
|
||||||
this.singleStepInterval = 1000 / speed;
|
|
||||||
if (this._steppingInterval) {
|
|
||||||
self.clearInterval(this._steppingInterval);
|
|
||||||
this.start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emit glows/glow clears for blocks and scripts after a single tick.
|
|
||||||
* Looks at `this.threads` and notices which have turned on/off new glows.
|
* Looks at `this.threads` and notices which have turned on/off new glows.
|
||||||
* @param {Array.<Thread>=} opt_extraThreads Optional list of inactive threads.
|
* @param {Array.<Thread>=} opt_extraThreads Optional list of inactive threads.
|
||||||
*/
|
*/
|
||||||
|
@ -635,10 +572,8 @@ Runtime.prototype._updateGlows = function (opt_extraThreads) {
|
||||||
}
|
}
|
||||||
// Set of scripts that request a glow this frame.
|
// Set of scripts that request a glow this frame.
|
||||||
var requestedGlowsThisFrame = [];
|
var requestedGlowsThisFrame = [];
|
||||||
var requestedBlockGlowsThisFrame = [];
|
|
||||||
// Final set of scripts glowing during this frame.
|
// Final set of scripts glowing during this frame.
|
||||||
var finalScriptGlows = [];
|
var finalScriptGlows = [];
|
||||||
var finalBlockGlows = [];
|
|
||||||
// Find all scripts that should be glowing.
|
// Find all scripts that should be glowing.
|
||||||
for (var i = 0; i < searchThreads.length; i++) {
|
for (var i = 0; i < searchThreads.length; i++) {
|
||||||
var thread = searchThreads[i];
|
var thread = searchThreads[i];
|
||||||
|
@ -657,10 +592,6 @@ Runtime.prototype._updateGlows = function (opt_extraThreads) {
|
||||||
requestedGlowsThisFrame.push(script);
|
requestedGlowsThisFrame.push(script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only show block glows in single-stepping mode.
|
|
||||||
if (this.singleStepping && blockForThread) {
|
|
||||||
requestedBlockGlowsThisFrame.push(blockForThread);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Compare to previous frame.
|
// Compare to previous frame.
|
||||||
|
@ -682,30 +613,7 @@ Runtime.prototype._updateGlows = function (opt_extraThreads) {
|
||||||
finalScriptGlows.push(currentFrameGlow);
|
finalScriptGlows.push(currentFrameGlow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (var m = 0; m < this._blockGlowsPreviousFrame.length; m++) {
|
|
||||||
var previousBlockGlow = this._blockGlowsPreviousFrame[m];
|
|
||||||
if (requestedBlockGlowsThisFrame.indexOf(previousBlockGlow) < 0) {
|
|
||||||
// Glow turned off.
|
|
||||||
try {
|
|
||||||
this.glowBlock(previousBlockGlow, false);
|
|
||||||
} catch (e) {
|
|
||||||
// Block has been removed.
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Still glowing.
|
|
||||||
finalBlockGlows.push(previousBlockGlow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (var p = 0; p < requestedBlockGlowsThisFrame.length; p++) {
|
|
||||||
var currentBlockFrameGlow = requestedBlockGlowsThisFrame[p];
|
|
||||||
if (this._blockGlowsPreviousFrame.indexOf(currentBlockFrameGlow) < 0) {
|
|
||||||
// Glow turned on.
|
|
||||||
this.glowBlock(currentBlockFrameGlow, true);
|
|
||||||
finalBlockGlows.push(currentBlockFrameGlow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this._scriptGlowsPreviousFrame = finalScriptGlows;
|
this._scriptGlowsPreviousFrame = finalScriptGlows;
|
||||||
this._blockGlowsPreviousFrame = finalBlockGlows;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -70,13 +70,6 @@ Sequencer.prototype.stepThreads = function () {
|
||||||
activeThread.warpTimer = null;
|
activeThread.warpTimer = null;
|
||||||
}
|
}
|
||||||
if (activeThread.status === Thread.STATUS_RUNNING) {
|
if (activeThread.status === Thread.STATUS_RUNNING) {
|
||||||
// After stepping, status is still running.
|
|
||||||
// If we're in single-stepping mode, mark the thread as
|
|
||||||
// a single-tick yield so it doesn't re-execute
|
|
||||||
// until the next frame.
|
|
||||||
if (this.runtime.singleStepping) {
|
|
||||||
activeThread.status = Thread.STATUS_YIELD_TICK;
|
|
||||||
}
|
|
||||||
numActiveThreads++;
|
numActiveThreads++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,11 +162,6 @@ Sequencer.prototype.stepThread = function (thread) {
|
||||||
// Get next block of existing block on the stack.
|
// Get next block of existing block on the stack.
|
||||||
thread.goToNextBlock();
|
thread.goToNextBlock();
|
||||||
}
|
}
|
||||||
// In single-stepping mode, force `stepThread` to only run one block
|
|
||||||
// at a time.
|
|
||||||
if (this.runtime.singleStepping) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
29
src/index.js
29
src/index.js
|
@ -75,15 +75,6 @@ VirtualMachine.prototype.setTurboMode = function (turboModeOn) {
|
||||||
this.runtime.turboMode = !!turboModeOn;
|
this.runtime.turboMode = !!turboModeOn;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether the VM is in "pause mode."
|
|
||||||
* When true, nothing is stepped.
|
|
||||||
* @param {Boolean} pauseModeOn Whether pause mode should be set.
|
|
||||||
*/
|
|
||||||
VirtualMachine.prototype.setPauseMode = function (pauseModeOn) {
|
|
||||||
this.runtime.setPauseMode(!!pauseModeOn);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether the VM is in 2.0 "compatibility mode."
|
* Set whether the VM is in 2.0 "compatibility mode."
|
||||||
* When true, ticks go at 2.0 speed (30 TPS).
|
* When true, ticks go at 2.0 speed (30 TPS).
|
||||||
|
@ -93,26 +84,6 @@ VirtualMachine.prototype.setCompatibilityMode = function (compatibilityModeOn) {
|
||||||
this.runtime.setCompatibilityMode(!!compatibilityModeOn);
|
this.runtime.setCompatibilityMode(!!compatibilityModeOn);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether the VM is in "single stepping mode."
|
|
||||||
* When true, blocks execute slowly and are highlighted visually.
|
|
||||||
* @param {Boolean} singleSteppingOn Whether single-stepping mode is set.
|
|
||||||
*/
|
|
||||||
VirtualMachine.prototype.setSingleSteppingMode = function (singleSteppingOn) {
|
|
||||||
this.runtime.setSingleSteppingMode(!!singleSteppingOn);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set single-stepping mode speed.
|
|
||||||
* When in single-stepping mode, adjusts the speed of execution.
|
|
||||||
* @param {Number} speed Interval length in ms.
|
|
||||||
*/
|
|
||||||
VirtualMachine.prototype.setSingleSteppingSpeed = function (speed) {
|
|
||||||
this.runtime.setSingleSteppingSpeed(speed);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop all threads and running activities.
|
* Stop all threads and running activities.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue