From 19ccf7ce881d3ab844080a25119f3f9d758730ea Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 7 Jan 2025 20:03:38 +0000 Subject: [PATCH] Split endian_write from endian Only `endian_write` functions require SDL, splitting them out will allow us to clean up the dependencies a bit. --- Source/dvlnet/frame_queue.cpp | 1 + Source/dvlnet/packet.h | 1 + Source/engine/load_cl2.hpp | 1 + Source/levels/reencode_dun_cels.cpp | 1 + Source/utils/cel_to_clx.cpp | 1 + Source/utils/cl2_to_clx.cpp | 1 + Source/utils/endian.hpp | 15 --------------- Source/utils/endian_stream.hpp | 1 + Source/utils/endian_write.hpp | 22 ++++++++++++++++++++++ Source/utils/pcx_to_clx.cpp | 1 + Source/utils/surface_to_clx.cpp | 1 + 11 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 Source/utils/endian_write.hpp diff --git a/Source/dvlnet/frame_queue.cpp b/Source/dvlnet/frame_queue.cpp index 56613b0a4af..e4c826cbfd6 100644 --- a/Source/dvlnet/frame_queue.cpp +++ b/Source/dvlnet/frame_queue.cpp @@ -6,6 +6,7 @@ #include "dvlnet/packet.h" #include "utils/attributes.h" #include "utils/endian.hpp" +#include "utils/endian_write.hpp" namespace devilution { namespace net { diff --git a/Source/dvlnet/packet.h b/Source/dvlnet/packet.h index f93dc06aeaa..e407d62d95b 100644 --- a/Source/dvlnet/packet.h +++ b/Source/dvlnet/packet.h @@ -16,6 +16,7 @@ #include "appfat.h" #include "dvlnet/abstract_net.h" #include "utils/attributes.h" +#include "utils/endian_write.hpp" #include "utils/str_cat.hpp" #include "utils/stubs.h" diff --git a/Source/engine/load_cl2.hpp b/Source/engine/load_cl2.hpp index 85bf46e1a56..96c61eded57 100644 --- a/Source/engine/load_cl2.hpp +++ b/Source/engine/load_cl2.hpp @@ -14,6 +14,7 @@ #include "mpq/mpq_common.hpp" #include "utils/cl2_to_clx.hpp" #include "utils/endian.hpp" +#include "utils/endian_write.hpp" #include "utils/pointer_value_union.hpp" #include "utils/static_vector.hpp" #include "utils/status_macros.hpp" diff --git a/Source/levels/reencode_dun_cels.cpp b/Source/levels/reencode_dun_cels.cpp index 578a7bf4b20..43d7cdeb9ae 100644 --- a/Source/levels/reencode_dun_cels.cpp +++ b/Source/levels/reencode_dun_cels.cpp @@ -12,6 +12,7 @@ #include "levels/dun_tile.hpp" #include "utils/attributes.h" #include "utils/endian.hpp" +#include "utils/endian_write.hpp" #include "utils/format_int.hpp" #include "utils/log.hpp" diff --git a/Source/utils/cel_to_clx.cpp b/Source/utils/cel_to_clx.cpp index b1865ab30fa..8bf4a00d028 100644 --- a/Source/utils/cel_to_clx.cpp +++ b/Source/utils/cel_to_clx.cpp @@ -13,6 +13,7 @@ #include "appfat.h" #include "utils/clx_encode.hpp" #include "utils/endian.hpp" +#include "utils/endian_write.hpp" namespace devilution { diff --git a/Source/utils/cl2_to_clx.cpp b/Source/utils/cl2_to_clx.cpp index 12eae863f4e..66d090c4871 100644 --- a/Source/utils/cl2_to_clx.cpp +++ b/Source/utils/cl2_to_clx.cpp @@ -8,6 +8,7 @@ #include "utils/clx_decode.hpp" #include "utils/clx_encode.hpp" #include "utils/endian.hpp" +#include "utils/endian_write.hpp" namespace devilution { diff --git a/Source/utils/endian.hpp b/Source/utils/endian.hpp index 14c344b5c92..50bebba6113 100644 --- a/Source/utils/endian.hpp +++ b/Source/utils/endian.hpp @@ -1,9 +1,6 @@ #pragma once #include -#include - -#include namespace devilution { @@ -39,16 +36,4 @@ constexpr uint32_t LoadBE32(const T *b) return (static_cast(b[0]) << 24) | (static_cast(b[1]) << 16) | (static_cast(b[2]) << 8) | static_cast(b[3]); } -inline void WriteLE16(void *out, uint16_t val) -{ - const uint16_t littleEndian = SDL_SwapLE16(val); - memcpy(out, &littleEndian, 2); -} - -inline void WriteLE32(void *out, uint32_t val) -{ - const uint32_t littleEndian = SDL_SwapLE32(val); - memcpy(out, &littleEndian, 4); -} - } // namespace devilution diff --git a/Source/utils/endian_stream.hpp b/Source/utils/endian_stream.hpp index 0e40d320ce4..8f7a0c68aed 100644 --- a/Source/utils/endian_stream.hpp +++ b/Source/utils/endian_stream.hpp @@ -7,6 +7,7 @@ #include #include "utils/endian.hpp" +#include "utils/endian_write.hpp" #include "utils/log.hpp" namespace devilution { diff --git a/Source/utils/endian_write.hpp b/Source/utils/endian_write.hpp new file mode 100644 index 00000000000..7354bdf0e60 --- /dev/null +++ b/Source/utils/endian_write.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +#include + +namespace devilution { + +inline void WriteLE16(void *out, uint16_t val) +{ + const uint16_t littleEndian = SDL_SwapLE16(val); + memcpy(out, &littleEndian, 2); +} + +inline void WriteLE32(void *out, uint32_t val) +{ + const uint32_t littleEndian = SDL_SwapLE32(val); + memcpy(out, &littleEndian, 4); +} + +} // namespace devilution diff --git a/Source/utils/pcx_to_clx.cpp b/Source/utils/pcx_to_clx.cpp index baba20b5f92..639065b1fdb 100644 --- a/Source/utils/pcx_to_clx.cpp +++ b/Source/utils/pcx_to_clx.cpp @@ -13,6 +13,7 @@ #include "appfat.h" #include "utils/clx_encode.hpp" #include "utils/endian.hpp" +#include "utils/endian_write.hpp" #include "utils/pcx.hpp" #ifdef DEBUG_PCX_TO_CL2_SIZE diff --git a/Source/utils/surface_to_clx.cpp b/Source/utils/surface_to_clx.cpp index 8ecba479033..7c9155b34f2 100644 --- a/Source/utils/surface_to_clx.cpp +++ b/Source/utils/surface_to_clx.cpp @@ -6,6 +6,7 @@ #include "utils/clx_encode.hpp" #include "utils/endian.hpp" +#include "utils/endian_write.hpp" #ifdef DEBUG_SURFACE_TO_CLX_SIZE #include