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 "game.h"
#include "chatmessage.h" #include "chatmessage.h"
#include "translation.h" #include "translation.h"
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
#include <SDL.h>
#endif
extern gui::IGUIEnvironment* guienv; extern gui::IGUIEnvironment* guienv;
@ -696,10 +693,9 @@ bool Client::loadMedia(const std::string &data, const std::string &filename,
rfile->drop(); rfile->drop();
return false; return false;
} }
#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR >= 9
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_ float memoryMax = porting::getTotalSystemMemory() / 1024;
if (SDL_GetSystemRAM() < 2048) { if (memoryMax <= 2) {
core::dimension2du dimensions = img->getDimension();
irr::video::ECOLOR_FORMAT format = img->getColorFormat(); irr::video::ECOLOR_FORMAT format = img->getColorFormat();
irr::video::ECOLOR_FORMAT new_format = irr::video::ECF_UNKNOWN; 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) { if (new_format != irr::video::ECF_UNKNOWN) {
core::dimension2du dimensions = img->getDimension();
irr::video::IImage* converted_img = vdrv->createImage(new_format, dimensions); irr::video::IImage* converted_img = vdrv->createImage(new_format, dimensions);
img->copyTo(converted_img, core::position2d<s32>(0, 0)); img->copyTo(converted_img, core::position2d<s32>(0, 0));
img->drop(); img->drop();
@ -730,6 +727,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename,
} }
} }
#endif #endif
m_tsrc->insertSourceImage(filename, img); m_tsrc->insertSourceImage(filename, img);
img->drop(); img->drop();
rfile->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] // Set the optimal settings depending on the memory size [Android] | model [iOS]
#ifdef __ANDROID__ #ifdef __ANDROID__
float memoryMax = SDL_GetSystemRAM() / 1024; float memoryMax = porting::getTotalSystemMemory() / 1024;
if (memoryMax < 2) { if (memoryMax < 2) {
// minimal settings for less than 2GB RAM // minimal settings for less than 2GB RAM

View File

@ -60,6 +60,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <FindDirectory.h> #include <FindDirectory.h>
#endif #endif
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
#include <SDL.h>
#endif
#include "config.h" #include "config.h"
#include "debug.h" #include "debug.h"
#include "filesys.h" #include "filesys.h"
@ -749,6 +753,16 @@ std::string getSecretKey(const std::string &key)
} }
#endif #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) bool open_directory(const std::string &path)
{ {
if (!fs::IsDir(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); std::string getSecretKey(const std::string &key);
#endif #endif
/**
* Get total device memory
*/
float getTotalSystemMemory();
bool open_directory(const std::string &path); bool open_directory(const std::string &path);
} // namespace porting } // namespace porting