diff --git a/hmm.json b/hmm.json index 52aea2a2..06defb1c 100644 --- a/hmm.json +++ b/hmm.json @@ -22,7 +22,7 @@ "type": "git", "dir": "flxanimate", "ref": "master", - "url": "https://github.com/Dot-Stuff/flxanimate/" + "url": "https://github.com/YoshiCrafter29/flxanimate/" }, { "name": "format", diff --git a/source/funkin/utils/MemoryUtil.hx b/source/funkin/utils/MemoryUtil.hx index 66f5c603..db6d2685 100644 --- a/source/funkin/utils/MemoryUtil.hx +++ b/source/funkin/utils/MemoryUtil.hx @@ -12,53 +12,20 @@ import neko.vm.Gc; #end import openfl.system.System; +using StringTools; + #if cpp @:cppFileCode(" #if defined(HX_WINDOWS) -#include - -long long totalMem() { - unsigned long long allocatedRAM = 0; - GetPhysicallyInstalledSystemMemory(&allocatedRAM); - return (allocatedRAM / 1024); -} + #include #endif -#if define(HX_MAC) -#include -long long totalMem() { - 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; -} +#if defined(HX_MAC) + #include #endif + #if defined(HX_LINUX) -#include - -long long totalMem() { - 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; -} + #include #endif ") #end @@ -112,7 +79,44 @@ class MemoryUtil { } #if cpp - @:functionCode("return totalMem();") + @:functionCode(" +#if defined(HX_WINDOWS) + unsigned long long allocatedRAM = 0; + GetPhysicallyInstalledSystemMemory(&allocatedRAM); + return (allocatedRAM / 1024); +#endif + +#if defined(HX_MAC) + 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; +#endif + +#if defined(HX_LINUX) + 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; +#endif + ") public static function getTotalMem():Float { return 0; @@ -167,7 +171,9 @@ class MemoryUtil { if (memoryOutput != -1) return memoryMap[memoryOutput]; #elseif mac var process = new HiddenProcess("system_profiler", ["SPMemoryDataType"]); - if (process.exitCode() == 0) return process.stdout.readAll().toString().match(/Type: (.+)/)[1]; + var reg = ~/Type: (.+)/; + reg.match(process.stdout.readAll().toString()); + if (process.exitCode() == 0) return reg.matched(1); #elseif linux var process = HiddenProcess("sudo", ["dmidecode", "--type", "17"]); if (process.exitCode() != 0) return "Unknown";