diff --git a/Source/control.cpp b/Source/control.cpp index 7a8c7d73f..270bddd0b 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -77,7 +77,7 @@ char infostr[64]; int numpanbtns; char panelstr[4][64]; bool panelflag; -BYTE SplTransTbl[256]; +uint8_t SplTransTbl[256]; int initialDropGoldValue; bool panbtndown; bool spselflag; diff --git a/Source/dead.h b/Source/dead.h index a6e14b854..8ad1c1da8 100644 --- a/Source/dead.h +++ b/Source/dead.h @@ -15,7 +15,7 @@ namespace devilution { static constexpr unsigned MaxDead = 31; struct DeadStruct { - std::array _deadData; + std::array _deadData; int _deadFrame; int _deadWidth; uint8_t _deadtrans; diff --git a/Source/diablo.cpp b/Source/diablo.cpp index b579bd548..868734df8 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1500,11 +1500,11 @@ void LoadLvlGFX() switch (leveltype) { case DTYPE_TOWN: if (gbIsHellfire) { - pDungeonCels = LoadFileInMem("NLevels\\TownData\\Town.CEL"); + pDungeonCels = LoadFileInMem("NLevels\\TownData\\Town.CEL"); pMegaTiles = LoadFileInMem("NLevels\\TownData\\Town.TIL"); pLevelPieces = LoadFileInMem("NLevels\\TownData\\Town.MIN"); } else { - pDungeonCels = LoadFileInMem("Levels\\TownData\\Town.CEL"); + pDungeonCels = LoadFileInMem("Levels\\TownData\\Town.CEL"); pMegaTiles = LoadFileInMem("Levels\\TownData\\Town.TIL"); pLevelPieces = LoadFileInMem("Levels\\TownData\\Town.MIN"); } @@ -1512,37 +1512,37 @@ void LoadLvlGFX() break; case DTYPE_CATHEDRAL: if (currlevel < 21) { - pDungeonCels = LoadFileInMem("Levels\\L1Data\\L1.CEL"); + pDungeonCels = LoadFileInMem("Levels\\L1Data\\L1.CEL"); pMegaTiles = LoadFileInMem("Levels\\L1Data\\L1.TIL"); pLevelPieces = LoadFileInMem("Levels\\L1Data\\L1.MIN"); pSpecialCels = LoadCel("Levels\\L1Data\\L1S.CEL", SpecialCelWidth); } else { - pDungeonCels = LoadFileInMem("NLevels\\L5Data\\L5.CEL"); + pDungeonCels = LoadFileInMem("NLevels\\L5Data\\L5.CEL"); pMegaTiles = LoadFileInMem("NLevels\\L5Data\\L5.TIL"); pLevelPieces = LoadFileInMem("NLevels\\L5Data\\L5.MIN"); pSpecialCels = LoadCel("NLevels\\L5Data\\L5S.CEL", SpecialCelWidth); } break; case DTYPE_CATACOMBS: - pDungeonCels = LoadFileInMem("Levels\\L2Data\\L2.CEL"); + pDungeonCels = LoadFileInMem("Levels\\L2Data\\L2.CEL"); pMegaTiles = LoadFileInMem("Levels\\L2Data\\L2.TIL"); pLevelPieces = LoadFileInMem("Levels\\L2Data\\L2.MIN"); pSpecialCels = LoadCel("Levels\\L2Data\\L2S.CEL", SpecialCelWidth); break; case DTYPE_CAVES: if (currlevel < 17) { - pDungeonCels = LoadFileInMem("Levels\\L3Data\\L3.CEL"); + pDungeonCels = LoadFileInMem("Levels\\L3Data\\L3.CEL"); pMegaTiles = LoadFileInMem("Levels\\L3Data\\L3.TIL"); pLevelPieces = LoadFileInMem("Levels\\L3Data\\L3.MIN"); } else { - pDungeonCels = LoadFileInMem("NLevels\\L6Data\\L6.CEL"); + pDungeonCels = LoadFileInMem("NLevels\\L6Data\\L6.CEL"); pMegaTiles = LoadFileInMem("NLevels\\L6Data\\L6.TIL"); pLevelPieces = LoadFileInMem("NLevels\\L6Data\\L6.MIN"); } pSpecialCels = LoadCel("Levels\\L1Data\\L1S.CEL", SpecialCelWidth); break; case DTYPE_HELL: - pDungeonCels = LoadFileInMem("Levels\\L4Data\\L4.CEL"); + pDungeonCels = LoadFileInMem("Levels\\L4Data\\L4.CEL"); pMegaTiles = LoadFileInMem("Levels\\L4Data\\L4.TIL"); pLevelPieces = LoadFileInMem("Levels\\L4Data\\L4.MIN"); pSpecialCels = LoadCel("Levels\\L2Data\\L2S.CEL", SpecialCelWidth); diff --git a/Source/engine.cpp b/Source/engine.cpp index 7a39d2c44..0d007c53d 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -77,7 +77,7 @@ constexpr std::uint8_t GetCelTransparentWidth(std::uint8_t control) constexpr std::uint8_t MaxCl2Width = 65; -BYTE *GetLightTable(char light) +uint8_t *GetLightTable(char light) { int idx = 4096; if (light == 2) @@ -91,19 +91,19 @@ BYTE *GetLightTable(char light) CelSprite LoadCel(const char *pszName, int width) { - return CelSprite(LoadFileInMem(pszName), width); + return CelSprite(LoadFileInMem(pszName), width); } CelSprite LoadCel(const char *pszName, const int *widths) { - return CelSprite(LoadFileInMem(pszName), widths); + return CelSprite(LoadFileInMem(pszName), widths); } std::pair MeasureSolidHorizontalBounds(const CelSprite &cel, int frame) { int nDataSize; - const BYTE *src = CelGetFrame(cel.Data(), frame, &nDataSize); - const BYTE *end = src + nDataSize; + auto src = reinterpret_cast(CelGetFrame(cel.Data(), frame, &nDataSize)); + auto end = &src[nDataSize]; const int celWidth = cel.Width(frame); int xBegin = celWidth; @@ -149,22 +149,22 @@ std::pair MeasureSolidHorizontalBounds(const CelSprite &cel, int frame void CelDrawTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame) { int nDataSize; - const BYTE *pRLEBytes = CelGetFrame(cel.Data(), frame, &nDataSize); + auto pRLEBytes = reinterpret_cast(CelGetFrame(cel.Data(), frame, &nDataSize)); CelBlitSafeTo(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame)); } void CelClippedDrawTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame) { int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); CelBlitSafeTo(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame)); } -void CelDrawLightTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, BYTE *tbl) +void CelDrawLightTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, uint8_t *tbl) { int nDataSize; - const BYTE *pRLEBytes = CelGetFrame(cel.Data(), frame, &nDataSize); + auto pRLEBytes = reinterpret_cast(CelGetFrame(cel.Data(), frame, &nDataSize)); if (light_table_index != 0 || tbl != nullptr) CelBlitLightSafeTo(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame), tbl); @@ -175,7 +175,7 @@ void CelDrawLightTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite void CelClippedDrawLightTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame) { int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); if (light_table_index != 0) CelBlitLightSafeTo(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame), nullptr); @@ -186,14 +186,14 @@ void CelClippedDrawLightTo(const CelOutputBuffer &out, int sx, int sy, const Cel void CelDrawLightRedTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, char light) { int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); BYTE *dst = out.at(sx, sy); - BYTE *tbl = GetLightTable(light); + uint8_t *tbl = GetLightTable(light); const auto celWidth = cel.Width(frame); - for (const BYTE *end = &pRLEBytes[nDataSize]; pRLEBytes != end; dst -= out.pitch() + celWidth) { + for (const uint8_t *end = &pRLEBytes[nDataSize]; pRLEBytes != end; dst -= out.pitch() + celWidth) { for (int w = celWidth; w > 0;) { - BYTE width = *pRLEBytes++; + uint8_t width = *pRLEBytes++; if (!IsCelTransparent(width)) { w -= width; while (width > 0) { @@ -211,16 +211,16 @@ void CelDrawLightRedTo(const CelOutputBuffer &out, int sx, int sy, const CelSpri } } -void CelBlitSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth) +void CelBlitSafeTo(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth) { assert(pRLEBytes != nullptr); - const BYTE *src = pRLEBytes; + const uint8_t *src = pRLEBytes; BYTE *dst = out.at(sx, sy); for (; src != &pRLEBytes[nDataSize]; dst -= out.pitch() + nWidth) { for (int w = nWidth; w > 0;) { - BYTE width = *src++; + uint8_t width = *src++; if (!IsCelTransparent(width)) { w -= width; if (dst < out.end() && dst >= out.begin()) { @@ -240,15 +240,15 @@ void CelBlitSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEB void CelClippedDrawSafeTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame) { int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); CelBlitSafeTo(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame)); } -void CelBlitLightSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *tbl) +void CelBlitLightSafeTo(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth, uint8_t *tbl) { assert(pRLEBytes != nullptr); - const BYTE *src = pRLEBytes; + const uint8_t *src = pRLEBytes; BYTE *dst = out.at(sx, sy); if (tbl == nullptr) @@ -256,7 +256,7 @@ void CelBlitLightSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE * for (; src != &pRLEBytes[nDataSize]; dst -= out.pitch() + nWidth) { for (int w = nWidth; w > 0;) { - BYTE width = *src++; + uint8_t width = *src++; if (!IsCelTransparent(width)) { w -= width; if (dst < out.end() && dst > out.begin()) { @@ -294,18 +294,18 @@ void CelBlitLightSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE * } } -void CelBlitLightTransSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth) +void CelBlitLightTransSafeTo(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth) { assert(pRLEBytes != nullptr); - const BYTE *src = pRLEBytes; + const uint8_t *src = pRLEBytes; BYTE *dst = out.at(sx, sy); - BYTE *tbl = &pLightTbl[light_table_index * 256]; + uint8_t *tbl = &pLightTbl[light_table_index * 256]; bool shift = ((size_t)dst % 2) != 0; for (; src != &pRLEBytes[nDataSize]; dst -= out.pitch() + nWidth, shift = !shift) { for (int w = nWidth; w > 0;) { - BYTE width = *src++; + uint8_t width = *src++; if (!IsCelTransparent(width)) { w -= width; if (dst < out.end() && dst > out.begin()) { @@ -374,18 +374,18 @@ void CelBlitLightTransSafeTo(const CelOutputBuffer &out, int sx, int sy, const B * @param nWidth Width of sprite * @param tbl Palette translation table */ -static void CelBlitLightBlendedSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *tbl) +static void CelBlitLightBlendedSafeTo(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth, uint8_t *tbl) { assert(pRLEBytes != nullptr); - const BYTE *src = pRLEBytes; + const uint8_t *src = pRLEBytes; BYTE *dst = out.at(sx, sy); if (tbl == nullptr) tbl = &pLightTbl[light_table_index * 256]; for (; src != &pRLEBytes[nDataSize]; dst -= out.pitch() + nWidth) { for (int w = nWidth; w > 0;) { - BYTE width = *src++; + uint8_t width = *src++; if (!IsCelTransparent(width)) { w -= width; if (dst < out.end() && dst > out.begin()) { @@ -426,7 +426,7 @@ static void CelBlitLightBlendedSafeTo(const CelOutputBuffer &out, int sx, int sy void CelClippedBlitLightTransTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame) { int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); if (cel_transparency_active) { if (sgOptions.Graphics.bBlendedTransparancy) @@ -442,16 +442,16 @@ void CelClippedBlitLightTransTo(const CelOutputBuffer &out, int sx, int sy, cons void CelDrawLightRedSafeTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, char light) { int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); BYTE *dst = out.at(sx, sy); - BYTE *tbl = GetLightTable(light); - const BYTE *end = &pRLEBytes[nDataSize]; + uint8_t *tbl = GetLightTable(light); + const uint8_t *end = &pRLEBytes[nDataSize]; const int celWidth = static_cast(cel.Width(frame)); for (; pRLEBytes != end; dst -= out.pitch() + celWidth) { for (int w = celWidth; w > 0;) { - BYTE width = *pRLEBytes++; + uint8_t width = *pRLEBytes++; if (!IsCelTransparent(width)) { w -= width; if (dst < out.end() && dst > out.begin()) { @@ -477,14 +477,14 @@ void CelDrawLightRedSafeTo(const CelOutputBuffer &out, int sx, int sy, const Cel void CelDrawUnsafeTo(const CelOutputBuffer &out, int x, int y, const CelSprite &cel, int frame) { int nDataSize; - const BYTE *pRLEBytes = CelGetFrame(cel.Data(), frame, &nDataSize); - const BYTE *end = &pRLEBytes[nDataSize]; + auto *pRLEBytes = reinterpret_cast(CelGetFrame(cel.Data(), frame, &nDataSize)); + auto *end = &pRLEBytes[nDataSize]; BYTE *dst = out.at(x, y); const int celWidth = static_cast(cel.Width(frame)); for (; pRLEBytes != end; dst -= out.pitch() + celWidth) { for (int w = celWidth; w > 0;) { - BYTE width = *pRLEBytes++; + auto width = *pRLEBytes++; if (!IsCelTransparent(width)) { w -= width; memcpy(dst, pRLEBytes, width); @@ -499,18 +499,18 @@ void CelDrawUnsafeTo(const CelOutputBuffer &out, int x, int y, const CelSprite & } } -void CelBlitOutlineTo(const CelOutputBuffer &out, BYTE col, int sx, int sy, const CelSprite &cel, int frame, bool skipColorIndexZero) +void CelBlitOutlineTo(const CelOutputBuffer &out, uint8_t col, int sx, int sy, const CelSprite &cel, int frame, bool skipColorIndexZero) { int nDataSize; - const BYTE *src = CelGetFrameClipped(cel.Data(), frame, &nDataSize); - const BYTE *end = &src[nDataSize]; + const uint8_t *src = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *end = &src[nDataSize]; BYTE *dst = out.at(sx, sy); const int celWidth = static_cast(cel.Width(frame)); for (; src != end; dst -= out.pitch() + celWidth) { for (int w = celWidth; w > 0;) { - BYTE width = *src++; + uint8_t width = *src++; if (!IsCelTransparent(width)) { w -= width; if (dst < out.end() && dst > out.begin()) { @@ -752,46 +752,19 @@ void LoadFileData(const char *pszName, byte *buffer, size_t fileLen) SFileCloseFile(file); } -/** - * @brief Load a file in to the given buffer - * @param pszName Path of file - * @param p Target buffer - * @return Size of file - */ -DWORD LoadFileWithMem(const char *pszName, BYTE *p) -{ - assert(pszName); - if (p == nullptr) { - app_fatal("LoadFileWithMem(NULL):\n%s", pszName); - } - - HANDLE hsFile; - SFileOpenFile(pszName, &hsFile); - - DWORD dwFileLen = SFileGetFileSize(hsFile, nullptr); - if (dwFileLen == 0) { - app_fatal("Zero length SFILE:\n%s", pszName); - } - - SFileReadFileThreadSafe(hsFile, p, dwFileLen); - SFileCloseFile(hsFile); - - return dwFileLen; -} - /** * @brief Apply the color swaps to a CL2 sprite * @param p CL2 buffer * @param ttbl Palette translation table * @param nCel Frame number in CL2 file */ -void Cl2ApplyTrans(BYTE *p, const std::array &ttbl, int nCel) +void Cl2ApplyTrans(byte *p, const std::array &ttbl, int nCel) { assert(p != nullptr); for (int i = 1; i <= nCel; i++) { int nDataSize; - BYTE *dst = CelGetFrame(p, i, &nDataSize) + 10; + auto dst = reinterpret_cast(CelGetFrame(p, i, &nDataSize) + 10); nDataSize -= 10; while (nDataSize > 0) { char width = *dst++; @@ -826,9 +799,9 @@ void Cl2ApplyTrans(BYTE *p, const std::array &ttbl, int nCel) * @param nDataSize Size of CL2 in bytes * @param nWidth Width of sprite */ -static void Cl2BlitSafe(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth) +static void Cl2BlitSafe(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth) { - const BYTE *src = pRLEBytes; + const uint8_t *src = pRLEBytes; BYTE *dst = out.at(sx, sy); int w = nWidth; @@ -840,7 +813,7 @@ static void Cl2BlitSafe(const CelOutputBuffer &out, int sx, int sy, const BYTE * if (width > MaxCl2Width) { width -= MaxCl2Width; nDataSize--; - BYTE fill = *src++; + uint8_t fill = *src++; if (dst < out.end() && dst > out.begin()) { w -= width; while (width > 0) { @@ -901,9 +874,9 @@ static void Cl2BlitSafe(const CelOutputBuffer &out, int sx, int sy, const BYTE * * @param nWidth Width of sprite * @param col Color index from current palette */ -static void Cl2BlitOutlineSafe(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE col) +static void Cl2BlitOutlineSafe(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth, uint8_t col) { - const BYTE *src = pRLEBytes; + const uint8_t *src = pRLEBytes; BYTE *dst = out.at(sx, sy); int w = nWidth; @@ -984,9 +957,9 @@ static void Cl2BlitOutlineSafe(const CelOutputBuffer &out, int sx, int sy, const * @param nWidth With of CL2 sprite * @param pTable Light color table */ -static void Cl2BlitLightSafe(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *pTable) +static void Cl2BlitLightSafe(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth, uint8_t *pTable) { - const BYTE *src = pRLEBytes; + const uint8_t *src = pRLEBytes; BYTE *dst = out.at(sx, sy); int w = nWidth; @@ -998,7 +971,7 @@ static void Cl2BlitLightSafe(const CelOutputBuffer &out, int sx, int sy, const B if (width > MaxCl2Width) { width -= MaxCl2Width; nDataSize--; - BYTE fill = pTable[*src++]; + uint8_t fill = pTable[*src++]; if (dst < out.end() && dst > out.begin()) { w -= width; while (width > 0) { @@ -1054,17 +1027,17 @@ void Cl2Draw(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, i assert(frame > 0); int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); Cl2BlitSafe(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame)); } -void Cl2DrawOutline(const CelOutputBuffer &out, BYTE col, int sx, int sy, const CelSprite &cel, int frame) +void Cl2DrawOutline(const CelOutputBuffer &out, uint8_t col, int sx, int sy, const CelSprite &cel, int frame) { assert(frame > 0); int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); const CelOutputBuffer &sub = out.subregionY(0, out.h() - 1); Cl2BlitOutlineSafe(sub, sx, sy, pRLEBytes, nDataSize, cel.Width(frame), col); @@ -1075,7 +1048,7 @@ void Cl2DrawLightTbl(const CelOutputBuffer &out, int sx, int sy, const CelSprite assert(frame > 0); int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); Cl2BlitLightSafe(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame), GetLightTable(light)); } @@ -1084,7 +1057,7 @@ void Cl2DrawLight(const CelOutputBuffer &out, int sx, int sy, const CelSprite &c assert(frame > 0); int nDataSize; - const BYTE *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); + const uint8_t *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); if (light_table_index != 0) Cl2BlitLightSafe(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame), &pLightTbl[light_table_index * 256]); diff --git a/Source/engine.h b/Source/engine.h index b2afeb06c..a08a945f8 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -139,13 +139,11 @@ struct ActorPosition { Point temp; }; -inline BYTE *CelGetFrameStart(BYTE *pCelBuff, int nCel) +inline byte *CelGetFrameStart(byte *pCelBuff, int nCel) { - DWORD *pFrameTable; + const uint32_t *pFrameTable = reinterpret_cast(pCelBuff); - pFrameTable = (DWORD *)pCelBuff; - - return pCelBuff + SDL_SwapLE32(pFrameTable[nCel]); + return &pCelBuff[SDL_SwapLE32(pFrameTable[nCel])]; } template @@ -172,29 +170,41 @@ constexpr uint32_t LoadBE32(const T *b) #endif } -inline BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize) +inline byte *CelGetFrame(byte *pCelBuff, int nCel, int *nDataSize) { - DWORD nCellStart = LoadLE32(&pCelBuff[nCel * 4]); - *nDataSize = LoadLE32(&pCelBuff[(nCel + 1) * 4]) - nCellStart; - return pCelBuff + nCellStart; + auto frameTable = reinterpret_cast(pCelBuff); + const uint32_t nCellStart = SDL_SwapLE32(frameTable[nCel]); + *nDataSize = SDL_SwapLE32(frameTable[nCel + 1]) - nCellStart; + return &pCelBuff[nCellStart]; } -inline const BYTE *CelGetFrame(const BYTE *pCelBuff, int nCel, int *nDataSize) +inline const byte *CelGetFrame(const byte *pCelBuff, int nCel, int *nDataSize) { - DWORD nCellStart = LoadLE32(&pCelBuff[nCel * 4]); - *nDataSize = LoadLE32(&pCelBuff[(nCel + 1) * 4]) - nCellStart; - return pCelBuff + nCellStart; + auto frameTable = reinterpret_cast(pCelBuff); + const uint32_t nCellStart = SDL_SwapLE32(frameTable[nCel]); + *nDataSize = SDL_SwapLE32(frameTable[nCel + 1]) - nCellStart; + return &pCelBuff[nCellStart]; } -inline const BYTE *CelGetFrameClipped(const BYTE *pCelBuff, int nCel, int *nDataSize) +struct FrameHeader { + uint16_t row0; + uint16_t row32; + uint16_t row64; + uint16_t row96; + uint16_t row128; +}; + +inline const uint8_t *CelGetFrameClipped(const byte *pCelBuff, int nCel, int *nDataSize) { - DWORD nDataStart; - const BYTE *pRLEBytes = CelGetFrame(pCelBuff, nCel, nDataSize); + const byte *pRLEBytes = CelGetFrame(pCelBuff, nCel, nDataSize); - nDataStart = pRLEBytes[1] << 8 | pRLEBytes[0]; + FrameHeader frameHeader; + memcpy(&frameHeader, pRLEBytes, sizeof(FrameHeader)); + + uint16_t nDataStart = SDL_SwapLE16(frameHeader.row0); *nDataSize -= nDataStart; - return pRLEBytes + nDataStart; + return reinterpret_cast(&pRLEBytes[nDataStart]); } struct CelOutputBuffer { @@ -265,16 +275,16 @@ struct CelOutputBuffer { return *at(p.x, p.y); } - BYTE *at(int x, int y) const + uint8_t *at(int x, int y) const { - return static_cast(surface->pixels) + region.x + x + surface->pitch * (region.y + y); + return static_cast(surface->pixels) + region.x + x + surface->pitch * (region.y + y); } - BYTE *begin() const + uint8_t *begin() const { return at(0, 0); } - BYTE *end() const + uint8_t *end() const { return at(0, region.h); } @@ -328,14 +338,14 @@ struct CelOutputBuffer { */ class CelSprite { public: - CelSprite(std::unique_ptr data, int width) + CelSprite(std::unique_ptr data, int width) : data_(std::move(data)) , data_ptr_(data_.get()) , width_(width) { } - CelSprite(std::unique_ptr data, const int *widths) + CelSprite(std::unique_ptr data, const int *widths) : data_(std::move(data)) , data_ptr_(data_.get()) , widths_(widths) @@ -346,7 +356,7 @@ public: * Constructs an unowned sprite. * Ideally we'd like to remove all uses of this constructor. */ - CelSprite(const BYTE *data, int width) + CelSprite(const byte *data, int width) : data_ptr_(data) , width_(width) { @@ -355,7 +365,7 @@ public: CelSprite(CelSprite &&) noexcept = default; CelSprite &operator=(CelSprite &&) noexcept = default; - [[nodiscard]] const BYTE *Data() const + [[nodiscard]] const byte *Data() const { return data_ptr_; } @@ -366,8 +376,8 @@ public: } private: - std::unique_ptr data_; - const BYTE *data_ptr_; + std::unique_ptr data_; + const byte *data_ptr_; int width_ = 0; const int *widths_ = nullptr; // unowned }; @@ -422,7 +432,7 @@ void CelClippedDrawTo(const CelOutputBuffer &out, int sx, int sy, const CelSprit * @param cel CEL sprite * @param frame CEL frame number */ -void CelDrawLightTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, BYTE *tbl); +void CelDrawLightTo(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, int frame, uint8_t *tbl); /** * @brief Same as CelDrawLightTo but with the option to skip parts of the top and bottom of the sprite @@ -463,7 +473,7 @@ void CelDrawLightRedTo(const CelOutputBuffer &out, int sx, int sy, const CelSpri * @param pRLEBytes CEL pixel stream (run-length encoded) * @param nDataSize Size of CEL in bytes */ -void CelBlitSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth); +void CelBlitSafeTo(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth); /** * @brief Same as CelClippedDrawTo but checks for drawing outside the buffer @@ -484,7 +494,7 @@ void CelClippedDrawSafeTo(const CelOutputBuffer &out, int sx, int sy, const CelS * @param nDataSize Size of CEL in bytes * @param tbl Palette translation table */ -void CelBlitLightSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth, BYTE *tbl); +void CelBlitLightSafeTo(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth, uint8_t *tbl); /** * @brief Same as CelBlitLightSafeTo but with stippled transparancy applied @@ -494,7 +504,7 @@ void CelBlitLightSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE * * @param pRLEBytes CEL pixel stream (run-length encoded) * @param nDataSize Size of CEL in bytes */ -void CelBlitLightTransSafeTo(const CelOutputBuffer &out, int sx, int sy, const BYTE *pRLEBytes, int nDataSize, int nWidth); +void CelBlitLightTransSafeTo(const CelOutputBuffer &out, int sx, int sy, const uint8_t *pRLEBytes, int nDataSize, int nWidth); /** * @brief Same as CelDrawLightRedTo but checks for drawing outside the buffer @@ -517,7 +527,7 @@ void CelDrawLightRedSafeTo(const CelOutputBuffer &out, int sx, int sy, const Cel * @param frame CEL frame number * @param skipColorIndexZero If true, color in index 0 will be treated as transparent (these are typically used for shadows in sprites) */ -void CelBlitOutlineTo(const CelOutputBuffer &out, BYTE col, int sx, int sy, const CelSprite &cel, int frame, bool skipColorIndexZero = true); +void CelBlitOutlineTo(const CelOutputBuffer &out, uint8_t col, int sx, int sy, const CelSprite &cel, int frame, bool skipColorIndexZero = true); /** * @brief Set the value of a single pixel in the back buffer, checks bounds @@ -552,7 +562,7 @@ void Cl2Draw(const CelOutputBuffer &out, int sx, int sy, const CelSprite &cel, i * @param pCelBuff CL2 buffer * @param nCel CL2 frame number */ -void Cl2DrawOutline(const CelOutputBuffer &out, BYTE col, int sx, int sy, const CelSprite &cel, int frame); +void Cl2DrawOutline(const CelOutputBuffer &out, uint8_t col, int sx, int sy, const CelSprite &cel, int frame); /** * @brief Blit CL2 sprite, and apply a given lighting, to the given buffer at the given coordianates @@ -636,8 +646,11 @@ size_t GetFileSize(const char *pszName); void LoadFileData(const char *pszName, byte *buffer, size_t bufferSize); template -void LoadFileInMem(const char *path, T *data, std::size_t count) +void LoadFileInMem(const char *path, T *data, std::size_t count = 0) { + if (count == 0) + count = GetFileSize(path); + LoadFileData(path, reinterpret_cast(data), count * sizeof(T)); } @@ -671,8 +684,7 @@ std::unique_ptr LoadFileInMem(const char *path, size_t *elements = nullptr) return buf; } -DWORD LoadFileWithMem(const char *pszName, BYTE *p); -void Cl2ApplyTrans(BYTE *p, const std::array &ttbl, int nCel); +void Cl2ApplyTrans(byte *p, const std::array &ttbl, int nCel); void PlayInGameMovie(const char *pszMovie); } // namespace devilution diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 91c32af6b..a960b328c 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -52,7 +52,7 @@ int AnimationInfo::GetFrameToUseForRendering() const return absoluteAnimationFrame; } -void AnimationInfo::SetNewAnimation(uint8_t *pData, int numberOfFrames, int delayLen, AnimationDistributionFlags flags /*= AnimationDistributionFlags::None*/, int numSkippedFrames /*= 0*/, int distributeFramesBeforeFrame /*= 0*/) +void AnimationInfo::SetNewAnimation(byte *pData, int numberOfFrames, int delayLen, AnimationDistributionFlags flags /*= AnimationDistributionFlags::None*/, int numSkippedFrames /*= 0*/, int distributeFramesBeforeFrame /*= 0*/) { if ((flags & AnimationDistributionFlags::RepeatedAction) == AnimationDistributionFlags::RepeatedAction && distributeFramesBeforeFrame != 0 && NumberOfFrames == numberOfFrames && CurrentFrame >= distributeFramesBeforeFrame && CurrentFrame != NumberOfFrames) { // We showed the same Animation (for example a melee attack) before but truncated the Animation. diff --git a/Source/engine/animationinfo.h b/Source/engine/animationinfo.h index ba708a2d8..fe6b81e8a 100644 --- a/Source/engine/animationinfo.h +++ b/Source/engine/animationinfo.h @@ -8,6 +8,8 @@ #include #include +#include "engine.h" + namespace devilution { /** @@ -37,7 +39,7 @@ public: /* * @brief Pointer to Animation Data */ - uint8_t *pData; + byte *pData; /* * @brief Additional delay of each animation in the current animation */ @@ -70,7 +72,7 @@ public: * @param numSkippedFrames Number of Frames that will be skipped (for example with modifier "faster attack") * @param distributeFramesBeforeFrame Distribute the numSkippedFrames only before this frame */ - void SetNewAnimation(uint8_t *pData, int numberOfFrames, int delayLen, AnimationDistributionFlags flags = AnimationDistributionFlags::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0); + void SetNewAnimation(byte *pData, int numberOfFrames, int delayLen, AnimationDistributionFlags flags = AnimationDistributionFlags::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0); /* * @brief Process the Animation for a game tick (for example advances the frame) diff --git a/Source/gendung.cpp b/Source/gendung.cpp index b37986908..9e80f3036 100644 --- a/Source/gendung.cpp +++ b/Source/gendung.cpp @@ -30,7 +30,7 @@ std::optional pSpecialCels; /** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */ std::unique_ptr pMegaTiles; std::unique_ptr pLevelPieces; -std::unique_ptr pDungeonCels; +std::unique_ptr pDungeonCels; std::array block_lvid; std::array nBlockTable; std::array nSolidTable; diff --git a/Source/gendung.h b/Source/gendung.h index 24e64ee24..ccb82adf6 100644 --- a/Source/gendung.h +++ b/Source/gendung.h @@ -132,7 +132,7 @@ extern bool setloadflag; extern std::optional pSpecialCels; extern std::unique_ptr pMegaTiles; extern std::unique_ptr pLevelPieces; -extern std::unique_ptr pDungeonCels; +extern std::unique_ptr pDungeonCels; /** * List of transparancy masks to use for dPieces */ diff --git a/Source/misdat.h b/Source/misdat.h index 2a549823a..2b1091f38 100644 --- a/Source/misdat.h +++ b/Source/misdat.h @@ -8,6 +8,7 @@ #include #include "effects.h" +#include "engine.h" namespace devilution { @@ -105,7 +106,7 @@ typedef struct MisFileData { uint8_t mAnimName; uint8_t mAnimFAmt; uint32_t mFlags; - BYTE *mAnimData[16]; + byte *mAnimData[16]; uint8_t mAnimDelay[16]; uint8_t mAnimLen[16]; int16_t mAnimWidth[16]; diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 4bd522fc5..652856497 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1140,16 +1140,16 @@ void LoadMissileGFX(BYTE mi) char pszName[256]; if ((mfd->mFlags & MFLAG_ALLOW_SPECIAL) != 0) { sprintf(pszName, "Missiles\\%s.CL2", mfd->mName); - BYTE *file = LoadFileInMem(pszName).release(); + byte *file = LoadFileInMem(pszName).release(); for (unsigned i = 0; i < mfd->mAnimFAmt; i++) mfd->mAnimData[i] = CelGetFrameStart(file, i); } else if (mfd->mAnimFAmt == 1) { sprintf(pszName, "Missiles\\%s.CL2", mfd->mName); - mfd->mAnimData[0] = LoadFileInMem(pszName).release(); + mfd->mAnimData[0] = LoadFileInMem(pszName).release(); } else { for (unsigned i = 0; i < mfd->mAnimFAmt; i++) { sprintf(pszName, "Missiles\\%s%u.CL2", mfd->mName, i + 1); - mfd->mAnimData[i] = LoadFileInMem(pszName).release(); + mfd->mAnimData[i] = LoadFileInMem(pszName).release(); } } } diff --git a/Source/missiles.h b/Source/missiles.h index a5c26bab5..f75a30d8b 100644 --- a/Source/missiles.h +++ b/Source/missiles.h @@ -42,7 +42,7 @@ struct MissileStruct { bool _miDelFlag; // Indicate whether the missile should be deleted uint8_t _miAnimType; int _miAnimFlags; - BYTE *_miAnimData; + byte *_miAnimData; int _miAnimDelay; // Tick length of each frame in the current animation int _miAnimLen; // Number of frames in current animation int _miAnimWidth; diff --git a/Source/monster.cpp b/Source/monster.cpp index 279173f8c..20dd0b5e2 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -346,9 +346,9 @@ void InitMonsterGFX(int monst) if ((animletter[anim] != 's' || monsterdata[mtype].has_special) && frames > 0) { sprintf(strBuff, monsterdata[mtype].GraphicType, animletter[anim]); - BYTE *celBuf; + byte *celBuf; { - auto celData = LoadFileInMem(strBuff); + auto celData = LoadFileInMem(strBuff); celBuf = celData.get(); Monsters[monst].Anims[anim].CMem = std::move(celData); } @@ -853,7 +853,7 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize) } sprintf(filestr, "Monsters\\Monsters\\%s.TRN", Uniq->mTrnName); - LoadFileWithMem(filestr, &pLightTbl[256 * (uniquetrans + 19)]); + LoadFileInMem("PlrGFX\\Infra.TRN", &pLightTbl[256 * (uniquetrans + 19)], 256); Monst->_uniqtrans = uniquetrans++; diff --git a/Source/monster.h b/Source/monster.h index 7165d4ed5..931bc3325 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -109,8 +109,8 @@ enum placeflag : uint8_t { }; struct AnimStruct { - std::unique_ptr CMem; - std::array Data; + std::unique_ptr CMem; + std::array Data; int Frames; int Rate; }; @@ -147,7 +147,7 @@ struct MonsterStruct { // note: missing field _mAFNum int _menemy; /** Usually correspond's to the enemy's future position */ Point enemyPosition; - uint8_t *_mAnimData; + byte *_mAnimData; /** Tick length of each frame in the current animation */ int _mAnimDelay; /** Increases by one each game tick, counting how close we are to _pAnimDelay */ diff --git a/Source/objects.cpp b/Source/objects.cpp index 1035e4f10..571c42478 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -68,7 +68,7 @@ enum shrine_type : uint8_t { int trapid; int trapdir; -std::unique_ptr pObjCels[40]; +std::unique_ptr pObjCels[40]; object_graphic_id ObjFileList[40]; int objectactive[MAXOBJECTS]; /** Specifies the number of active objects. */ @@ -314,7 +314,7 @@ void InitObjectGFX() sprintf(filestr, "Objects\\%s.CEL", ObjHiveLoadList[i]); else if (currlevel >= 21) sprintf(filestr, "Objects\\%s.CEL", ObjCryptLoadList[i]); - pObjCels[numobjfiles] = LoadFileInMem(filestr); + pObjCels[numobjfiles] = LoadFileInMem(filestr); numobjfiles++; } } @@ -1225,7 +1225,7 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty) ObjFileList[numobjfiles] = (object_graphic_id)i; sprintf(filestr, "Objects\\%s.CEL", ObjMasterLoadList[i]); - pObjCels[numobjfiles] = LoadFileInMem(filestr); + pObjCels[numobjfiles] = LoadFileInMem(filestr); numobjfiles++; } @@ -2242,7 +2242,7 @@ void ObjSetMicro(int dx, int dy, int pn) int blocks = leveltype != DTYPE_HELL ? 10 : 16; - uint16_t *piece = &pLevelPieces[blocks * pn ]; + uint16_t *piece = &pLevelPieces[blocks * pn]; MICROS µs = dpiece_defs_map_2[dx][dy]; for (int i = 0; i < blocks; i++) { diff --git a/Source/objects.h b/Source/objects.h index 17739aee7..ea1f7f823 100644 --- a/Source/objects.h +++ b/Source/objects.h @@ -20,7 +20,7 @@ struct ObjectStruct { Point position; bool _oLight; uint32_t _oAnimFlag; - unsigned char *_oAnimData; + byte *_oAnimData; int _oAnimDelay; // Tick length of each frame in the current animation int _oAnimCnt; // Increases by one each game tick, counting how close we are to _pAnimDelay int _oAnimLen; // Number of frames in current animation diff --git a/Source/player.cpp b/Source/player.cpp index 7e8022197..da71279e3 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -291,7 +291,7 @@ void PlayerStruct::Stop() destAction = ACTION_NONE; } -void SetPlayerGPtrs(BYTE *pData, BYTE **pAnim) +void SetPlayerGPtrs(byte *pData, byte **pAnim) { int i; @@ -306,8 +306,8 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) char pszName[256]; const char *szCel; PlayerStruct *p; - BYTE *pData, *pAnim; - DWORD i; + byte *pData; + byte **pAnim; if ((DWORD)pnum >= MAX_PLRS) { app_fatal("LoadPlrGFX: illegal player %d", pnum); @@ -325,7 +325,7 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) sprintf(prefix, "%c%c%c", CharChar[static_cast(c)], ArmourChar[p->_pgfxnum >> 4], WepChar[p->_pgfxnum & 0xF]); const char *cs = ClassPathTbl[static_cast(c)]; - for (i = 1; i <= PFILE_NONDEATH; i <<= 1) { + for (unsigned i = 1; i <= PFILE_NONDEATH; i <<= 1) { if ((i & gfxflag) == 0) { continue; } @@ -337,7 +337,7 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) szCel = "ST"; } pData = p->_pNData; - pAnim = (BYTE *)p->_pNAnim; + pAnim = p->_pNAnim; break; case PFILE_WALK: szCel = "AW"; @@ -345,7 +345,7 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) szCel = "WL"; } pData = p->_pWData; - pAnim = (BYTE *)p->_pWAnim; + pAnim = p->_pWAnim; break; case PFILE_ATTACK: if (leveltype == DTYPE_TOWN) { @@ -353,7 +353,7 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) } szCel = "AT"; pData = p->_pAData; - pAnim = (BYTE *)p->_pAAnim; + pAnim = p->_pAAnim; break; case PFILE_HIT: if (leveltype == DTYPE_TOWN) { @@ -361,7 +361,7 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) } szCel = "HT"; pData = p->_pHData; - pAnim = (BYTE *)p->_pHAnim; + pAnim = p->_pHAnim; break; case PFILE_LIGHTNING: if (leveltype == DTYPE_TOWN) { @@ -369,7 +369,7 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) } szCel = "LM"; pData = p->_pLData; - pAnim = (BYTE *)p->_pLAnim; + pAnim = p->_pLAnim; break; case PFILE_FIRE: if (leveltype == DTYPE_TOWN) { @@ -377,7 +377,7 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) } szCel = "FM"; pData = p->_pFData; - pAnim = (BYTE *)p->_pFAnim; + pAnim = p->_pFAnim; break; case PFILE_MAGIC: if (leveltype == DTYPE_TOWN) { @@ -385,7 +385,7 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) } szCel = "QM"; pData = p->_pTData; - pAnim = (BYTE *)p->_pTAnim; + pAnim = p->_pTAnim; break; case PFILE_DEATH: if ((p->_pgfxnum & 0xF) != 0) { @@ -393,7 +393,7 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) } szCel = "DT"; pData = p->_pDData; - pAnim = (BYTE *)p->_pDAnim; + pAnim = p->_pDAnim; break; case PFILE_BLOCK: if (leveltype == DTYPE_TOWN) { @@ -405,15 +405,15 @@ void LoadPlrGFX(int pnum, player_graphic gfxflag) szCel = "BL"; pData = p->_pBData; - pAnim = (BYTE *)p->_pBAnim; + pAnim = p->_pBAnim; break; default: app_fatal("PLR:2"); } sprintf(pszName, "PlrGFX\\%s\\%s\\%s%s.CL2", cs, prefix, prefix, szCel); - LoadFileWithMem(pszName, pData); - SetPlayerGPtrs((BYTE *)pData, (BYTE **)pAnim); + LoadFileInMem(pszName, pData); + SetPlayerGPtrs(pData, pAnim); p->_pGFXLoad |= i; } } @@ -496,31 +496,31 @@ void InitPlrGFXMem(int pnum) const HeroClass c = player._pClass; // STAND (ST: TOWN, AS: DUNGEON) - player._pNData = new std::uint8_t[std::max(GetPlrGFXSize(c, "ST"), GetPlrGFXSize(c, "AS"))]; + player._pNData = new byte[std::max(GetPlrGFXSize(c, "ST"), GetPlrGFXSize(c, "AS"))]; // WALK (WL: TOWN, AW: DUNGEON) - player._pWData = new std::uint8_t[std::max(GetPlrGFXSize(c, "WL"), GetPlrGFXSize(c, "AW"))]; + player._pWData = new byte[std::max(GetPlrGFXSize(c, "WL"), GetPlrGFXSize(c, "AW"))]; // ATTACK - player._pAData = new std::uint8_t[GetPlrGFXSize(c, "AT")]; + player._pAData = new byte[GetPlrGFXSize(c, "AT")]; // HIT - player._pHData = new std::uint8_t[GetPlrGFXSize(c, "HT")]; + player._pHData = new byte[GetPlrGFXSize(c, "HT")]; // LIGHTNING - player._pLData = new std::uint8_t[GetPlrGFXSize(c, "LM")]; + player._pLData = new byte[GetPlrGFXSize(c, "LM")]; // FIRE - player._pFData = new std::uint8_t[GetPlrGFXSize(c, "FM")]; + player._pFData = new byte[GetPlrGFXSize(c, "FM")]; // MAGIC - player._pTData = new std::uint8_t[GetPlrGFXSize(c, "QM")]; + player._pTData = new byte[GetPlrGFXSize(c, "QM")]; // DEATH - player._pDData = new std::uint8_t[GetPlrGFXSize(c, "DT")]; + player._pDData = new byte[GetPlrGFXSize(c, "DT")]; // BLOCK - player._pBData = new std::uint8_t[GetPlrGFXSize(c, "BL")]; + player._pBData = new byte[GetPlrGFXSize(c, "BL")]; player._pGFXLoad = 0; } @@ -552,7 +552,7 @@ void FreePlayerGFX(int pnum) plr[pnum]._pGFXLoad = 0; } -void NewPlrAnim(int pnum, BYTE *pData, int numberOfFrames, int delayLen, int width, AnimationDistributionFlags flags /*= AnimationDistributionFlags::None*/, int numSkippedFrames /*= 0*/, int distributeFramesBeforeFrame /*= 0*/) +void NewPlrAnim(int pnum, byte *pData, int numberOfFrames, int delayLen, int width, AnimationDistributionFlags flags /*= AnimationDistributionFlags::None*/, int numSkippedFrames /*= 0*/, int distributeFramesBeforeFrame /*= 0*/) { if ((DWORD)pnum >= MAX_PLRS) { app_fatal("NewPlrAnim: illegal player %d", pnum); diff --git a/Source/player.h b/Source/player.h index 5374d0c8c..b46db84f5 100644 --- a/Source/player.h +++ b/Source/player.h @@ -237,29 +237,29 @@ struct PlayerStruct { bool _pSLvlVisited[NUMLEVELS]; // only 10 used /** Using player_graphic as bitflags */ int _pGFXLoad; - uint8_t *_pNAnim[8]; // Stand animations + byte *_pNAnim[8]; // Stand animations int _pNFrames; int _pNWidth; - uint8_t *_pWAnim[8]; // Walk animations + byte *_pWAnim[8]; // Walk animations int _pWFrames; int _pWWidth; - uint8_t *_pAAnim[8]; // Attack animations + byte *_pAAnim[8]; // Attack animations int _pAFrames; int _pAWidth; int _pAFNum; - uint8_t *_pLAnim[8]; // Lightning spell cast animations - uint8_t *_pFAnim[8]; // Fire spell cast animations - uint8_t *_pTAnim[8]; // Generic spell cast animations + byte *_pLAnim[8]; // Lightning spell cast animations + byte *_pFAnim[8]; // Fire spell cast animations + byte *_pTAnim[8]; // Generic spell cast animations int _pSFrames; int _pSWidth; int _pSFNum; - uint8_t *_pHAnim[8]; // Getting hit animations + byte *_pHAnim[8]; // Getting hit animations int _pHFrames; int _pHWidth; - uint8_t *_pDAnim[8]; // Death animations + byte *_pDAnim[8]; // Death animations int _pDFrames; int _pDWidth; - uint8_t *_pBAnim[8]; // Block animations + byte *_pBAnim[8]; // Block animations int _pBFrames; int _pBWidth; ItemStruct InvBody[NUM_INVLOC]; @@ -299,15 +299,15 @@ struct PlayerStruct { uint8_t pDiabloKillLevel; _difficulty pDifficulty; uint32_t pDamAcFlags; - uint8_t *_pNData; - uint8_t *_pWData; - uint8_t *_pAData; - uint8_t *_pLData; - uint8_t *_pFData; - uint8_t *_pTData; - uint8_t *_pHData; - uint8_t *_pDData; - uint8_t *_pBData; + byte *_pNData; + byte *_pWData; + byte *_pAData; + byte *_pLData; + byte *_pFData; + byte *_pTData; + byte *_pHData; + byte *_pDData; + byte *_pBData; /** * @brief Gets the most valuable item out of all the player's items that match the given predicate. @@ -403,7 +403,7 @@ void FreePlayerGFX(int pnum); * @param numSkippedFrames Number of Frames that will be skipped (for example with modifier "faster attack") * @param distributeFramesBeforeFrame Distribute the numSkippedFrames only before this frame */ -void NewPlrAnim(int pnum, BYTE *pData, int numberOfFrames, int delayLen, int width, AnimationDistributionFlags flags = AnimationDistributionFlags::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0); +void NewPlrAnim(int pnum, byte *pData, int numberOfFrames, int delayLen, int width, AnimationDistributionFlags flags = AnimationDistributionFlags::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0); void SetPlrAnims(int pnum); void CreatePlayer(int pnum, HeroClass c); int CalcStatDiff(int pnum); diff --git a/Source/render.cpp b/Source/render.cpp index c7ad1098c..8edcc1948 100644 --- a/Source/render.cpp +++ b/Source/render.cpp @@ -1314,7 +1314,7 @@ void RenderTile(const CelOutputBuffer &out, int x, int y) const std::uint8_t *tbl = &pLightTbl[256 * light_table_index]; const auto *pFrameTable = reinterpret_cast(pDungeonCels.get()); - const std::uint8_t *src = &pDungeonCels[SDL_SwapLE32(pFrameTable[level_cel_block & 0xFFF])]; + const auto *src = reinterpret_cast(&pDungeonCels[SDL_SwapLE32(pFrameTable[level_cel_block & 0xFFF])]); std::uint8_t *dst = out.at(static_cast(x + clip.left), static_cast(y - clip.bottom)); const auto dstPitch = out.pitch(); mask -= clip.bottom; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 34f76c4e6..407c4c168 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -242,13 +242,13 @@ void DrawMissilePrivate(const CelOutputBuffer &out, MissileStruct *m, int sx, in if (m->_miPreFlag != pre || !m->_miDrawFlag) return; - BYTE *pCelBuff = m->_miAnimData; - if (pCelBuff == nullptr) { + if (m->_miAnimData == nullptr) { Log("Draw Missile 2 type {}: NULL Cel Buffer", m->_mitype); return; } int nCel = m->_miAnimFrame; - int frames = SDL_SwapLE32(*(DWORD *)pCelBuff); + auto frameTable = reinterpret_cast(m->_miAnimData); + int frames = SDL_SwapLE32(frameTable[0]); if (nCel < 1 || frames > 50 || nCel > frames) { Log("Draw Missile 2: frame {} of {}, missile type=={}", nCel, frames, m->_mitype); return; @@ -312,14 +312,14 @@ static void DrawMonster(const CelOutputBuffer &out, int x, int y, int mx, int my return; } - BYTE *pCelBuff = monster[m]._mAnimData; - if (pCelBuff == nullptr) { + if (monster[m]._mAnimData == nullptr) { Log("Draw Monster \"{}\": NULL Cel Buffer", monster[m].mName); return; } int nCel = monster[m]._mAnimFrame; - int frames = SDL_SwapLE32(*(DWORD *)pCelBuff); + auto frameTable = reinterpret_cast(monster[m]._mAnimData); + int frames = SDL_SwapLE32(frameTable[0]); if (nCel < 1 || frames > 50 || nCel > frames) { const char *szMode = "unknown action"; if (monster[m]._mmode <= 17) @@ -370,7 +370,7 @@ static void DrawManaShield(const CelOutputBuffer &out, int pnum, int x, int y, b x += CalculateWidth2(plr[pnum]._pAnimWidth) - misfiledata[MFILE_MANASHLD].mAnimWidth2[0]; int width = misfiledata[MFILE_MANASHLD].mAnimWidth[0]; - BYTE *pCelBuff = misfiledata[MFILE_MANASHLD].mAnimData[0]; + byte *pCelBuff = misfiledata[MFILE_MANASHLD].mAnimData[0]; CelSprite cel { pCelBuff, width }; @@ -407,7 +407,7 @@ static void DrawPlayer(const CelOutputBuffer &out, int pnum, int x, int y, int p PlayerStruct *pPlayer = &plr[pnum]; - BYTE *pCelBuff = pPlayer->AnimInfo.pData; + byte *pCelBuff = pPlayer->AnimInfo.pData; int nCel = pPlayer->AnimInfo.GetFrameToUseForRendering(); if (pCelBuff == nullptr) { @@ -519,14 +519,14 @@ static void DrawObject(const CelOutputBuffer &out, int x, int y, int ox, int oy, assert(bv >= 0 && bv < MAXOBJECTS); - BYTE *pCelBuff = object[bv]._oAnimData; + byte *pCelBuff = object[bv]._oAnimData; if (pCelBuff == nullptr) { Log("Draw Object type {}: NULL Cel Buffer", object[bv]._otype); return; } int nCel = object[bv]._oAnimFrame; - int frames = SDL_SwapLE32(*(DWORD *)pCelBuff); + auto frames = SDL_SwapLE32(reinterpret_cast(pCelBuff)[0]); if (nCel < 1 || frames > 50 || nCel > frames) { Log("Draw Object: frame {} of {}, object type=={}", nCel, frames, object[bv]._otype); return; @@ -761,11 +761,10 @@ static void scrollrt_draw_dungeon(const CelOutputBuffer &out, int sx, int sy, in DeadStruct *pDeadGuy = &dead[(bDead & 0x1F) - 1]; auto dd = static_cast((bDead >> 5) & 7); int px = dx - CalculateWidth2(pDeadGuy->_deadWidth); - BYTE *pCelBuff = pDeadGuy->_deadData[dd]; + byte *pCelBuff = pDeadGuy->_deadData[dd]; assert(pCelBuff != nullptr); - if (pCelBuff == nullptr) - break; - int frames = SDL_SwapLE32(*(DWORD *)pCelBuff); + auto frameTable = reinterpret_cast(pCelBuff); + int frames = SDL_SwapLE32(frameTable[0]); int nCel = pDeadGuy->_deadFrame; if (nCel < 1 || frames > 50 || nCel > frames) { Log("Unclipped dead: frame {} of {}, deadnum=={}", nCel, frames, (bDead & 0x1F) - 1); diff --git a/Source/towners.cpp b/Source/towners.cpp index 615e18bd0..e520f52cc 100644 --- a/Source/towners.cpp +++ b/Source/towners.cpp @@ -13,7 +13,7 @@ namespace devilution { namespace { -std::unique_ptr pCowCels; +std::unique_ptr pCowCels; } // namespace bool storeflag; @@ -186,16 +186,16 @@ int GetActiveTowner(int t) return -1; } -void SetTownerGPtrs(BYTE *pData, byte **pAnim) +void SetTownerGPtrs(byte *pData, byte **pAnim) { for (int i = 0; i < 8; i++) { - pAnim[i] = (byte *)CelGetFrameStart(pData, i); + pAnim[i] = CelGetFrameStart(pData, i); } } void NewTownerAnim(int tnum, byte *pAnim, uint8_t numFrames, int Delay) { - towners[tnum]._tAnimData = (BYTE *)pAnim; + towners[tnum]._tAnimData = pAnim; towners[tnum]._tAnimLen = numFrames; towners[tnum]._tAnimFrame = 1; towners[tnum]._tAnimCnt = 0; @@ -232,9 +232,9 @@ void InitSmith() InitTownerInfo(numtowners, 96, true, TOWN_SMITH, 62, 63, 0); InitQstSnds(numtowners, TOWN_SMITH); - towners[numtowners]._tNData = LoadFileInMem("Towners\\Smith\\SmithN.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Smith\\SmithN.CEL"); for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 16; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_SW], towners[numtowners]._tNFrames, 3); @@ -246,9 +246,9 @@ void InitBarOwner() { InitTownerInfo(numtowners, 96, true, TOWN_TAVERN, 55, 62, 3); InitQstSnds(numtowners, TOWN_TAVERN); - towners[numtowners]._tNData = LoadFileInMem("Towners\\TwnF\\TwnFN.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\TwnF\\TwnFN.CEL"); for (auto &towner : towners[numtowners]._tNAnim) { - towner = (byte *)towners[numtowners]._tNData.get(); + towner = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 16; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_SW], towners[numtowners]._tNFrames, 3); @@ -258,13 +258,11 @@ void InitBarOwner() void InitTownDead() { - int i; - InitTownerInfo(numtowners, 96, true, TOWN_DEADGUY, 24, 32, -1); InitQstSnds(numtowners, TOWN_DEADGUY); - towners[numtowners]._tNData = LoadFileInMem("Towners\\Butch\\Deadguy.CEL"); - for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Butch\\Deadguy.CEL"); + for (int i = 0; i < 8; i++) { + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 8; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_N], towners[numtowners]._tNFrames, 6); @@ -278,9 +276,9 @@ void InitWitch() InitTownerInfo(numtowners, 96, true, TOWN_WITCH, 80, 20, 5); InitQstSnds(numtowners, TOWN_WITCH); - towners[numtowners]._tNData = LoadFileInMem("Towners\\TownWmn1\\Witch.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\TownWmn1\\Witch.CEL"); for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 19; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 6); @@ -294,9 +292,9 @@ void InitBarmaid() InitTownerInfo(numtowners, 96, true, TOWN_BMAID, 43, 66, -1); InitQstSnds(numtowners, TOWN_BMAID); - towners[numtowners]._tNData = LoadFileInMem("Towners\\TownWmn1\\WmnN.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\TownWmn1\\WmnN.CEL"); for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 18; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 6); @@ -310,9 +308,9 @@ void InitBoy() InitTownerInfo(numtowners, 96, true, TOWN_PEGBOY, 11, 53, -1); InitQstSnds(numtowners, TOWN_PEGBOY); - towners[numtowners]._tNData = LoadFileInMem("Towners\\TownBoy\\PegKid1.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\TownBoy\\PegKid1.CEL"); for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 20; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 6); @@ -326,9 +324,9 @@ void InitHealer() InitTownerInfo(numtowners, 96, true, TOWN_HEALER, 55, 79, 1); InitQstSnds(numtowners, TOWN_HEALER); - towners[numtowners]._tNData = LoadFileInMem("Towners\\Healer\\Healer.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Healer\\Healer.CEL"); for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 20; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_SE], towners[numtowners]._tNFrames, 6); @@ -342,9 +340,9 @@ void InitTeller() InitTownerInfo(numtowners, 96, true, TOWN_STORY, 62, 71, 2); InitQstSnds(numtowners, TOWN_STORY); - towners[numtowners]._tNData = LoadFileInMem("Towners\\Strytell\\Strytell.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Strytell\\Strytell.CEL"); for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 25; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 3); @@ -358,9 +356,9 @@ void InitDrunk() InitTownerInfo(numtowners, 96, true, TOWN_DRUNK, 71, 84, 4); InitQstSnds(numtowners, TOWN_DRUNK); - towners[numtowners]._tNData = LoadFileInMem("Towners\\Drunk\\TwnDrunk.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Drunk\\TwnDrunk.CEL"); for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 18; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 3); @@ -375,7 +373,7 @@ void InitCows() //if ( pCowCels ) // assertion_failed(__LINE__, __FILE__, "! pCowCels"); - pCowCels = LoadFileInMem("Towners\\Animals\\Cow.CEL"); + pCowCels = LoadFileInMem("Towners\\Animals\\Cow.CEL"); for (i = 0; i < 3; i++) { x = TownCowX[i]; y = TownCowY[i]; @@ -408,9 +406,9 @@ void InitFarmer() InitTownerInfo(numtowners, 96, true, TOWN_FARMER, 62, 16, -1); InitQstSnds(numtowners, TOWN_FARMER); - towners[numtowners]._tNData = LoadFileInMem("Towners\\Farmer\\Farmrn2.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Farmer\\Farmrn2.CEL"); for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 15; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 3); @@ -425,12 +423,12 @@ void InitCowFarmer() InitTownerInfo(numtowners, 96, true, TOWN_COWFARM, 61, 22, -1); InitQstSnds(numtowners, TOWN_COWFARM); if (quests[Q_JERSEY]._qactive != QUEST_DONE) { - towners[numtowners]._tNData = LoadFileInMem("Towners\\Farmer\\cfrmrn2.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Farmer\\cfrmrn2.CEL"); } else { - towners[numtowners]._tNData = LoadFileInMem("Towners\\Farmer\\mfrmrn2.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Farmer\\mfrmrn2.CEL"); } for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 15; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_SW], towners[numtowners]._tNFrames, 3); @@ -445,12 +443,12 @@ void InitGirl() InitTownerInfo(numtowners, 96, true, TOWN_GIRL, 77, 43, -1); InitQstSnds(numtowners, TOWN_GIRL); if (quests[Q_GIRL]._qactive != QUEST_DONE) { - towners[numtowners]._tNData = LoadFileInMem("Towners\\Girl\\Girlw1.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Girl\\Girlw1.CEL"); } else { - towners[numtowners]._tNData = LoadFileInMem("Towners\\Girl\\Girls1.CEL"); + towners[numtowners]._tNData = LoadFileInMem("Towners\\Girl\\Girls1.CEL"); } for (i = 0; i < 8; i++) { - towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get(); + towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get(); } towners[numtowners]._tNFrames = 20; NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 6); diff --git a/Source/towners.h b/Source/towners.h index 6f6eabb3b..3e013824f 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -42,8 +42,8 @@ struct TNQ { struct TownerStruct { byte *_tNAnim[8]; - std::unique_ptr _tNData; - uint8_t *_tAnimData; + std::unique_ptr _tNData; + byte *_tAnimData; int16_t _tSeed; /** Tile position of NPC */ Point position;