Skip to content

Commit a4695af

Browse files
committed
make pausing also pause stack frames like it shuld
1 parent 13c9502 commit a4695af

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/engine/thread.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const log = require('../util/log');
2+
const Timer = require('../util/timer');
23

34
/**
45
* Recycle bin for empty stackFrame objects
@@ -405,6 +406,7 @@ class Thread {
405406
* pause this thread
406407
*/
407408
pause () {
409+
this.pauseTime = Timer.nowObj.now();
408410
this.originalStatus = this.status;
409411
this.status = Thread.STATUS_PAUSED;
410412
if (this.timer) this.timer.pause();
@@ -414,7 +416,20 @@ class Thread {
414416
* unpause this thread
415417
*/
416418
play () {
419+
const dt = Timer.nowObj.now() - this.pauseTime;
417420
this.status = this.originalStatus;
421+
422+
// reference the SA/TurboWarp pause addon for this
423+
// we need to update compat & execution context timers when unpausing
424+
const stackFrame = this.peekStackFrame();
425+
if (stackFrame && stackFrame.executionContext && stackFrame.executionContext.timer) {
426+
stackFrame.executionContext.timer.startTime += dt;
427+
}
428+
429+
if (this.compatibilityStackFrame && this.compatibilityStackFrame.timer) {
430+
this.compatibilityStackFrame.timer.startTime += dt;
431+
}
432+
418433
if (this.timer) this.timer.play();
419434
}
420435

0 commit comments

Comments
 (0)