diff --git a/buildnumber.txt b/buildnumber.txt index 5ee5d632..abf9e63a 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -2034 \ No newline at end of file +2036 \ No newline at end of file diff --git a/source/funkin/system/AssetsLibraryList.hx b/source/funkin/system/AssetsLibraryList.hx index 1410662e..e9b370cc 100644 --- a/source/funkin/system/AssetsLibraryList.hx +++ b/source/funkin/system/AssetsLibraryList.hx @@ -95,16 +95,12 @@ class AssetsLibraryList extends AssetLibrary { public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH):Dynamic { try { - #if cpp - cpp.vm.Gc.enable(false); - #end + MemoryUtil.disable(); if (!id.startsWith("assets/")) { var ass = getSpecificAsset('assets/$id', type, source); if (ass != null) { - #if cpp - cpp.vm.Gc.enable(true); - #end + MemoryUtil.enable(); return ass; } } @@ -113,22 +109,15 @@ class AssetsLibraryList extends AssetLibrary { var asset = e.getAsset(id, type); if (asset != null) { - #if cpp - cpp.vm.Gc.enable(true); - #end + MemoryUtil.enable(); return asset; } } - - #if cpp - cpp.vm.Gc.enable(true); - #end + MemoryUtil.enable(); return null; } catch(e) { - #if cpp - cpp.vm.Gc.enable(true); - #end + MemoryUtil.enable(); throw e; } return null; diff --git a/source/funkin/system/FramerateField.hx b/source/funkin/system/FramerateField.hx index 74e5d41d..80b48e8d 100644 --- a/source/funkin/system/FramerateField.hx +++ b/source/funkin/system/FramerateField.hx @@ -21,7 +21,7 @@ class FramerateField extends TextField { */ public var debugMode:Bool = false; - public var peak:UInt = 0; + public var peak:Float = 0; public var lastFPS:Float = 0; public function new(x:Float = 10, y:Float = 10, color:Int = 0x000000) @@ -59,12 +59,13 @@ class FramerateField extends TextField { text.push('FPS: ${Std.int(lastFPS)}'); } #if !web + var totalMemory = MemoryUtil.currentMemUsage(); if (showMemory || debugMode) { - text.push('RAM: ${CoolUtil.getSizeString(cast(System.totalMemory, UInt))}'); + text.push('RAM: ${CoolUtil.getSizeString(totalMemory)}'); } if (showMemoryPeak || debugMode) { - if (peak < System.totalMemory) - peak = System.totalMemory; + if (peak < totalMemory) + peak = totalMemory; text.push('RAM PEAK: (${CoolUtil.getSizeString(peak)})'); } #end diff --git a/source/funkin/system/Main.hx b/source/funkin/system/Main.hx index 7da031bd..f28f78c8 100644 --- a/source/funkin/system/Main.hx +++ b/source/funkin/system/Main.hx @@ -244,8 +244,6 @@ class Main extends Sprite Paths.assetsTree.clearCache(); - #if cpp - cpp.vm.Gc.run(true); - #end + MemoryUtil.clearMajor(); } } diff --git a/source/funkin/utils/MemoryUtil.hx b/source/funkin/utils/MemoryUtil.hx new file mode 100644 index 00000000..22aea742 --- /dev/null +++ b/source/funkin/utils/MemoryUtil.hx @@ -0,0 +1,53 @@ +package funkin.utils; + +#if cpp +import cpp.vm.Gc; +#elseif hl +import hl.Gc; +#elseif java +import java.vm.Gc; +#elseif neko +import neko.vm.Gc; +#end +import openfl.system.System; + +class MemoryUtil { + public static function clearMinor() { + #if (cpp || java || neko) + Gc.run(false); + #end + } + + public static function clearMajor() { + #if cpp + Gc.run(true); + Gc.compact(); + #elseif hl + Gc.major(); + #elseif (java || neko) + Gc.run(true); + #end + } + + public static function enable() { + #if (cpp || hl) + Gc.enable(true); + #end + } + + public static function disable() { + #if (cpp || hl) + Gc.enable(false); + #end + } + + public static inline function currentMemUsage() { + #if cpp + return Gc.memInfo64(Gc.MEM_INFO_USAGE); + #elseif sys + return cast(cast(System.totalMemory, UInt), Float); + #else + return 0; + #end + } +} \ No newline at end of file