#include "app.hpp" #include "src/world.hpp" #include "loader/loader.hpp" #include "src/tile-atlas.hpp" #include 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, variant_t(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++) { const auto &a1 = a[i], &b1 = b[i]; if (a1 != b1) return false; } return true; } void test_app::test_serializer() { 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); auto &c1 = w[coord], &c2 = w2[coord]; fm_assert(chunks_equal(c1, c2)); } } // namespace floormat