summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/imgui-editors.cpp2
-rw-r--r--loader/ground-atlas.cpp33
-rw-r--r--loader/ground-info.hpp2
-rw-r--r--loader/loader.cpp1
-rw-r--r--loader/loader.hpp1
-rw-r--r--loader/wall-atlas.cpp7
-rw-r--r--loader/wall-info.hpp2
-rw-r--r--serialize/ground-atlas.cpp6
-rw-r--r--serialize/wall-atlas.cpp38
-rw-r--r--serialize/wall-atlas.hpp6
-rw-r--r--src/ground-atlas.hpp2
11 files changed, 48 insertions, 52 deletions
diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp
index 2e585d6b..2712dc5f 100644
--- a/editor/imgui-editors.cpp
+++ b/editor/imgui-editors.cpp
@@ -36,7 +36,7 @@ StringView scenery_type_to_string(const scenery_& sc)
StringView scenery_path(const wall_info* wa) { return wa->atlas->name(); }
StringView scenery_name(StringView, const scenery_& sc) { return sc.descr; }
StringView scenery_name(StringView, const vobj_& vobj) { return vobj.descr; }
-StringView scenery_name(StringView, const wall_info* w) { return w->descr; }
+StringView scenery_name(StringView, const wall_info* w) { return w->name; }
std::shared_ptr<anim_atlas> get_atlas(const scenery_& sc) { return sc.proto.atlas; }
std::shared_ptr<anim_atlas> get_atlas(const vobj_& vobj) { return vobj.factory->atlas(); }
std::shared_ptr<wall_atlas> get_atlas(const wall_info* w) { return loader.wall_atlas(w->name); }
diff --git a/loader/ground-atlas.cpp b/loader/ground-atlas.cpp
index d93313ea..c4e4a516 100644
--- a/loader/ground-atlas.cpp
+++ b/loader/ground-atlas.cpp
@@ -4,24 +4,15 @@
#include "compat/exception.hpp"
#include "serialize/json-helper.hpp"
#include "serialize/corrade-string.hpp"
+#include "serialize/ground-atlas.hpp"
+#include "src/tile-defs.hpp"
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Utility/Path.h>
#include <Magnum/Trade/ImageData.h>
#include <Magnum/ImageView.h>
namespace floormat {
-
-using nlohmann::json;
using loader_detail::loader_impl;
-
-[[maybe_unused]] static void from_json(const json& j, ground_info& val)
-{
-}
-
-[[maybe_unused]] static void to_json(json& j, const ground_info& val)
-{
-}
-
} // namespace floormat
namespace floormat::loader_detail {
@@ -103,10 +94,28 @@ void loader_impl::get_ground_atlas_list()
for (auto& x : ground_atlas_array)
{
-
+ fm_soft_assert(x.name != "<invalid>"_s);
+ fm_soft_assert(check_atlas_name(x.name));
+ StringView name = x.name;
+ ground_atlas_map[name] = &x;
+ fm_debug_assert(name.data() == ground_atlas_map[name]->name.data());
}
fm_assert(!ground_atlas_map.empty());
}
+const ground_info& loader_impl::make_invalid_ground_atlas()
+{
+ if (invalid_ground_atlas) [[likely]]
+ return *invalid_ground_atlas;
+
+ auto atlas = std::make_shared<class ground_atlas>(
+ ""_s, loader.INVALID, make_error_texture(Vector2ui(iTILE_SIZE2)),
+ Vector2ub{1,1}, pass_mode::pass);
+ invalid_ground_atlas = Pointer<ground_info>{
+ InPlaceInit, atlas->name(),
+ atlas, atlas->num_tiles2(), atlas->pass_mode()};
+ return *invalid_ground_atlas;
+}
+
} // namespace floormat::loader_detail
diff --git a/loader/ground-info.hpp b/loader/ground-info.hpp
index 3b96428e..44c4c638 100644
--- a/loader/ground-info.hpp
+++ b/loader/ground-info.hpp
@@ -10,7 +10,7 @@ class ground_atlas;
struct ground_info
{
- String name; // todo add descr?
+ String name;
std::shared_ptr<ground_atlas> atlas;
Vector2ub size;
pass_mode pass;
diff --git a/loader/loader.cpp b/loader/loader.cpp
index 80599c3d..df712f39 100644
--- a/loader/loader.cpp
+++ b/loader/loader.cpp
@@ -39,6 +39,7 @@ StringView loader_::strip_prefix(StringView name)
return name;
}
+const StringView loader_::INVALID = "<invalid>"_s; // todo use it
const StringView loader_::IMAGE_PATH_ = "images/"_s;
const StringView loader_::ANIM_PATH = "anim/"_s;
const StringView loader_::SCENERY_PATH = "scenery/"_s;
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 499a1f30..b62988ca 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -48,6 +48,7 @@ struct loader_
virtual ~loader_() noexcept;
+ static const StringView INVALID;
static const StringView IMAGE_PATH_;
static const StringView ANIM_PATH;
static const StringView SCENERY_PATH;
diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp
index 69666e8c..ce136fdb 100644
--- a/loader/wall-atlas.cpp
+++ b/loader/wall-atlas.cpp
@@ -23,17 +23,11 @@ using loader_detail::loader_impl;
val = {};
val.name = j["name"];
fm_soft_assert(loader.check_atlas_name(val.name));
- if (j.contains("descr"))
- val.descr = j["descr"];
- else
- val.descr = Path::split(val.name).second();
}
[[maybe_unused]] static void to_json(json& j, const wall_info& val)
{
j["name"] = val.name;
- if (val.descr)
- j["descr"] = val.descr;
}
} // namespace floormat
@@ -132,7 +126,6 @@ void loader_impl::get_wall_atlas_list()
{
fm_soft_assert(x.name != "<invalid>"_s);
fm_soft_assert(check_atlas_name(x.name));
- //x.atlas = get_wall_atlas(x.name, WALL_TILESET_PATH);
StringView name = x.name;
wall_atlas_map[name] = &x;
fm_debug_assert(name.data() == wall_atlas_map[name]->name.data());
diff --git a/loader/wall-info.hpp b/loader/wall-info.hpp
index acd5cdc4..9b586a10 100644
--- a/loader/wall-info.hpp
+++ b/loader/wall-info.hpp
@@ -8,7 +8,7 @@ class wall_atlas;
struct wall_info
{
- String name, descr{};
+ String name;
std::shared_ptr<wall_atlas> atlas;
};
diff --git a/serialize/ground-atlas.cpp b/serialize/ground-atlas.cpp
index 8703881d..3522e85c 100644
--- a/serialize/ground-atlas.cpp
+++ b/serialize/ground-atlas.cpp
@@ -1,13 +1,9 @@
#include "ground-atlas.hpp"
-#include "src/ground-atlas.hpp"
#include "serialize/corrade-string.hpp"
#include "serialize/magnum-vector.hpp"
-#include "loader/loader.hpp"
#include "serialize/pass-mode.hpp"
-#include "compat/exception.hpp"
+#include "loader/ground-info.hpp"
#include <tuple>
-#include <Corrade/Containers/Optional.h>
-#include <Corrade/Containers/String.h>
#include <nlohmann/json.hpp>
namespace floormat {
diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp
index 85de29ec..0ba1c297 100644
--- a/serialize/wall-atlas.cpp
+++ b/serialize/wall-atlas.cpp
@@ -13,7 +13,25 @@
#include <Magnum/Trade/ImageData.h>
#include <nlohmann/json.hpp>
-// todo add test on dummy files that generates 100% coverage on the j.contains() blocks!
+namespace floormat::Wall {
+NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Frame, offset, size)
+NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Info, name, depth)
+} // namespace floormat::Wall
+
+namespace nlohmann {
+
+using floormat::Wall::Frame;
+
+template<>
+struct adl_serializer<floormat::Wall::Frame> {
+ static void to_json(json& j, const Frame& val);
+ static void from_json(const json& j, Frame& val);
+};
+
+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
namespace floormat {
@@ -170,6 +188,8 @@ bool is_direction_defined(const Direction& dir)
return false;
}
+// todo add test on dummy files that generates 100% coverage on the j.contains() blocks!
+
Group read_group_metadata(const json& jgroup)
{
fm_assert(jgroup.is_object());
@@ -312,19 +332,3 @@ void write_info_header(json& jroot, const Info& info)
}
} // namespace floormat::Wall::detail
-
-namespace floormat::Wall {
-
-NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Frame, offset, size)
-NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Info, name, depth)
-
-} // namespace floormat::Wall
-
-namespace nlohmann {
-
-using floormat::Wall::Frame;
-
-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/serialize/wall-atlas.hpp b/serialize/wall-atlas.hpp
index febdf583..e7e553ce 100644
--- a/serialize/wall-atlas.hpp
+++ b/serialize/wall-atlas.hpp
@@ -4,12 +4,6 @@
#include <memory>
#include <nlohmann/json_fwd.hpp>
-template<>
-struct nlohmann::adl_serializer<floormat::Wall::Frame> {
- static void to_json(json& j, const floormat::Wall::Frame& val);
- static void from_json(const json& j, floormat::Wall::Frame& val);
-};
-
namespace floormat::Wall::detail {
using nlohmann::json;
diff --git a/src/ground-atlas.hpp b/src/ground-atlas.hpp
index e6e2d5ba..94da682f 100644
--- a/src/ground-atlas.hpp
+++ b/src/ground-atlas.hpp
@@ -28,9 +28,7 @@ class ground_atlas final
public:
ground_atlas(StringView path, StringView name, const ImageView2D& img, Vector2ub tile_count, enum pass_mode pass_mode);
-
texcoords texcoords_for_id(size_t id) const;
-
[[maybe_unused]] Vector2ui pixel_size() const { return size_; }
size_t num_tiles() const;
Vector2ub num_tiles2() const { return dims_; }