summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/save.cpp2
-rw-r--r--loader/loader.hpp6
-rw-r--r--loader/policy.hpp10
-rw-r--r--serialize/old-savegame.cpp13
-rw-r--r--serialize/savegame.cpp10
-rw-r--r--src/world.hpp5
-rw-r--r--test/serializer.cpp4
7 files changed, 30 insertions, 20 deletions
diff --git a/editor/save.cpp b/editor/save.cpp
index e9ab39a8..ef14c11c 100644
--- a/editor/save.cpp
+++ b/editor/save.cpp
@@ -53,7 +53,7 @@ void app::do_quickload()
return;
}
fputs("quickload... ", stderr); fflush(stderr);
- reset_world(world::deserialize(file));
+ reset_world(world::deserialize(file, loader_policy::warn));
fputs("done\n", stderr); fflush(stderr);
}
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 5c72a719..a9b1d262 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "compat/defs.hpp"
#include "src/pass-mode.hpp"
+#include "loader/policy.hpp"
#include <stdio.h>
#include <memory>
#include <Corrade/Containers/String.h>
@@ -29,11 +30,6 @@ struct vobj_info final
std::shared_ptr<anim_atlas> atlas;
};
-enum class loader_policy : uint8_t
-{
- error, warn, ignore, DEFAULT = error,
-};
-
struct loader_
{
virtual StringView shader(StringView filename) noexcept = 0;
diff --git a/loader/policy.hpp b/loader/policy.hpp
new file mode 100644
index 00000000..438b4248
--- /dev/null
+++ b/loader/policy.hpp
@@ -0,0 +1,10 @@
+#pragma once
+
+namespace floormat {
+
+enum class loader_policy : uint8_t
+{
+ error, warn, ignore, DEFAULT = error,
+};
+
+} // namespace floormat
diff --git a/serialize/old-savegame.cpp b/serialize/old-savegame.cpp
index 8a050022..df0cbbb5 100644
--- a/serialize/old-savegame.cpp
+++ b/serialize/old-savegame.cpp
@@ -118,7 +118,7 @@ constexpr inline atlasid scenery_id_flag_mask_ = meta_short_scenery_bit_ | meta_
constexpr inline atlasid scenery_id_max_ = int_traits<atlasid>::max & ~scenery_id_flag_mask_;
struct reader_state final {
- explicit reader_state(world& world) noexcept;
+ explicit reader_state(world& world, loader_policy policy) noexcept;
void deserialize_world(ArrayView<const char> buf, proto_t proto);
private:
@@ -139,13 +139,14 @@ private:
std::vector<String> atlases;
world* _world;
uint16_t PROTO = proto_version;
+ loader_policy asset_policy;
Array<chunk::object_draw_order> draw_array;
Array<std::array<chunk::vertex, 4>> draw_vertexes;
Array<std::array<UnsignedShort, 6>> draw_indexes;
};
-reader_state::reader_state(world& world) noexcept : _world{&world} {}
+reader_state::reader_state(world& world, loader_policy p) noexcept : _world{&world}, asset_policy{p} {}
void reader_state::read_atlases(reader_t& s)
{
@@ -325,13 +326,13 @@ void reader_state::read_chunks(reader_t& s)
auto name = lookup_atlas(id);
if constexpr(std::is_same_v<ground_atlas, T>)
{
- auto atlas = loader.ground_atlas(name, loader_policy::warn);
+ auto atlas = loader.ground_atlas(name, asset_policy);
fm_soft_assert(v < atlas->num_tiles());
return { atlas, v };
}
else if (std::is_same_v<wall_atlas, T>)
{
- auto atlas = loader.wall_atlas(name, loader_policy::warn);
+ auto atlas = loader.wall_atlas(name, asset_policy);
return { atlas, v };
}
else
@@ -636,9 +637,9 @@ void reader_state::deserialize_world(ArrayView<const char> buf, proto_t proto)
namespace floormat {
-void world::deserialize_old(class world& w, ArrayView<const char> buf, proto_t proto)
+void world::deserialize_old(class world& w, ArrayView<const char> buf, proto_t proto, loader_policy asset_policy)
{
- reader_state s{w};
+ reader_state s{w, asset_policy};
s.deserialize_world(buf, proto);
}
diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp
index af151684..4f5d2025 100644
--- a/serialize/savegame.cpp
+++ b/serialize/savegame.cpp
@@ -717,7 +717,9 @@ struct reader final : visitor_<reader>
uint32_t nstrings = 0, natlases = 0, nchunks = 0;
class world& w;
- reader(class world& w) : w{w} {}
+ loader_policy asset_policy;
+
+ reader(class world& w, loader_policy asset_policy) : w{w}, asset_policy{asset_policy} {}
using visitor_<reader>::visit;
@@ -799,7 +801,7 @@ ok:
PROTO << s;
if (PROTO < proto_version_min && PROTO > 0)
{
- w.deserialize_old(w, buf.exceptPrefix(s.bytes_read()), PROTO);
+ w.deserialize_old(w, buf.exceptPrefix(s.bytes_read()), PROTO, asset_policy);
return true;
}
else
@@ -982,7 +984,7 @@ ok:
} // namespace
-class world world::deserialize(StringView filename) noexcept(false)
+class world world::deserialize(StringView filename, loader_policy asset_policy) noexcept(false)
{
char errbuf[128];
buffer buf;
@@ -1010,7 +1012,7 @@ class world world::deserialize(StringView filename) noexcept(false)
}
class world w;
- struct reader r{w};
+ struct reader r{w, asset_policy};
r.deserialize_world(buf);
//fm_assert("todo" && false);
diff --git a/src/world.hpp b/src/world.hpp
index 99ce131f..8e6b9815 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -3,6 +3,7 @@
#include "chunk.hpp"
#include "global-coords.hpp"
#include "object-type.hpp"
+#include "loader/policy.hpp"
#include <memory>
#include <unordered_map>
#include <Corrade/Utility/Move.h>
@@ -65,8 +66,8 @@ public:
const auto& chunks() const noexcept { return _chunks; }
void serialize(StringView filename);
- static class world deserialize(StringView filename) noexcept(false);
- static void deserialize_old(class world& w, ArrayView<const char> buf, uint16_t proto) noexcept(false);
+ static class world deserialize(StringView filename, loader_policy asset_policy) noexcept(false);
+ static void deserialize_old(class world& w, ArrayView<const char> buf, uint16_t proto, enum loader_policy asset_policy) noexcept(false);
auto frame_no() const { return _current_frame; }
auto increment_frame_no() { return _current_frame++; }
diff --git a/test/serializer.cpp b/test/serializer.cpp
index 6153d6ee..906a911f 100644
--- a/test/serializer.cpp
+++ b/test/serializer.cpp
@@ -121,7 +121,7 @@ void test_serializer(StringView input, StringView tmp)
chunk_coords_ coord{};
world w;
if (input)
- w = world::deserialize(input);
+ w = world::deserialize(input, loader_policy::ignore);
else
{
coord = {1, 1, 0};
@@ -130,7 +130,7 @@ void test_serializer(StringView input, StringView tmp)
fm_assert(!c.empty(true));
}
w.serialize(tmp);
- auto w2 = world::deserialize(tmp);
+ auto w2 = world::deserialize(tmp, loader_policy::ignore);
auto& c2 = w2[coord];
fm_assert(!c2.empty(true));
assert_chunks_equal(w[coord], c2);