if optimize mode is on, then remove assets and free memory

This commit is contained in:
KadeDeveloper 2021-08-13 17:20:55 -07:00
parent c3020d9dff
commit 5eb3a66b0c
9 changed files with 49 additions and 0 deletions

View File

@ -67,6 +67,7 @@ class FreeplayState extends MusicBeatState
override function create()
{
clean();
var initSonglist = CoolUtil.coolTextFile(Paths.txt('data/freeplaySonglist'));
//var diffList = "";
@ -398,6 +399,7 @@ class FreeplayState extends MusicBeatState
PlayState.isSM = false;
#end
LoadingState.loadAndSwitchState(new PlayState());
clean();
}
}

View File

@ -1,3 +1,4 @@
import flixel.FlxG;
import flixel.math.FlxMath;
class HelperFunctions

View File

@ -49,6 +49,7 @@ class MainMenuState extends MusicBeatState
override function create()
{
clean();
#if windows
// Updating Discord Rich Presence
DiscordClient.changePresence("In the Menus", null);

View File

@ -1,5 +1,6 @@
package;
import flixel.FlxBasic;
#if windows
import Discord.DiscordClient;
#end
@ -22,6 +23,24 @@ class MusicBeatState extends FlxUIState
inline function get_controls():Controls
return PlayerSettings.player1.controls;
private var assets:Array<FlxBasic> = [];
override function add(Object:flixel.FlxBasic):flixel.FlxBasic
{
if (FlxG.save.data.optimize)
assets.push(Object);
return super.add(Object);
}
public function clean()
{
if (FlxG.save.data.optimize)
for(i in assets)
{
remove(i);
}
}
override function create()
{
TimingStruct.clearTimings();

View File

@ -134,12 +134,15 @@ class OptionsMenu extends MusicBeatState
override function update(elapsed:Float)
{
clean();
super.update(elapsed);
if (acceptInput)
{
if (controls.BACK && !isCat)
{
FlxG.switchState(new MainMenuState());
}
else if (controls.BACK)
{
isCat = false;

View File

@ -209,6 +209,7 @@ class PauseSubState extends MusicBeatSubstate
{
var daSelected:String = menuItems[curSelected];
switch (daSelected)
{
case "Resume":
@ -221,6 +222,7 @@ class PauseSubState extends MusicBeatSubstate
PlayState.instance.remove(PlayState.instance.videoSprite);
PlayState.instance.removedVideo = true;
}
PlayState.instance.clean();
FlxG.resetState();
case "Exit to menu":
PlayState.startTime = 0;
@ -247,6 +249,8 @@ class PauseSubState extends MusicBeatSubstate
if (FlxG.save.data.fpsCap > 290)
(cast (Lib.current.getChildAt(0), Main)).setFPSCap(290);
PlayState.instance.clean();
if (PlayState.isStoryMode)
FlxG.switchState(new StoryMenuState());
else

View File

@ -2443,6 +2443,7 @@ class PlayState extends MusicBeatState
{
trace('GITAROO MAN EASTER EGG');
FlxG.switchState(new GitarooPause());
clean();
}
else
openSubState(new PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
@ -2464,7 +2465,9 @@ class PlayState extends MusicBeatState
#if windows
DiscordClient.changePresence("Chart Editor", null, null, true);
#end
FlxG.switchState(new ChartingState());
clean();
FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput);
FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput);
#if windows
@ -2518,6 +2521,7 @@ class PlayState extends MusicBeatState
}
FlxG.switchState(new AnimationDebug(SONG.player2));
clean();
FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput);
FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput);
#if windows
@ -2532,6 +2536,7 @@ class PlayState extends MusicBeatState
if (FlxG.keys.justPressed.ZERO)
{
FlxG.switchState(new AnimationDebug(SONG.player1));
clean();
FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput);
FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput);
#if windows
@ -3392,6 +3397,7 @@ class PlayState extends MusicBeatState
FlxG.sound.playMusic(Paths.music('freakyMenu'));
offsetTesting = false;
LoadingState.loadAndSwitchState(new OptionsMenu());
clean();
FlxG.save.data.offset = offsetTest;
}
else
@ -3429,6 +3435,7 @@ class PlayState extends MusicBeatState
FlxG.sound.playMusic(Paths.music('freakyMenu'));
Conductor.changeBPM(102);
FlxG.switchState(new StoryMenuState());
clean();
}
#if windows
@ -3483,6 +3490,7 @@ class PlayState extends MusicBeatState
FlxG.sound.music.stop();
LoadingState.loadAndSwitchState(new PlayState());
clean();
}
}
else
@ -3503,7 +3511,10 @@ class PlayState extends MusicBeatState
});
}
else
{
FlxG.switchState(new FreeplayState());
clean();
}
}
}
}

View File

@ -218,6 +218,7 @@ class ResultsScreen extends FlxSubState
}
else
FlxG.switchState(new FreeplayState());
PlayState.instance.clean();
}
if (FlxG.keys.justPressed.F1 && !PlayState.loadRep)
@ -288,6 +289,7 @@ class ResultsScreen extends FlxSubState
PlayState.isStoryMode = false;
PlayState.storyDifficulty = PlayState.rep.replay.songDiff;
LoadingState.loadAndSwitchState(new PlayState());
PlayState.instance.clean();
}
if (FlxG.keys.justPressed.F2 && !PlayState.loadRep)
@ -324,6 +326,7 @@ class ResultsScreen extends FlxSubState
PlayState.isStoryMode = false;
PlayState.storyDifficulty = PlayState.storyDifficulty;
LoadingState.loadAndSwitchState(new PlayState());
PlayState.instance.clean();
}
super.update(elapsed);

View File

@ -99,8 +99,10 @@ class TitleState extends MusicBeatState
#if FREEPLAY
FlxG.switchState(new FreeplayState());
clean();
#elseif CHARTING
FlxG.switchState(new ChartingState());
clean();
#else
#if !cpp
new FlxTimer().start(1, function(tmr:FlxTimer)
@ -305,16 +307,19 @@ class TitleState extends MusicBeatState
OutdatedSubState.needVer = returnedData[0];
OutdatedSubState.currChanges = returnedData[1];
FlxG.switchState(new OutdatedSubState());
clean();
}
else
{
FlxG.switchState(new MainMenuState());
clean();
}
}
http.onError = function (error) {
trace('error: $error');
FlxG.switchState(new MainMenuState()); // fail but we go anyway
clean();
}
http.request();