1
0

Add porting::getTotalSystemMemory() function

* becouse Convert textures to (A1)R5G6B5 format on low memory device
  tune up the commit 03737c4e9baeae7087ff986cbb901c64d312e8a6
* backported from 3bb240919a
This commit is contained in:
mckaygerhard 2024-06-02 00:10:16 -04:00
parent 284a473584
commit 1f161e2217
4 changed files with 27 additions and 9 deletions

View File

@ -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 <SDL.h>
#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<s32>(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();

View File

@ -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

View File

@ -57,7 +57,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif
#if defined(__HAIKU__)
#include <FindDirectory.h>
#include <FindDirectory.h>
#endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
#include <SDL.h>
#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)) {

View File

@ -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