diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 8deb50107..f4bb98719 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -29,10 +29,10 @@ namespace { /** Cursor images CEL */ std::optional pCursCels; std::optional pCursCels2; -constexpr int InvItems1Size = 180; +constexpr uint16_t InvItems1Size = 180; /** Maps from objcurs.cel frame number to frame width. */ -const int InvItemWidth1[] = { +const uint16_t InvItemWidth1[] = { // clang-format off // Cursors 0, 33, 32, 32, 32, 32, 32, 32, 32, 32, 32, 23, @@ -55,7 +55,7 @@ const int InvItemWidth1[] = { 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, 2 * 28, }; -const int InvItemWidth2[] = { +const uint16_t InvItemWidth2[] = { 0, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, @@ -67,7 +67,7 @@ const int InvItemWidth2[] = { }; /** Maps from objcurs.cel frame number to frame height. */ -const int InvItemHeight1[] = { +const uint16_t InvItemHeight1[] = { // clang-format off // Cursors 0, 29, 32, 32, 32, 32, 32, 32, 32, 32, 32, 35, @@ -90,7 +90,7 @@ const int InvItemHeight1[] = { 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, 3 * 28, }; -const int InvItemHeight2[] = { +const uint16_t InvItemHeight2[] = { 0, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, 1 * 28, diff --git a/Source/dead.h b/Source/dead.h index c9bb08bfe..b34b66107 100644 --- a/Source/dead.h +++ b/Source/dead.h @@ -18,7 +18,7 @@ static constexpr unsigned MaxCorpses = 31; struct Corpse { std::array data; int frame; - unsigned width; + uint16_t width; uint8_t translationPaletteIndex; }; diff --git a/Source/engine/cel_sprite.hpp b/Source/engine/cel_sprite.hpp index c9fcfd95c..ea849815f 100644 --- a/Source/engine/cel_sprite.hpp +++ b/Source/engine/cel_sprite.hpp @@ -15,13 +15,13 @@ class OwnedCelSprite; */ class CelSprite { public: - CelSprite(const byte *data, int width) + CelSprite(const byte *data, uint16_t width) : data_ptr_(data) , width_(width) { } - CelSprite(const byte *data, const int *widths) + CelSprite(const byte *data, const uint16_t *widths) : data_ptr_(data) , widths_(widths) { @@ -39,7 +39,7 @@ public: return data_ptr_; } - [[nodiscard]] int Width(std::size_t frame = 1) const + [[nodiscard]] uint16_t Width(std::size_t frame = 1) const { return widths_ == nullptr ? width_ : widths_[frame]; } @@ -55,8 +55,8 @@ public: private: const byte *data_ptr_; - int width_ = 0; - const int *widths_ = nullptr; // unowned + uint16_t width_ = 0; + const uint16_t *widths_ = nullptr; // unowned }; /** @@ -65,13 +65,13 @@ private: */ class OwnedCelSprite : public CelSprite { public: - OwnedCelSprite(std::unique_ptr data, int width) + OwnedCelSprite(std::unique_ptr data, uint16_t width) : CelSprite(data.get(), width) , data_(std::move(data)) { } - OwnedCelSprite(std::unique_ptr data, const int *widths) + OwnedCelSprite(std::unique_ptr data, const uint16_t *widths) : CelSprite(data.get(), widths) , data_(std::move(data)) { diff --git a/Source/engine/load_cel.cpp b/Source/engine/load_cel.cpp index 0391fecc2..14261f5e5 100644 --- a/Source/engine/load_cel.cpp +++ b/Source/engine/load_cel.cpp @@ -4,12 +4,12 @@ namespace devilution { -OwnedCelSprite LoadCel(const char *pszName, int width) +OwnedCelSprite LoadCel(const char *pszName, uint16_t width) { return OwnedCelSprite(LoadFileInMem(pszName), width); } -OwnedCelSprite LoadCel(const char *pszName, const int *widths) +OwnedCelSprite LoadCel(const char *pszName, const uint16_t *widths) { return OwnedCelSprite(LoadFileInMem(pszName), widths); } diff --git a/Source/engine/load_cel.hpp b/Source/engine/load_cel.hpp index 7c8c7056a..14e031750 100644 --- a/Source/engine/load_cel.hpp +++ b/Source/engine/load_cel.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "engine/cel_sprite.hpp" namespace devilution { @@ -7,7 +9,7 @@ namespace devilution { /** * @brief Loads a Cel sprite and sets its width */ -OwnedCelSprite LoadCel(const char *pszName, int width); -OwnedCelSprite LoadCel(const char *pszName, const int *widths); +OwnedCelSprite LoadCel(const char *pszName, uint16_t width); +OwnedCelSprite LoadCel(const char *pszName, const uint16_t *widths); } // namespace devilution diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 2a1f5147d..bc382b3b0 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -732,7 +732,7 @@ void LoadObject(LoadHelper &file, Object &object) object._oAnimCnt = file.NextLE(); object._oAnimLen = file.NextLE(); object._oAnimFrame = file.NextLE(); - object._oAnimWidth = file.NextLE(); + object._oAnimWidth = static_cast(file.NextLE()); file.Skip(4); // Skip _oAnimWidth2 object._oDelFlag = file.NextBool32(); object._oBreak = file.NextLE(); @@ -1403,7 +1403,7 @@ void SaveObject(SaveHelper &file, const Object &object) file.WriteLE(object._oAnimLen); file.WriteLE(object._oAnimFrame); file.WriteLE(object._oAnimWidth); - file.WriteLE(CalculateWidth2(object._oAnimWidth)); // Write _oAnimWidth2 for vanilla compatibility + file.WriteLE(CalculateWidth2(static_cast(object._oAnimWidth))); // Write _oAnimWidth2 for vanilla compatibility file.WriteLE(object._oDelFlag ? 1 : 0); file.WriteLE(object._oBreak); file.Skip(3); // Alignment diff --git a/Source/misdat.cpp b/Source/misdat.cpp index 0b517fdbb..a34fbd042 100644 --- a/Source/misdat.cpp +++ b/Source/misdat.cpp @@ -217,7 +217,7 @@ std::array maybeAutofill(std::initializer_list list) MissileFileData::MissileFileData(string_view name, uint8_t animName, uint8_t animFAmt, MissileDataFlags flags, std::initializer_list animDelay, std::initializer_list animLen, - int16_t animWidth, int16_t animWidth2) + uint16_t animWidth, int16_t animWidth2) : name(name) , animName(animName) , animFAmt(animFAmt) diff --git a/Source/misdat.h b/Source/misdat.h index 6183667aa..bec646bc0 100644 --- a/Source/misdat.h +++ b/Source/misdat.h @@ -10,6 +10,7 @@ #include "effects.h" #include "engine.h" +#include "engine/cel_sprite.hpp" #include "utils/stdcompat/cstddef.hpp" #include "utils/stdcompat/string_view.hpp" @@ -141,14 +142,14 @@ struct MissileFileData { MissileDataFlags flags; std::array animDelay = {}; std::array animLen = {}; - int16_t animWidth; + uint16_t animWidth; int16_t animWidth2; std::unique_ptr animData; std::array frameOffsets; MissileFileData(string_view name, uint8_t animName, uint8_t animFAmt, MissileDataFlags flags, std::initializer_list animDelay, std::initializer_list animLen, - int16_t animWidth, int16_t animWidth2); + uint16_t animWidth, int16_t animWidth2); void LoadGFX(); @@ -164,6 +165,11 @@ struct MissileFileData { return animData.get() + frameOffsets[i]; } + CelSprite Sprite() const + { + return CelSprite { GetFirstFrame(), animWidth }; + } + void FreeGFX() { animData = nullptr; diff --git a/Source/missiles.h b/Source/missiles.h index 35e0ff77e..26d6f0568 100644 --- a/Source/missiles.h +++ b/Source/missiles.h @@ -97,8 +97,8 @@ struct Missile { const byte *_miAnimData; int _miAnimDelay; // Tick length of each frame in the current animation int _miAnimLen; // Number of frames in current animation - int _miAnimWidth; - int _miAnimWidth2; + uint16_t _miAnimWidth; + int16_t _miAnimWidth2; int _miAnimCnt; // Increases by one each game tick, counting how close we are to _pAnimDelay int _miAnimAdd; int _miAnimFrame; // Current frame of animation. diff --git a/Source/monster.h b/Source/monster.h index 1edb3eeec..83f9d15b6 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -137,11 +137,11 @@ struct AnimStruct { const byte *spriteData = CelSpritesForDirections[static_cast(direction)]; if (spriteData == nullptr) return std::nullopt; - return CelSprite(spriteData, static_cast(Width)); + return CelSprite(spriteData, Width); } std::array CelSpritesForDirections; - unsigned Width; + uint16_t Width; int Frames; int Rate; }; diff --git a/Source/objdat.h b/Source/objdat.h index ff51c7758..38b60a47a 100644 --- a/Source/objdat.h +++ b/Source/objdat.h @@ -234,7 +234,7 @@ struct ObjectData { int oAnimFlag; // TODO Create enum int oAnimDelay; // Tick length of each frame in the current animation int oAnimLen; // Number of frames in current animation - int oAnimWidth; + uint16_t oAnimWidth; bool oSolidFlag; bool oMissFlag; bool oLightFlag; diff --git a/Source/objects.h b/Source/objects.h index e1a00ae9c..b181b685f 100644 --- a/Source/objects.h +++ b/Source/objects.h @@ -29,7 +29,7 @@ struct Object { int _oAnimCnt; // Increases by one each game tick, counting how close we are to _pAnimDelay uint32_t _oAnimLen; // Number of frames in current animation uint32_t _oAnimFrame; // Current frame of animation. - int _oAnimWidth; + uint16_t _oAnimWidth; bool _oDelFlag; int8_t _oBreak; bool _oSolidFlag; diff --git a/Source/panels/spell_book.cpp b/Source/panels/spell_book.cpp index 6f5a9e0f0..6f359aa2a 100644 --- a/Source/panels/spell_book.cpp +++ b/Source/panels/spell_book.cpp @@ -85,7 +85,7 @@ void InitSpellBook() pSpellBkCel = LoadCel("Data\\SpellBk.CEL", SPANEL_WIDTH); if (gbIsHellfire) { - static const int SBkBtnHellfireWidths[] = { 0, 61, 61, 61, 61, 61, 76 }; + static const uint16_t SBkBtnHellfireWidths[] = { 0, 61, 61, 61, 61, 61, 76 }; pSBkBtnCel = LoadCel("Data\\SpellBkB.CEL", SBkBtnHellfireWidths); } else { pSBkBtnCel = LoadCel("Data\\SpellBkB.CEL", 76); diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 1ad44689b..54ed5c179 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -455,12 +455,9 @@ void DrawMonster(const Surface &out, Point tilePosition, Point targetBufferPosit */ void DrawPlayerIconHelper(const Surface &out, int pnum, missile_graphic_id missileGraphicId, Point position, bool lighting) { - position.x += CalculateWidth2(Players[pnum].AnimInfo.celSprite->Width()) - MissileSpriteData[missileGraphicId].animWidth2; + position.x += CalculateWidth2(static_cast(Players[pnum].AnimInfo.celSprite->Width()) - MissileSpriteData[missileGraphicId].animWidth2); - int width = MissileSpriteData[missileGraphicId].animWidth; - const byte *pCelBuff = MissileSpriteData[missileGraphicId].GetFirstFrame(); - - CelSprite cel { pCelBuff, width }; + const CelSprite cel = MissileSpriteData[missileGraphicId].Sprite(); if (pnum == MyPlayerId) { Cl2Draw(out, position.x, position.y, cel, 1); @@ -750,7 +747,7 @@ void DrawMonsterHelper(const Surface &out, Point tilePosition, Point targetBuffe auto &towner = Towners[mi]; int px = targetBufferPosition.x - CalculateWidth2(towner._tAnimWidth); const Point position { px, targetBufferPosition.y }; - CelSprite sprite { towner._tAnimData, towner._tAnimWidth }; + const CelSprite sprite = towner.Sprite(); if (mi == pcursmonst) { CelBlitOutlineTo(out, 166, position, sprite, towner._tAnimFrame); } diff --git a/Source/towners.h b/Source/towners.h index cb8aac527..38340100d 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -43,7 +43,7 @@ struct Towner { int16_t seed; /** Tile position of NPC */ Point position; - int16_t _tAnimWidth; + uint16_t _tAnimWidth; /** Tick length of each frame in the current animation */ int16_t _tAnimDelay; /** Increases by one each game tick, counting how close we are to _pAnimDelay */ @@ -59,6 +59,11 @@ struct Towner { std::size_t animOrderSize; void (*talk)(Player &player, Towner &towner); _talker_id _ttype; + + CelSprite Sprite() const + { + return CelSprite { _tAnimData, _tAnimWidth }; + } }; extern Towner Towners[NUM_TOWNERS];