Browse Source

Untangle more dependencies

This allows us to make `clx_render_benchmark` and
`text_render_integration_test` standalone.
pull/8076/head
Gleb Mazovetskiy 8 months ago
parent
commit
d3248e969a
  1. 180
      Source/CMakeLists.txt
  2. 1
      Source/controls/plrctrls.cpp
  3. 1
      Source/controls/touch/event_handlers.cpp
  4. 1
      Source/controls/touch/renderers.cpp
  5. 15
      Source/diablo.cpp
  6. 2
      Source/diablo.h
  7. 1
      Source/engine/demomode.cpp
  8. 1
      Source/engine/load_cel.cpp
  9. 2
      Source/engine/load_cl2.cpp
  10. 3
      Source/engine/load_cl2.hpp
  11. 7
      Source/engine/load_clx.cpp
  12. 8
      Source/engine/palette.cpp
  13. 33
      Source/engine/render/clx_render.hpp
  14. 31
      Source/engine/render/scrollrt.cpp
  15. 22
      Source/engine/render/text_render.cpp
  16. 4
      Source/engine/render/text_render.hpp
  17. 1
      Source/engine/sound.cpp
  18. 1
      Source/game_mode.cpp
  19. 2
      Source/game_mode.hpp
  20. 1
      Source/gamemenu.cpp
  21. 1
      Source/multi.cpp
  22. 6
      Source/nthread.cpp
  23. 1
      Source/qol/monhealthbar.cpp
  24. 1
      Source/qol/xpbar.cpp
  25. 8
      Source/utils/palette_blending.cpp
  26. 4
      Source/utils/palette_blending.hpp
  27. 1
      Source/utils/pcx_to_clx.cpp
  28. 2
      Source/utils/pcx_to_clx.hpp
  29. 30
      test/CMakeLists.txt
  30. 21
      test/palette_blending_benchmark.cpp
  31. 9
      test/palette_blending_test.cpp

180
Source/CMakeLists.txt

@ -79,20 +79,13 @@ set(libdevilutionx_SRCS
engine/backbuffer_state.cpp
engine/dx.cpp
engine/events.cpp
engine/load_cel.cpp
engine/load_cl2.cpp
engine/load_clx.cpp
engine/load_pcx.cpp
engine/palette.cpp
engine/sound_position.cpp
engine/ticks.cpp
engine/trn.cpp
engine/render/automap_render.cpp
engine/render/dun_render.cpp
engine/render/primitive_render.cpp
engine/render/scrollrt.cpp
engine/render/text_render.cpp
items/validation.cpp
@ -155,12 +148,8 @@ set(libdevilutionx_SRCS
storm/storm_net.cpp
storm/storm_svid.cpp
utils/cel_to_clx.cpp
utils/cl2_to_clx.cpp
utils/display.cpp
utils/language.cpp
utils/pcx_to_clx.cpp
utils/sdl_bilinear_scale.cpp
utils/sdl_thread.cpp
utils/surface_to_clx.cpp
@ -204,13 +193,30 @@ target_link_dependencies(libdevilutionx_assets PUBLIC
${DEVILUTIONX_PLATFORM_ASSETS_LINK_LIBRARIES}
)
add_devilutionx_object_library(libdevilutionx_cel_to_clx
utils/cel_to_clx.cpp
)
target_link_dependencies(libdevilutionx_cel_to_clx
PRIVATE
libdevilutionx_endian_write
)
add_devilutionx_object_library(libdevilutionx_cl2_to_clx
utils/cl2_to_clx.cpp
)
target_link_dependencies(libdevilutionx_cl2_to_clx
PRIVATE
libdevilutionx_endian_write
)
add_devilutionx_object_library(libdevilutionx_clx_render
engine/render/clx_render.cpp
)
target_link_dependencies(libdevilutionx_clx_render PUBLIC
DevilutionX::SDL
fmt::fmt
libdevilutionx_lighting
libdevilutionx_light_render
libdevilutionx_palette_blending
libdevilutionx_strings
)
@ -255,6 +261,25 @@ target_link_dependencies(libdevilutionx_paths PUBLIC
libdevilutionx_sdl2_to_1_2_backports
)
add_devilutionx_object_library(libdevilutionx_pcx_to_clx
utils/pcx_to_clx.cpp
)
target_link_dependencies(libdevilutionx_pcx_to_clx
PUBLIC
DevilutionX::SDL
libdevilutionx_assets
libdevilutionx_endian_write
)
add_devilutionx_object_library(libdevilutionx_primitive_render
engine/render/primitive_render.cpp
)
target_link_dependencies(libdevilutionx_primitive_render
PUBLIC
libdevilutionx_palette_blending
libdevilutionx_surface
)
add_devilutionx_object_library(libdevilutionx_crawl
crawl.cpp
)
@ -266,6 +291,11 @@ add_devilutionx_object_library(libdevilutionx_direction
engine/direction.cpp
)
add_library(libdevilutionx_endian_write INTERFACE)
target_link_libraries(libdevilutionx_endian_write INTERFACE
DevilutionX::SDL
)
add_devilutionx_object_library(libdevilutionx_surface
engine/surface.cpp
)
@ -329,6 +359,78 @@ target_link_dependencies(libdevilutionx_init PUBLIC
libdevilutionx_options
)
add_devilutionx_object_library(libdevilutionx_load_cel
engine/load_cel.cpp
)
target_link_dependencies(libdevilutionx_load_cel
PUBLIC
tl
PRIVATE
libdevilutionx_strings
)
if(SUPPORTS_MPQ)
target_link_dependencies(libdevilutionx_load_cel PRIVATE
libdevilutionx_mpq
libdevilutionx_cel_to_clx
)
else()
target_link_dependencies(libdevilutionx_load_cel PRIVATE
libdevilutionx_load_clx
)
endif()
add_devilutionx_object_library(libdevilutionx_load_cl2
engine/load_cl2.cpp
)
target_link_dependencies(libdevilutionx_load_cl2
PUBLIC
tl
libdevilutionx_endian_write
PRIVATE
libdevilutionx_strings
)
if(SUPPORTS_MPQ)
target_link_dependencies(libdevilutionx_load_cl2 PUBLIC
libdevilutionx_mpq
libdevilutionx_cl2_to_clx
)
else()
target_link_dependencies(libdevilutionx_load_cl2 PRIVATE
libdevilutionx_load_clx
)
endif()
add_devilutionx_object_library(libdevilutionx_load_clx
engine/load_clx.cpp
)
target_link_dependencies(libdevilutionx_load_clx
PUBLIC
tl
PRIVATE
libdevilutionx_assets
)
add_devilutionx_object_library(libdevilutionx_load_pcx
engine/load_pcx.cpp
)
target_link_dependencies(libdevilutionx_load_pcx
PRIVATE
DevilutionX::SDL
libdevilutionx_sdl2_to_1_2_backports
libdevilutionx_log
libdevilutionx_strings
)
if(SUPPORTS_MPQ)
target_link_dependencies(libdevilutionx_load_pcx PUBLIC
libdevilutionx_assets
libdevilutionx_pcx_to_clx
)
else()
target_link_dependencies(libdevilutionx_load_pcx PRIVATE
libdevilutionx_load_clx
)
endif()
add_devilutionx_object_library(libdevilutionx_light_render
engine/render/light_render.cpp
)
@ -408,13 +510,16 @@ add_devilutionx_object_library(libdevilutionx_monster
monstdat.cpp
monster.cpp
)
target_link_dependencies(libdevilutionx_monster PUBLIC
target_link_dependencies(libdevilutionx_monster
PUBLIC
DevilutionX::SDL
tl
libdevilutionx_game_mode
libdevilutionx_headless_mode
libdevilutionx_sound
libdevilutionx_txtdata
PRIVATE
libdevilutionx_cl2_to_clx
)
add_devilutionx_object_library(libdevilutionx_palette_blending
@ -504,12 +609,16 @@ add_devilutionx_object_library(libdevilutionx_player
player.cpp
playerdat.cpp
)
target_link_dependencies(libdevilutionx_player PUBLIC
target_link_dependencies(libdevilutionx_player
PUBLIC
DevilutionX::SDL
fmt::fmt
tl
unordered_dense::unordered_dense
libdevilutionx_game_mode
PRIVATE
libdevilutionx_load_cl2
libdevilutionx_strings
)
add_devilutionx_object_library(libdevilutionx_quests
@ -538,6 +647,33 @@ target_link_dependencies(libdevilutionx_spells PUBLIC
libdevilutionx_txtdata
)
add_devilutionx_object_library(libdevilutionx_text_render
engine/render/text_render.cpp
)
target_link_dependencies(libdevilutionx_text_render
PUBLIC
libdevilutionx_surface
PRIVATE
fmt::fmt
unordered_dense::unordered_dense
libdevilutionx_clx_render
libdevilutionx_game_mode
libdevilutionx_load_cel
libdevilutionx_load_clx
libdevilutionx_load_pcx
libdevilutionx_log
libdevilutionx_primitive_render
libdevilutionx_ticks
libdevilutionx_utf8
)
add_devilutionx_object_library(libdevilutionx_ticks
engine/ticks.cpp
)
target_link_dependencies(libdevilutionx_ticks PRIVATE
DevilutionX::SDL
)
add_devilutionx_object_library(libdevilutionx_txtdata
data/file.cpp
data/parser.cpp
@ -682,10 +818,18 @@ if(DEVILUTIONX_SCREENSHOT_FORMAT STREQUAL DEVILUTIONX_SCREENSHOT_FORMAT_PCX)
utils/surface_to_pcx.cpp
)
endif()
if(DEVILUTIONX_SCREENSHOT_FORMAT STREQUAL DEVILUTIONX_SCREENSHOT_FORMAT_PNG)
list(APPEND libdevilutionx_SRCS
add_devilutionx_object_library(libdevilutionx_surface_to_png
utils/surface_to_png.cpp
)
target_link_dependencies(libdevilutionx_surface_to_png
PUBLIC
DevilutionX::SDL
SDL2::SDL2_image
tl
libdevilutionx_surface
)
endif()
add_devilutionx_object_library(libdevilutionx ${libdevilutionx_SRCS})
@ -729,6 +873,7 @@ target_link_dependencies(libdevilutionx PUBLIC
libdevilutionx_pathfinding
libdevilutionx_pkware_encrypt
libdevilutionx_player
libdevilutionx_primitive_render
libdevilutionx_quests
libdevilutionx_quick_messages
libdevilutionx_random
@ -736,10 +881,15 @@ target_link_dependencies(libdevilutionx PUBLIC
libdevilutionx_spells
libdevilutionx_stores
libdevilutionx_strings
libdevilutionx_text_render
libdevilutionx_txtdata
libdevilutionx_ticks
libdevilutionx_utf8
libdevilutionx_utils_console
)
if(DEVILUTIONX_SCREENSHOT_FORMAT STREQUAL DEVILUTIONX_SCREENSHOT_FORMAT_PNG)
target_link_dependencies(libdevilutionx PUBLIC libdevilutionx_surface_to_png)
endif()
# Use file GENERATE instead of configure_file because configure_file
# does not support generator expressions.

1
Source/controls/plrctrls.cpp

@ -22,6 +22,7 @@
#include "doom.h"
#include "engine/point.hpp"
#include "engine/points_in_rectangle_range.hpp"
#include "game_mode.hpp"
#include "gmenu.h"
#include "help.h"
#include "hwcursor.hpp"

1
Source/controls/touch/event_handlers.cpp

@ -6,6 +6,7 @@
#include "diablo.h"
#include "engine/render/primitive_render.hpp"
#include "engine/render/scrollrt.h"
#include "game_mode.hpp"
#include "gmenu.h"
#include "inv.h"
#include "panels/spell_book.hpp"

1
Source/controls/touch/renderers.cpp

@ -7,6 +7,7 @@
#include "engine/events.hpp"
#include "engine/render/clx_render.hpp"
#include "engine/render/primitive_render.hpp"
#include "game_mode.hpp"
#include "init.hpp"
#include "inv.h"
#include "levels/gendung.h"

15
Source/diablo.cpp

@ -120,7 +120,6 @@ namespace devilution {
uint32_t DungeonSeeds[NUMLEVELS];
std::optional<uint32_t> LevelSeeds[NUMLEVELS];
Point MousePosition;
bool gbRunGame;
bool gbRunGameResult;
bool ReturnToMainMenu;
/** Enable updating of player character, set to false once Diablo dies */
@ -1701,6 +1700,20 @@ bool CanAutomapBeToggledOff()
return false;
}
void OptionLanguageCodeChanged()
{
UnloadFonts();
LanguageInitialize();
LoadLanguageArchive();
effects_cleanup_sfx();
if (gbRunGame)
sound_init();
else
ui_sound_init();
}
const auto OptionChangeHandlerLanguage = (GetOptions().Language.code.SetValueChangedCallback(OptionLanguageCodeChanged), true);
} // namespace
void InitKeymapActions()

2
Source/diablo.h

@ -66,7 +66,7 @@ enum class MouseActionType : uint8_t {
extern uint32_t DungeonSeeds[NUMLEVELS];
extern DVL_API_FOR_TEST std::optional<uint32_t> LevelSeeds[NUMLEVELS];
extern Point MousePosition;
extern DVL_API_FOR_TEST bool gbRunGame;
extern bool gbRunGameResult;
extern bool ReturnToMainMenu;
extern bool gbProcessPlayers;

1
Source/engine/demomode.cpp

@ -14,6 +14,7 @@
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "engine/events.hpp"
#include "game_mode.hpp"
#include "gmenu.h"
#include "headless_mode.hpp"
#include "menu.h"

1
Source/engine/load_cel.cpp

@ -2,6 +2,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#ifdef DEBUG_CEL_TO_CL2_SIZE

2
Source/engine/load_cl2.cpp

@ -4,6 +4,8 @@
#include <memory>
#include <utility>
#include <expected.hpp>
#include "mpq/mpq_common.hpp"
#include "utils/status_macros.hpp"
#include "utils/str_cat.hpp"

3
Source/engine/load_cl2.hpp

@ -12,7 +12,6 @@
#include "engine/clx_sprite.hpp"
#include "engine/load_file.hpp"
#include "mpq/mpq_common.hpp"
#include "utils/cl2_to_clx.hpp"
#include "utils/endian_read.hpp"
#include "utils/endian_write.hpp"
#include "utils/pointer_value_union.hpp"
@ -23,6 +22,8 @@
#ifdef UNPACKED_MPQS
#define DEVILUTIONX_CL2_EXT ".clx"
#else
#include "utils/cl2_to_clx.hpp"
#define DEVILUTIONX_CL2_EXT ".cl2"
#endif

7
Source/engine/load_clx.cpp

@ -1,12 +1,9 @@
#include "engine/load_clx.hpp"
#include <cstddef>
#include <cstdint>
#include <SDL.h>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#endif
#include <expected.hpp>
#include "appfat.h"
#include "engine/assets.hpp"

8
Source/engine/palette.cpp

@ -185,11 +185,11 @@ void LoadPaletteAndInitBlending(const char *path)
if (HeadlessMode) return;
LoadPalette(path);
if (leveltype == DTYPE_CAVES || leveltype == DTYPE_CRYPT) {
GenerateBlendedLookupTable(/*skipFrom=*/1, /*skipTo=*/31);
GenerateBlendedLookupTable(logical_palette.data(), /*skipFrom=*/1, /*skipTo=*/31);
} else if (leveltype == DTYPE_NEST) {
GenerateBlendedLookupTable(/*skipFrom=*/1, /*skipTo=*/15);
GenerateBlendedLookupTable(logical_palette.data(), /*skipFrom=*/1, /*skipTo=*/15);
} else {
GenerateBlendedLookupTable();
GenerateBlendedLookupTable(logical_palette.data());
}
}
@ -399,7 +399,7 @@ void SetLogicalPaletteColor(unsigned i, const SDL_Color &color)
logical_palette[i] = color;
ApplyGlobalBrightnessSingleColor(system_palette[i], logical_palette[i]);
SystemPaletteUpdated(i, 1);
UpdateBlendedLookupTableSingleColor(i);
UpdateBlendedLookupTableSingleColor(logical_palette.data(), i);
}
} // namespace devilution

33
Source/engine/render/clx_render.hpp

@ -6,8 +6,6 @@
#pragma once
#include <cstdint>
#include <array>
#include <utility>
#ifdef DEBUG_CLX
@ -18,7 +16,6 @@
#include "engine/point.hpp"
#include "engine/render/light_render.hpp"
#include "engine/surface.hpp"
#include "lighting.h"
namespace devilution {
@ -91,21 +88,6 @@ void ClxDrawBlendedTRN(const Surface &out, Point position, ClxSprite clx, const
*/
void ClxDrawBlended(const Surface &out, Point position, ClxSprite clx);
/**
* @brief Blit CL2 sprite, and apply lighting, to the given buffer at the given coordinates
* @param out Output buffer
* @param position Target buffer coordinate
* @param clx CLX frame
*/
inline void ClxDrawLight(const Surface &out, Point position, ClxSprite clx, int lightTableIndex)
{
if (lightTableIndex != 0) {
ClxDrawTRN(out, position, clx, LightTables[lightTableIndex].data());
} else {
ClxDraw(out, position, clx);
}
}
/**
* @brief Blit CL2 sprite, and apply lighting, to the given buffer at the given coordinates
* @param out Output buffer
@ -115,21 +97,6 @@ inline void ClxDrawLight(const Surface &out, Point position, ClxSprite clx, int
*/
void ClxDrawWithLightmap(const Surface &out, Point position, ClxSprite clx, const Lightmap &lightmap);
/**
* @brief Blit CL2 sprite, and apply lighting and transparency blending, to the given buffer at the given coordinates
* @param out Output buffer
* @param position Target buffer coordinate
* @param clx CLX frame
*/
inline void ClxDrawLightBlended(const Surface &out, Point position, ClxSprite clx, int lightTableIndex)
{
if (lightTableIndex != 0) {
ClxDrawBlendedTRN(out, position, clx, LightTables[lightTableIndex].data());
} else {
ClxDrawBlended(out, position, clx);
}
}
/**
* @brief Blit CL2 sprite, and apply lighting and transparency blending, to the given buffer at the given coordinates
* @param out Output buffer

31
Source/engine/render/scrollrt.cpp

@ -29,6 +29,7 @@
#include "engine/render/text_render.hpp"
#include "engine/trn.hpp"
#include "engine/world_tile.hpp"
#include "game_mode.hpp"
#include "gmenu.h"
#include "headless_mode.hpp"
#include "help.h"
@ -219,6 +220,36 @@ bool ShouldShowCursor()
return false;
}
/**
* @brief Blit CL2 sprite, and apply lighting, to the given buffer at the given coordinates
* @param out Output buffer
* @param position Target buffer coordinate
* @param clx CLX frame
*/
inline void ClxDrawLight(const Surface &out, Point position, ClxSprite clx, int lightTableIndex)
{
if (lightTableIndex != 0) {
ClxDrawTRN(out, position, clx, LightTables[lightTableIndex].data());
} else {
ClxDraw(out, position, clx);
}
}
/**
* @brief Blit CL2 sprite, and apply lighting and transparency blending, to the given buffer at the given coordinates
* @param out Output buffer
* @param position Target buffer coordinate
* @param clx CLX frame
*/
inline void ClxDrawLightBlended(const Surface &out, Point position, ClxSprite clx, int lightTableIndex)
{
if (lightTableIndex != 0) {
ClxDrawBlendedTRN(out, position, clx, LightTables[lightTableIndex].data());
} else {
ClxDrawBlended(out, position, clx);
}
}
/**
* @brief Save the content behind the cursor to a temporary buffer, then draw the cursor.
*/

22
Source/engine/render/text_render.cpp

@ -10,6 +10,7 @@
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string_view>
#include <utility>
#include <variant>
@ -17,23 +18,22 @@
#include <fmt/core.h>
#include "DiabloUI/ui_flags.hpp"
#include "engine/clx_sprite.hpp"
#include "engine/load_cel.hpp"
#include "engine/load_clx.hpp"
#include "engine/load_file.hpp"
#include "engine/load_pcx.hpp"
#include "engine/palette.h"
#include "engine/point.hpp"
#include "engine/rectangle.hpp"
#include "engine/render/clx_render.hpp"
#include "engine/render/primitive_render.hpp"
#include "engine/surface.hpp"
#include "engine/ticks.hpp"
#include "options.h"
#include "game_mode.hpp"
#include "utils/algorithm/container.hpp"
#include "utils/display.h"
#include "utils/is_of.hpp"
#include "utils/language.h"
#include "utils/log.hpp"
#include "utils/sdl_compat.h"
#include "utils/utf8.hpp"
namespace devilution {
@ -491,20 +491,6 @@ uint32_t DoDrawString(const Surface &out, std::string_view text, Rectangle rect,
return static_cast<uint32_t>(remaining.data() - text.data());
}
void OptionLanguageCodeChanged()
{
UnloadFonts();
LanguageInitialize();
LoadLanguageArchive();
effects_cleanup_sfx();
if (gbRunGame)
sound_init();
else
ui_sound_init();
}
const auto OptionChangeHandlerResolution = (GetOptions().Language.code.SetValueChangedCallback(OptionLanguageCodeChanged), true);
} // namespace
void LoadSmallSelectionSpinner()

4
Source/engine/render/text_render.hpp

@ -5,6 +5,7 @@
*/
#pragma once
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
@ -13,11 +14,10 @@
#include <variant>
#include <vector>
#include <SDL.h>
#include "DiabloUI/ui_flags.hpp"
#include "engine/clx_sprite.hpp"
#include "engine/palette.h"
#include "engine/point.hpp"
#include "engine/rectangle.hpp"
#include "engine/surface.hpp"
#include "utils/enum_traits.h"

1
Source/engine/sound.cpp

@ -18,6 +18,7 @@
#include <expected.hpp>
#include "engine/assets.hpp"
#include "game_mode.hpp"
#include "options.h"
#include "utils/log.hpp"
#include "utils/math.h"

1
Source/game_mode.cpp

@ -13,6 +13,7 @@ void OptionSharewareChanged()
const auto OptionChangeHandlerShareware = (GetOptions().GameMode.shareware.SetValueChangedCallback(OptionSharewareChanged), true);
} // namespace
bool gbRunGame;
bool gbIsSpawn;
bool gbIsHellfire;
bool gbVanilla;

2
Source/game_mode.hpp

@ -4,6 +4,8 @@
namespace devilution {
/* Are we in-game? If false, we're in the main menu. */
extern DVL_API_FOR_TEST bool gbRunGame;
/** Indicate if we only have access to demo data */
extern DVL_API_FOR_TEST bool gbIsSpawn;
/** Indicate if we have loaded the Hellfire expansion data */

1
Source/gamemenu.cpp

@ -12,6 +12,7 @@
#include "engine/events.hpp"
#include "engine/sound.h"
#include "engine/sound_defs.hpp"
#include "game_mode.hpp"
#include "gmenu.h"
#include "headless_mode.hpp"
#include "loadsave.h"

1
Source/multi.cpp

@ -20,6 +20,7 @@
#include "engine/point.hpp"
#include "engine/random.hpp"
#include "engine/world_tile.hpp"
#include "game_mode.hpp"
#include "menu.h"
#include "monster.h"
#include "msg.h"

6
Source/nthread.cpp

@ -5,17 +5,19 @@
*/
#include "nthread.h"
#include <cstddef>
#include <cstdint>
#include <fmt/core.h>
#include <SDL.h>
#include "diablo.h"
#include "engine/animationinfo.h"
#include "engine/demomode.h"
#include "game_mode.hpp"
#include "gmenu.h"
#include "storm/storm_net.hpp"
#include "utils/sdl_mutex.h"
#include "utils/sdl_thread.h"
#include "utils/str_cat.hpp"
namespace devilution {

1
Source/qol/monhealthbar.cpp

@ -15,6 +15,7 @@
#include "engine/load_clx.hpp"
#include "engine/render/clx_render.hpp"
#include "engine/render/primitive_render.hpp"
#include "game_mode.hpp"
#include "options.h"
#include "utils/language.h"
#include "utils/str_cat.hpp"

1
Source/qol/xpbar.cpp

@ -16,6 +16,7 @@
#include "engine/point.hpp"
#include "engine/render/clx_render.hpp"
#include "engine/render/primitive_render.hpp"
#include "game_mode.hpp"
#include "options.h"
#include "playerdat.hpp"
#include "utils/format_int.hpp"

8
Source/utils/palette_blending.cpp

@ -19,8 +19,6 @@ uint8_t paletteTransparencyLookup[256][256];
uint16_t paletteTransparencyLookupBlack16[65536];
#endif
extern std::array<SDL_Color, 256> logical_palette;
namespace {
PaletteKdTree CurrentPaletteKdTree;
@ -45,9 +43,8 @@ void SetPaletteTransparencyLookupBlack16(unsigned i, unsigned j)
} // namespace
void GenerateBlendedLookupTable(int skipFrom, int skipTo)
void GenerateBlendedLookupTable(const SDL_Color *palette, int skipFrom, int skipTo)
{
const SDL_Color *palette = logical_palette.data();
CurrentPaletteKdTree = PaletteKdTree { palette, skipFrom, skipTo };
for (unsigned i = 0; i < 256; i++) {
paletteTransparencyLookup[i][i] = i;
@ -72,9 +69,8 @@ void GenerateBlendedLookupTable(int skipFrom, int skipTo)
#endif
}
void UpdateBlendedLookupTableSingleColor(unsigned i)
void UpdateBlendedLookupTableSingleColor(const SDL_Color *palette, unsigned i)
{
const SDL_Color *palette = logical_palette.data();
for (unsigned j = 0; j < 256; j++) {
if (i == j) { // No need to calculate transparency between 2 identical colors
paletteTransparencyLookup[i][j] = j;

4
Source/utils/palette_blending.hpp

@ -22,12 +22,12 @@ extern uint8_t paletteTransparencyLookup[256][256];
* @param skipFrom Do not use colors between this index and skipTo
* @param skipTo Do not use colors between skipFrom and this index
*/
void GenerateBlendedLookupTable(int skipFrom = -1, int skipTo = -1);
void GenerateBlendedLookupTable(const SDL_Color *palette, int skipFrom = -1, int skipTo = -1);
/**
* @brief Updates the transparency lookup table for a single color.
*/
void UpdateBlendedLookupTableSingleColor(unsigned i);
void UpdateBlendedLookupTableSingleColor(const SDL_Color *palette, unsigned i);
#if DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT
/**

1
Source/utils/pcx_to_clx.cpp

@ -6,6 +6,7 @@
#include <array>
#include <memory>
#include <optional>
#include <vector>
#include <SDL_endian.h>

2
Source/utils/pcx_to_clx.hpp

@ -3,6 +3,8 @@
#include <cstdint>
#include <optional>
#include <SDL.h>
#include "engine/assets.hpp"
#include "engine/clx_sprite.hpp"

30
test/CMakeLists.txt

@ -99,7 +99,17 @@ add_library(language_for_testing OBJECT language_for_testing.cpp)
target_sources(language_for_testing INTERFACE $<TARGET_OBJECTS:language_for_testing>)
target_link_dependencies(codec_test PRIVATE libdevilutionx_codec app_fatal_for_testing)
target_link_dependencies(clx_render_benchmark PRIVATE libdevilutionx_so)
target_link_dependencies(clx_render_benchmark
PRIVATE
DevilutionX::SDL
tl
app_fatal_for_testing
language_for_testing
libdevilutionx_clx_render
libdevilutionx_load_clx
libdevilutionx_log
libdevilutionx_surface
)
target_link_dependencies(crawl_test PRIVATE libdevilutionx_crawl)
target_link_dependencies(crawl_benchmark PRIVATE libdevilutionx_crawl)
target_link_dependencies(data_file_test PRIVATE libdevilutionx_txtdata app_fatal_for_testing language_for_testing)
@ -117,8 +127,22 @@ target_link_dependencies(path_benchmark PRIVATE libdevilutionx_pathfinding app_f
target_link_dependencies(random_test PRIVATE libdevilutionx_random)
target_link_dependencies(static_vector_test PRIVATE libdevilutionx_random app_fatal_for_testing)
target_link_dependencies(str_cat_test PRIVATE libdevilutionx_strings)
if(NOT USE_SDL1)
target_link_dependencies(text_render_integration_test PRIVATE libdevilutionx_so GTest::gtest GTest::gmock)
if(DEVILUTIONX_SCREENSHOT_FORMAT STREQUAL DEVILUTIONX_SCREENSHOT_FORMAT_PNG AND NOT USE_SDL1)
target_link_dependencies(text_render_integration_test
PRIVATE
DevilutionX::SDL
GTest::gmock
GTest::gtest
tl
app_fatal_for_testing
language_for_testing
libdevilutionx_primitive_render
libdevilutionx_strings
libdevilutionx_strings
libdevilutionx_surface
libdevilutionx_surface_to_png
libdevilutionx_text_render
)
endif()
target_link_dependencies(utf8_test PRIVATE libdevilutionx_utf8)

21
test/palette_blending_benchmark.cpp

@ -9,9 +9,6 @@
#include "utils/palette_kd_tree.hpp"
namespace devilution {
std::array<SDL_Color, 256> logical_palette;
namespace {
void GeneratePalette(SDL_Color palette[256])
@ -30,10 +27,10 @@ void GeneratePalette(SDL_Color palette[256])
void BM_GenerateBlendedLookupTable(benchmark::State &state)
{
SDL_Color *palette = logical_palette.data();
GeneratePalette(palette);
std::array<SDL_Color, 256> palette;
GeneratePalette(palette.data());
for (auto _ : state) {
GenerateBlendedLookupTable();
GenerateBlendedLookupTable(palette.data());
int result = paletteTransparencyLookup[17][98];
benchmark::DoNotOptimize(result);
}
@ -41,20 +38,20 @@ void BM_GenerateBlendedLookupTable(benchmark::State &state)
void BM_BuildTree(benchmark::State &state)
{
SDL_Color *palette = logical_palette.data();
GeneratePalette(palette);
std::array<SDL_Color, 256> palette;
GeneratePalette(palette.data());
for (auto _ : state) {
PaletteKdTree tree(palette, -1, -1);
PaletteKdTree tree(palette.data(), -1, -1);
benchmark::DoNotOptimize(tree);
}
}
void BM_FindNearestNeighbor(benchmark::State &state)
{
SDL_Color *palette = logical_palette.data();
GeneratePalette(palette);
PaletteKdTree tree(palette, -1, -1);
std::array<SDL_Color, 256> palette;
GeneratePalette(palette.data());
PaletteKdTree tree(palette.data(), -1, -1);
for (auto _ : state) {
for (int r = 0; r < 256; ++r) {

9
test/palette_blending_test.cpp

@ -19,9 +19,6 @@ void PrintTo(const SDL_Color &color, std::ostream *os)
}
namespace devilution {
std::array<SDL_Color, 256> logical_palette;
namespace {
MATCHER_P3(ColorIs, r, g, b,
@ -46,10 +43,10 @@ void GeneratePalette(SDL_Color palette[256])
TEST(GenerateBlendedLookupTableTest, BasicTest)
{
SDL_Color *palette = logical_palette.data();
GeneratePalette(palette);
std::array<SDL_Color, 256> palette;
GeneratePalette(palette.data());
GenerateBlendedLookupTable();
GenerateBlendedLookupTable(palette.data());
EXPECT_EQ(paletteTransparencyLookup[100][100], 100);

Loading…
Cancel
Save