Merge branch 'main' of https://github.com/YoshiCrafter29/CodenameEngine-Dev
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package;
|
||||
|
||||
#if windows
|
||||
@:headerCode("#include <windows.h>")
|
||||
#elseif linux
|
||||
@:headerCode("#include <stdio.h>")
|
||||
#elseif mac
|
||||
@:headerCode("#include <sys/sysctl.h>")
|
||||
#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;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package funkin.system.framerate;
|
||||
|
||||
import ExternalCode;
|
||||
import native.HiddenProcess;
|
||||
import funkin.utils.MemoryUtil;
|
||||
|
||||
@@ -14,7 +15,7 @@ class SystemInfo extends FramerateCategory {
|
||||
public static var memType:String = "Unknown";
|
||||
|
||||
public static inline function init() {
|
||||
osInfo = '${lime.system.System.platformLabel.replace(lime.system.System.platformVersion, "")} ${lime.system.System.platformVersion}';
|
||||
osInfo = '${lime.system.System.platformLabel.replace(lime.system.System.platformVersion, "").trim()} ${lime.system.System.platformVersion}';
|
||||
|
||||
#if windows
|
||||
var process = new HiddenProcess("wmic", ["cpu", "get", "name"]);
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -12,53 +12,20 @@ import neko.vm.Gc;
|
||||
#end
|
||||
import openfl.system.System;
|
||||
|
||||
using StringTools;
|
||||
|
||||
#if cpp
|
||||
@:cppFileCode("
|
||||
#if defined(HX_WINDOWS)
|
||||
#include <windows.h>
|
||||
|
||||
long long totalMem() {
|
||||
unsigned long long allocatedRAM = 0;
|
||||
GetPhysicallyInstalledSystemMemory(&allocatedRAM);
|
||||
return (allocatedRAM / 1024);
|
||||
}
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#if define(HX_MAC)
|
||||
#include <stdio.h>
|
||||
|
||||
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 <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#if defined(HX_LINUX)
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
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 <stdio.h>
|
||||
#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";
|
||||
|
||||
Reference in New Issue
Block a user