🚚 engine.h: Extract LoadLE32 and LoadBE32
This commit is contained in:
parent
1bc9c3973f
commit
4ea7ba0f5f
9 changed files with 33 additions and 17 deletions
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
#include "utils/endian.hpp"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include "monstdat.h"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
#include "engine/point.hpp"
|
||||
#include "engine/size.hpp"
|
||||
#include "miniwin/miniwin.h"
|
||||
#include "utils/endian.hpp"
|
||||
#include "utils/stdcompat/cstddef.hpp"
|
||||
|
||||
#define TILE_WIDTH 64
|
||||
|
|
@ -51,22 +52,6 @@ inline byte *CelGetFrameStart(byte *pCelBuff, int nCel)
|
|||
return &pCelBuff[SDL_SwapLE32(pFrameTable[nCel])];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr uint32_t LoadLE32(const T *b)
|
||||
{
|
||||
static_assert(sizeof(T) == 1, "invalid argument");
|
||||
|
||||
return ((uint32_t)(b)[3] << 24) | ((uint32_t)(b)[2] << 16) | ((uint32_t)(b)[1] << 8) | (uint32_t)(b)[0];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr uint32_t LoadBE32(const T *b)
|
||||
{
|
||||
static_assert(sizeof(T) == 1, "invalid argument");
|
||||
|
||||
return ((uint32_t)(b)[0] << 24) | ((uint32_t)(b)[1] << 16) | ((uint32_t)(b)[2] << 8) | (uint32_t)(b)[3];
|
||||
}
|
||||
|
||||
inline byte *CelGetFrame(byte *pCelBuff, int nCel, int *nDataSize)
|
||||
{
|
||||
const uint32_t nCellStart = LoadLE32(&pCelBuff[nCel * sizeof(std::uint32_t)]);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include "mpqapi.h"
|
||||
#include "pfile.h"
|
||||
#include "stores.h"
|
||||
#include "utils/endian.hpp"
|
||||
#include "utils/language.h"
|
||||
|
||||
namespace devilution {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include "appfat.h"
|
||||
#include "encrypt.h"
|
||||
#include "engine.h"
|
||||
#include "utils/endian.hpp"
|
||||
#include "utils/file_util.h"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include "storm/storm.h"
|
||||
#include "sync.h"
|
||||
#include "tmsg.h"
|
||||
#include "utils/endian.hpp"
|
||||
#include "utils/language.h"
|
||||
|
||||
namespace devilution {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "init.h"
|
||||
#include "loadsave.h"
|
||||
#include "stores.h"
|
||||
#include "utils/endian.hpp"
|
||||
|
||||
namespace devilution {
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include "mpqapi.h"
|
||||
#include "pack.h"
|
||||
#include "storm/storm.h"
|
||||
#include "utils/endian.hpp"
|
||||
#include "utils/file_util.h"
|
||||
#include "utils/language.h"
|
||||
#include "utils/paths.h"
|
||||
|
|
|
|||
|
|
@ -24,11 +24,12 @@
|
|||
#include "missiles.h"
|
||||
#include "nthread.h"
|
||||
#include "plrmsg.h"
|
||||
#include "qol/itemlabels.h"
|
||||
#include "qol/monhealthbar.h"
|
||||
#include "qol/xpbar.h"
|
||||
#include "qol/itemlabels.h"
|
||||
#include "stores.h"
|
||||
#include "towners.h"
|
||||
#include "utils/endian.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
|
|
|||
23
Source/utils/endian.hpp
Normal file
23
Source/utils/endian.hpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace devilution {
|
||||
|
||||
template <typename T>
|
||||
constexpr std::uint32_t LoadLE32(const T *b)
|
||||
{
|
||||
static_assert(sizeof(T) == 1, "invalid argument");
|
||||
// NOLINTNEXTLINE(readability-magic-numbers)
|
||||
return (static_cast<std::uint32_t>(b[3]) << 24) | (static_cast<std::uint32_t>(b[2]) << 16) | (static_cast<std::uint32_t>(b[1]) << 8) | static_cast<std::uint32_t>(b[0]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr std::uint32_t LoadBE32(const T *b)
|
||||
{
|
||||
static_assert(sizeof(T) == 1, "invalid argument");
|
||||
// NOLINTNEXTLINE(readability-magic-numbers)
|
||||
return (static_cast<std::uint32_t>(b[0]) << 24) | (static_cast<std::uint32_t>(b[1]) << 16) | (static_cast<std::uint32_t>(b[2]) << 8) | static_cast<std::uint32_t>(b[3]);
|
||||
}
|
||||
|
||||
} // namespace devilution
|
||||
Loading…
Add table
Add a link
Reference in a new issue