Skip to content

Commit

Permalink
Global sprite storage
Browse files Browse the repository at this point in the history
Keeps track of all the currently loaded sprites.
This should eventually allow Lua to access them by name.

Not sure if name-based access to currently-loaded sprites
is something that we'll ever want (might be too unstructured),
but at least this is useful for debugging sprite issues.

If this only ends up useful for debugging, we can add a couple
of `ifdefs` to only keep track of the sprites in debug mode.
  • Loading branch information
glebm committed Jul 14, 2024
1 parent 7211958 commit 97eb276
Show file tree
Hide file tree
Showing 30 changed files with 566 additions and 180 deletions.
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/clx_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/sprites.cpp
lua/modules/dev/towners.cpp
lua/modules/log.cpp
lua/modules/render.cpp
Expand Down
11 changes: 6 additions & 5 deletions Source/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void CreateHalfSizeItemSprites()
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,23 @@ void CreateHalfSizeItemSprites()
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);
std::string name = StrCat("runtime\\objcurs_half_size\\", cursId);
BilinearDownscaleByHalf8(itemSurface.surface, paletteTransparencyLookup, halfSurface.surface, 1);
HalfSizeItemSprites[outputIndex].emplace(SurfaceToClx(halfSurface, 1, 1));
HalfSizeItemSprites[outputIndex].emplace(SurfaceToClx(std::string(name), /*trnName=*/ {}, 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(std::move(name), /*trnName=*/"red", 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 510 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 514 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

0 comments on commit 97eb276

Please sign in to comment.