From 1f161e2217160b38ab913b9f40f0b4f507ba9daa Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Sun, 2 Jun 2024 00:10:16 -0400 Subject: [PATCH] Add `porting::getTotalSystemMemory()` function * becouse Convert textures to (A1)R5G6B5 format on low memory device tune up the commit 03737c4e9baeae7087ff986cbb901c64d312e8a6 * backported from https://github.com/MultiCraft/MultiCraft/commit/3bb240919ac68d58782453cd3cbab727f94643af --- src/client/client.cpp | 12 +++++------- src/defaultsettings.cpp | 2 +- src/porting.cpp | 16 +++++++++++++++- src/porting.h | 6 ++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 5eb2e54de..ce0357fde 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -59,9 +59,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "game.h" #include "chatmessage.h" #include "translation.h" -#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ -#include -#endif extern gui::IGUIEnvironment* guienv; @@ -696,10 +693,9 @@ bool Client::loadMedia(const std::string &data, const std::string &filename, rfile->drop(); return false; } - -#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ - if (SDL_GetSystemRAM() < 2048) { - core::dimension2du dimensions = img->getDimension(); +#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR >= 9 + float memoryMax = porting::getTotalSystemMemory() / 1024; + if (memoryMax <= 2) { irr::video::ECOLOR_FORMAT format = img->getColorFormat(); irr::video::ECOLOR_FORMAT new_format = irr::video::ECF_UNKNOWN; @@ -723,6 +719,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename, } if (new_format != irr::video::ECF_UNKNOWN) { + core::dimension2du dimensions = img->getDimension(); irr::video::IImage* converted_img = vdrv->createImage(new_format, dimensions); img->copyTo(converted_img, core::position2d(0, 0)); img->drop(); @@ -730,6 +727,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename, } } #endif + m_tsrc->insertSourceImage(filename, img); img->drop(); rfile->drop(); diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 7305161d5..3628d00f1 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -548,7 +548,7 @@ void set_default_settings() // Set the optimal settings depending on the memory size [Android] | model [iOS] #ifdef __ANDROID__ - float memoryMax = SDL_GetSystemRAM() / 1024; + float memoryMax = porting::getTotalSystemMemory() / 1024; if (memoryMax < 2) { // minimal settings for less than 2GB RAM diff --git a/src/porting.cpp b/src/porting.cpp index 28627f838..43bc1368e 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -57,7 +57,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif #if defined(__HAIKU__) - #include + #include +#endif + +#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ + #include #endif #include "config.h" @@ -749,6 +753,16 @@ std::string getSecretKey(const std::string &key) } #endif +float getTotalSystemMemory() +{ +#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_) + static const float retval = SDL_GetSystemRAM(); + return retval; +#else + return 0; +#endif +} + bool open_directory(const std::string &path) { if (!fs::IsDir(path)) { diff --git a/src/porting.h b/src/porting.h index bf97c2ad7..29d3dfed4 100644 --- a/src/porting.h +++ b/src/porting.h @@ -362,6 +362,12 @@ bool open_url(const std::string &url); std::string getSecretKey(const std::string &key); #endif +/** + * Get total device memory + */ + +float getTotalSystemMemory(); + bool open_directory(const std::string &path); } // namespace porting