Browse Source

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).
pull/4224/head
Gleb Mazovetskiy 4 years ago committed by Anders Jenbo
parent
commit
c884f1a354
  1. 1
      CMake/Definitions.cmake
  2. 2
      CMakeLists.txt
  3. 17
      Source/DiabloUI/art.cpp
  4. 9
      Source/utils/sdl_compat.h

1
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})

2
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()

17
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<uint8_t, 256> *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)

9
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)
{

Loading…
Cancel
Save