From 5a95eb1282e30bd803d7e0b352a8443795842e42 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 2 Nov 2022 19:03:32 +0100 Subject: fix build with Linux and/or GCC --- serialize/anim.hpp | 2 -- serialize/json-helper.hpp | 3 +-- serialize/world-impl.hpp | 8 ++++---- serialize/world-reader.cpp | 15 ++++++++------- serialize/world-writer.cpp | 19 ++++++++++--------- 5 files changed, 23 insertions(+), 24 deletions(-) (limited to 'serialize') diff --git a/serialize/anim.hpp b/serialize/anim.hpp index 957e733e..85d5facd 100644 --- a/serialize/anim.hpp +++ b/serialize/anim.hpp @@ -8,8 +8,6 @@ #include #include -namespace std::filesystem { class path; } - namespace floormat::Serialize { struct anim_frame final diff --git a/serialize/json-helper.hpp b/serialize/json-helper.hpp index 42cd73b3..e0e2c0ca 100644 --- a/serialize/json-helper.hpp +++ b/serialize/json-helper.hpp @@ -1,7 +1,6 @@ #pragma once #include - -namespace std::filesystem { class path; } +#include namespace floormat { diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp index caf5e8a7..4c206a7e 100644 --- a/serialize/world-impl.hpp +++ b/serialize/world-impl.hpp @@ -9,14 +9,14 @@ namespace floormat::Serialize { -namespace { - using tilemeta = std::uint8_t; using varid = decltype(tile_image_proto::variant); using atlasid = std::uint16_t; using chunksiz = std::uint16_t; using proto_t = std::uint16_t; +namespace { + template constexpr inline T int_max = std::numeric_limits::max(); #define file_magic ".floormat.save" @@ -30,6 +30,8 @@ constexpr inline auto chunk_magic = (std::uint16_t)~0xc0d3; constexpr inline std::underlying_type_t pass_mask = pass_blocked | pass_shoot_through | pass_ok; constexpr inline auto pass_bits = std::bit_width(pass_mask); +} // namespace + enum : tilemeta { meta_ground = 1 << (pass_bits + 0), meta_wall_n = 1 << (pass_bits + 1), @@ -38,8 +40,6 @@ enum : tilemeta { meta_short_variant = 1 << (pass_bits + 4), }; -} // namespace - } // namespace floormat::Serialize namespace floormat { diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index aa156609..e55ea059 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -4,11 +4,10 @@ #include "src/world.hpp" #include "src/loader.hpp" #include "src/tile-atlas.hpp" +#include namespace floormat::Serialize { -namespace { - struct reader_state final { explicit reader_state(world& world) noexcept; void deserialize_world(ArrayView buf); @@ -21,10 +20,10 @@ private: void read_chunks(reader_t& reader); std::unordered_map> atlases; - struct world* world; + world* _world; }; -reader_state::reader_state(struct world& world) noexcept : world{&world} {} +reader_state::reader_state(world& world) noexcept : _world{&world} {} void reader_state::read_atlases(reader_t& s) { @@ -61,7 +60,7 @@ void reader_state::read_chunks(reader_t& s) chunk_coords coord; s >> coord.x; s >> coord.y; - auto& chunk = (*world)[coord]; + auto& chunk = (*_world)[coord]; for (std::size_t i = 0; i < TILE_COUNT; i++) { const tilemeta flags = s.read(); @@ -111,8 +110,6 @@ void reader_state::deserialize_world(ArrayView buf) s.assert_end(); } -} // namespace - } // namespace floormat::Serialize namespace floormat { @@ -121,7 +118,11 @@ world world::deserialize(StringView filename) { char errbuf[128]; constexpr auto strerror = [] (char (&buf)[N]) -> const char* { +#ifndef _WIN32 + ::strerror_r(errno, buf, std::size(buf)); +#else ::strerror_s(buf, std::size(buf), errno); +#endif return buf; }; fm_assert(filename.flags() & StringViewFlag::NullTerminated); diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index c16dc32a..c33947dc 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -8,6 +8,7 @@ #include "src/world.hpp" #include #include +#include #include #include @@ -15,8 +16,6 @@ namespace Path = Corrade::Utility::Path; namespace floormat::Serialize { -namespace { - struct interned_atlas final { const tile_atlas* img; atlasid index; @@ -34,7 +33,7 @@ private: void serialize_chunk(const chunk& c, chunk_coords coord); void serialize_atlases(); - const struct world* world; + const world* _world; std::vector atlas_buf, chunk_buf, file_buf; std::vector> chunk_bufs; std::unordered_map tile_images; @@ -53,7 +52,7 @@ constexpr auto chunkbuf_size = #pragma warning(disable : 4996) #endif -writer_state::writer_state(const struct world& world) : world{&world} +writer_state::writer_state(const world& world) : _world{&world} { chunk_buf.reserve(chunkbuf_size); chunk_bufs.reserve(world.chunks().size()); @@ -201,7 +200,7 @@ void writer_state::serialize_atlases() ArrayView writer_state::serialize_world() { - for (const auto& [pos, c] : world->chunks()) + for (const auto& [pos, c] : _world->chunks()) { #ifndef FM_NO_DEBUG if (c.empty(true)) @@ -212,9 +211,9 @@ ArrayView writer_state::serialize_world() serialize_atlases(); using proto_t = std::decay_t; - union { chunksiz x; char bytes[sizeof x]; } c = {.x = maybe_byteswap((chunksiz)world->size())}; + union { chunksiz x; char bytes[sizeof x]; } c = {.x = maybe_byteswap((chunksiz)_world->size())}; union { proto_t x; char bytes[sizeof x]; } p = {.x = maybe_byteswap(proto_version)}; - fm_assert(world->size() <= int_max); + fm_assert(_world->size() <= int_max); std::size_t len = 0; len += std::size(file_magic)-1; @@ -248,8 +247,6 @@ ArrayView writer_state::serialize_world() #pragma warning(pop) #endif -} // namespace - } // namespace floormat::Serialize namespace floormat { @@ -259,7 +256,11 @@ void world::serialize(StringView filename) collect(true); char errbuf[128]; constexpr auto strerror = [] (char (&buf)[N]) -> const char* { +#ifndef _WIN32 + ::strerror_r(errno, buf, std::size(buf)); +#else ::strerror_s(buf, std::size(buf), errno); +#endif return buf; }; fm_assert(filename.flags() & StringViewFlag::NullTerminated); -- cgit v1.2.3