diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-18 23:42:07 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-18 23:42:07 +0100 |
commit | 4d9a82b720c8ce74b94f43f72ddd819ef21abbdf (patch) | |
tree | c0a5d21b8e19fbb60c286faec8e302e6f32b6679 /serialize | |
parent | 32b8c22828315292857e2cd9909fba620f30ff70 (diff) |
pre-declare integer types without cstddef/cstdint
Diffstat (limited to 'serialize')
-rw-r--r-- | serialize/binary-reader.hpp | 8 | ||||
-rw-r--r-- | serialize/binary-reader.inl | 12 | ||||
-rw-r--r-- | serialize/binary-serializer.cpp | 4 | ||||
-rw-r--r-- | serialize/binary-serializer.hpp | 14 | ||||
-rw-r--r-- | serialize/binary-writer.hpp | 4 | ||||
-rw-r--r-- | serialize/binary-writer.inl | 2 | ||||
-rw-r--r-- | serialize/json-helper.cpp | 2 | ||||
-rw-r--r-- | serialize/magnum-vector.hpp | 6 | ||||
-rw-r--r-- | serialize/magnum-vector2i.hpp | 6 | ||||
-rw-r--r-- | serialize/pass-mode.cpp | 2 | ||||
-rw-r--r-- | serialize/scenery.cpp | 8 | ||||
-rw-r--r-- | serialize/tile-atlas.cpp | 2 | ||||
-rw-r--r-- | serialize/tile.cpp | 2 | ||||
-rw-r--r-- | serialize/world-impl.hpp | 20 | ||||
-rw-r--r-- | serialize/world-reader.cpp | 48 | ||||
-rw-r--r-- | serialize/world-writer.cpp | 40 |
16 files changed, 88 insertions, 92 deletions
diff --git a/serialize/binary-reader.hpp b/serialize/binary-reader.hpp index 3c71c7fc..8251cb70 100644 --- a/serialize/binary-reader.hpp +++ b/serialize/binary-reader.hpp @@ -28,10 +28,10 @@ struct binary_reader final { constexpr binary_reader(It begin, It end) noexcept; constexpr void assert_end() noexcept(false); - constexpr std::size_t bytes_read() const noexcept { return num_bytes_read; } + constexpr size_t bytes_read() const noexcept { return num_bytes_read; } template<serializable T> constexpr T read() noexcept(false); - template<std::size_t N> constexpr std::array<char, N> read() noexcept(false); - template<std::size_t Max> constexpr auto read_asciiz_string() noexcept(false); + template<size_t N> constexpr std::array<char, N> read() noexcept(false); + template<size_t Max> constexpr auto read_asciiz_string() noexcept(false); binary_reader(binary_reader&&) noexcept = default; binary_reader& operator=(binary_reader&&) noexcept = default; @@ -41,7 +41,7 @@ struct binary_reader final { constexpr char peek() const; private: - std::size_t num_bytes_read = 0; + size_t num_bytes_read = 0; It it, end; }; diff --git a/serialize/binary-reader.inl b/serialize/binary-reader.inl index 587b9cd6..b83fefc6 100644 --- a/serialize/binary-reader.inl +++ b/serialize/binary-reader.inl @@ -19,8 +19,8 @@ template<string_input_iterator It> template<serializable T> constexpr T binary_reader<It>::read() noexcept(false) { - constexpr std::size_t N = sizeof(T); - fm_soft_assert((std::ptrdiff_t)N <= std::distance(it, end)); + constexpr size_t N = sizeof(T); + fm_soft_assert((ptrdiff_t)N <= std::distance(it, end)); num_bytes_read += N; char buf[N]; for (auto i = 0_uz; i < N; i++) @@ -29,13 +29,13 @@ constexpr T binary_reader<It>::read() noexcept(false) } template<string_input_iterator It> -template<std::size_t N> +template<size_t N> constexpr std::array<char, N> binary_reader<It>::read() noexcept(false) { std::array<char, N> array; if (std::is_constant_evaluated()) array = {}; - fm_soft_assert(N <= (std::size_t)std::distance(it, end)); + fm_soft_assert(N <= (size_t)std::distance(it, end)); num_bytes_read += N; for (auto i = 0_uz; i < N; i++) array[i] = *it++; @@ -61,14 +61,14 @@ constexpr void operator<<(T& x, binary_reader<It>& reader) noexcept(false) } template<string_input_iterator It> -template<std::size_t MAX> +template<size_t MAX> constexpr auto binary_reader<It>::read_asciiz_string() noexcept(false) { static_assert(MAX > 0); struct fixed_string final { char buf[MAX]; - std::size_t len; + size_t len; constexpr operator StringView() const noexcept { return { buf, len, StringViewFlag::NullTerminated }; } }; diff --git a/serialize/binary-serializer.cpp b/serialize/binary-serializer.cpp index 12163792..ddd8b401 100644 --- a/serialize/binary-serializer.cpp +++ b/serialize/binary-serializer.cpp @@ -11,7 +11,7 @@ constexpr bool test1() { constexpr std::array<char, 4> bytes = { 1, 2, 3, 4 }; auto x = binary_reader(bytes.cbegin(), bytes.cend()); - return x.read<std::uint32_t>() == 67305985; + return x.read<uint32_t>() == 67305985; } static_assert(test1()); @@ -20,7 +20,7 @@ constexpr bool test2() { constexpr std::array<char, 4> bytes = { 4, 3, 2, 1 }; auto r = binary_reader(bytes.cbegin(), bytes.cend()); - const auto x = r.read<std::uint32_t>(); + const auto x = r.read<uint32_t>(); r.assert_end(); return x == 16909060; } diff --git a/serialize/binary-serializer.hpp b/serialize/binary-serializer.hpp index 338173c2..f277aae9 100644 --- a/serialize/binary-serializer.hpp +++ b/serialize/binary-serializer.hpp @@ -1,7 +1,5 @@ #pragma once -#include <cstddef> -#include <cstdint> #include <bit> #include <concepts> #include <type_traits> @@ -10,14 +8,14 @@ namespace floormat::Serialize { static_assert(std::endian::native == std::endian::big || std::endian::native == std::endian::little); -template<std::size_t N> struct make_integer; -template<std::size_t N> using make_integer_t = typename make_integer<N>::type; +template<size_t N> struct make_integer; +template<size_t N> using make_integer_t = typename make_integer<N>::type; #define FM_SERIALIZE_MAKE_INTEGER(T) template<> struct make_integer<sizeof(T)> { using type = T; } -FM_SERIALIZE_MAKE_INTEGER(std::uint8_t); -FM_SERIALIZE_MAKE_INTEGER(std::uint16_t); -FM_SERIALIZE_MAKE_INTEGER(std::uint32_t); -FM_SERIALIZE_MAKE_INTEGER(std::uint64_t); +FM_SERIALIZE_MAKE_INTEGER(uint8_t); +FM_SERIALIZE_MAKE_INTEGER(uint16_t); +FM_SERIALIZE_MAKE_INTEGER(uint32_t); +FM_SERIALIZE_MAKE_INTEGER(uint64_t); #undef FN_SERIALIZE_MAKE_INTEGER template<typename T> diff --git a/serialize/binary-writer.hpp b/serialize/binary-writer.hpp index 098f9aa2..625bb53c 100644 --- a/serialize/binary-writer.hpp +++ b/serialize/binary-writer.hpp @@ -10,11 +10,11 @@ struct binary_writer final { explicit constexpr binary_writer(It it) noexcept; template<serializable T> constexpr void write(T x) noexcept; constexpr void write_asciiz_string(StringView str) noexcept; - constexpr std::size_t bytes_written() const noexcept { return _bytes_written; } + constexpr size_t bytes_written() const noexcept { return _bytes_written; } private: It it; - std::size_t _bytes_written; + size_t _bytes_written; }; template<std::output_iterator<char> It, serializable T> diff --git a/serialize/binary-writer.inl b/serialize/binary-writer.inl index a847903d..3a5b83d6 100644 --- a/serialize/binary-writer.inl +++ b/serialize/binary-writer.inl @@ -15,7 +15,7 @@ template<serializable T> constexpr void binary_writer<It>::write(T x) noexcept { _bytes_written += sizeof(T); - constexpr std::size_t N = sizeof(T); + constexpr size_t N = sizeof(T); const auto buf = std::bit_cast<std::array<char, N>, T>(maybe_byteswap(x)); for (auto i = 0_uz; i < N; i++) *it++ = buf[i]; diff --git a/serialize/json-helper.cpp b/serialize/json-helper.cpp index 9c3b5034..c350f92e 100644 --- a/serialize/json-helper.cpp +++ b/serialize/json-helper.cpp @@ -16,7 +16,7 @@ static T open_stream(StringView filename) if (!s) { char errbuf[128]; - constexpr auto get_error_string = []<std::size_t N> (char (&buf)[N]) + constexpr auto get_error_string = []<size_t N> (char (&buf)[N]) { buf[0] = '\0'; #ifndef _WIN32 diff --git a/serialize/magnum-vector.hpp b/serialize/magnum-vector.hpp index b8383d96..d1afc0db 100644 --- a/serialize/magnum-vector.hpp +++ b/serialize/magnum-vector.hpp @@ -5,14 +5,14 @@ namespace nlohmann { -template<std::size_t N, typename T> +template<size_t N, typename T> struct adl_serializer<Magnum::Math::Vector<N, T>> { using vec = Magnum::Math::Vector<N, T>; static void to_json(json& j, const vec& val); static void from_json(const json& j, vec& val); }; -template <std::size_t N, typename T> +template <size_t N, typename T> void adl_serializer<Magnum::Math::Vector<N, T>>::to_json(json& j, const vec& val) { std::array<T, N> array{}; @@ -22,7 +22,7 @@ void adl_serializer<Magnum::Math::Vector<N, T>>::to_json(json& j, const vec& val to_json(j, array); } -template <std::size_t N, typename T> +template <size_t N, typename T> void adl_serializer<Magnum::Math::Vector<N, T>>::from_json(const json& j, vec& val) { std::array<T, N> array{}; diff --git a/serialize/magnum-vector2i.hpp b/serialize/magnum-vector2i.hpp index f63bd130..aa2c3939 100644 --- a/serialize/magnum-vector2i.hpp +++ b/serialize/magnum-vector2i.hpp @@ -14,7 +14,7 @@ struct adl_serializer<Magnum::Math::Vector2<t>> final static void to_json(json& j, const Magnum::Math::Vector2<t>& val) { char buf[64]; - using type = std::conditional_t<std::is_signed_v<t>, std::intmax_t, std::uintmax_t>; + using type = std::conditional_t<std::is_signed_v<t>, intmax_t, uintmax_t>; constexpr auto format_string = std::is_signed_v<t> ? "%jd x %jd" : "%ju x %ju"; snprintf(buf, sizeof(buf), format_string, (type)val[0], (type)val[1]); j = buf; @@ -23,12 +23,12 @@ struct adl_serializer<Magnum::Math::Vector2<t>> final { using namespace floormat; std::string str = j; - using type = std::conditional_t<std::is_signed_v<t>, std::intmax_t, std::uintmax_t>; + using type = std::conditional_t<std::is_signed_v<t>, intmax_t, uintmax_t>; constexpr auto format_string = std::is_signed_v<t> ? "%jd x %jd%n" : "%ju x %ju%n"; type x = 0, y = 0; int n = 0; int ret = std::sscanf(str.data(), format_string, &x, &y, &n); - if (ret != 2 || (std::size_t)n != str.size() || x != (t)x || y != (t)y) + if (ret != 2 || (size_t)n != str.size() || x != (t)x || y != (t)y) fm_throw("failed to parse Vector2 '{}'"_cf, str); val = { (t)x, (t)y }; } diff --git a/serialize/pass-mode.cpp b/serialize/pass-mode.cpp index 6d52a5de..e06bf99d 100644 --- a/serialize/pass-mode.cpp +++ b/serialize/pass-mode.cpp @@ -26,7 +26,7 @@ void adl_serializer<pass_mode>::to_json(json& j, pass_mode val) j = str; return; } - fm_throw("invalid pass mode '{}'"_cf, std::size_t(val)); + fm_throw("invalid pass mode '{}'"_cf, size_t(val)); } void adl_serializer<pass_mode>::from_json(const json& j, pass_mode& val) diff --git a/serialize/scenery.cpp b/serialize/scenery.cpp index 3cd084cd..6bcd5fa9 100644 --- a/serialize/scenery.cpp +++ b/serialize/scenery.cpp @@ -38,7 +38,7 @@ constexpr struct { { rotation::NW, "nw"_s }, }; -template<std::size_t N, typename T> +template<size_t N, typename T> auto foo_from_string(StringView str, const T(&map)[N], const char* desc) { for (const auto& [value, str2] : map) @@ -47,13 +47,13 @@ auto foo_from_string(StringView str, const T(&map)[N], const char* desc) fm_throw("wrong {} string '{}'"_cf, desc, str); } -template<std::size_t N, typename T> +template<size_t N, typename T> StringView foo_to_string(auto type, const T(&map)[N], const char* desc) { for (const auto& [type2, str] : map) if (type2 == type) return str; - fm_throw("wrong {} enum '{}'"_cf, desc, (std::size_t)type); + fm_throw("wrong {} enum '{}'"_cf, desc, (size_t)type); } } // namespace @@ -153,7 +153,7 @@ void adl_serializer<scenery_proto>::from_json(const json& j, scenery_proto& f) f.type = entity_type::scenery; f.sc_type = scenery_type::door; f.r = r; - f.frame = std::uint16_t(f.atlas->group(r).frames.size()-1); + f.frame = uint16_t(f.atlas->group(r).frames.size()-1); f.pass = pass_mode::blocked; f.interactive = true; f.closing = false; diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp index 068c1d9b..b56239c6 100644 --- a/serialize/tile-atlas.cpp +++ b/serialize/tile-atlas.cpp @@ -54,7 +54,7 @@ void adl_serializer<std::shared_ptr<tile_atlas>>::from_json(const json& j, std:: { int m = p2 ? int(*p2) : -1; const auto name = val->name(); - fm_throw("atlas {} wrong pass mode {} should be {}"_cf, StringView{name.data(), name.size()}, m, std::uint8_t(*p)); + fm_throw("atlas {} wrong pass mode {} should be {}"_cf, StringView{name.data(), name.size()}, m, uint8_t(*p)); } } } diff --git a/serialize/tile.cpp b/serialize/tile.cpp index 8b756772..1b6158e7 100644 --- a/serialize/tile.cpp +++ b/serialize/tile.cpp @@ -12,7 +12,7 @@ inline void to_json(nlohmann::json& j, const tile_image_ref& val) { j = tile_ima inline void from_json(const nlohmann::json& j, tile_image_ref& val) { val = tile_image_proto(j); } struct local_coords_ final { - std::uint8_t x, y; + uint8_t x, y; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(local_coords_, x, y) diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp index 3487d854..0756250c 100644 --- a/serialize/world-impl.hpp +++ b/serialize/world-impl.hpp @@ -8,8 +8,6 @@ #include "src/rotation.hpp" #include "src/entity-type.hpp" #include <bit> -#include <cstddef> -#include <cstdint> #include <cstdio> #include <limits> @@ -32,10 +30,10 @@ struct entity_proto; namespace floormat::Serialize { -using tilemeta = std::uint8_t; -using atlasid = std::uint16_t; -using chunksiz = std::uint16_t; -using proto_t = std::uint16_t; +using tilemeta = uint8_t; +using atlasid = uint16_t; +using chunksiz = uint16_t; +using proto_t = uint16_t; namespace { @@ -43,15 +41,15 @@ template<typename T> constexpr inline T int_max = std::numeric_limits<T>::max(); #define file_magic ".floormat.save" -constexpr inline std::size_t atlas_name_max = 128; +constexpr inline size_t atlas_name_max = 128; constexpr inline auto null_atlas = (atlasid)-1LL; -constexpr inline std::size_t character_name_max = 128; +constexpr inline size_t character_name_max = 128; constexpr inline proto_t proto_version = 8; constexpr inline proto_t min_proto_version = 1; -constexpr inline auto chunk_magic = (std::uint16_t)~0xc0d3; -constexpr inline auto scenery_magic = (std::uint16_t)~0xb00b; +constexpr inline auto chunk_magic = (uint16_t)~0xc0d3; +constexpr inline auto scenery_magic = (uint16_t)~0xb00b; using pass_mode_i = std::underlying_type_t<pass_mode>; constexpr inline pass_mode_i pass_mask = pass_mode_COUNT - 1; @@ -59,7 +57,7 @@ constexpr inline auto pass_bits = std::bit_width(pass_mask); using entity_type_i = std::underlying_type_t<entity_type>; template<typename T> constexpr inline auto highbit = T(1) << sizeof(T)*8-1; -template<typename T, std::size_t N, std::size_t off> +template<typename T, size_t N, size_t off> constexpr inline auto highbits = (T(1) << N)-1 << sizeof(T)*8-N-off; constexpr inline atlasid meta_short_scenery_bit = highbit<atlasid>; diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index 0b84dbf0..0a99f74f 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -28,12 +28,12 @@ private: void read_atlases(reader_t& reader); void read_sceneries(reader_t& reader); void read_chunks(reader_t& reader); - void read_old_scenery(reader_t& s, chunk_coords ch, std::size_t i); + void read_old_scenery(reader_t& s, chunk_coords ch, size_t i); std::vector<scenery_proto> sceneries; std::vector<std::shared_ptr<tile_atlas>> atlases; world* _world; - std::uint16_t PROTO = 0; + uint16_t PROTO = 0; }; reader_state::reader_state(world& world) noexcept : _world{&world} {} @@ -58,7 +58,7 @@ template<typename T, entity_subtype U> bool read_entity_flags(binary_reader<T>& s, U& e) { constexpr auto tag = entity_type_<U>::value; - std::uint8_t flags; flags << s; + uint8_t flags; flags << s; e.pass = pass_mode(flags & pass_mask); if (e.type != tag) fm_abort("invalid entity type '%d'", (int)e.type); @@ -81,7 +81,7 @@ void reader_state::read_sceneries(reader_t& s) { (void)loader.sceneries(); - std::uint16_t magic; magic << s; + uint16_t magic; magic << s; if (magic != scenery_magic) fm_throw("bad scenery magic"_cf); atlasid sz; sz << s; @@ -91,7 +91,7 @@ void reader_state::read_sceneries(reader_t& s) auto i = 0_uz; while (i < sz) { - std::uint8_t num; num << s; + uint8_t num; num << s; fm_soft_assert(num > 0); auto str = s.read_asciiz_string<atlas_name_max>(); auto sc = loader.scenery(str); @@ -103,7 +103,7 @@ void reader_state::read_sceneries(reader_t& s) bool short_frame = read_entity_flags(s, sc); fm_debug_assert(sc.atlas != nullptr); if (short_frame) - sc.frame = s.read<std::uint8_t>(); + sc.frame = s.read<uint8_t>(); else sc.frame << s; fm_soft_assert(sc.frame < sc.atlas->info().nframes); @@ -140,7 +140,7 @@ void reader_state::read_chunks(reader_t& s) { const auto N = s.read<chunksiz>(); #ifndef FM_NO_DEBUG - [[maybe_unused]] std::size_t nbytes_read = 0; + [[maybe_unused]] size_t nbytes_read = 0; #endif for (auto k = 0_uz; k < N; k++) @@ -161,7 +161,7 @@ void reader_state::read_chunks(reader_t& s) SET_CHUNK_SIZE(); const tilemeta flags = s.read<tilemeta>(); tile_ref t = c[i]; - using uchar = std::uint8_t; + using uchar = uint8_t; const auto make_atlas = [&]() -> tile_image_proto { atlasid id; if (PROTO < 8) [[unlikely]] @@ -173,8 +173,8 @@ void reader_state::read_chunks(reader_t& s) v << s; else v = flags & meta_short_variant_ - ? s.read<std::uint8_t>() - : std::uint8_t(s.read<std::uint16_t>()); + ? s.read<uint8_t>() + : uint8_t(s.read<uint16_t>()); auto atlas = lookup_atlas(id); fm_soft_assert(v < atlas->num_tiles()); return { atlas, v }; @@ -192,7 +192,7 @@ void reader_state::read_chunks(reader_t& s) read_old_scenery(s, ch, i); SET_CHUNK_SIZE(); } - std::uint32_t entity_count = 0; + uint32_t entity_count = 0; if (PROTO >= 8) [[likely]] entity_count << s; @@ -200,12 +200,12 @@ void reader_state::read_chunks(reader_t& s) for (auto i = 0_uz; i < entity_count; i++) { - std::uint64_t _id; _id << s; + object_id _id; _id << s; const auto oid = _id & (1ULL << 60)-1; fm_soft_assert(oid != 0); static_assert(entity_type_BITS == 3); const auto type = entity_type(_id >> 61); - const auto local = local_coords{s.read<std::uint8_t>()}; + const auto local = local_coords{s.read<uint8_t>()}; constexpr auto read_offsets = [](auto& s, auto& e) { s >> e.offset[0]; s >> e.offset[1]; @@ -219,10 +219,10 @@ void reader_state::read_chunks(reader_t& s) { case entity_type::character: { character_proto proto; - std::uint8_t id; id << s; + uint8_t id; id << s; proto.r = rotation(id >> sizeof(id)*8-1-rotation_BITS & rotation_MASK); if (read_entity_flags(s, proto)) - proto.frame = s.read<std::uint8_t>(); + proto.frame = s.read<uint8_t>(); else proto.frame << s; Vector2s offset_frac; @@ -249,7 +249,7 @@ void reader_state::read_chunks(reader_t& s) if (!exact) { if (read_entity_flags(s, sc)) - sc.frame = s.read<std::uint8_t>(); + sc.frame = s.read<uint8_t>(); else sc.frame << s; read_offsets(s, sc); @@ -276,7 +276,7 @@ void reader_state::read_chunks(reader_t& s) } } -void reader_state::read_old_scenery(reader_t& s, chunk_coords ch, std::size_t i) +void reader_state::read_old_scenery(reader_t& s, chunk_coords ch, size_t i) { atlasid id; id << s; const bool exact = id & meta_short_scenery_bit; @@ -288,7 +288,7 @@ void reader_state::read_old_scenery(reader_t& s, chunk_coords ch, std::size_t i) if (!exact) { if (read_entity_flags(s, sc)) - sc.frame = s.read<std::uint8_t>(); + sc.frame = s.read<uint8_t>(); else sc.frame << s; if (PROTO >= 5) [[likely]] @@ -311,7 +311,7 @@ void reader_state::read_old_scenery(reader_t& s, chunk_coords ch, std::size_t i) if (PROTO >= 4) [[likely]] sc.delta << s; else - sc.delta = (std::uint16_t)Math::clamp(int(s.read<float>() * 65535), 0, 65535); + sc.delta = (uint16_t)Math::clamp(int(s.read<float>() * 65535), 0, 65535); } } global_coords coord{ch, local_coords{i}}; @@ -329,10 +329,10 @@ void reader_state::deserialize_world(ArrayView<const char> buf) proto << s; if (!(proto >= min_proto_version && proto <= proto_version)) fm_throw("bad proto version '{}' (should be between '{}' and '{}')"_cf, - (std::size_t)proto, (std::size_t)min_proto_version, (std::size_t)proto_version); + (size_t)proto, (size_t)min_proto_version, (size_t)proto_version); PROTO = proto; fm_assert(PROTO > 0); - std::uint64_t entity_counter = 0; + object_id entity_counter = 0; read_atlases(s); if (PROTO >= 3) [[likely]] read_sceneries(s); @@ -355,7 +355,7 @@ namespace floormat { world world::deserialize(StringView filename) { char errbuf[128]; - constexpr auto get_error_string = []<std::size_t N> (char (&buf)[N]) -> const char* { + constexpr auto get_error_string = []<size_t N> (char (&buf)[N]) -> const char* { buf[0] = '\0'; #ifndef _WIN32 (void)::strerror_r(errno, buf, std::size(buf)); @@ -372,9 +372,9 @@ world world::deserialize(StringView filename) } if (int ret = ::fseek(f, 0, SEEK_END); ret != 0) fm_throw("fseek(SEEK_END): {}"_cf, get_error_string(errbuf)); - std::size_t len; + size_t len; if (auto len_ = ::ftell(f); len_ >= 0) - len = (std::size_t)len_; + len = (size_t)len_; else fm_throw("ftell: {}"_cf, get_error_string(errbuf)); if (int ret = ::fseek(f, 0, SEEK_SET); ret != 0) diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index e04dad36..801657e5 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -166,7 +166,7 @@ scenery_pair writer_state::intern_scenery(const scenery& sc, bool create) template<typename T, entity_subtype U> void write_entity_flags(binary_writer<T>& s, const U& e) { - std::uint8_t flags = 0; + uint8_t flags = 0; auto pass = (pass_mode_i)e.pass; fm_assert((pass & pass_mask) == pass); flags |= pass; @@ -225,12 +225,12 @@ void writer_state::serialize_atlases() } constexpr auto atlasbuf_size0 = sizeof(atlasid) + sizeof(scenery); -constexpr auto atlasbuf_size1 = sizeof(std::uint8_t) + atlasbuf_size0*int_max<std::uint8_t> + atlas_name_max; +constexpr auto atlasbuf_size1 = sizeof(uint8_t) + atlasbuf_size0*int_max<uint8_t> + atlas_name_max; void writer_state::serialize_scenery() { fm_assert(scenery_map_size < scenery_id_max); - const std::size_t sz = scenery_map_size; + const size_t sz = scenery_map_size; std::vector<interned_scenery> vec; vec.reserve(scenery_map_size); for (const auto& x : scenery_map) for (const auto& s : x.second) @@ -246,12 +246,12 @@ void writer_state::serialize_scenery() return cmp == std::strong_ordering::less; }); - const auto atlasbuf_size = sizeof(std::uint16_t) + sizeof(sz) + atlasbuf_size1*sz; + const auto atlasbuf_size = sizeof(uint16_t) + sizeof(sz) + atlasbuf_size1*sz; scenery_buf.resize(atlasbuf_size); auto s = binary_writer{scenery_buf.begin()}; - s << std::uint16_t{scenery_magic}; + s << uint16_t{scenery_magic}; fm_assert(sz < scenery_id_max); s << (atlasid)sz; @@ -267,14 +267,14 @@ void writer_state::serialize_scenery() auto num = 1_uz; for (auto j = i+1; j < sz && vec[j].s->name == sc->name; j++) num++; - fm_assert(num < int_max<std::uint8_t>); - s << (std::uint8_t)num; + fm_assert(num < int_max<uint8_t>); + s << (uint8_t)num; s.write_asciiz_string(sc->name); } s << idx; write_entity_flags(s, sc->proto); if (sc->proto.frame <= 0xff) - s << (std::uint8_t)sc->proto.frame; + s << (uint8_t)sc->proto.frame; else s << sc->proto.frame; } @@ -288,7 +288,7 @@ const auto def_char_pass = character_proto{}.pass; void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) { fm_assert(chunk_buf.empty()); - const auto es_size = sizeof(std::uint32_t) + entity_size*c.entities().size(); + const auto es_size = sizeof(uint32_t) + entity_size*c.entities().size(); chunk_buf.resize(chunkbuf_size + es_size); auto s = binary_writer{chunk_buf.begin()}; @@ -337,17 +337,17 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) } } - const auto entity_count = (std::uint32_t)c.entities().size(); + const auto entity_count = (uint32_t)c.entities().size(); s << entity_count; fm_assert(entity_count == c.entities().size()); for (const auto& e_ : c.entities()) { const auto& e = *e_; - std::uint64_t oid = e.id; - fm_assert((oid & ((std::uint64_t)1 << 60)-1) == oid); + object_id oid = e.id; + fm_assert((oid & ((object_id)1 << 60)-1) == oid); static_assert(entity_type_BITS == 3); fm_assert(((entity_type_i)e.type & (1 << entity_type_BITS)-1) == (entity_type_i)e.type); - oid |= (std::uint64_t)e.type << 64 - entity_type_BITS; + oid |= (object_id)e.type << 64 - entity_type_BITS; s << oid; const auto local = e.coord.local(); s << local.to_index(); @@ -365,7 +365,7 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) fm_abort("invalid entity type '%d'", (int)e.type); case entity_type::character: { const auto& C = static_cast<const character&>(e); - std::uint8_t id = 0; + uint8_t id = 0; const auto sc_exact = C.offset.isZero() && C.bbox_offset.isZero() && C.bbox_size == def_char_bbox_size; @@ -374,7 +374,7 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) s << id; write_entity_flags(s, C); if (C.frame <= 0xff) - s << (std::uint8_t)C.frame; + s << (uint8_t)C.frame; else s << C.frame; s << C.offset_frac[0]; @@ -403,7 +403,7 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) write_entity_flags(s, sc); fm_assert(sc.active || sc.delta == 0); if (sc.frame <= 0xff) - s << (std::uint8_t)sc.frame; + s << (uint8_t)sc.frame; else s << sc.frame; write_offsets(s, sc); @@ -473,7 +473,7 @@ ArrayView<const char> writer_state::serialize_world() len += sizeof(proto_t); len += atlas_buf.size(); len += scenery_buf.size(); - len += sizeof(std::uint64_t); + len += sizeof(object_id); len += sizeof(chunksiz); for (const auto& buf : chunk_bufs) len += buf.size(); @@ -487,7 +487,7 @@ ArrayView<const char> writer_state::serialize_world() len2 = std::distance(it, file_buf.end()); fm_assert(len1 <= len2); it = std::copy(std::cbegin(in), std::cend(in), it); - bytes_written += (std::size_t)len1; + bytes_written += (size_t)len1; }; const auto copy_int = [&]<typename T>(const T& value) { union { T x; char bytes[sizeof x]; } c = {.x = maybe_byteswap(value)}; @@ -497,7 +497,7 @@ ArrayView<const char> writer_state::serialize_world() copy_int((proto_t)proto_version); copy(atlas_buf); copy(scenery_buf); - copy_int((std::uint64_t)_world->entity_counter()); + copy_int((object_id)_world->entity_counter()); copy_int((chunksiz)_world->size()); for (const auto& buf : chunk_bufs) copy(buf); @@ -521,7 +521,7 @@ void world::serialize(StringView filename) { collect(true); char errbuf[128]; - constexpr auto get_error_string = []<std::size_t N> (char (&buf)[N]) -> const char* { + constexpr auto get_error_string = []<size_t N> (char (&buf)[N]) -> const char* { buf[0] = '\0'; #ifndef _WIN32 (void)::strerror_r(errno, buf, std::size(buf)); |