Skip to content

Commit

Permalink
Split endian_write from endian
Browse files Browse the repository at this point in the history
Only `endian_write` functions require SDL, splitting them out
will allow us to clean up the dependencies a bit.
  • Loading branch information
glebm committed Jan 8, 2025
1 parent 4931cc6 commit 19ccf7c
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions Source/dvlnet/frame_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions Source/dvlnet/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions Source/engine/load_cl2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Source/levels/reencode_dun_cels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions Source/utils/cel_to_clx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "appfat.h"
#include "utils/clx_encode.hpp"
#include "utils/endian.hpp"
#include "utils/endian_write.hpp"

namespace devilution {

Expand Down
1 change: 1 addition & 0 deletions Source/utils/cl2_to_clx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
15 changes: 0 additions & 15 deletions Source/utils/endian.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#pragma once

#include <cstdint>
#include <cstring>

#include <SDL_endian.h>

namespace devilution {

Expand Down Expand Up @@ -39,16 +36,4 @@ constexpr uint32_t LoadBE32(const T *b)
return (static_cast<uint8_t>(b[0]) << 24) | (static_cast<uint8_t>(b[1]) << 16) | (static_cast<uint8_t>(b[2]) << 8) | static_cast<uint8_t>(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
1 change: 1 addition & 0 deletions Source/utils/endian_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstring>

#include "utils/endian.hpp"
#include "utils/endian_write.hpp"
#include "utils/log.hpp"

namespace devilution {
Expand Down
22 changes: 22 additions & 0 deletions Source/utils/endian_write.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <cstdint>
#include <cstring>

#include <SDL_endian.h>

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
1 change: 1 addition & 0 deletions Source/utils/pcx_to_clx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Source/utils/surface_to_clx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iomanip>
Expand Down

0 comments on commit 19ccf7c

Please sign in to comment.