From aeacb0fb3ef3f0e13a821a4e0d5d3bea8601cd8e Mon Sep 17 00:00:00 2001 From: NeeEoo Date: Fri, 24 Mar 2023 02:06:15 +0100 Subject: [PATCH] Working total ram, but needs restructuring --- source/ExternalCode.hx | 55 ++++++++++++++++++++ source/funkin/system/framerate/SystemInfo.hx | 7 ++- 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 source/ExternalCode.hx diff --git a/source/ExternalCode.hx b/source/ExternalCode.hx new file mode 100644 index 00000000..70575c83 --- /dev/null +++ b/source/ExternalCode.hx @@ -0,0 +1,55 @@ +package; + +#if windows +@:headerCode("#include ") +#elseif linux +@:headerCode("#include ") +#elseif mac +@:headerCode("#include ") +#end +class ExternalCode { + #if windows + @:functionCode(" + // simple but effective code + unsigned long long allocatedRAM = 0; + GetPhysicallyInstalledSystemMemory(&allocatedRAM); + return (allocatedRAM / 1024); + ") + #elseif linux + @:functionCode(' + FILE *meminfo = fopen("/proc/meminfo", "r"); + + if(meminfo == NULL) + return -1; + + char line[256]; + while(fgets(line, sizeof(line), meminfo)) + { + int ram; + if(sscanf(line, "MemTotal: %d kB", &ram) == 1) + { + fclose(meminfo); + return (ram / 1024); + } + } + + fclose(meminfo); + return -1; + ') + #elseif mac + @:functionCode(' + int mib [] = { CTL_HW, HW_MEMSIZE }; + int64_t value = 0; + size_t length = sizeof(value); + + if(-1 == sysctl(mib, 2, &value, &length, NULL, 0)) + return -1; // An error occurred + + return value / 1024 / 1024; + ') + #end + public static function getTotalRam():Float + { + return 0; + } +} \ No newline at end of file diff --git a/source/funkin/system/framerate/SystemInfo.hx b/source/funkin/system/framerate/SystemInfo.hx index cd8d3b50..2e4a182b 100644 --- a/source/funkin/system/framerate/SystemInfo.hx +++ b/source/funkin/system/framerate/SystemInfo.hx @@ -1,5 +1,6 @@ package funkin.system.framerate; +import ExternalCode; import native.HiddenProcess; import funkin.utils.MemoryUtil; @@ -39,8 +40,10 @@ class SystemInfo extends FramerateCategory { vRAM = CoolUtil.getSizeString(cast(flixel.FlxG.stage.context3D.gl.getParameter(openfl.display3D.Context3D.__glMemoryTotalAvailable), UInt) * 1000); } - #if cpp - totalMem = Std.string(MemoryUtil.getTotalMem() / 1024) + " GB"; + #if cpp + var total = ExternalCode.getTotalRam(); + trace("Total Ram: " + total); + totalMem = Std.string(total / 1024) + " GB"; #end memType = MemoryUtil.getMemType(); }