summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/tile-image.cpp11
-rw-r--r--src/tile-image.hpp8
-rw-r--r--src/tile.cpp8
-rw-r--r--src/tile.hpp2
-rw-r--r--test/CMakeLists.txt3
-rw-r--r--test/app.hpp1
-rw-r--r--test/main.cpp1
-rw-r--r--test/serializer.cpp57
8 files changed, 83 insertions, 8 deletions
diff --git a/src/tile-image.cpp b/src/tile-image.cpp
new file mode 100644
index 00000000..4210db94
--- /dev/null
+++ b/src/tile-image.cpp
@@ -0,0 +1,11 @@
+#include "tile-image.hpp"
+
+namespace floormat {
+
+bool operator==(const tile_image& a, const tile_image& b) noexcept
+{
+ return a.atlas == b.atlas && a.variant == b.variant;
+}
+
+} // namespace floormat
+
diff --git a/src/tile-image.hpp b/src/tile-image.hpp
index 06d0cb41..6c90a2d5 100644
--- a/src/tile-image.hpp
+++ b/src/tile-image.hpp
@@ -13,12 +13,8 @@ struct tile_image final
std::uint16_t variant = (std::uint16_t)-1;
explicit operator bool() const noexcept { return !!atlas; }
-
- std::strong_ordering operator<=>(const tile_image& o) const noexcept
- {
- const auto ret = atlas.get() <=> o.atlas.get();
- return ret != std::strong_ordering::equal ? ret : variant <=> o.variant;
- }
};
+bool operator==(const tile_image& a, const tile_image& b) noexcept;
+
} // namespace floormat
diff --git a/src/tile.cpp b/src/tile.cpp
index 82970c76..7e988a27 100644
--- a/src/tile.cpp
+++ b/src/tile.cpp
@@ -2,4 +2,12 @@
namespace floormat {
+bool operator==(const tile& a, const tile& b) noexcept
+{
+ return a.ground == b.ground &&
+ a.wall_north == b.wall_north &&
+ a.wall_west == b.wall_west &&
+ a.passability == b.passability;
+}
+
} // namespace floormat
diff --git a/src/tile.hpp b/src/tile.hpp
index 1997f747..52d06b9d 100644
--- a/src/tile.hpp
+++ b/src/tile.hpp
@@ -17,4 +17,6 @@ struct tile final
fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(tile);
};
+bool operator==(const tile& a, const tile& b) noexcept;
+
} //namespace floormat
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index ea0009f8..0ef13ac6 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -6,6 +6,5 @@ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/test")
link_libraries(${PROJECT_NAME})
link_libraries(Magnum::WindowlessWglApplication Magnum::Trade)
-#add_executable(${self} "${sources}" "../loader/loader-impl.cpp")
-add_library(${self} STATIC "${sources}" "../loader/loader-impl.cpp")
+add_executable(${self} "${sources}" "../loader/loader-impl.cpp")
install(TARGETS ${self} RUNTIME DESTINATION bin)
diff --git a/test/app.hpp b/test/app.hpp
index 943e53a3..31df8a35 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -10,5 +10,6 @@ struct floormat final : Platform::WindowlessWglApplication // NOLINT(cppcoreguid
static bool test_json();
static bool test_tile_iter();
static bool test_const_math();
+ static bool test_serializer();
};
} // namespace floormat
diff --git a/test/main.cpp b/test/main.cpp
index 75e2950f..38127c05 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -28,6 +28,7 @@ int floormat::exec()
ret &= test_json();
ret &= test_tile_iter();
ret &= test_const_math();
+ ret &= test_serializer();
return !ret;
}
diff --git a/test/serializer.cpp b/test/serializer.cpp
new file mode 100644
index 00000000..7970bdac
--- /dev/null
+++ b/test/serializer.cpp
@@ -0,0 +1,57 @@
+#include "app.hpp"
+#include "src/world.hpp"
+#include "src/loader.hpp"
+#include "src/tile-atlas.hpp"
+#include <Corrade/Utility/Path.h>
+
+namespace floormat {
+
+namespace Path = Corrade::Utility::Path;
+
+static chunk make_test_chunk()
+{
+ auto metal1 = loader.tile_atlas("metal1", {2, 2}),
+ metal2 = loader.tile_atlas("metal2", {2, 2}),
+ tiles = loader.tile_atlas("tiles", {8, 5});
+ constexpr auto N = TILE_MAX_DIM;
+ chunk c;
+ for (auto& [x, k, pt] : c) {
+ x.ground = { tiles, decltype(tile_image::variant)(k % tiles->num_tiles()) };
+ }
+ constexpr auto K = N/2;
+ c[{K, K }].wall_north = { metal1, 0 };
+ c[{K, K }].wall_west = { metal2, 0 };
+ c[{K, K+1}].wall_north = { metal1, 0 };
+ c[{K+1, K }].wall_west = { metal2, 0 };
+ return c;
+}
+
+static bool chunks_equal(const chunk& a, const chunk& b)
+{
+ for (std::size_t i = 0; i < TILE_COUNT; i++)
+ if (a[i] != b[i])
+ return false;
+ return true;
+}
+
+static bool test_serializer1()
+{
+ constexpr auto filename = "../test/test-serializer1.dat";
+ if (Path::exists(filename))
+ Path::remove(filename);
+ world w;
+ const chunk_coords coord{1, 1};
+ w[coord] = make_test_chunk();
+ w.serialize(filename);
+ auto w2 = world::deserialize(filename);
+ return chunks_equal(w[coord], w2[coord]);
+}
+
+bool floormat::test_serializer()
+{
+ bool ret = true;
+ ret &= test_serializer1();
+ return ret;
+}
+
+} // namespace floormat