diff --git a/source/funkin/external/apple/AudioSession.hx b/source/funkin/external/apple/AudioSession.hx index 34c9d734d..d647c83e4 100644 --- a/source/funkin/external/apple/AudioSession.hx +++ b/source/funkin/external/apple/AudioSession.hx @@ -1,6 +1,6 @@ package funkin.external.apple; -#if (ios || macos) +#if ((ios || macos) && cpp) /** * A utility class to manage the audio session on apple devices. */ diff --git a/source/funkin/external/apple/MemoryUtil.hx b/source/funkin/external/apple/MemoryUtil.hx new file mode 100644 index 000000000..401a877b6 --- /dev/null +++ b/source/funkin/external/apple/MemoryUtil.hx @@ -0,0 +1,20 @@ +package funkin.external.apple; + +#if ((ios || macos) && cpp) +/** + * A utility class to get information about the mem usage. + */ +@:build(funkin.util.macro.LinkerMacro.xml('project/Build.xml')) +@:include('MemoryUtil.hpp') +@:unreflective +extern class MemoryUtil +{ + /** + * Retrieves the current process's resident set size (RSS) in bytes on Apple platforms. + * + * @return The resident set size (RSS) in bytes if successful; otherwise, returns 0 on failure. + */ + @:native('Apple_MemoryUtil_GetCurrentProcessRss') + static function getCurrentProcessRss():cpp.SizeT; +} +#end diff --git a/source/funkin/external/apple/ScreenUtil.hx b/source/funkin/external/apple/ScreenUtil.hx index 042ee4e70..6257e46fe 100644 --- a/source/funkin/external/apple/ScreenUtil.hx +++ b/source/funkin/external/apple/ScreenUtil.hx @@ -1,6 +1,6 @@ package funkin.external.apple; -#if (ios || macos) +#if ((ios || macos) && cpp) /** * A utility class to get screen related informations on apple devices. */ diff --git a/source/funkin/external/apple/project/Build.xml b/source/funkin/external/apple/project/Build.xml index c141a246b..3a4dc3fe2 100644 --- a/source/funkin/external/apple/project/Build.xml +++ b/source/funkin/external/apple/project/Build.xml @@ -13,8 +13,9 @@ - + + diff --git a/source/funkin/external/apple/project/include/MemoryUtil.hpp b/source/funkin/external/apple/project/include/MemoryUtil.hpp new file mode 100644 index 000000000..d2dfe9ef8 --- /dev/null +++ b/source/funkin/external/apple/project/include/MemoryUtil.hpp @@ -0,0 +1,8 @@ +#pragma once + +/** + * Retrieves the current process's resident set size (RSS) in bytes on Apple platforms. + * + * @return The resident set size (RSS) in bytes if successful; otherwise, returns 0 on failure. + */ +size_t Apple_MemoryUtil_GetCurrentProcessRss(); diff --git a/source/funkin/external/apple/project/src/MemoryUtil.mm b/source/funkin/external/apple/project/src/MemoryUtil.mm new file mode 100644 index 000000000..84b9c950a --- /dev/null +++ b/source/funkin/external/apple/project/src/MemoryUtil.mm @@ -0,0 +1,13 @@ +#import "MemoryUtil.hpp" + +#include + +size_t Apple_MemoryUtil_GetCurrentProcessRss() +{ + task_basic_info info; + + if (task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &TASK_BASIC_INFO_COUNT) != KERN_SUCCESS) + return 0; + + return info.resident_size; +} diff --git a/source/funkin/util/MemoryUtil.hx b/source/funkin/util/MemoryUtil.hx index e95b10fe4..843c2056a 100644 --- a/source/funkin/util/MemoryUtil.hx +++ b/source/funkin/util/MemoryUtil.hx @@ -47,7 +47,7 @@ class MemoryUtil public static function supportsTaskMem():Bool { - #if ((windows && cpp) || linux || android) + #if ((cpp && (windows || ios || macos)) || linux || android) return true; #else return false; @@ -58,6 +58,8 @@ class MemoryUtil { #if (windows && cpp) return funkin.external.windows.WinAPI.getProcessMemoryWorkingSetSize(); + #elseif ((ios || macos) && cpp) + return funkin.external.apple.MemoryUtil.getCurrentProcessRss(); #elseif (linux || android) try {