From d3248e969a4fbf7a5a4cf431d9634f5867de4877 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 20 Jul 2025 11:47:00 +0100 Subject: [PATCH] Untangle more dependencies This allows us to make `clx_render_benchmark` and `text_render_integration_test` standalone. --- Source/CMakeLists.txt | 180 +++++++++++++++++++++-- Source/controls/plrctrls.cpp | 1 + Source/controls/touch/event_handlers.cpp | 1 + Source/controls/touch/renderers.cpp | 1 + Source/diablo.cpp | 15 +- Source/diablo.h | 2 +- Source/engine/demomode.cpp | 1 + Source/engine/load_cel.cpp | 1 + Source/engine/load_cl2.cpp | 2 + Source/engine/load_cl2.hpp | 3 +- Source/engine/load_clx.cpp | 7 +- Source/engine/palette.cpp | 8 +- Source/engine/render/clx_render.hpp | 33 ----- Source/engine/render/scrollrt.cpp | 31 ++++ Source/engine/render/text_render.cpp | 22 +-- Source/engine/render/text_render.hpp | 4 +- Source/engine/sound.cpp | 1 + Source/game_mode.cpp | 1 + Source/game_mode.hpp | 2 + Source/gamemenu.cpp | 1 + Source/multi.cpp | 1 + Source/nthread.cpp | 6 +- Source/qol/monhealthbar.cpp | 1 + Source/qol/xpbar.cpp | 1 + Source/utils/palette_blending.cpp | 8 +- Source/utils/palette_blending.hpp | 4 +- Source/utils/pcx_to_clx.cpp | 1 + Source/utils/pcx_to_clx.hpp | 2 + test/CMakeLists.txt | 30 +++- test/palette_blending_benchmark.cpp | 21 ++- test/palette_blending_test.cpp | 9 +- 31 files changed, 290 insertions(+), 111 deletions(-) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index a2a778452..99747fcff 100644 --- a/Source/CMakeLists.txt +++ b/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. diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 9b09f40a2..1b71f731e 100644 --- a/Source/controls/plrctrls.cpp +++ b/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" diff --git a/Source/controls/touch/event_handlers.cpp b/Source/controls/touch/event_handlers.cpp index a065926e3..9afce792f 100644 --- a/Source/controls/touch/event_handlers.cpp +++ b/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" diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 3d856828b..fdd9802a4 100644 --- a/Source/controls/touch/renderers.cpp +++ b/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" diff --git a/Source/diablo.cpp b/Source/diablo.cpp index f91f7039c..2cba929e6 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -120,7 +120,6 @@ namespace devilution { uint32_t DungeonSeeds[NUMLEVELS]; std::optional 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() diff --git a/Source/diablo.h b/Source/diablo.h index de321dccb..e397bcda2 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -66,7 +66,7 @@ enum class MouseActionType : uint8_t { extern uint32_t DungeonSeeds[NUMLEVELS]; extern DVL_API_FOR_TEST std::optional LevelSeeds[NUMLEVELS]; extern Point MousePosition; -extern DVL_API_FOR_TEST bool gbRunGame; + extern bool gbRunGameResult; extern bool ReturnToMainMenu; extern bool gbProcessPlayers; diff --git a/Source/engine/demomode.cpp b/Source/engine/demomode.cpp index 1468e9ec3..f8eb52a82 100644 --- a/Source/engine/demomode.cpp +++ b/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" diff --git a/Source/engine/load_cel.cpp b/Source/engine/load_cel.cpp index b3d11511e..5adc1a365 100644 --- a/Source/engine/load_cel.cpp +++ b/Source/engine/load_cel.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #ifdef DEBUG_CEL_TO_CL2_SIZE diff --git a/Source/engine/load_cl2.cpp b/Source/engine/load_cl2.cpp index e1730f730..499c51731 100644 --- a/Source/engine/load_cl2.cpp +++ b/Source/engine/load_cl2.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include "mpq/mpq_common.hpp" #include "utils/status_macros.hpp" #include "utils/str_cat.hpp" diff --git a/Source/engine/load_cl2.hpp b/Source/engine/load_cl2.hpp index 88e85602b..46d46bca3 100644 --- a/Source/engine/load_cl2.hpp +++ b/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 diff --git a/Source/engine/load_clx.cpp b/Source/engine/load_clx.cpp index 2e016ddae..1db52a0fb 100644 --- a/Source/engine/load_clx.cpp +++ b/Source/engine/load_clx.cpp @@ -1,12 +1,9 @@ #include "engine/load_clx.hpp" +#include #include -#include - -#ifdef USE_SDL1 -#include "utils/sdl2_to_1_2_backports.h" -#endif +#include #include "appfat.h" #include "engine/assets.hpp" diff --git a/Source/engine/palette.cpp b/Source/engine/palette.cpp index c563ddf6a..fe353b56e 100644 --- a/Source/engine/palette.cpp +++ b/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 diff --git a/Source/engine/render/clx_render.hpp b/Source/engine/render/clx_render.hpp index 62a62ca0f..9db4a909a 100644 --- a/Source/engine/render/clx_render.hpp +++ b/Source/engine/render/clx_render.hpp @@ -6,8 +6,6 @@ #pragma once #include - -#include #include #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 diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 04d5870da..31c36a164 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/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. */ diff --git a/Source/engine/render/text_render.cpp b/Source/engine/render/text_render.cpp index fb593be14..4c77e1a19 100644 --- a/Source/engine/render/text_render.cpp +++ b/Source/engine/render/text_render.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -17,23 +18,22 @@ #include #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(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() diff --git a/Source/engine/render/text_render.hpp b/Source/engine/render/text_render.hpp index 2bf746748..957d137d8 100644 --- a/Source/engine/render/text_render.hpp +++ b/Source/engine/render/text_render.hpp @@ -5,6 +5,7 @@ */ #pragma once +#include #include #include #include @@ -13,11 +14,10 @@ #include #include -#include - #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" diff --git a/Source/engine/sound.cpp b/Source/engine/sound.cpp index 1c1093578..61c8ee7d6 100644 --- a/Source/engine/sound.cpp +++ b/Source/engine/sound.cpp @@ -18,6 +18,7 @@ #include #include "engine/assets.hpp" +#include "game_mode.hpp" #include "options.h" #include "utils/log.hpp" #include "utils/math.h" diff --git a/Source/game_mode.cpp b/Source/game_mode.cpp index 53bd4be96..dd37d530f 100644 --- a/Source/game_mode.cpp +++ b/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; diff --git a/Source/game_mode.hpp b/Source/game_mode.hpp index 60ac5e8f0..efe9fb09a 100644 --- a/Source/game_mode.hpp +++ b/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 */ diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index 711f109c2..dc739927d 100644 --- a/Source/gamemenu.cpp +++ b/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" diff --git a/Source/multi.cpp b/Source/multi.cpp index c2a7ce06d..c8ea526a0 100644 --- a/Source/multi.cpp +++ b/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" diff --git a/Source/nthread.cpp b/Source/nthread.cpp index ebea8a303..7c268bb82 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -5,17 +5,19 @@ */ #include "nthread.h" +#include #include -#include +#include #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 { diff --git a/Source/qol/monhealthbar.cpp b/Source/qol/monhealthbar.cpp index 3a1b9e188..5e8958e00 100644 --- a/Source/qol/monhealthbar.cpp +++ b/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" diff --git a/Source/qol/xpbar.cpp b/Source/qol/xpbar.cpp index b096c02af..1de30ae17 100644 --- a/Source/qol/xpbar.cpp +++ b/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" diff --git a/Source/utils/palette_blending.cpp b/Source/utils/palette_blending.cpp index f6cb825a5..94cdbb4c4 100644 --- a/Source/utils/palette_blending.cpp +++ b/Source/utils/palette_blending.cpp @@ -19,8 +19,6 @@ uint8_t paletteTransparencyLookup[256][256]; uint16_t paletteTransparencyLookupBlack16[65536]; #endif -extern std::array 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; diff --git a/Source/utils/palette_blending.hpp b/Source/utils/palette_blending.hpp index faf6bee3e..a5185007c 100644 --- a/Source/utils/palette_blending.hpp +++ b/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 /** diff --git a/Source/utils/pcx_to_clx.cpp b/Source/utils/pcx_to_clx.cpp index 031c5ad5b..d00c74832 100644 --- a/Source/utils/pcx_to_clx.cpp +++ b/Source/utils/pcx_to_clx.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/Source/utils/pcx_to_clx.hpp b/Source/utils/pcx_to_clx.hpp index 2eca4cc3b..b29198b58 100644 --- a/Source/utils/pcx_to_clx.hpp +++ b/Source/utils/pcx_to_clx.hpp @@ -3,6 +3,8 @@ #include #include +#include + #include "engine/assets.hpp" #include "engine/clx_sprite.hpp" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 55feffd07..96cbe751f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -99,7 +99,17 @@ add_library(language_for_testing OBJECT language_for_testing.cpp) target_sources(language_for_testing INTERFACE $) 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) diff --git a/test/palette_blending_benchmark.cpp b/test/palette_blending_benchmark.cpp index 7d54d8ec2..553f9f420 100644 --- a/test/palette_blending_benchmark.cpp +++ b/test/palette_blending_benchmark.cpp @@ -9,9 +9,6 @@ #include "utils/palette_kd_tree.hpp" namespace devilution { - -std::array 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 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 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 palette; + GeneratePalette(palette.data()); + PaletteKdTree tree(palette.data(), -1, -1); for (auto _ : state) { for (int r = 0; r < 256; ++r) { diff --git a/test/palette_blending_test.cpp b/test/palette_blending_test.cpp index 0a564a9d0..09bf3e43d 100644 --- a/test/palette_blending_test.cpp +++ b/test/palette_blending_test.cpp @@ -19,9 +19,6 @@ void PrintTo(const SDL_Color &color, std::ostream *os) } namespace devilution { - -std::array 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 palette; + GeneratePalette(palette.data()); - GenerateBlendedLookupTable(); + GenerateBlendedLookupTable(palette.data()); EXPECT_EQ(paletteTransparencyLookup[100][100], 100);