Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@ <h2>Scratch VM Playground</h2>
<div>
Turbo: <input id='turbomode' type='checkbox' />
</div>
<div>
Pause: <input id='pausemode' type='checkbox' />
</div>
<div>
Compatibility (30 TPS): <input id='compatmode' type='checkbox' />
</div>
<div>
Single stepping: <input id='singlestepmode' type='checkbox' />
<input id='singlestepspeed' type='range' min='1' max='20' value='10' />
</div>
<br />
<ul id="playgroundLinks">
<li><a id="renderexplorer-link" href="#">Renderer</a></li>
Expand Down
15 changes: 0 additions & 15 deletions playground/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,26 +249,11 @@ window.onload = function() {
var turboOn = document.getElementById('turbomode').checked;
vm.setTurboMode(turboOn);
});
document.getElementById('pausemode').addEventListener('change', function() {
var pauseOn = document.getElementById('pausemode').checked;
vm.setPauseMode(pauseOn);
});
document.getElementById('compatmode').addEventListener('change',
function() {
var compatibilityMode = document.getElementById('compatmode').checked;
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 tabThreadExplorer = document.getElementById('tab-threadexplorer');
var tabRenderExplorer = document.getElementById('tab-renderexplorer');
Expand Down
94 changes: 1 addition & 93 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ function Runtime () {
*/
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.
* @type {number}
Expand All @@ -101,24 +95,12 @@ function Runtime () {
*/
this.turboMode = false;

/**
* Whether the project is in "pause mode."
* @type {Boolean}
*/
this.pauseMode = false;

/**
* Whether the project is in "compatibility mode" (30 TPS).
* @type {Boolean}
*/
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.
* Can be updated dynamically.
Expand Down Expand Up @@ -542,10 +524,6 @@ Runtime.prototype.stopAll = function () {
* inactive threads after each iteration.
*/
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.
for (var hatType in this._hats) {
var hat = this._hats[hatType];
Expand All @@ -569,23 +547,6 @@ Runtime.prototype.setEditingTarget = function (editingTarget) {
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.
* @param {boolean} compatibilityModeOn True iff in compatibility mode.
Expand All @@ -599,31 +560,7 @@ Runtime.prototype.setCompatibilityMode = function (compatibilityModeOn) {
};

/**
* Set whether we are in single-stepping mode.
* @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.
* Emit glows/glow clears for scripts after a single tick.
* Looks at `this.threads` and notices which have turned on/off new glows.
* @param {Array.<Thread>=} opt_extraThreads Optional list of inactive threads.
*/
Expand All @@ -635,10 +572,8 @@ Runtime.prototype._updateGlows = function (opt_extraThreads) {
}
// Set of scripts that request a glow this frame.
var requestedGlowsThisFrame = [];
var requestedBlockGlowsThisFrame = [];
// Final set of scripts glowing during this frame.
var finalScriptGlows = [];
var finalBlockGlows = [];
// Find all scripts that should be glowing.
for (var i = 0; i < searchThreads.length; i++) {
var thread = searchThreads[i];
Expand All @@ -657,10 +592,6 @@ Runtime.prototype._updateGlows = function (opt_extraThreads) {
requestedGlowsThisFrame.push(script);
}
}
// Only show block glows in single-stepping mode.
if (this.singleStepping && blockForThread) {
requestedBlockGlowsThisFrame.push(blockForThread);
}
}
}
// Compare to previous frame.
Expand All @@ -682,30 +613,7 @@ Runtime.prototype._updateGlows = function (opt_extraThreads) {
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._blockGlowsPreviousFrame = finalBlockGlows;
};

/**
Expand Down
12 changes: 0 additions & 12 deletions src/engine/sequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ Sequencer.prototype.stepThreads = function () {
activeThread.warpTimer = null;
}
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++;
}
}
Expand Down Expand Up @@ -169,11 +162,6 @@ Sequencer.prototype.stepThread = function (thread) {
// Get next block of existing block on the stack.
thread.goToNextBlock();
}
// In single-stepping mode, force `stepThread` to only run one block
// at a time.
if (this.runtime.singleStepping) {
return;
}
}
};

Expand Down
29 changes: 0 additions & 29 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ VirtualMachine.prototype.setTurboMode = function (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."
* When true, ticks go at 2.0 speed (30 TPS).
Expand All @@ -93,26 +84,6 @@ VirtualMachine.prototype.setCompatibilityMode = function (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.
*/
Expand Down