summaryrefslogtreecommitdiffhomepage
path: root/serialize
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-02 19:03:32 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-02 20:25:31 +0100
commit5a95eb1282e30bd803d7e0b352a8443795842e42 (patch)
treec97bc43e4d5107a427817c65aa1b0c2eeb64a427 /serialize
parent0fe5336b9a53f20817f54be0bd7cd935db14914c (diff)
fix build with Linux and/or GCC
Diffstat (limited to 'serialize')
-rw-r--r--serialize/anim.hpp2
-rw-r--r--serialize/json-helper.hpp3
-rw-r--r--serialize/world-impl.hpp8
-rw-r--r--serialize/world-reader.cpp15
-rw-r--r--serialize/world-writer.cpp19
5 files changed, 23 insertions, 24 deletions
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 <Magnum/Math/Vector2.h>
#include <nlohmann/json_fwd.hpp>
-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 <nlohmann/json.hpp>
-
-namespace std::filesystem { class path; }
+#include <filesystem>
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<typename T> constexpr inline T int_max = std::numeric_limits<T>::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_mode> 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 <cstring>
namespace floormat::Serialize {
-namespace {
-
struct reader_state final {
explicit reader_state(world& world) noexcept;
void deserialize_world(ArrayView<const char> buf);
@@ -21,10 +20,10 @@ private:
void read_chunks(reader_t& reader);
std::unordered_map<atlasid, std::shared_ptr<tile_atlas>> 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<tilemeta>();
@@ -111,8 +110,6 @@ void reader_state::deserialize_world(ArrayView<const char> 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 = []<std::size_t N> (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 <vector>
#include <algorithm>
+#include <cstring>
#include <Corrade/Containers/StringView.h>
#include <Corrade/Utility/Path.h>
@@ -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<char> atlas_buf, chunk_buf, file_buf;
std::vector<std::vector<char>> chunk_bufs;
std::unordered_map<const void*, interned_atlas> 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<const char> 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<const char> writer_state::serialize_world()
serialize_atlases();
using proto_t = std::decay_t<decltype(proto_version)>;
- 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<chunksiz>);
+ fm_assert(_world->size() <= int_max<chunksiz>);
std::size_t len = 0;
len += std::size(file_magic)-1;
@@ -248,8 +247,6 @@ ArrayView<const char> 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 = []<std::size_t N> (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);