mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
2a60391fb4
These compatibility changes: - Use runtime.currentMSecs for the Clock timer "now" value - Start executing hats before other threads change values - Update test and fixtures to work with earlier hat execution - Add test for hat execution block order
39 lines
935 B
JavaScript
39 lines
935 B
JavaScript
const Timer = require('../util/timer');
|
|
|
|
class Clock {
|
|
constructor (runtime) {
|
|
this._projectTimer = new Timer({now: () => runtime.currentMSecs});
|
|
this._projectTimer.start();
|
|
this._pausedTime = null;
|
|
this._paused = false;
|
|
/**
|
|
* Reference to the owning Runtime.
|
|
* @type{!Runtime}
|
|
*/
|
|
this.runtime = runtime;
|
|
}
|
|
|
|
projectTimer () {
|
|
if (this._paused) {
|
|
return this._pausedTime / 1000;
|
|
}
|
|
return this._projectTimer.timeElapsed() / 1000;
|
|
}
|
|
|
|
pause () {
|
|
this._paused = true;
|
|
this._pausedTime = this._projectTimer.timeElapsed();
|
|
}
|
|
|
|
resume () {
|
|
this._paused = false;
|
|
const dt = this._projectTimer.timeElapsed() - this._pausedTime;
|
|
this._projectTimer.startTime += dt;
|
|
}
|
|
|
|
resetProjectTimer () {
|
|
this._projectTimer.start();
|
|
}
|
|
}
|
|
|
|
module.exports = Clock;
|