From 2db47b1ba9fc91c90e2a9f3b52810398ab210ff6 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 7 Jun 2021 21:14:50 -0400 Subject: [PATCH] memory optimizations --- source/FreeplayState.hx | 27 ++++++++++++++++--- source/Note.hx | 7 +++++ source/ui/animDebugShit/DebugBoundingState.hx | 1 - 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/source/FreeplayState.hx b/source/FreeplayState.hx index d6040e87c..e05963a0a 100644 --- a/source/FreeplayState.hx +++ b/source/FreeplayState.hx @@ -1,11 +1,9 @@ package; -#if discord_rpc -import Discord.DiscordClient; -#end import flash.text.TextField; import flixel.FlxG; import flixel.FlxSprite; +import flixel.FlxState; import flixel.addons.display.FlxGridOverlay; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.math.FlxMath; @@ -16,6 +14,10 @@ import lime.utils.Assets; using StringTools; +#if discord_rpc +import Discord.DiscordClient; +#end + class FreeplayState extends MusicBeatState { var songs:Array = []; @@ -247,6 +249,12 @@ class FreeplayState extends MusicBeatState } } + override function switchTo(nextState:FlxState):Bool + { + clearDaCache(songs[curSelected].songName); + return super.switchTo(nextState); + } + function changeDiff(change:Int = 0) { curDifficulty += change; @@ -264,6 +272,19 @@ class FreeplayState extends MusicBeatState positionHighscore(); } + // Clears the cache of songs, frees up memory, they'll have to be loaded in later tho + function clearDaCache(actualSongTho:String) + { + for (song in songs) + { + if (song.songName != actualSongTho) + { + trace('trying to remove: ' + song.songName); + openfl.Assets.cache.clear(Paths.inst(song.songName)); + } + } + } + function changeSelection(change:Int = 0) { NGio.logEvent('Fresh'); diff --git a/source/Note.hx b/source/Note.hx index 325529a2a..00acfcb34 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -194,6 +194,13 @@ class Note extends FlxSprite } } + override function destroy() + { + prevNote = null; + + super.destroy(); + } + public function updateColors():Void { colorSwap.update(arrowColors[noteData]); diff --git a/source/ui/animDebugShit/DebugBoundingState.hx b/source/ui/animDebugShit/DebugBoundingState.hx index 23495d2f5..bfc90ed70 100644 --- a/source/ui/animDebugShit/DebugBoundingState.hx +++ b/source/ui/animDebugShit/DebugBoundingState.hx @@ -30,7 +30,6 @@ class DebugBoundingState extends FlxState /* TODAY'S TO-DO - Cleaner UI - - Loading the spritesheet and spritesheet data from offsetview */ var bg:FlxSprite; var fileInfo:FlxText;