From fd4b989d1747fec33ae2ac1cd44037f07383b0c5 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 21 Dec 2021 16:37:38 -0700 Subject: [PATCH] destroy SceneFlxStates when a FlxMovie ends --- .../src/hollywoo_flixel/FlxDirector.kiss | 3 +++ .../hollywoo_flixel/HollywooFlixelDSL.kiss | 5 +++++ .../src/hollywoo_flixel/MovieFlxState.kiss | 7 +----- projects/hollywoo/src/hollywoo/Director.hx | 2 ++ .../hollywoo/src/hollywoo/HollywooDSL.kiss | 22 +++++++++++++------ 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss index b50654ad..68dcb56d 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss @@ -22,6 +22,9 @@ (FlxG.state.openSubState currentState) (cc)) +(method :Void cleanup [] + (FlxG.state.openSubState null)) + (var STAGE_LEFT_X 150) (var STAGE_RIGHT_X (- 1280 150)) (var ACTOR_Y 500) diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss b/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss index e10794fd..3b08d0f1 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss @@ -9,6 +9,11 @@ (setSprite.loadGraphic (dictGet sets set)) (newScene name (cast (new SceneFlxState setSprite time perspective))))) +// Destroy substates when the movie end is reached: +(cleanup + (doFor =>name scene scenes + (.destroy (cast scene SceneFlxState)))) + (method newFlxSound [name path &opt :Float volume] (set volume (or volume 1)) (assert (<= 0 volume 1)) diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/MovieFlxState.kiss b/projects/hollywoo-flixel/src/hollywoo_flixel/MovieFlxState.kiss index 6df745b2..61c25ffb 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/MovieFlxState.kiss +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/MovieFlxState.kiss @@ -1,11 +1,6 @@ (prop &mut :FlxDirector director) -(prop &mut :FlxMovie movie) (method &override :Void create [] (set destroySubStates false) (super.create) - (set director (new FlxDirector)) - (set movie (new FlxMovie director))) - -(method &override :Void update [:Float elapsed] - (super.update elapsed)) \ No newline at end of file + (set director (new FlxDirector))) \ No newline at end of file diff --git a/projects/hollywoo/src/hollywoo/Director.hx b/projects/hollywoo/src/hollywoo/Director.hx index a756c5a7..6628feca 100644 --- a/projects/hollywoo/src/hollywoo/Director.hx +++ b/projects/hollywoo/src/hollywoo/Director.hx @@ -25,4 +25,6 @@ interface Director) will be collected. When (end) is called, they will // be injected into a method called (doPreload). // This allows assets to be declared in Hollywoo files where they first appear, but still loaded before execution starts. -(collectBlocks preload (cc)) +(collectBlocks preload (#when (StringTools.contains kissFile className) (cc))) +(collectBlocks cleanup (#when (StringTools.contains kissFile className) (cc))) (prop :Map labelsByName (new Map)) (prop :Array labels []) @@ -21,10 +22,17 @@ (dictSet labelsByName ,label ,idx) (labels.push ,idx) })] - `(method doPreload [:Void->Void cc] - (set isLoading true) - (collectedBlocks preload) - (set isLoading false) - ,@labelSetters - (cc)))) + `{ + (method doPreload [:Void->Void cc] + (set isLoading true) + (collectedBlocks preload) + (set isLoading false) + ,@labelSetters + (cc)) + (method doCleanup [] + (director.cleanup) + (set lastInstructionPointer -2) + (collectedBlocks cleanup)) + (doCleanup) + })) // TODO also &bof could call (doPreload)