From 74755c8be7499ab4e60c5e3d763a7afece11eb4a Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 13 Aug 2023 10:40:45 +0900 Subject: [PATCH] Remove utils/stdcompat/cstddef.hpp --- CMakeLists.txt | 4 +- Source/codec.cpp | 25 +++-- Source/codec.h | 6 +- Source/encrypt.cpp | 8 +- Source/encrypt.h | 11 +-- Source/engine.h | 2 +- Source/engine/load_file.hpp | 9 +- Source/levels/gendung.cpp | 2 +- Source/levels/gendung.h | 2 +- Source/loadsave.cpp | 6 +- Source/misdat.h | 2 +- Source/monster.cpp | 2 +- Source/monster.h | 2 +- Source/mpq/mpq_reader.cpp | 6 +- Source/mpq/mpq_reader.hpp | 3 +- Source/mpq/mpq_writer.cpp | 6 +- Source/mpq/mpq_writer.hpp | 6 +- Source/msg.cpp | 152 ++++++++++++++--------------- Source/msg.h | 4 +- Source/multi.cpp | 36 +++---- Source/multi.h | 8 +- Source/pfile.cpp | 18 ++-- Source/pfile.h | 8 +- Source/sha.h | 3 +- Source/sync.cpp | 2 +- Source/sync.h | 5 +- Source/tmsg.cpp | 10 +- Source/tmsg.h | 7 +- Source/towners.h | 4 +- Source/utils/language.cpp | 8 +- Source/utils/pcx_to_clx.cpp | 2 +- Source/utils/static_vector.hpp | 4 +- Source/utils/stdcompat/cstddef.hpp | 7 -- 33 files changed, 183 insertions(+), 197 deletions(-) delete mode 100644 Source/utils/stdcompat/cstddef.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index aa67083b9..0a8b35c98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -294,8 +294,8 @@ if(GPERF) endif() # Despite setting C++ standard to 20, features from this version are not being used. -# The oldest compiler used is GCC 6.5 - and that defines our C++ feature set (meaning most of C++17). -# It's present only to take advantage of fmt::format build time errors. +# DevilutionX is compatible with C++ 17. +# Here we set it to 20 only to take advantage of the fmt::format build time errors. set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD_REQUIRED OFF) diff --git a/Source/codec.cpp b/Source/codec.cpp index 55e95598b..a58de0c6c 100644 --- a/Source/codec.cpp +++ b/Source/codec.cpp @@ -7,7 +7,6 @@ #include "sha.h" #include "utils/endian.hpp" #include "utils/log.hpp" -#include "utils/stdcompat/cstddef.hpp" namespace devilution { namespace { @@ -53,7 +52,7 @@ SHA1Context CodecInitKey(const char *pszPassword) return context; } -CodecSignature GetCodecSignature(byte *src) +CodecSignature GetCodecSignature(std::byte *src) { CodecSignature result; result.checksum = LoadLE32(src); @@ -63,16 +62,16 @@ CodecSignature GetCodecSignature(byte *src) return result; } -void SetCodecSignature(byte *dst, CodecSignature sig) +void SetCodecSignature(std::byte *dst, CodecSignature sig) { - *dst++ = static_cast(sig.checksum); - *dst++ = static_cast(sig.checksum >> 8); - *dst++ = static_cast(sig.checksum >> 16); - *dst++ = static_cast(sig.checksum >> 24); - *dst++ = static_cast(sig.error); - *dst++ = static_cast(sig.lastChunkSize); - *dst++ = static_cast(0); - *dst++ = static_cast(0); + *dst++ = static_cast(sig.checksum); + *dst++ = static_cast(sig.checksum >> 8); + *dst++ = static_cast(sig.checksum >> 16); + *dst++ = static_cast(sig.checksum >> 24); + *dst++ = static_cast(sig.error); + *dst++ = static_cast(sig.lastChunkSize); + *dst++ = static_cast(0); + *dst++ = static_cast(0); } void ByteSwapBlock(uint32_t *data) @@ -89,7 +88,7 @@ void XorBlock(const uint32_t *shaResult, uint32_t *out) } // namespace -std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPassword) +std::size_t codec_decode(std::byte *pbSrcDst, std::size_t size, const char *pszPassword) { uint32_t buf[BlockSize]; uint32_t dst[SHA1HashSize]; @@ -134,7 +133,7 @@ std::size_t codec_get_encoded_len(std::size_t dwSrcBytes) return dwSrcBytes + SignatureSize; } -void codec_encode(byte *pbSrcDst, std::size_t size, std::size_t size64, const char *pszPassword) +void codec_encode(std::byte *pbSrcDst, std::size_t size, std::size_t size64, const char *pszPassword) { uint32_t buf[BlockSize]; uint32_t tmp[SHA1HashSize]; diff --git a/Source/codec.h b/Source/codec.h index 5acc9d28d..f6d716d02 100644 --- a/Source/codec.h +++ b/Source/codec.h @@ -5,12 +5,12 @@ */ #pragma once -#include "utils/stdcompat/cstddef.hpp" +#include namespace devilution { -std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPassword); +std::size_t codec_decode(std::byte *pbSrcDst, std::size_t size, const char *pszPassword); std::size_t codec_get_encoded_len(std::size_t dwSrcBytes); -void codec_encode(byte *pbSrcDst, std::size_t size, std::size_t size_64, const char *pszPassword); +void codec_encode(std::byte *pbSrcDst, std::size_t size, std::size_t size_64, const char *pszPassword); } // namespace devilution diff --git a/Source/encrypt.cpp b/Source/encrypt.cpp index 48101ff13..7bbe61480 100644 --- a/Source/encrypt.cpp +++ b/Source/encrypt.cpp @@ -102,7 +102,7 @@ uint32_t Hash(const char *s, int type) return seed1; } -uint32_t PkwareCompress(byte *srcData, uint32_t size) +uint32_t PkwareCompress(std::byte *srcData, uint32_t size) { std::unique_ptr ptr = std::make_unique(CMP_BUFFER_SIZE); @@ -110,7 +110,7 @@ uint32_t PkwareCompress(byte *srcData, uint32_t size) if (destSize < 2 * 4096) destSize = 2 * 4096; - std::unique_ptr destData { new byte[destSize] }; + std::unique_ptr destData { new std::byte[destSize] }; TDataInfo param; param.srcData = srcData; @@ -131,10 +131,10 @@ uint32_t PkwareCompress(byte *srcData, uint32_t size) return size; } -void PkwareDecompress(byte *inBuff, uint32_t recvSize, int maxBytes) +void PkwareDecompress(std::byte *inBuff, uint32_t recvSize, int maxBytes) { std::unique_ptr ptr = std::make_unique(CMP_BUFFER_SIZE); - std::unique_ptr outBuff { new byte[maxBytes] }; + std::unique_ptr outBuff { new std::byte[maxBytes] }; TDataInfo info; info.srcData = inBuff; diff --git a/Source/encrypt.h b/Source/encrypt.h index b6ec9c793..cf53d3f31 100644 --- a/Source/encrypt.h +++ b/Source/encrypt.h @@ -5,16 +5,15 @@ */ #pragma once +#include #include -#include "utils/stdcompat/cstddef.hpp" - namespace devilution { struct TDataInfo { - byte *srcData; + std::byte *srcData; uint32_t srcOffset; - byte *destData; + std::byte *destData; uint32_t destOffset; uint32_t size; }; @@ -22,7 +21,7 @@ struct TDataInfo { void Decrypt(uint32_t *castBlock, uint32_t size, uint32_t key); void Encrypt(uint32_t *castBlock, uint32_t size, uint32_t key); uint32_t Hash(const char *s, int type); -uint32_t PkwareCompress(byte *srcData, uint32_t size); -void PkwareDecompress(byte *inBuff, uint32_t recvSize, int maxBytes); +uint32_t PkwareCompress(std::byte *srcData, uint32_t size); +void PkwareDecompress(std::byte *inBuff, uint32_t recvSize, int maxBytes); } // namespace devilution diff --git a/Source/engine.h b/Source/engine.h index 23cd804f7..484fddd8b 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -25,6 +25,7 @@ // defines for `PRIuMAX` et al. SDL transitively includes `inttypes.h`. // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97044 #include +#include #include @@ -36,7 +37,6 @@ #include "engine/point.hpp" #include "engine/size.hpp" #include "engine/surface.hpp" -#include "utils/stdcompat/cstddef.hpp" #define TILE_WIDTH 64 #define TILE_HEIGHT 32 diff --git a/Source/engine/load_file.hpp b/Source/engine/load_file.hpp index 9168afe53..ce57ae536 100644 --- a/Source/engine/load_file.hpp +++ b/Source/engine/load_file.hpp @@ -13,7 +13,6 @@ #include "engine/assets.hpp" #include "mpq/mpq_common.hpp" #include "utils/static_vector.hpp" -#include "utils/stdcompat/cstddef.hpp" #include "utils/str_cat.hpp" namespace devilution { @@ -58,7 +57,7 @@ void LoadFileInMem(const char *path, std::array &data) * @param numRead Number of T elements read * @return Buffer with content of file */ -template +template std::unique_ptr LoadFileInMem(const char *path, std::size_t *numRead = nullptr) { size_t size; @@ -95,10 +94,10 @@ struct MultiFileLoader { * @param pathFn a function that returns the path for the given index * @param outOffsets a buffer index for the start of each file will be written here, then the total file size at the end. * @param filterFn a function that returns whether to load a file for the given index - * @return std::unique_ptr the buffer with all the files + * @return std::unique_ptr the buffer with all the files */ template - [[nodiscard]] std::unique_ptr operator()(size_t numFiles, PathFn &&pathFn, uint32_t *outOffsets, + [[nodiscard]] std::unique_ptr operator()(size_t numFiles, PathFn &&pathFn, uint32_t *outOffsets, FilterFn filterFn = DefaultFilterFn {}) { StaticVector, MaxFiles> paths; @@ -125,7 +124,7 @@ struct MultiFileLoader { ++j; } outOffsets[files.size()] = totalSize; - std::unique_ptr buf { new byte[totalSize] }; + std::unique_ptr buf { new std::byte[totalSize] }; for (size_t i = 0, j = 0; i < numFiles; ++i) { if (!filterFn(i)) continue; diff --git a/Source/levels/gendung.cpp b/Source/levels/gendung.cpp index 7b7cf835f..e6f9565c4 100644 --- a/Source/levels/gendung.cpp +++ b/Source/levels/gendung.cpp @@ -25,7 +25,7 @@ WorldTileRectangle SetPiece; std::unique_ptr pSetPiece; OptionalOwnedClxSpriteList pSpecialCels; std::unique_ptr pMegaTiles; -std::unique_ptr pDungeonCels; +std::unique_ptr pDungeonCels; std::array SOLData; WorldTilePosition dminPosition; WorldTilePosition dmaxPosition; diff --git a/Source/levels/gendung.h b/Source/levels/gendung.h index 19f0a4330..d629fa2b8 100644 --- a/Source/levels/gendung.h +++ b/Source/levels/gendung.h @@ -163,7 +163,7 @@ extern std::unique_ptr pSetPiece; extern OptionalOwnedClxSpriteList pSpecialCels; /** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */ extern DVL_API_FOR_TEST std::unique_ptr pMegaTiles; -extern std::unique_ptr pDungeonCels; +extern std::unique_ptr pDungeonCels; /** * List tile properties */ diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 425c87a52..d829ed489 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -81,7 +81,7 @@ T SwapBE(T in) } class LoadHelper { - std::unique_ptr m_buffer_; + std::unique_ptr m_buffer_; size_t m_cur_ = 0; size_t m_size_; @@ -168,7 +168,7 @@ public: class SaveHelper { SaveWriter &m_mpqWriter; const char *m_szFileName_; - std::unique_ptr m_buffer_; + std::unique_ptr m_buffer_; size_t m_cur_ = 0; size_t m_capacity_; @@ -176,7 +176,7 @@ public: SaveHelper(SaveWriter &mpqWriter, const char *szFileName, size_t bufferLen) : m_mpqWriter(mpqWriter) , m_szFileName_(szFileName) - , m_buffer_(new byte[codec_get_encoded_len(bufferLen)]) + , m_buffer_(new std::byte[codec_get_encoded_len(bufferLen)]) , m_capacity_(bufferLen) { } diff --git a/Source/misdat.h b/Source/misdat.h index aef08e95e..a2e8ba75c 100644 --- a/Source/misdat.h +++ b/Source/misdat.h @@ -5,6 +5,7 @@ */ #pragma once +#include #include #include #include @@ -14,7 +15,6 @@ #include "engine/clx_sprite.hpp" #include "spelldat.h" #include "utils/enum_traits.h" -#include "utils/stdcompat/cstddef.hpp" #include "utils/stdcompat/string_view.hpp" namespace devilution { diff --git a/Source/monster.cpp b/Source/monster.cpp index 01055fcbd..3880bd5ab 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3372,7 +3372,7 @@ void InitMonsterGFX(CMonster &monsterType) } animOffsets[clxData.size()] = accumulatedSize; monsterType.animData = nullptr; - monsterType.animData = std::unique_ptr(new byte[accumulatedSize]); + monsterType.animData = std::unique_ptr(new std::byte[accumulatedSize]); for (size_t i = 0; i < clxData.size(); ++i) { memcpy(&monsterType.animData[animOffsets[i]], clxData[i].data(), clxData[i].size()); } diff --git a/Source/monster.h b/Source/monster.h index 21c18ae86..31a3d9ebe 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -176,7 +176,7 @@ enum class MonsterSound : uint8_t { }; struct CMonster { - std::unique_ptr animData; + std::unique_ptr animData; AnimStruct anims[6]; std::unique_ptr sounds[4][2]; const MonsterData *data; diff --git a/Source/mpq/mpq_reader.cpp b/Source/mpq/mpq_reader.cpp index 85f0e1629..53a578959 100644 --- a/Source/mpq/mpq_reader.cpp +++ b/Source/mpq/mpq_reader.cpp @@ -62,9 +62,9 @@ bool MpqArchive::GetFileNumber(MpqArchive::FileHash fileHash, uint32_t &fileNumb return libmpq__file_number_from_hash(archive_, fileHash[0], fileHash[1], fileHash[2], &fileNumber) == 0; } -std::unique_ptr MpqArchive::ReadFile(const char *filename, std::size_t &fileSize, int32_t &error) +std::unique_ptr MpqArchive::ReadFile(const char *filename, std::size_t &fileSize, int32_t &error) { - std::unique_ptr result; + std::unique_ptr result; std::uint32_t fileNumber; error = libmpq__file_number(archive_, filename, &fileNumber); if (error != 0) @@ -79,7 +79,7 @@ std::unique_ptr MpqArchive::ReadFile(const char *filename, std::size_t & if (error != 0) return result; - result = std::make_unique(unpackedSize); + result = std::make_unique(unpackedSize); const std::size_t blockSize = GetBlockSize(fileNumber, 0, error); if (error != 0) diff --git a/Source/mpq/mpq_reader.hpp b/Source/mpq/mpq_reader.hpp index 995eef113..083613384 100644 --- a/Source/mpq/mpq_reader.hpp +++ b/Source/mpq/mpq_reader.hpp @@ -7,7 +7,6 @@ #include #include -#include "utils/stdcompat/cstddef.hpp" #include "utils/stdcompat/optional.hpp" // Forward-declare so that we can avoid exposing libmpq. @@ -43,7 +42,7 @@ public: // Returns false if the file does not exit. bool GetFileNumber(FileHash fileHash, uint32_t &fileNumber); - std::unique_ptr ReadFile(const char *filename, std::size_t &fileSize, int32_t &error); + std::unique_ptr ReadFile(const char *filename, std::size_t &fileSize, int32_t &error); // Returns error code. int32_t ReadBlock(uint32_t fileNumber, uint32_t blockNumber, uint8_t *out, uint32_t outSize); diff --git a/Source/mpq/mpq_writer.cpp b/Source/mpq/mpq_writer.cpp index 1d3ab8b50..dc6dc0c03 100644 --- a/Source/mpq/mpq_writer.cpp +++ b/Source/mpq/mpq_writer.cpp @@ -362,7 +362,7 @@ MpqBlockEntry *MpqWriter::AddFile(const char *filename, MpqBlockEntry *block, ui return block; } -bool MpqWriter::WriteFileContents(const char *filename, const byte *fileData, size_t fileSize, MpqBlockEntry *block) +bool MpqWriter::WriteFileContents(const char *filename, const std::byte *fileData, size_t fileSize, MpqBlockEntry *block) { const char *tmp; while ((tmp = strchr(filename, ':')) != nullptr) @@ -408,7 +408,7 @@ bool MpqWriter::WriteFileContents(const char *filename, const byte *fileData, si #endif uint32_t destSize = offsetTableByteSize; - byte mpqBuf[BlockSize]; + std::byte mpqBuf[BlockSize]; size_t curSector = 0; while (true) { uint32_t len = std::min(fileSize, BlockSize); @@ -504,7 +504,7 @@ void MpqWriter::RemoveHashEntries(bool (*fnGetName)(uint8_t, char *)) } } -bool MpqWriter::WriteFile(const char *filename, const byte *data, size_t size) +bool MpqWriter::WriteFile(const char *filename, const std::byte *data, size_t size) { MpqBlockEntry *blockEntry; diff --git a/Source/mpq/mpq_writer.hpp b/Source/mpq/mpq_writer.hpp index f707ad23e..6a6d25452 100644 --- a/Source/mpq/mpq_writer.hpp +++ b/Source/mpq/mpq_writer.hpp @@ -5,11 +5,11 @@ */ #pragma once +#include #include #include "mpq/mpq_common.hpp" #include "utils/logged_fstream.hpp" -#include "utils/stdcompat/cstddef.hpp" namespace devilution { class MpqWriter { @@ -27,7 +27,7 @@ public: void RemoveHashEntry(const char *filename); void RemoveHashEntries(bool (*fnGetName)(uint8_t, char *)); - bool WriteFile(const char *filename, const byte *data, size_t size); + bool WriteFile(const char *filename, const std::byte *data, size_t size); void RenameFile(const char *name, const char *newName); private: @@ -37,7 +37,7 @@ private: bool ReadMPQHeader(MpqFileHeader *hdr); MpqBlockEntry *AddFile(const char *filename, MpqBlockEntry *block, uint32_t blockIndex); - bool WriteFileContents(const char *filename, const byte *fileData, size_t fileSize, MpqBlockEntry *block); + bool WriteFileContents(const char *filename, const std::byte *fileData, size_t fileSize, MpqBlockEntry *block); // Returns an unused entry in the block entry table. MpqBlockEntry *NewBlock(uint32_t *blockIndex = nullptr); diff --git a/Source/msg.cpp b/Source/msg.cpp index d33905abf..f118e7b95 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -150,7 +150,7 @@ string_view CmdIdString(_cmd_id cmd) struct TMegaPkt { uint32_t spaceLeft; - byte data[32000]; + std::byte data[32000]; TMegaPkt() : spaceLeft(sizeof(data)) @@ -220,7 +220,7 @@ uint8_t sbLastCmd; /** * @brief buffer used to receive level deltas, size is the worst expected case assuming every object on a level was touched */ -byte sgRecvBuf[1U + sizeof(DLevel::item) + sizeof(uint8_t) + (sizeof(WorldTilePosition) + sizeof(_cmd_id)) * MAXOBJECTS + sizeof(DLevel::monster)]; +std::byte sgRecvBuf[1U + sizeof(DLevel::item) + sizeof(uint8_t) + (sizeof(WorldTilePosition) + sizeof(_cmd_id)) * MAXOBJECTS + sizeof(DLevel::monster)]; _cmd_id sgbRecvCmd; std::unordered_map LocalLevels; DJunk sgJunk; @@ -338,7 +338,7 @@ void PrePacket() { uint8_t playerId = std::numeric_limits::max(); for (TMegaPkt &pkt : MegaPktList) { - byte *data = pkt.data; + std::byte *data = pkt.data; size_t spaceLeft = sizeof(pkt.data); while (spaceLeft != pkt.spaceLeft) { auto cmdId = static_cast<_cmd_id>(*data); @@ -426,11 +426,11 @@ int WaitForTurns() return 100 * sgbDeltaChunks / MAX_CHUNKS; } -byte *DeltaExportItem(byte *dst, const TCmdPItem *src) +std::byte *DeltaExportItem(std::byte *dst, const TCmdPItem *src) { for (int i = 0; i < MAXITEMS; i++, src++) { if (src->bCmd == CMD_INVALID) { - *dst++ = byte { 0xFF }; + *dst++ = std::byte { 0xFF }; } else { memcpy(dst, src, sizeof(TCmdPItem)); dst += sizeof(TCmdPItem); @@ -440,11 +440,11 @@ byte *DeltaExportItem(byte *dst, const TCmdPItem *src) return dst; } -size_t DeltaImportItem(const byte *src, TCmdPItem *dst) +size_t DeltaImportItem(const std::byte *src, TCmdPItem *dst) { size_t size = 0; for (int i = 0; i < MAXITEMS; i++, dst++) { - if (src[size] == byte { 0xFF }) { + if (src[size] == std::byte { 0xFF }) { memset(dst, 0xFF, sizeof(TCmdPItem)); size++; } else { @@ -456,19 +456,19 @@ size_t DeltaImportItem(const byte *src, TCmdPItem *dst) return size; } -byte *DeltaExportObject(byte *dst, const std::unordered_map &src) +std::byte *DeltaExportObject(std::byte *dst, const std::unordered_map &src) { - *dst++ = static_cast(src.size()); + *dst++ = static_cast(src.size()); for (auto &pair : src) { - *dst++ = static_cast(pair.first.x); - *dst++ = static_cast(pair.first.y); - *dst++ = static_cast(pair.second.bCmd); + *dst++ = static_cast(pair.first.x); + *dst++ = static_cast(pair.first.y); + *dst++ = static_cast(pair.second.bCmd); } return dst; } -const byte *DeltaImportObjects(const byte *src, std::unordered_map &dst) +const std::byte *DeltaImportObjects(const std::byte *src, std::unordered_map &dst) { dst.clear(); @@ -484,11 +484,11 @@ const byte *DeltaImportObjects(const byte *src, std::unordered_mapposition.x == 0xFF) { - *dst++ = byte { 0xFF }; + *dst++ = std::byte { 0xFF }; } else { memcpy(dst, src, sizeof(DMonsterStr)); dst += sizeof(DMonsterStr); @@ -498,11 +498,11 @@ byte *DeltaExportMonster(byte *dst, const DMonsterStr *src) return dst; } -void DeltaImportMonster(const byte *src, DMonsterStr *dst) +void DeltaImportMonster(const std::byte *src, DMonsterStr *dst) { size_t size = 0; for (size_t i = 0; i < MaxMonsters; i++, dst++) { - if (src[size] == byte { 0xFF }) { + if (src[size] == std::byte { 0xFF }) { memset(dst, 0xFF, sizeof(DMonsterStr)); size++; } else { @@ -512,11 +512,11 @@ void DeltaImportMonster(const byte *src, DMonsterStr *dst) } } -byte *DeltaExportJunk(byte *dst) +std::byte *DeltaExportJunk(std::byte *dst) { for (auto &portal : sgJunk.portal) { if (portal.x == 0xFF) { - *dst++ = byte { 0xFF }; + *dst++ = std::byte { 0xFF }; } else { memcpy(dst, &portal, sizeof(DPortal)); dst += sizeof(DPortal); @@ -541,10 +541,10 @@ byte *DeltaExportJunk(byte *dst) return dst; } -void DeltaImportJunk(const byte *src) +void DeltaImportJunk(const std::byte *src) { for (int i = 0; i < MAXPORTAL; i++) { - if (*src == byte { 0xFF }) { + if (*src == std::byte { 0xFF }) { memset(&sgJunk.portal[i], 0xFF, sizeof(DPortal)); src++; } else { @@ -564,17 +564,17 @@ void DeltaImportJunk(const byte *src) } } -uint32_t CompressData(byte *buffer, byte *end) +uint32_t CompressData(std::byte *buffer, std::byte *end) { #ifdef USE_PKWARE const auto size = static_cast(end - buffer - 1); const uint32_t pkSize = PkwareCompress(buffer + 1, size); - *buffer = size != pkSize ? byte { 1 } : byte { 0 }; + *buffer = size != pkSize ? std::byte { 1 } : std::byte { 0 }; return pkSize + 1; #else - *buffer = byte { 0 }; + *buffer = std::byte { 0 }; return end - buffer; #endif } @@ -582,11 +582,11 @@ uint32_t CompressData(byte *buffer, byte *end) void DeltaImportData(_cmd_id cmd, uint32_t recvOffset) { #ifdef USE_PKWARE - if (sgRecvBuf[0] != byte { 0 }) + if (sgRecvBuf[0] != std::byte { 0 }) PkwareDecompress(&sgRecvBuf[1], recvOffset, sizeof(sgRecvBuf) - 1); #endif - const byte *src = &sgRecvBuf[1]; + const std::byte *src = &sgRecvBuf[1]; if (cmd == CMD_DLEVEL_JUNK) { DeltaImportJunk(src); } else if (cmd == CMD_DLEVEL) { @@ -823,7 +823,7 @@ void NetSendCmdGItem2(bool usonly, _cmd_id bCmd, uint8_t mast, uint8_t pnum, con if (!usonly) { cmd.dwTime = 0; - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); return; } @@ -834,7 +834,7 @@ void NetSendCmdGItem2(bool usonly, _cmd_id bCmd, uint8_t mast, uint8_t pnum, con return; } - tmsg_add((byte *)&cmd, sizeof(cmd)); + tmsg_add((std::byte *)&cmd, sizeof(cmd)); } bool NetSendCmdReq2(_cmd_id bCmd, uint8_t mast, uint8_t pnum, const TCmdGItem &item) @@ -852,7 +852,7 @@ bool NetSendCmdReq2(_cmd_id bCmd, uint8_t mast, uint8_t pnum, const TCmdGItem &i else if (ticks - SDL_SwapLE32(cmd.dwTime) > 5000) return false; - tmsg_add((byte *)&cmd, sizeof(cmd)); + tmsg_add((std::byte *)&cmd, sizeof(cmd)); return true; } @@ -864,7 +864,7 @@ void NetSendCmdExtra(const TCmdGItem &item) memcpy(&cmd, &item, sizeof(cmd)); cmd.dwTime = 0; cmd.bCmd = CMD_ITEMEXTRA; - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } size_t OnWalk(const TCmd *pCmd, Player &player) @@ -2428,10 +2428,10 @@ void DeltaExportData(int pnum) + sizeof(uint8_t) /* count of object interactions which caused a state change since dungeon generation */ + (sizeof(WorldTilePosition) + sizeof(DObjectStr)) * deltaLevel.object.size() /* location/action pairs for the object interactions */ + sizeof(deltaLevel.monster); /* latest monster state */ - std::unique_ptr dst { new byte[bufferSize] }; + std::unique_ptr dst { new std::byte[bufferSize] }; - byte *dstEnd = &dst.get()[1]; - *dstEnd = static_cast(it.first); + std::byte *dstEnd = &dst.get()[1]; + *dstEnd = static_cast(it.first); dstEnd += sizeof(uint8_t); dstEnd = DeltaExportItem(dstEnd, deltaLevel.item); dstEnd = DeltaExportObject(dstEnd, deltaLevel.object); @@ -2440,13 +2440,13 @@ void DeltaExportData(int pnum) multi_send_zero_packet(pnum, CMD_DLEVEL, dst.get(), size); } - byte dst[sizeof(DJunk) + 1]; - byte *dstEnd = &dst[1]; + std::byte dst[sizeof(DJunk) + 1]; + std::byte *dstEnd = &dst[1]; dstEnd = DeltaExportJunk(dstEnd); uint32_t size = CompressData(dst, dstEnd); multi_send_zero_packet(pnum, CMD_DLEVEL_JUNK, dst, size); - byte src[1] = { static_cast(0) }; + std::byte src[1] = { static_cast(0) }; multi_send_zero_packet(pnum, CMD_DLEVEL_END, src, 1); } @@ -2730,9 +2730,9 @@ void NetSendCmd(bool bHiPri, _cmd_id bCmd) cmd.bCmd = bCmd; if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdGolem(uint8_t mx, uint8_t my, Direction dir, uint8_t menemy, int hp, uint8_t cl) @@ -2746,7 +2746,7 @@ void NetSendCmdGolem(uint8_t mx, uint8_t my, Direction dir, uint8_t menemy, int cmd._menemy = menemy; cmd._mhitpoints = hp; cmd._currlevel = cl; - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdLoc(size_t playerId, bool bHiPri, _cmd_id bCmd, Point position) @@ -2760,9 +2760,9 @@ void NetSendCmdLoc(size_t playerId, bool bHiPri, _cmd_id bCmd, Point position) cmd.x = position.x; cmd.y = position.y; if (bHiPri) - NetSendHiPri(playerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(playerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(playerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(playerId, (std::byte *)&cmd, sizeof(cmd)); MyPlayer->UpdatePreviewCelSprite(bCmd, position, 0, 0); } @@ -2779,9 +2779,9 @@ void NetSendCmdLocParam1(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa cmd.y = position.y; cmd.wParam1 = SDL_SwapLE16(wParam1); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, 0); } @@ -2799,9 +2799,9 @@ void NetSendCmdLocParam2(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa cmd.wParam1 = SDL_SwapLE16(wParam1); cmd.wParam2 = SDL_SwapLE16(wParam2); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2); } @@ -2820,9 +2820,9 @@ void NetSendCmdLocParam3(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa cmd.wParam2 = SDL_SwapLE16(wParam2); cmd.wParam3 = SDL_SwapLE16(wParam3); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam2); } @@ -2842,9 +2842,9 @@ void NetSendCmdLocParam4(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa cmd.wParam3 = SDL_SwapLE16(wParam3); cmd.wParam4 = SDL_SwapLE16(wParam4); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3); } @@ -2865,9 +2865,9 @@ void NetSendCmdLocParam5(bool bHiPri, _cmd_id bCmd, Point position, uint16_t wPa cmd.wParam4 = SDL_SwapLE16(wParam4); cmd.wParam5 = SDL_SwapLE16(wParam5); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); MyPlayer->UpdatePreviewCelSprite(bCmd, position, wParam1, wParam3); } @@ -2882,9 +2882,9 @@ void NetSendCmdParam1(bool bHiPri, _cmd_id bCmd, uint16_t wParam1) cmd.bCmd = bCmd; cmd.wParam1 = SDL_SwapLE16(wParam1); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); MyPlayer->UpdatePreviewCelSprite(bCmd, {}, wParam1, 0); } @@ -2897,9 +2897,9 @@ void NetSendCmdParam2(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar cmd.wParam1 = SDL_SwapLE16(wParam1); cmd.wParam2 = SDL_SwapLE16(wParam2); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdParam5(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wParam2, uint16_t wParam3, uint16_t wParam4, uint16_t wParam5) @@ -2916,9 +2916,9 @@ void NetSendCmdParam5(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar cmd.wParam4 = SDL_SwapLE16(wParam4); cmd.wParam5 = SDL_SwapLE16(wParam5); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); MyPlayer->UpdatePreviewCelSprite(bCmd, {}, wParam1, wParam2); } @@ -2935,9 +2935,9 @@ void NetSendCmdQuest(bool bHiPri, const Quest &quest) cmd.qmsg = quest._qmsg; if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t pnum, uint8_t ii) @@ -2955,9 +2955,9 @@ void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t pnum, uint8_t ii) PrepareItemForNetwork(Items[ii], cmd); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item) @@ -2972,9 +2972,9 @@ void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item ItemLimbo = item; if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdChItem(bool bHiPri, uint8_t bLoc, bool forceSpellChange) @@ -2989,9 +2989,9 @@ void NetSendCmdChItem(bool bHiPri, uint8_t bLoc, bool forceSpellChange) PrepareItemForNetwork(item, cmd); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc) @@ -3001,9 +3001,9 @@ void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc) cmd.bLoc = bLoc; cmd.bCmd = CMD_DELPLRITEMS; if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSyncInvItem(const Player &player, int invListIndex) @@ -3031,9 +3031,9 @@ void NetSendCmdChInvItem(bool bHiPri, int invGridIndex) PrepareItemForNetwork(item, cmd); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdChBeltItem(bool bHiPri, int beltIndex) @@ -3047,9 +3047,9 @@ void NetSendCmdChBeltItem(bool bHiPri, int beltIndex) PrepareItemForNetwork(item, cmd); if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam, DamageType damageType) @@ -3061,9 +3061,9 @@ void NetSendCmdDamage(bool bHiPri, uint8_t bPlr, uint32_t dwDam, DamageType dama cmd.dwDam = dwDam; cmd.damageType = damageType; if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam) @@ -3074,9 +3074,9 @@ void NetSendCmdMonDmg(bool bHiPri, uint16_t wMon, uint32_t dwDam) cmd.wMon = wMon; cmd.dwDam = dwDam; if (bHiPri) - NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendHiPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); else - NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); + NetSendLoPri(MyPlayerId, (std::byte *)&cmd, sizeof(cmd)); } void NetSendCmdString(uint32_t pmask, const char *pszStr) @@ -3085,7 +3085,7 @@ void NetSendCmdString(uint32_t pmask, const char *pszStr) cmd.bCmd = CMD_STRING; CopyUtf8(cmd.str, pszStr, sizeof(cmd.str)); - multi_send_msg_packet(pmask, (byte *)&cmd, strlen(cmd.str) + 2); + multi_send_msg_packet(pmask, (std::byte *)&cmd, strlen(cmd.str) + 2); } void delta_close_portal(int pnum) diff --git a/Source/msg.h b/Source/msg.h index 0d4f3d3a6..46956871e 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -708,13 +708,13 @@ struct TPktHdr { struct TPkt { TPktHdr hdr; - byte body[493]; + std::byte body[493]; }; #pragma pack(pop) struct TBuffer { uint32_t dwNextWriteOffset; - byte bData[4096]; + std::byte bData[4096]; }; extern uint8_t gbBufferMsgs; diff --git a/Source/multi.cpp b/Source/multi.cpp index 32452f585..180b2a5d7 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -4,6 +4,7 @@ * Implementation of functions for keeping multiplaye games in sync. */ +#include #include #include @@ -28,7 +29,6 @@ #include "tmsg.h" #include "utils/endian.hpp" #include "utils/language.h" -#include "utils/stdcompat/cstddef.hpp" #include "utils/stdcompat/string_view.hpp" #include "utils/str_cat.hpp" @@ -88,27 +88,27 @@ uint32_t sgbSentThisCycle; void BufferInit(TBuffer *pBuf) { pBuf->dwNextWriteOffset = 0; - pBuf->bData[0] = byte { 0 }; + pBuf->bData[0] = std::byte { 0 }; } -void CopyPacket(TBuffer *buf, const byte *packet, size_t size) +void CopyPacket(TBuffer *buf, const std::byte *packet, size_t size) { if (buf->dwNextWriteOffset + size + 2 > 0x1000) { return; } - byte *p = &buf->bData[buf->dwNextWriteOffset]; + std::byte *p = &buf->bData[buf->dwNextWriteOffset]; buf->dwNextWriteOffset += size + 1; - *p = static_cast(size); + *p = static_cast(size); p++; memcpy(p, packet, size); - p[size] = byte { 0 }; + p[size] = std::byte { 0 }; } -byte *CopyBufferedPackets(byte *destination, TBuffer *source, size_t *size) +std::byte *CopyBufferedPackets(std::byte *destination, TBuffer *source, size_t *size) { if (source->dwNextWriteOffset != 0) { - byte *srcPtr = source->bData; + std::byte *srcPtr = source->bData; while (true) { auto chunkSize = static_cast(*srcPtr); if (chunkSize == 0) @@ -192,7 +192,7 @@ void CheckPlayerInfoTimeouts() } } -void SendPacket(int playerId, const byte *packet, size_t size) +void SendPacket(int playerId, const std::byte *packet, size_t size) { TPkt pkt; @@ -324,7 +324,7 @@ void BeginTimeout() CheckDropPlayer(); } -void HandleAllPackets(size_t pnum, const byte *data, size_t size) +void HandleAllPackets(size_t pnum, const std::byte *data, size_t size) { for (unsigned offset = 0; offset < size;) { size_t messageSize = ParseCmd(pnum, reinterpret_cast(&data[offset])); @@ -338,7 +338,7 @@ void HandleAllPackets(size_t pnum, const byte *data, size_t size) void ProcessTmsgs() { while (true) { - std::unique_ptr msg; + std::unique_ptr msg; uint8_t size = tmsg_get(&msg); if (size == 0) break; @@ -352,7 +352,7 @@ void SendPlayerInfo(int pnum, _cmd_id cmd) PlayerNetPack packed; Player &myPlayer = *MyPlayer; PackNetPlayer(packed, myPlayer); - multi_send_zero_packet(pnum, cmd, reinterpret_cast(&packed), sizeof(PlayerNetPack)); + multi_send_zero_packet(pnum, cmd, reinterpret_cast(&packed), sizeof(PlayerNetPack)); } void SetupLocalPositions() @@ -495,7 +495,7 @@ void InitGameInfo() sgGameInitInfo.fullQuests = (!gbIsMultiplayer || *sgOptions.Gameplay.multiplayerFullQuests) ? 1 : 0; } -void NetSendLoPri(int playerId, const byte *data, size_t size) +void NetSendLoPri(int playerId, const std::byte *data, size_t size) { if (data != nullptr && size != 0) { CopyPacket(&lowPriorityBuffer, data, size); @@ -503,7 +503,7 @@ void NetSendLoPri(int playerId, const byte *data, size_t size) } } -void NetSendHiPri(int playerId, const byte *data, size_t size) +void NetSendHiPri(int playerId, const std::byte *data, size_t size) { if (data != nullptr && size != 0) { CopyPacket(&highPriorityBuffer, data, size); @@ -513,7 +513,7 @@ void NetSendHiPri(int playerId, const byte *data, size_t size) shareNextHighPriorityMessage = false; TPkt pkt; NetReceivePlayerData(&pkt); - byte *destination = pkt.body; + std::byte *destination = pkt.body; size_t remainingSpace = gdwNormalMsgSize - sizeof(TPktHdr); destination = CopyBufferedPackets(destination, &highPriorityBuffer, &remainingSpace); destination = CopyBufferedPackets(destination, &lowPriorityBuffer, &remainingSpace); @@ -525,7 +525,7 @@ void NetSendHiPri(int playerId, const byte *data, size_t size) } } -void multi_send_msg_packet(uint32_t pmask, const byte *data, size_t size) +void multi_send_msg_packet(uint32_t pmask, const std::byte *data, size_t size) { TPkt pkt; NetReceivePlayerData(&pkt); @@ -676,14 +676,14 @@ void multi_process_network_packets() } } } - HandleAllPackets(playerId, (const byte *)(pkt + 1), dwMsgSize - sizeof(TPktHdr)); + HandleAllPackets(playerId, (const std::byte *)(pkt + 1), dwMsgSize - sizeof(TPktHdr)); } if (SErrGetLastError() != STORM_ERROR_NO_MESSAGES_WAITING) nthread_terminate_game("SNetReceiveMsg"); CheckPlayerInfoTimeouts(); } -void multi_send_zero_packet(size_t pnum, _cmd_id bCmd, const byte *data, size_t size) +void multi_send_zero_packet(size_t pnum, _cmd_id bCmd, const std::byte *data, size_t size) { assert(pnum != MyPlayerId); assert(data != nullptr); diff --git a/Source/multi.h b/Source/multi.h index 0772828ee..bc8c5c804 100644 --- a/Source/multi.h +++ b/Source/multi.h @@ -56,9 +56,9 @@ extern uint32_t player_state[MAX_PLRS]; extern bool IsLoopback; void InitGameInfo(); -void NetSendLoPri(int playerId, const byte *data, size_t size); -void NetSendHiPri(int playerId, const byte *data, size_t size); -void multi_send_msg_packet(uint32_t pmask, const byte *data, size_t size); +void NetSendLoPri(int playerId, const std::byte *data, size_t size); +void NetSendHiPri(int playerId, const std::byte *data, size_t size); +void multi_send_msg_packet(uint32_t pmask, const std::byte *data, size_t size); void multi_msg_countdown(); void multi_player_left(int pnum, int reason); void multi_net_ping(); @@ -68,7 +68,7 @@ void multi_net_ping(); */ bool multi_handle_delta(); void multi_process_network_packets(); -void multi_send_zero_packet(size_t pnum, _cmd_id bCmd, const byte *data, size_t size); +void multi_send_zero_packet(size_t pnum, _cmd_id bCmd, const std::byte *data, size_t size); void NetClose(); bool NetInit(bool bSinglePlayer); void recv_plrinfo(int pnum, const TCmdPlrInfoHdr &header, bool recv); diff --git a/Source/pfile.cpp b/Source/pfile.cpp index a3bb1b4e3..8f9a5dce1 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -144,7 +144,7 @@ bool ReadHero(SaveReader &archive, PlayerPack *pPack) void EncodeHero(SaveWriter &saveWriter, const PlayerPack *pack) { size_t packedLen = codec_get_encoded_len(sizeof(*pack)); - std::unique_ptr packed { new byte[packedLen] }; + std::unique_ptr packed { new std::byte[packedLen] }; memcpy(packed.get(), pack, sizeof(*pack)); codec_encode(packed.get(), sizeof(*pack), packedLen, pfile_get_password()); @@ -233,7 +233,7 @@ std::optional CreateSaveReader(std::string &&path) #ifndef DISABLE_DEMOMODE struct CompareInfo { - std::unique_ptr &data; + std::unique_ptr &data; size_t currentPosition; size_t size; bool isTownLevel; @@ -275,7 +275,7 @@ void CreateDetailDiffs(string_view prefix, string_view memoryMapFile, CompareInf } size_t readBytes = SDL_RWsize(handle); - std::unique_ptr memoryMapFileData { new byte[readBytes] }; + std::unique_ptr memoryMapFileData { new std::byte[readBytes] }; SDL_RWread(handle, memoryMapFileData.get(), readBytes, 1); const string_view buffer(reinterpret_cast(memoryMapFileData.get()), readBytes); @@ -502,9 +502,9 @@ void pfile_write_hero(SaveWriter &saveWriter, bool writeGameData) } // namespace #ifdef UNPACKED_SAVES -std::unique_ptr SaveReader::ReadFile(const char *filename, std::size_t &fileSize, int32_t &error) +std::unique_ptr SaveReader::ReadFile(const char *filename, std::size_t &fileSize, int32_t &error) { - std::unique_ptr result; + std::unique_ptr result; error = 0; const std::string path = dir_ + filename; uintmax_t size; @@ -518,7 +518,7 @@ std::unique_ptr SaveReader::ReadFile(const char *filename, std::size_t & error = 1; return nullptr; } - result.reset(new byte[size]); + result.reset(new std::byte[size]); if (std::fread(result.get(), size, 1, file) != 1) { std::fclose(file); error = 1; @@ -528,7 +528,7 @@ std::unique_ptr SaveReader::ReadFile(const char *filename, std::size_t & return result; } -bool SaveWriter::WriteFile(const char *filename, const byte *data, size_t size) +bool SaveWriter::WriteFile(const char *filename, const std::byte *data, size_t size) { const std::string path = dir_ + filename; FILE *file = OpenFile(path.c_str(), "wb"); @@ -563,12 +563,12 @@ std::optional OpenStashArchive() return CreateSaveReader(GetStashSavePath()); } -std::unique_ptr ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen) +std::unique_ptr ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen) { int32_t error; std::size_t length; - std::unique_ptr result = archive.ReadFile(pszName, length, error); + std::unique_ptr result = archive.ReadFile(pszName, length, error); if (error != 0) return nullptr; diff --git a/Source/pfile.h b/Source/pfile.h index 4f17612ee..5d84729d6 100644 --- a/Source/pfile.h +++ b/Source/pfile.h @@ -35,7 +35,7 @@ struct SaveReader { return dir_; } - std::unique_ptr ReadFile(const char *filename, std::size_t &fileSize, int32_t &error); + std::unique_ptr ReadFile(const char *filename, std::size_t &fileSize, int32_t &error); bool HasFile(const char *path) { @@ -52,7 +52,7 @@ struct SaveWriter { { } - bool WriteFile(const char *filename, const byte *data, size_t size); + bool WriteFile(const char *filename, const std::byte *data, size_t size); bool HasFile(const char *path) { @@ -96,7 +96,7 @@ struct HeroCompareResult { std::optional OpenSaveArchive(uint32_t saveNum); std::optional OpenStashArchive(); const char *pfile_get_password(); -std::unique_ptr ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen = nullptr); +std::unique_ptr ReadArchive(SaveReader &archive, const char *pszName, size_t *pdwLen = nullptr); void pfile_write_hero(bool writeGameData = false); #ifndef DISABLE_DEMOMODE @@ -124,7 +124,7 @@ void pfile_read_player_from_save(uint32_t saveNum, Player &player); void pfile_save_level(); void pfile_convert_levels(); void pfile_remove_temp_files(); -std::unique_ptr pfile_read(const char *pszName, size_t *pdwLen); +std::unique_ptr pfile_read(const char *pszName, size_t *pdwLen); void pfile_update(bool forceSave); } // namespace devilution diff --git a/Source/sha.h b/Source/sha.h index 689d210de..441e6e5ca 100644 --- a/Source/sha.h +++ b/Source/sha.h @@ -5,10 +5,9 @@ */ #pragma once +#include #include -#include "utils/stdcompat/cstddef.hpp" - namespace devilution { constexpr size_t BlockSize = 16; diff --git a/Source/sync.cpp b/Source/sync.cpp index c058e82dd..58db6171c 100644 --- a/Source/sync.cpp +++ b/Source/sync.cpp @@ -250,7 +250,7 @@ bool IsTSyncMonsterValidate(const TSyncMonster &monsterSync) } // namespace -uint32_t sync_all_monsters(byte *pbBuf, uint32_t dwMaxLen) +uint32_t sync_all_monsters(std::byte *pbBuf, uint32_t dwMaxLen) { if (ActiveMonsterCount < 1) { return dwMaxLen; diff --git a/Source/sync.h b/Source/sync.h index 36a421a14..9277cad03 100644 --- a/Source/sync.h +++ b/Source/sync.h @@ -5,13 +5,12 @@ */ #pragma once +#include #include -#include "utils/stdcompat/cstddef.hpp" - namespace devilution { -uint32_t sync_all_monsters(byte *pbBuf, uint32_t dwMaxLen); +uint32_t sync_all_monsters(std::byte *pbBuf, uint32_t dwMaxLen); uint32_t OnSyncData(const TCmd *pCmd, size_t pnum); void sync_init(); diff --git a/Source/tmsg.cpp b/Source/tmsg.cpp index d83b4f248..48a77e99d 100644 --- a/Source/tmsg.cpp +++ b/Source/tmsg.cpp @@ -16,12 +16,12 @@ namespace { struct TMsg { uint32_t time; - std::unique_ptr body; + std::unique_ptr body; uint8_t len; - TMsg(uint32_t time, const byte *data, uint8_t len) + TMsg(uint32_t time, const std::byte *data, uint8_t len) : time(time) - , body(new byte[len]) + , body(new std::byte[len]) , len(len) { memcpy(body.get(), data, len); @@ -32,7 +32,7 @@ std::list TimedMsgList; } // namespace -uint8_t tmsg_get(std::unique_ptr *msg) +uint8_t tmsg_get(std::unique_ptr *msg) { if (TimedMsgList.empty()) return 0; @@ -47,7 +47,7 @@ uint8_t tmsg_get(std::unique_ptr *msg) return len; } -void tmsg_add(const byte *msg, uint8_t len) +void tmsg_add(const std::byte *msg, uint8_t len) { uint32_t time = SDL_GetTicks() + gnTickDelay * 10; TimedMsgList.emplace_back(time, msg, len); diff --git a/Source/tmsg.h b/Source/tmsg.h index 597888696..6692186a6 100644 --- a/Source/tmsg.h +++ b/Source/tmsg.h @@ -5,15 +5,14 @@ */ #pragma once +#include #include #include -#include "utils/stdcompat/cstddef.hpp" - namespace devilution { -uint8_t tmsg_get(std::unique_ptr *msg); -void tmsg_add(const byte *msg, uint8_t bLen); +uint8_t tmsg_get(std::unique_ptr *msg); +void tmsg_add(const std::byte *msg, uint8_t bLen); void tmsg_start(); void tmsg_cleanup(); diff --git a/Source/towners.h b/Source/towners.h index 18e62f3b7..f6a1cc91a 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -5,14 +5,14 @@ */ #pragma once -#include "utils/stdcompat/string_view.hpp" +#include #include #include #include "items.h" #include "player.h" #include "quests.h" -#include "utils/stdcompat/cstddef.hpp" +#include "utils/stdcompat/string_view.hpp" namespace devilution { diff --git a/Source/utils/language.cpp b/Source/utils/language.cpp index 24f04b4e2..64faa4e52 100644 --- a/Source/utils/language.cpp +++ b/Source/utils/language.cpp @@ -272,7 +272,7 @@ bool ReadEntry(AssetHandle &handle, const MoEntry &e, char *result) return handle.read(result, e.length); } -bool CopyData(void *dst, const byte *data, size_t dataSize, size_t offset, size_t length) +bool CopyData(void *dst, const std::byte *data, size_t dataSize, size_t offset, size_t length) { if (offset + length > dataSize) return false; @@ -280,7 +280,7 @@ bool CopyData(void *dst, const byte *data, size_t dataSize, size_t offset, size_ return true; } -bool ReadEntry(const byte *data, size_t dataSize, const MoEntry &e, char *result) +bool ReadEntry(const std::byte *data, size_t dataSize, const MoEntry &e, char *result) { if (!CopyData(result, data, dataSize, e.offset, e.length)) return false; @@ -410,9 +410,9 @@ void LanguageInitialize() const bool readWholeFile = handle.handle->type == SDL_RWOPS_UNKNOWN; #endif - std::unique_ptr data; + std::unique_ptr data; if (readWholeFile) { - data.reset(new byte[fileSize]); + data.reset(new std::byte[fileSize]); if (!handle.read(data.get(), fileSize)) return; handle = {}; diff --git a/Source/utils/pcx_to_clx.cpp b/Source/utils/pcx_to_clx.cpp index e235762c9..cb94648cc 100644 --- a/Source/utils/pcx_to_clx.cpp +++ b/Source/utils/pcx_to_clx.cpp @@ -1,5 +1,6 @@ #include "utils/pcx_to_clx.hpp" +#include #include #include @@ -13,7 +14,6 @@ #include "utils/clx_encode.hpp" #include "utils/endian.hpp" #include "utils/pcx.hpp" -#include "utils/stdcompat/cstddef.hpp" #ifdef DEBUG_PCX_TO_CL2_SIZE #include diff --git a/Source/utils/static_vector.hpp b/Source/utils/static_vector.hpp index a10745983..58aa5e4f0 100644 --- a/Source/utils/static_vector.hpp +++ b/Source/utils/static_vector.hpp @@ -1,11 +1,11 @@ #pragma once +#include #include #include #include #include "appfat.h" -#include "utils/stdcompat/cstddef.hpp" namespace devilution { @@ -79,7 +79,7 @@ public: private: struct AlignedStorage { - alignas(alignof(T)) byte data[sizeof(T)]; + alignas(alignof(T)) std::byte data[sizeof(T)]; const T *ptr() const { diff --git a/Source/utils/stdcompat/cstddef.hpp b/Source/utils/stdcompat/cstddef.hpp deleted file mode 100644 index 6bd176dea..000000000 --- a/Source/utils/stdcompat/cstddef.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include // IWYU pragma: export - -namespace devilution { -using ::std::byte; -}