reorganized memory code (NEEDS TESTING ON LINUX & MAC)
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
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,3 +1,3 @@
|
||||
package native;
|
||||
package funkin.native;
|
||||
|
||||
typedef HiddenProcess = sys.io.Process;
|
||||
@@ -0,0 +1,30 @@
|
||||
package funkin.native;
|
||||
|
||||
#if linux
|
||||
class 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;
|
||||
')
|
||||
public static function getTotalRam():Float
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#end
|
||||
@@ -0,0 +1,20 @@
|
||||
package funkin.native;
|
||||
|
||||
#if mac
|
||||
class 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;
|
||||
')
|
||||
public static function getTotalRam():Float
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#end
|
||||
@@ -1,4 +1,4 @@
|
||||
package native;
|
||||
package funkin.native;
|
||||
|
||||
import funkin.windows.WindowsAPI.MessageBoxIcon;
|
||||
#if windows
|
||||
@@ -113,7 +113,7 @@ class AudioFixClient : public IMMNotificationClient {
|
||||
AudioFixClient *curAudioFix;
|
||||
')
|
||||
@:dox(hide)
|
||||
class WinAPI {
|
||||
class Windows {
|
||||
|
||||
public static var __audioChangeCallback:Void->Void = function() {
|
||||
trace("test");
|
||||
@@ -178,5 +178,16 @@ class WinAPI {
|
||||
SetProcessDPIAware();
|
||||
')
|
||||
public static function registerAsDPICompatible() {}
|
||||
|
||||
@:functionCode("
|
||||
// simple but effective code
|
||||
unsigned long long allocatedRAM = 0;
|
||||
GetPhysicallyInstalledSystemMemory(&allocatedRAM);
|
||||
return (allocatedRAM / 1024);
|
||||
")
|
||||
public static function getTotalRam():Float
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#end
|
||||
@@ -1,7 +1,7 @@
|
||||
package funkin.system.framerate;
|
||||
|
||||
import ExternalCode;
|
||||
import native.HiddenProcess;
|
||||
import funkin.windows.WindowsAPI;
|
||||
import funkin.native.HiddenProcess;
|
||||
import funkin.utils.MemoryUtil;
|
||||
|
||||
using StringTools;
|
||||
@@ -41,7 +41,7 @@ class SystemInfo extends FramerateCategory {
|
||||
}
|
||||
|
||||
#if cpp
|
||||
var total = ExternalCode.getTotalRam();
|
||||
var total = WindowsAPI.getTotalRam();
|
||||
trace("Total Ram: " + total);
|
||||
totalMem = Std.string(total / 1024) + " GB";
|
||||
#end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package funkin.utils;
|
||||
|
||||
import native.HiddenProcess;
|
||||
import funkin.native.HiddenProcess;
|
||||
#if cpp
|
||||
import cpp.vm.Gc;
|
||||
#elseif hl
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
package funkin.windows;
|
||||
|
||||
import funkin.native.*;
|
||||
|
||||
/**
|
||||
* Class for Windows-only functions, such as transparent windows, message boxes, and more.
|
||||
* Does not have any effect on other platforms.
|
||||
@@ -9,13 +11,13 @@ package funkin.windows;
|
||||
class WindowsAPI {
|
||||
@:dox(hide) public static function registerAudio() {
|
||||
#if windows
|
||||
native.WinAPI.registerAudio();
|
||||
Windows.registerAudio();
|
||||
#end
|
||||
}
|
||||
|
||||
@:dox(hide) public static function registerAsDPICompatible() {
|
||||
#if windows
|
||||
native.WinAPI.registerAsDPICompatible();
|
||||
Windows.registerAsDPICompatible();
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -24,8 +26,8 @@ class WindowsAPI {
|
||||
*/
|
||||
public static function allocConsole() {
|
||||
#if windows
|
||||
native.WinAPI.allocConsole();
|
||||
native.WinAPI.clearScreen();
|
||||
Windows.allocConsole();
|
||||
Windows.clearScreen();
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -34,7 +36,7 @@ class WindowsAPI {
|
||||
*/
|
||||
public static function setDarkMode(enable:Bool) {
|
||||
#if windows
|
||||
native.WinAPI.setDarkMode(enable);
|
||||
Windows.setDarkMode(enable);
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -43,7 +45,7 @@ class WindowsAPI {
|
||||
*/
|
||||
public static function showMessageBox(caption:String, message:String, icon:MessageBoxIcon = MSG_WARNING) {
|
||||
#if windows
|
||||
native.WinAPI.showMessageBox(caption, message, icon);
|
||||
Windows.showMessageBox(caption, message, icon);
|
||||
#else
|
||||
lime.app.Application.current.window.alert(message, caption);
|
||||
#end
|
||||
@@ -56,7 +58,19 @@ class WindowsAPI {
|
||||
#if windows
|
||||
var fg = cast(foregroundColor, Int);
|
||||
var bg = cast(backgroundColor, Int);
|
||||
native.WinAPI.setConsoleColors((bg * 16) + fg);
|
||||
Windows.setConsoleColors((bg * 16) + fg);
|
||||
#end
|
||||
}
|
||||
|
||||
public static function getTotalRam() {
|
||||
#if windows
|
||||
return Windows.getTotalRam();
|
||||
#elseif mac
|
||||
return Mac.getTotalRam();
|
||||
#elseif linux
|
||||
return Linux.getTotalRam();
|
||||
#else
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user