From 9b367eac1f951d819d86b994c552da9fc293a04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Ja=C5=82ocha?= Date: Sun, 5 Jan 2025 23:56:55 +0100 Subject: [PATCH] fix: incorrectly aligned looktypes for 32x32 idle sprites --- src/client/thingtype.cpp | 55 ++++++++-------------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/src/client/thingtype.cpp b/src/client/thingtype.cpp index a73b64ce0..90ac2ec4a 100644 --- a/src/client/thingtype.cpp +++ b/src/client/thingtype.cpp @@ -333,41 +333,6 @@ void ThingType::unserializeAppearance(const uint16_t clientId, const ThingCatego totalSpritesCount += totalSprites; } - if (sizes.size() > 1) { - // correction for some sprites - for (const auto& s : sizes) { - m_size.setWidth(std::max(m_size.width(), s.width())); - m_size.setHeight(std::max(m_size.height(), s.height())); - } - const size_t expectedSize = m_size.area() * m_layers * m_numPatternX * m_numPatternY * m_numPatternZ * m_animationPhases; - if (expectedSize != m_spritesIndex.size()) { - const std::vector sprites(std::move(m_spritesIndex)); - m_spritesIndex.clear(); - m_spritesIndex.reserve(expectedSize); - for (size_t i = 0, idx = 0; i < sizes.size(); ++i) { - const int totalSprites = total_sprites[i]; - if (m_size == sizes[i]) { - for (int j = 0; j < totalSprites; ++j) { - m_spritesIndex.push_back(sprites[idx++]); - } - continue; - } - const size_t patterns = (totalSprites / sizes[i].area()); - for (size_t p = 0; p < patterns; ++p) { - for (int x = 0; x < m_size.width(); ++x) { - for (int y = 0; y < m_size.height(); ++y) { - if (x < sizes[i].width() && y < sizes[i].height()) { - m_spritesIndex.push_back(sprites[idx++]); - continue; - } - m_spritesIndex.push_back(0); - } - } - } - } - } - } - prepareTextureLoad(sizes, total_sprites); } @@ -596,9 +561,7 @@ void ThingType::prepareTextureLoad(const std::vector& sizes, const std::ve for (int y = 0; y < m_size.height(); ++y) { if (x < sizes[i].width() && y < sizes[i].height()) { m_spritesIndex.push_back(sprites[idx++]); - continue; } - m_spritesIndex.push_back(0); } } } @@ -752,20 +715,22 @@ void ThingType::loadTexture(const int animationPhase) if (protobufSupported) { const uint32_t spriteIndex = getSpriteIndex(-1, -1, spriteMask ? 1 : l, x, y, z, animationPhase); const auto& spriteImage = g_sprites.getSpriteImage(m_spritesIndex[spriteIndex]); - if (!spriteImage) { - continue; - } // verifies that the first block in the lower right corner is transparent. - if (spriteImage->hasTransparentPixel()) { + if (!spriteImage || spriteImage->hasTransparentPixel()) { fullImage->setTransparentPixel(true); } - if (spriteMask) { - spriteImage->overwriteMask(maskColors[(l - 1)]); - } + if (spriteImage) { + if (spriteMask) { + spriteImage->overwriteMask(maskColors[(l - 1)]); + } - fullImage->blit(framePos, spriteImage); + auto spriteSize = spriteImage->getSize() / g_gameConfig.getSpriteSize(); + + const Point& spritePos = Point(m_size.width() - spriteSize.width(), m_size.height() - spriteSize.height()) * g_gameConfig.getSpriteSize(); + fullImage->blit(framePos + spritePos, spriteImage); + } } else { for (int h = 0; h < m_size.height(); ++h) { for (int w = 0; w < m_size.width(); ++w) {