diff --git a/source/GameOverState.hx b/source/GameOverState.hx index 373fc5c..f73fe7a 100644 --- a/source/GameOverState.hx +++ b/source/GameOverState.hx @@ -23,6 +23,10 @@ class GameOverState extends FlxTransitionableState override function create() { + if (!FlxG.save.data.GC) { + Gc.enable(true); + trace("Player died. We can reenable the garbage collector"); + } var loser:FlxSprite = new FlxSprite(100, 100); var loseTex = Paths.getSparrowAtlas('lose'); loser.frames = loseTex; diff --git a/source/KadeEngineData.hx b/source/KadeEngineData.hx index 9556ed3..e11e04e 100644 --- a/source/KadeEngineData.hx +++ b/source/KadeEngineData.hx @@ -46,10 +46,10 @@ class KadeEngineData if (FlxG.save.data.fpsRain == null) FlxG.save.data.fpsRain = false; - if (FlxG.save.data.fpsCap == null) - FlxG.save.data.fpsCap = 120; + /*if (FlxG.save.data.fpsCap == null) + FlxG.save.data.fpsCap = 120;*/ - if (FlxG.save.data.fpsCap > 285 || FlxG.save.data.fpsCap < 60) + if (FlxG.save.data.fpsCap > 1000 || FlxG.save.data.fpsCap < 60) FlxG.save.data.fpsCap = 120; // baby proof so you can't hard lock ur copy of kade engine if (FlxG.save.data.scrollSpeed == null) @@ -118,6 +118,9 @@ class KadeEngineData if (FlxG.save.data.zoom == null) FlxG.save.data.zoom = 1; + if (FlxG.save.data.GC == null) + FlxG.save.data.GC == true; + var gamepad:FlxGamepad = FlxG.gamepads.lastActive; KeyBinds.gamepad = gamepad != null; diff --git a/source/Main.hx b/source/Main.hx index f17cec3..4d5c41e 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -1,5 +1,6 @@ package; +import cpp.vm.Gc; import lime.app.Application; #if windows import Discord.DiscordClient; @@ -102,6 +103,8 @@ class Main extends Sprite fpsCounter = new FPS(10, 3, 0xFFFFFF); addChild(fpsCounter); toggleFPS(FlxG.save.data.fps); + memory = new Memory(10, 15, 0xFFFFFF); + addChild(memory); #end } @@ -109,6 +112,8 @@ class Main extends Sprite var fpsCounter:FPS; + var memory:Memory; + public function toggleFPS(fpsEnabled:Bool):Void { fpsCounter.visible = fpsEnabled; } diff --git a/source/Memory.hx b/source/Memory.hx new file mode 100644 index 0000000..f7c7ed5 --- /dev/null +++ b/source/Memory.hx @@ -0,0 +1,45 @@ +package; + +import flixel.util.FlxStringUtil; +import openfl.events.Event; +import openfl.text.TextFormat; +import cpp.vm.Gc; +import openfl.text.TextField; +import openfl.Lib; + +class Memory extends TextField { + private var overCounter = 0; + private var isOver = false; + + @:noCompletion private var cacheCount:Int; + @:noCompletion private var currentTime:Float; + @:noCompletion private var times:Array; + + public function new(x:Float = 15, y:Float = 20, color:Int = 0x000000) { + super(); + + this.x = x; + this.y = y; + + defaultTextFormat = new TextFormat("_sans", 12, color); + text = "Memory: "; + + addEventListener(Event.ENTER_FRAME, function(e) + { + var usedMemory:Float = Gc.memUsage(); + if (Gc.memUsage() < 0 && !isOver) + { + isOver = true; + } + if (Gc.memUsage() > 0 && isOver) + { + overCounter++; + isOver = false; + } + if (isOver) { + usedMemory = 2147483647+(2147483647-(Math.abs(Gc.memUsage()))); // funny math to represent values over 2GB + } + text = "Memory: " + FlxStringUtil.formatBytes(usedMemory + 4294967296*overCounter); + }); + } +} \ No newline at end of file diff --git a/source/Options.hx b/source/Options.hx index 0248a8d..77b1330 100644 --- a/source/Options.hx +++ b/source/Options.hx @@ -530,10 +530,10 @@ class FPSCapOption extends Option } override function right():Bool { - if (FlxG.save.data.fpsCap >= 290) + if (FlxG.save.data.fpsCap >= 1000) { - FlxG.save.data.fpsCap = 290; - (cast (Lib.current.getChildAt(0), Main)).setFPSCap(290); + FlxG.save.data.fpsCap = 1000; + (cast (Lib.current.getChildAt(0), Main)).setFPSCap(1000); } else FlxG.save.data.fpsCap = FlxG.save.data.fpsCap + 10; @@ -543,8 +543,8 @@ class FPSCapOption extends Option } override function left():Bool { - if (FlxG.save.data.fpsCap > 290) - FlxG.save.data.fpsCap = 290; + if (FlxG.save.data.fpsCap > 1000) + FlxG.save.data.fpsCap = 1000; else if (FlxG.save.data.fpsCap < 60) FlxG.save.data.fpsCap = Application.current.window.displayMode.refreshRate; else @@ -631,6 +631,27 @@ class RainbowFPSOption extends Option } } +class GarbageCollection extends Option +{ + public function new(desc:String) + { + super(); + description = desc; + } + + public override function press():Bool + { + FlxG.save.data.GC = !FlxG.save.data.GC; + display = updateDisplay(); + return true; + } + + private override function updateDisplay():String + { + return "Garbage Collection " + ((FlxG.save.data.GC) ? " ON " : "OFF") ; + } +} + class Optimization extends Option { public function new(desc:String) @@ -946,6 +967,7 @@ class ResetSettings extends Option FlxG.save.data.optimize = null; FlxG.save.data.cacheImages = null; FlxG.save.data.editor = null; + FlxG.save.data.GC = null; KadeEngineData.initSave(); confirm = false; diff --git a/source/OptionsMenu.hx b/source/OptionsMenu.hx index 440df09..a03e304 100644 --- a/source/OptionsMenu.hx +++ b/source/OptionsMenu.hx @@ -60,6 +60,7 @@ class OptionsMenu extends MusicBeatState new MissSoundsOption("Toggle miss sounds playing when you don't hit a note."), new ScoreScreen("Show the score screen after the end of a song"), new ShowInput("Display every single input on the score screen."), + new GarbageCollection("Reduces lag at the cost of immense RAM usage."), new Optimization("No characters or backgrounds. Just a usual rhythm game layout."), new GraphicLoading("On startup, cache every character. Significantly decrease load times. (HIGH MEMORY)"), new BotPlay("Showcase your charts and mods with autoplay.") diff --git a/source/PauseSubState.hx b/source/PauseSubState.hx index 8f22367..3ba26d7 100644 --- a/source/PauseSubState.hx +++ b/source/PauseSubState.hx @@ -33,6 +33,8 @@ class PauseSubState extends MusicBeatSubstate public function new(x:Float, y:Float) { super(); + cpp.vm.Gc.run(true); + trace("Game paused. We can run the garbage collector"); if (PlayState.instance.useVideo) { @@ -225,6 +227,10 @@ class PauseSubState extends MusicBeatSubstate PlayState.instance.clean(); FlxG.resetState(); case "Exit to menu": + if (!FlxG.save.data.GC) { + cpp.vm.Gc.enable(true); + trace("Exiting the song. We can reenable the garbage collector"); + } PlayState.startTime = 0; if (PlayState.instance.useVideo) { @@ -246,8 +252,8 @@ class PauseSubState extends MusicBeatSubstate PlayState.luaModchart = null; } #end - if (FlxG.save.data.fpsCap > 290) - (cast (Lib.current.getChildAt(0), Main)).setFPSCap(290); + if (FlxG.save.data.fpsCap > 1000) + (cast (Lib.current.getChildAt(0), Main)).setFPSCap(1000); PlayState.instance.clean(); diff --git a/source/PlayState.hx b/source/PlayState.hx index 3acdc32..3551437 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1,6 +1,7 @@ package; +import cpp.vm.Gc; import Song.Event; import openfl.media.Sound; #if sys @@ -1692,6 +1693,10 @@ class PlayState extends MusicBeatState function startSong():Void { + if (!FlxG.save.data.GC) { + Gc.enable(false); + trace("Song started. Garbage collection has been disabled"); + } startingSong = false; songStarted = true; previousFrameTime = FlxG.game.ticks; @@ -3313,6 +3318,10 @@ class PlayState extends MusicBeatState function endSong():Void { + if (!FlxG.save.data.GC) { + Gc.enable(true); + trace("Song ended. We can reenable the garbage collector"); + } endingSong = true; FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput); FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput); @@ -3334,8 +3343,8 @@ class PlayState extends MusicBeatState PlayStateChangeables.useDownscroll = false; } - if (FlxG.save.data.fpsCap > 290) - (cast(Lib.current.getChildAt(0), Main)).setFPSCap(290); + if (FlxG.save.data.fpsCap > 1000) + (cast(Lib.current.getChildAt(0), Main)).setFPSCap(1000); #if cpp if (luaModchart != null) diff --git a/source/TimingStruct.hx b/source/TimingStruct.hx index d1301c1..42c5e06 100644 --- a/source/TimingStruct.hx +++ b/source/TimingStruct.hx @@ -40,7 +40,7 @@ class TimingStruct if (msTime >= i.startTime * 1000 && msTime < (i.startTime + i.length) * 1000) return i; } - trace('Apparently ' + msTime + ' is out of any segs'); + /*trace('Apparently ' + msTime + ' is out of any segs');*/ return null; }