From c884f1a354f53fd989a9fd3363fb770c116b5e62 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 23 Mar 2022 11:03:08 +0000 Subject: [PATCH] An option to RLE-compress masked art Saves about 200 KiB RAM in dungeon at a large performance cost. Almost never a good idea, except for severely RAM-constrained devices (e.g. RG99). --- CMake/Definitions.cmake | 1 + CMakeLists.txt | 2 ++ Source/DiabloUI/art.cpp | 17 +++++++++++++++-- Source/utils/sdl_compat.h | 9 --------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CMake/Definitions.cmake b/CMake/Definitions.cmake index 207815f27..5c48a83a7 100644 --- a/CMake/Definitions.cmake +++ b/CMake/Definitions.cmake @@ -15,6 +15,7 @@ foreach( GPERF_HEAP_FIRST_GAME_ITERATION STREAM_ALL_AUDIO PACKET_ENCRYPTION + DEVILUTIONX_MASKED_ART_RLE ) if(${def_name}) list(APPEND DEVILUTIONX_DEFINITIONS ${def_name}) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ba33c6d2..f49050e2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,8 @@ mark_as_advanced(DISABLE_STREAMING_SOUNDS) option(STREAM_ALL_AUDIO "Stream all the audio. For extremely RAM-constrained platforms.") mark_as_advanced(STREAM_ALL_AUDIO) +option(DEVILUTIONX_MASKED_ART_RLE "RLE-compress masked art in memory (e.g. fonts). Slightly lower RAM usage at a significant performance cost." OFF) + if(TSAN) set(ASAN OFF) endif() diff --git a/Source/DiabloUI/art.cpp b/Source/DiabloUI/art.cpp index 64b048e57..788f654b7 100644 --- a/Source/DiabloUI/art.cpp +++ b/Source/DiabloUI/art.cpp @@ -148,8 +148,21 @@ void LoadArt(const char *pszFile, Art *art, int frames, SDL_Color *pPalette, con void LoadMaskedArt(const char *pszFile, Art *art, int frames, int mask, const std::array *colorMapping) { LoadArt(pszFile, art, frames, nullptr, colorMapping); - if (art->surface != nullptr) - SDLC_SetColorKey(art->surface.get(), mask); + if (art->surface == nullptr) + return; + SDL_Surface *surface = art->surface.get(); +#if SDL_VERSION_ATLEAST(2, 0, 0) +#ifdef DEVILUTIONX_MASKED_ART_RLE + SDL_SetSurfaceRLE(surface, 1); +#endif + SDL_SetColorKey(surface, SDL_TRUE, mask); +#else + int flags = SDL_SRCCOLORKEY; +#ifdef DEVILUTIONX_MASKED_ART_RLE + flags |= SDL_RLEACCEL; +#endif + SDL_SetColorKey(surface, flags, mask); +#endif } void LoadArt(Art *art, const std::uint8_t *artData, int w, int h, int frames) diff --git a/Source/utils/sdl_compat.h b/Source/utils/sdl_compat.h index bf1d79d4f..4704f164d 100644 --- a/Source/utils/sdl_compat.h +++ b/Source/utils/sdl_compat.h @@ -35,15 +35,6 @@ inline const Uint8 *SDLC_GetKeyState() #endif } -inline int SDLC_SetColorKey(SDL_Surface *surface, Uint32 key) -{ -#ifdef USE_SDL1 - return SDL_SetColorKey(surface, SDL_SRCCOLORKEY, key); -#else - return SDL_SetColorKey(surface, SDL_TRUE, key); -#endif -} - // Copies the colors into the surface's palette. inline int SDLC_SetSurfaceColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) {