summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/save.cpp (renamed from editor/json.cpp)31
-rw-r--r--serialize/world-impl.hpp4
-rw-r--r--serialize/world-reader.cpp9
-rw-r--r--serialize/world-writer.cpp2
-rw-r--r--src/world.hpp2
5 files changed, 16 insertions, 32 deletions
diff --git a/editor/json.cpp b/editor/save.cpp
index 777f9d22..6b6f5ce2 100644
--- a/editor/json.cpp
+++ b/editor/save.cpp
@@ -5,16 +5,9 @@
namespace floormat {
-#define FM_SAVE_BINARY
-
-#ifdef FM_SAVE_BINARY
-#define quicksave_file save_dir "/" "quicksave.dat"
-#else
-#define quicksave_file save_dir "/" "quicksave.json"
-#endif
-
#define save_dir "../save"
-#define quicksave_tmp quicksave_file ".tmp"
+#define quicksave_file save_dir "/" "quicksave.dat"
+#define quicksave_tmp save_dir "/" "quicksave.tmp"
namespace Path = Corrade::Utility::Path;
using std::filesystem::path;
@@ -38,30 +31,24 @@ void app::do_quicksave()
world.collect(true);
if (Path::exists(quicksave_tmp))
Path::remove(quicksave_tmp);
- fputs("quicksave...", stderr); fflush(stderr);
+ fputs("quicksave... ", stderr); fflush(stderr);
world.serialize(quicksave_tmp);
Path::move(quicksave_tmp, quicksave_file);
- fputs(" done\n", stderr); fflush(stderr);
+ fputs("done\n", stderr); fflush(stderr);
}
void app::do_quickload()
{
- ensure_save_directory();
+ if (!ensure_save_directory())
+ return;
if (!Path::exists(quicksave_file))
{
fm_warn("no quicksave");
return;
}
- auto& world = M->world();
- fputs("quickload...", stderr); fflush(stderr);
-#if 0
-#ifdef FM_SAVE_BINARY
- world = json_helper::from_binary<struct world>(quicksave_file);
-#else
- world = json_helper::from_json<struct world>(quicksave_file);
-#endif
-#endif
- fputs(" done\n", stderr); fflush(stderr);
+ fputs("quickload... ", stderr); fflush(stderr);
+ M->world() = world::deserialize(quicksave_file);
+ fputs("done\n", stderr); fflush(stderr);
}
} // namespace floormat
diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp
index 26073edd..252f361e 100644
--- a/serialize/world-impl.hpp
+++ b/serialize/world-impl.hpp
@@ -1,5 +1,3 @@
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-macros"
#ifndef FM_SERIALIZE_WORLD_IMPL
#error "not meant to be included directly"
#endif
@@ -56,5 +54,3 @@ private:
} // namespace
} // namespace floormat
-
-#pragma clang diagnostic pop
diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp
index 299386de..4b5d365c 100644
--- a/serialize/world-reader.cpp
+++ b/serialize/world-reader.cpp
@@ -64,7 +64,7 @@ void reader_state::read_chunks(reader_t& s)
for (std::size_t i = 0; i < TILE_COUNT; i++)
{
const tilemeta flags = s.read<tilemeta>();
- const auto make_atlas = [&] -> tile_image {
+ const auto make_atlas = [&]() -> tile_image {
auto atlas = lookup_atlas(s.read<atlasid>());
auto id = s.read<imgvar>();
return { atlas, id };
@@ -120,7 +120,7 @@ world world::deserialize(StringView filename)
return buf;
};
fm_assert(filename.flags() & StringViewFlag::NullTerminated);
- FILE_raii f = ::fopen(filename.data(), "r");
+ FILE_raii f = ::fopen(filename.data(), "rb");
if (!f)
fm_abort("fopen(\"%s\", \"r\"): %s", filename.data(), strerror(errbuf));
if (int ret = ::fseek(f, 0, SEEK_END); ret != 0)
@@ -133,8 +133,9 @@ world world::deserialize(StringView filename)
if (int ret = ::fseek(f, 0, SEEK_SET); ret != 0)
fm_abort("fseek(SEEK_SET): %s", strerror(errbuf));
auto buf_ = std::make_unique<char[]>(len);
- if (auto ret = ::fread(&buf_[0], len, 1, f); ret != 1)
- fm_abort("fread %zu: %s", len, strerror(errbuf));
+
+ if (auto ret = ::fread(&buf_[0], 1, len, f); ret != len)
+ fm_abort("fread short read: %s", strerror(errbuf));
world w;
Serialize::reader_state s{w};
diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp
index c0f59e9b..faf60849 100644
--- a/serialize/world-writer.cpp
+++ b/serialize/world-writer.cpp
@@ -217,7 +217,7 @@ void world::serialize(StringView filename)
fm_assert(filename.flags() & StringViewFlag::NullTerminated);
if (Path::exists(filename))
Path::remove(filename);
- FILE_raii file = ::fopen(filename.data(), "w");
+ FILE_raii file = ::fopen(filename.data(), "wb");
if (!file)
fm_abort("fopen(\"%s\", \"w\"): %s", filename.data(), strerror(errbuf));
Serialize::writer_state s{*this};
diff --git a/src/world.hpp b/src/world.hpp
index a18f41f8..ae7b6240 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -39,7 +39,7 @@ public:
bool contains(chunk_coords c) const noexcept;
void clear();
void collect(bool force = false);
- constexpr std::size_t size() const noexcept { return _chunks.size(); }
+ std::size_t size() const noexcept { return _chunks.size(); }
[[deprecated]] const auto& chunks() const noexcept { return _chunks; } // only for serialization