Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global resource tracking #7191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMake/functions/devilutionx_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ function(add_devilutionx_library NAME)
target_link_libraries(${NAME} PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>")
endif()

if(DEVILUTIONX_RESOURCE_TRACKING_ENABLED)
genex_for_option(DEVILUTIONX_RESOURCE_TRACKING_ENABLED)
target_compile_definitions(${NAME} PUBLIC "$<${DEVILUTIONX_RESOURCE_TRACKING_ENABLED_GENEX}:DEVILUTIONX_RESOURCE_TRACKING_ENABLED>")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
genex_for_option(DEVILUTIONX_STATIC_CXX_STDLIB)
target_link_libraries(${NAME} PUBLIC $<${DEVILUTIONX_STATIC_CXX_STDLIB_GENEX}:-static-libgcc;-static-libstdc++>)
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ DEBUG_OPTION(ASAN "Enable address sanitizer")
DEBUG_OPTION(UBSAN "Enable undefined behaviour sanitizer")
option(TSAN "Enable thread sanitizer (not compatible with ASAN=ON)" OFF)
DEBUG_OPTION(DEBUG "Enable debug mode in engine")
DEBUG_OPTION(DEVILUTIONX_RESOURCE_TRACKING_ENABLED "Enable resource tracking")
option(GPERF "Build with GPerfTools profiler" OFF)
cmake_dependent_option(GPERF_HEAP_FIRST_GAME_ITERATION "Save heap profile of the first game iteration" OFF "GPERF" OFF)
option(ENABLE_CODECOVERAGE "Instrument code for code coverage (only enabled with BUILD_TESTING)" OFF)
Expand Down
2 changes: 2 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ set(libdevilutionx_SRCS
engine/animationinfo.cpp
engine/assets.cpp
engine/backbuffer_state.cpp
engine/resource_store.cpp
engine/direction.cpp
engine/dx.cpp
engine/events.cpp
Expand Down Expand Up @@ -147,6 +148,7 @@ set(libdevilutionx_SRCS
lua/modules/dev/player/stats.cpp
lua/modules/dev/quests.cpp
lua/modules/dev/search.cpp
lua/modules/dev/resources.cpp
lua/modules/dev/towners.cpp
lua/modules/log.cpp
lua/modules/render.cpp
Expand Down
21 changes: 16 additions & 5 deletions Source/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
OwnedSurface ownedItemSurface { MaxWidth, MaxHeight };
OwnedSurface ownedHalfSurface { MaxWidth / 2, MaxHeight / 2 };

const auto createHalfSize = [&, redTrn](const ClxSprite itemSprite, size_t outputIndex) {
const auto createHalfSize = [&, redTrn](const ClxSprite itemSprite, size_t outputIndex, int cursId) {
if (itemSprite.width() <= 28 && itemSprite.height() <= 28) {
// Skip creating half-size sprites for 1x1 items because we always render them at full size anyway.
return;
Expand All @@ -495,22 +495,33 @@
const Surface halfSurface = ownedHalfSurface.subregion(0, 0, itemSurface.w() / 2, itemSurface.h() / 2);
SDL_Rect halfSurfaceRect = MakeSdlRect(0, 0, halfSurface.w(), halfSurface.h());
SDL_SetClipRect(halfSurface.surface, &halfSurfaceRect);
#ifdef DEVILUTIONX_RESOURCE_TRACKING_ENABLED
std::string name = StrCat("runtime\\objcurs_half_size\\", cursId);
#endif
BilinearDownscaleByHalf8(itemSurface.surface, paletteTransparencyLookup, halfSurface.surface, 1);
HalfSizeItemSprites[outputIndex].emplace(SurfaceToClx(halfSurface, 1, 1));
HalfSizeItemSprites[outputIndex].emplace(SurfaceToClx(
#ifdef DEVILUTIONX_RESOURCE_TRACKING_ENABLED
std::string(name), /*trnName=*/ {},
#endif
halfSurface, 1, 1));

SDL_FillRect(itemSurface.surface, nullptr, 1);
ClxDrawTRN(itemSurface, { 0, itemSurface.h() }, itemSprite, redTrn);
BilinearDownscaleByHalf8(itemSurface.surface, paletteTransparencyLookup, halfSurface.surface, 1);
HalfSizeItemSpritesRed[outputIndex].emplace(SurfaceToClx(halfSurface, 1, 1));
HalfSizeItemSpritesRed[outputIndex].emplace(SurfaceToClx(
#ifdef DEVILUTIONX_RESOURCE_TRACKING_ENABLED
std::move(name), /*trnName=*/"red",
#endif
halfSurface, 1, 1));
};

size_t outputIndex = 0;
for (size_t i = static_cast<int>(CURSOR_FIRSTITEM) - 1, n = pCursCels->numSprites(); i < n; ++i, ++outputIndex) {
createHalfSize((*pCursCels)[i], outputIndex);
createHalfSize((*pCursCels)[i], outputIndex, i + 1);

Check warning on line 520 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'size_t' to 'int', possible loss of data
}
if (gbIsHellfire) {
for (size_t i = 0, n = pCursCels2->numSprites(); i < n; ++i, ++outputIndex) {
createHalfSize((*pCursCels2)[i], outputIndex);
createHalfSize((*pCursCels2)[i], outputIndex, i + pCursCels->numSprites() + 1);

Check warning on line 524 in Source/cursor.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'size_t' to 'int', possible loss of data
}
}
}
Expand Down
Loading
Loading