diff --git a/utils/helpers.cpp b/utils/helpers.cpp index 743eadd..37c6502 100644 --- a/utils/helpers.cpp +++ b/utils/helpers.cpp @@ -6,6 +6,25 @@ #include "SDL3/SDL.h" +#include + +#if defined(_WIN32) || defined(_WIN64) + +#include + +#elif defined(__linux__) && !defined(__ANDROID__) +#include +#elif defined(__APPLE__) +#include +#include +#elif defined(__ANDROID__) +#include +#include +#include +#elif defined(__EMSCRIPTEN__) +#include +#endif + bool Helpers::imguiTexturesVisible = false; bool Helpers::imguiAudioVisible = false; bool Helpers::imguiInputVisible = false; @@ -525,4 +544,45 @@ const char *Helpers::TextFormat(const char *text, ...) { return currentBuffer; } +uint64_t Helpers::GetTotalSystemMemory() { +#if defined(_WIN32) || defined(_WIN64) + MEMORYSTATUSEX statex; + statex.dwLength = sizeof(statex); + if (GlobalMemoryStatusEx(&statex)) { + return statex.ullTotalPhys; + } else { + return 0; // Failed to get memory status + } +#elif defined(__linux__) && !defined(__ANDROID__) + struct sysinfo info; + if (sysinfo(&info) == 0) { + return info.totalram * info.mem_unit; + } else { + return 0; // Failed to get memory status + } +#elif defined(__APPLE__) + int mib[2] = {CTL_HW, HW_MEMSIZE}; + uint64_t totalMemory = 0; + size_t length = sizeof(totalMemory); + if (sysctl(mib, 2, &totalMemory, &length, NULL, 0) == 0) { + return totalMemory; + } else { + return 0; // Failed to get memory status + } +#elif defined(__ANDROID__) + struct sysinfo info; + if (sysinfo(&info) == 0) { + return info.totalram * info.mem_unit; + } else { + return 0; // Failed to get memory status + } +#elif defined(__EMSCRIPTEN__) + return EM_ASM_INT({ + return HEAP8.length; + }); +#else + return 0; // Unsupported platform +#endif +} + diff --git a/utils/helpers.h b/utils/helpers.h index 0b905c3..26dd4ff 100644 --- a/utils/helpers.h +++ b/utils/helpers.h @@ -36,6 +36,7 @@ class Helpers { static int GetRandomValue(int min, int max); + static uint64_t GetTotalSystemMemory(); static bool imguiTexturesVisible; static bool imguiAudioVisible;