mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-27 08:22:31 -05:00
e49f076fa1
* Thread stepping rework; interp.redraw equivalent * Add turbo mode and pause mode * Yielding behavior to match Scratch 2.0 * Implement warp-mode procedure threads * Add check for recursive call * Inline wait block timer * Revert to setInterval and always drawing * Restore yielding in glide * 30TPS compatibility mode * 5-call count recursion limit * Removing dead primitive code * To simplify, access runtime.threads inline in `stepThreads`. * Warp mode/timer fixes; recursive check fixes; clean-up * Add basic single-stepping * Add single-stepping speed slider * Allow yielding threads to run in single-stepping * Restore inactive threads tracking for block glows * Add clock pausing during pause mode * Documentation and clean-up throughout * Don't look for block glows in `thread.topBlock`. * Add null check for block glows; rename `_updateScriptGlows` to reflect block glowing * Use the current executed block for glow, instead of stack * Add more comments to `stepToProcedure`, and re-arrange to match 2.0 * Tweak to Blocks.prototype.getTopLevelScript * Revert previous * Fix threads array to be resilient to changes during `stepThreads` * Restore inactive threads filtering * Fix typo in "procedure" * !! instead of == true
37 lines
881 B
JavaScript
37 lines
881 B
JavaScript
var Timer = require('../util/timer');
|
|
|
|
function Clock (runtime) {
|
|
this._projectTimer = new Timer();
|
|
this._projectTimer.start();
|
|
this._pausedTime = null;
|
|
this._paused = false;
|
|
/**
|
|
* Reference to the owning Runtime.
|
|
* @type{!Runtime}
|
|
*/
|
|
this.runtime = runtime;
|
|
}
|
|
|
|
Clock.prototype.projectTimer = function () {
|
|
if (this._paused) {
|
|
return this._pausedTime / 1000;
|
|
}
|
|
return this._projectTimer.timeElapsed() / 1000;
|
|
};
|
|
|
|
Clock.prototype.pause = function () {
|
|
this._paused = true;
|
|
this._pausedTime = this._projectTimer.timeElapsed();
|
|
};
|
|
|
|
Clock.prototype.resume = function () {
|
|
this._paused = false;
|
|
var dt = this._projectTimer.timeElapsed() - this._pausedTime;
|
|
this._projectTimer.startTime += dt;
|
|
};
|
|
|
|
Clock.prototype.resetProjectTimer = function () {
|
|
this._projectTimer.start();
|
|
};
|
|
|
|
module.exports = Clock;
|