From fc99875c19d6a2579b193f1dfcee14efafd4ef3a Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 18 Sep 2023 19:58:17 -0600 Subject: [PATCH] allow script-skipping to be spread across multiple frames --- src/kiss/AsyncEmbeddedScript2.hx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/kiss/AsyncEmbeddedScript2.hx b/src/kiss/AsyncEmbeddedScript2.hx index 462d378..fe78ebc 100644 --- a/src/kiss/AsyncEmbeddedScript2.hx +++ b/src/kiss/AsyncEmbeddedScript2.hx @@ -176,6 +176,10 @@ class AsyncEmbeddedScript2 { public var onSkipStart(default, null):Continuation2 = null; public var onSkipEnd(default, null):Continuation2 = null; + + // When skipping, you might end up with hundreds of instructions running in a single frame. + // This flag forces the skipped instructions to run one-per-frame so your program doesn't hang. + public var skipAsync(default, null):Bool = false; private function runInstruction(instructionPointer:Int, withBreakPoints = true):Void { var wasRunning = running; @@ -212,7 +216,8 @@ class AsyncEmbeddedScript2 { // When this happens, make sure other scheduled continuations are canceled // by verifying that lastInstructionPointer hasn't changed if (lastInstructionPointer == instructionPointer) { - tryCallNextWithTailRecursion = true; + if (!skipping || !skipAsync) + tryCallNextWithTailRecursion = true; if (unwindWithTimerDelay) { haxe.Timer.delay(()->{ if (!nextCalledWithTailRecursion)