summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--bench/loader.cpp6
-rw-r--r--loader/impl.hpp2
-rw-r--r--loader/wall-atlas.cpp26
-rw-r--r--serialize/anim.cpp14
-rw-r--r--serialize/tile.cpp10
-rw-r--r--serialize/wall-atlas.cpp2
-rw-r--r--test/loader.cpp3
8 files changed, 45 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 40df9b3a..9b7ab130 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -257,7 +257,7 @@ if(TARGET benchmark::benchmark OR TARGET benchmark)
add_subdirectory(bench)
endif()
-install(DIRECTORY images anim scenery vobj DESTINATION "share/floormat")
+install(DIRECTORY images anim scenery vobj wall-tilesets DESTINATION "share/floormat")
fm_run_hook(fm-userconfig-post)
diff --git a/bench/loader.cpp b/bench/loader.cpp
index 6e891ab7..ec0eed17 100644
--- a/bench/loader.cpp
+++ b/bench/loader.cpp
@@ -10,6 +10,8 @@ namespace floormat {
namespace {
+using nlohmann::json;
+
void Loader_json(benchmark::State& state)
{
loader.destroy();
@@ -17,7 +19,7 @@ void Loader_json(benchmark::State& state)
// warmup
{ for (const auto& x : loader.anim_atlas_list())
json_helper::from_json<anim_def>(Path::join(loader.ANIM_PATH, ""_s.join({x, ".json"})));
- json_helper::from_json<std::vector<nlohmann::json>>(Path::join(loader.VOBJ_PATH, "vobj.json"));
+ json_helper::from_json<std::vector<json>>(Path::join(loader.VOBJ_PATH, "vobj.json"));
}
for (auto _ : state)
@@ -25,7 +27,7 @@ void Loader_json(benchmark::State& state)
{
for (const auto& x : loader.anim_atlas_list())
json_helper::from_json<anim_def>(Path::join(loader.ANIM_PATH, ""_s.join({x, ".json"})));
- json_helper::from_json<std::vector<nlohmann::json>>(Path::join(loader.VOBJ_PATH, "vobj.json"));
+ json_helper::from_json<std::vector<json>>(Path::join(loader.VOBJ_PATH, "vobj.json"));
}
}
diff --git a/loader/impl.hpp b/loader/impl.hpp
index ec571ae4..38a89265 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -45,7 +45,7 @@ struct loader_impl final : loader_
// >-----> walls >----->
struct wall_index { uint32_t val = (uint32_t)-1; };
- tsl::robin_map<StringView, const wall_info*> wall_atlas_map;
+ tsl::robin_map<StringView, wall_info*> wall_atlas_map;
std::vector<wall_info> wall_atlas_array;
const wall_info& wall_atlas(StringView name, StringView dir) override;
diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp
index 1784f4e2..57b89ded 100644
--- a/loader/wall-atlas.cpp
+++ b/loader/wall-atlas.cpp
@@ -16,7 +16,25 @@
#include <vector>
namespace floormat {
-NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(wall_info, name, descr)
+
+using nlohmann::json;
+
+static void from_json(const json& j, wall_info& val)
+{
+ val = {};
+ val.name = j["name"];
+ fm_soft_assert(loader.check_atlas_name(val.name));
+ if (j.contains("descr"))
+ val.descr = j["descr"];
+}
+
+static void to_json(json& j, const wall_info& val)
+{
+ j["name"] = val.name;
+ if (val.descr)
+ j["descr"] = val.descr;
+}
+
} // namespace floormat
namespace floormat::loader_detail {
@@ -41,9 +59,7 @@ const wall_info& loader_impl::wall_atlas(StringView name, StringView dir)
fm_throw("no such wall atlas '{}'"_cf, path);
fm_assert(it->second != nullptr);
if (!it->second->atlas)
- {
- const_cast<wall_info*>(it->second)->atlas = get_wall_atlas(it->second->name, path);
- }
+ it->second->atlas = get_wall_atlas(it->second->name, path);
return *it->second;
}
@@ -54,7 +70,7 @@ void loader_impl::get_wall_atlas_list()
wall_atlas_map.clear();
wall_atlas_map.reserve(wall_atlas_array.size()*2);
- for (const auto& x : wall_atlas_array)
+ for (auto& x : wall_atlas_array)
{
fm_soft_assert(check_atlas_name(x.name));
StringView name = x.name;
diff --git a/serialize/anim.cpp b/serialize/anim.cpp
index 8d8bc2bb..8cf074c8 100644
--- a/serialize/anim.cpp
+++ b/serialize/anim.cpp
@@ -11,7 +11,9 @@ namespace floormat {
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_group, name, frames, ground, offset)
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_def, object_name, anim_name, pixel_size, nframes, actionframe, fps, groups, scale)
-static void to_json(nlohmann::json& j, const anim_frame& val)
+using nlohmann::json;
+
+static void to_json(json& j, const anim_frame& val)
{
constexpr anim_frame def;
@@ -23,7 +25,7 @@ static void to_json(nlohmann::json& j, const anim_frame& val)
j["size"] = val.size;
}
-static void from_json(const nlohmann::json& j, anim_frame& val)
+static void from_json(const json& j, anim_frame& val)
{
val = {};
if (j.contains("ground"))
@@ -34,7 +36,7 @@ static void from_json(const nlohmann::json& j, anim_frame& val)
val.size = j["size"];
}
-static void to_json(nlohmann::json& j, const anim_group& val)
+static void to_json(json& j, const anim_group& val)
{
const anim_group def{};
@@ -53,7 +55,7 @@ static void to_json(nlohmann::json& j, const anim_group& val)
j["depth-offset"] = val.depth_offset;
}
-static void from_json(const nlohmann::json& j, anim_group& val)
+static void from_json(const json& j, anim_group& val)
{
val = {};
val.name = j["name"];
@@ -75,7 +77,7 @@ static void from_json(const nlohmann::json& j, anim_group& val)
val.depth_offset = j["depth-offset"];
}
-static void to_json(nlohmann::json& j, const anim_def& val)
+static void to_json(json& j, const anim_def& val)
{
const anim_def def{};
@@ -96,7 +98,7 @@ static void to_json(nlohmann::json& j, const anim_def& val)
j["scale"] = val.scale;
}
-static void from_json(const nlohmann::json& j, anim_def& val)
+static void from_json(const json& j, anim_def& val)
{
val = {};
val.object_name = j["object_name"];
diff --git a/serialize/tile.cpp b/serialize/tile.cpp
index 783a9853..7a0b1bed 100644
--- a/serialize/tile.cpp
+++ b/serialize/tile.cpp
@@ -7,10 +7,12 @@
namespace floormat {
+using nlohmann::json;
+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(tile_image_proto, atlas, variant)
-inline void to_json(nlohmann::json& j, const tile_image_ref& val) { j = tile_image_proto(val); }
-inline void from_json(const nlohmann::json& j, tile_image_ref& val) { val = tile_image_proto(j); }
+inline void to_json(json& j, const tile_image_ref& val) { j = tile_image_proto(val); }
+inline void from_json(const json& j, tile_image_ref& val) { val = tile_image_proto(j); }
struct local_coords_ final {
uint8_t x, y;
@@ -20,8 +22,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(local_coords_, x, y)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords, x, y)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords_, x, y, z)
-inline void to_json(nlohmann::json& j, global_coords coord) { j = std::tuple<chunk_coords, local_coords, int8_t>{ coord.chunk(), coord.local(), coord.z() }; }
-inline void from_json(const nlohmann::json& j, global_coords& coord) { std::tuple<chunk_coords, local_coords, int8_t> t = j; auto [ch, pos, z] = t; coord = { ch, pos, z }; }
+inline void to_json(json& j, global_coords coord) { j = std::tuple<chunk_coords, local_coords, int8_t>{ coord.chunk(), coord.local(), coord.z() }; }
+inline void from_json(const json& j, global_coords& coord) { std::tuple<chunk_coords, local_coords, int8_t> t = j; auto [ch, pos, z] = t; coord = { ch, pos, z }; }
} // namespace floormat
diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp
index b8c2eb7a..82210f57 100644
--- a/serialize/wall-atlas.cpp
+++ b/serialize/wall-atlas.cpp
@@ -309,7 +309,7 @@ namespace nlohmann {
using floormat::Wall::Frame;
-void adl_serializer<Frame>::to_json(nlohmann::json& j, const Frame& x) { using nlohmann::to_json; to_json(j, x); }
+void adl_serializer<Frame>::to_json(json& j, const Frame& x) { using nlohmann::to_json; to_json(j, x); }
void adl_serializer<Frame>::from_json(const json& j, Frame& x) { using nlohmann::from_json; from_json(j, x); }
} // namespace nlohmann
diff --git a/test/loader.cpp b/test/loader.cpp
index 69804c89..95c61489 100644
--- a/test/loader.cpp
+++ b/test/loader.cpp
@@ -2,6 +2,7 @@
#include "compat/assert.hpp"
#include "loader/loader.hpp"
#include "src/tile-atlas.hpp"
+#include "loader/wall-info.hpp"
namespace floormat {
@@ -14,6 +15,8 @@ void test_app::test_loader()
loader.sceneries();
for (StringView name : loader.anim_atlas_list())
loader.anim_atlas(name);
+ for (const auto& info : loader.wall_atlas_list())
+ (void)loader.wall_atlas(info.name);
}
} // namespace floormat