mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Merge remote-tracking branch 'refs/remotes/LLK/develop' into bug/WhiteSpaceEqualsZero
This commit is contained in:
commit
246ff28363
7 changed files with 59 additions and 25 deletions
|
@ -110,7 +110,7 @@ Scratch3ControlBlocks.prototype.stop = function (args, util) {
|
|||
option === 'other scripts in stage') {
|
||||
util.stopOtherTargetThreads();
|
||||
} else if (option === 'this script') {
|
||||
util.stopThread();
|
||||
util.stopThisScript();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -147,6 +147,7 @@ Scratch3PenBlocks.prototype._updatePenColor = function (penState) {
|
|||
penState.penAttributes.color4f[0] = rgb.r / 255.0;
|
||||
penState.penAttributes.color4f[1] = rgb.g / 255.0;
|
||||
penState.penAttributes.color4f[2] = rgb.b / 255.0;
|
||||
penState.penAttributes.color4f[3] = 1;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -260,6 +261,8 @@ Scratch3PenBlocks.prototype.setPenColorToColor = function (args, util) {
|
|||
penState.penAttributes.color4f[2] = rgb.b / 255.0;
|
||||
if (rgb.hasOwnProperty('a')) { // Will there always be an 'a'?
|
||||
penState.penAttributes.color4f[3] = rgb.a / 255.0;
|
||||
} else {
|
||||
penState.penAttributes.color4f[3] = 1;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -183,8 +183,8 @@ var execute = function (sequencer, thread) {
|
|||
stopOtherTargetThreads: function () {
|
||||
runtime.stopForTarget(target, thread);
|
||||
},
|
||||
stopThread: function () {
|
||||
sequencer.retireThread(thread);
|
||||
stopThisScript: function () {
|
||||
thread.stopThisScript();
|
||||
},
|
||||
startProcedure: function (procedureCode) {
|
||||
sequencer.stepToProcedure(thread, procedureCode);
|
||||
|
|
|
@ -140,6 +140,27 @@ Thread.prototype.popStack = function () {
|
|||
return this.stack.pop();
|
||||
};
|
||||
|
||||
/**
|
||||
* Pop back down the stack frame until we hit a procedure call or the stack frame is emptied
|
||||
*/
|
||||
Thread.prototype.stopThisScript = function () {
|
||||
var blockID = this.peekStack();
|
||||
while (blockID !== null) {
|
||||
var block = this.target.blocks.getBlock(blockID);
|
||||
if (typeof block !== 'undefined' && block.opcode === 'procedures_callnoreturn') {
|
||||
break;
|
||||
}
|
||||
this.popStack();
|
||||
blockID = this.peekStack();
|
||||
}
|
||||
|
||||
if (this.stack.length === 0) {
|
||||
// Clean up!
|
||||
this.requestScriptGlowInFrame = false;
|
||||
this.status = Thread.STATUS_DONE;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get top stack item.
|
||||
* @return {?string} Block ID on top of stack.
|
||||
|
|
|
@ -23,16 +23,35 @@ var Timer = function () {};
|
|||
*/
|
||||
Timer.prototype.startTime = 0;
|
||||
|
||||
/**
|
||||
* Disable use of self.performance for now as it results in lower performance
|
||||
* However, instancing it like below (caching the self.performance to a local variable) negates most of the issues.
|
||||
* @type {boolean}
|
||||
*/
|
||||
var USE_PERFORMANCE = false;
|
||||
|
||||
/**
|
||||
* Legacy object to allow for us to call now to get the old style date time (for backwards compatibility)
|
||||
* @deprecated This is only called via the nowObj.now() if no other means is possible...
|
||||
*/
|
||||
var legacyDateCode = {
|
||||
now: function () {
|
||||
return new Date().getTime();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Use this object to route all time functions through single access points.
|
||||
*/
|
||||
var nowObj = (USE_PERFORMANCE && typeof self !== 'undefined' && self.performance && 'now' in self.performance) ?
|
||||
self.performance : Date.now ? Date : legacyDateCode;
|
||||
|
||||
/**
|
||||
* Return the currently known absolute time, in ms precision.
|
||||
* @returns {number} ms elapsed since 1 January 1970 00:00:00 UTC.
|
||||
*/
|
||||
Timer.prototype.time = function () {
|
||||
if (Date.now) {
|
||||
return Date.now();
|
||||
} else {
|
||||
return new Date().getTime();
|
||||
}
|
||||
return nowObj.now();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -43,12 +62,7 @@ Timer.prototype.time = function () {
|
|||
* @returns {number} ms-scale accurate time relative to other relative times.
|
||||
*/
|
||||
Timer.prototype.relativeTime = function () {
|
||||
if (typeof self !== 'undefined' &&
|
||||
self.performance && 'now' in self.performance) {
|
||||
return self.performance.now();
|
||||
} else {
|
||||
return this.time();
|
||||
}
|
||||
return nowObj.now();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -56,15 +70,11 @@ Timer.prototype.relativeTime = function () {
|
|||
* at the most accurate precision possible.
|
||||
*/
|
||||
Timer.prototype.start = function () {
|
||||
this.startTime = this.relativeTime();
|
||||
this.startTime = nowObj.now();
|
||||
};
|
||||
|
||||
/**
|
||||
* Check time elapsed since `timer.start` was called.
|
||||
* @returns {number} Time elapsed, in ms (possibly sub-ms precision).
|
||||
*/
|
||||
Timer.prototype.timeElapsed = function () {
|
||||
return this.relativeTime() - this.startTime;
|
||||
return nowObj.now() - this.startTime;
|
||||
};
|
||||
|
||||
module.exports = Timer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue