summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--loader/atlas.cpp68
-rw-r--r--loader/ground-atlas.cpp10
-rw-r--r--loader/impl.hpp2
-rw-r--r--loader/json.cpp8
-rw-r--r--loader/loader.hpp8
-rw-r--r--loader/wall-atlas.cpp16
6 files changed, 66 insertions, 46 deletions
diff --git a/loader/atlas.cpp b/loader/atlas.cpp
index 555a2b02..b39bc8f5 100644
--- a/loader/atlas.cpp
+++ b/loader/atlas.cpp
@@ -42,8 +42,45 @@ bool loader_::check_atlas_name(StringView str) noexcept
return true;
}
+std::shared_ptr<class anim_atlas>
+loader_::get_anim_atlas(StringView path) noexcept(false)
+{
+
+ auto anim_info = deserialize_anim_def(path + ".json");
+
+ for (anim_group& group : anim_info.groups)
+ {
+ if (!group.mirror_from.isEmpty())
+ {
+ auto it = std::find_if(anim_info.groups.cbegin(), anim_info.groups.cend(),
+ [&](const anim_group& x) { return x.name == group.mirror_from; });
+ if (it == anim_info.groups.cend())
+ fm_throw("can't find group '{}' to mirror from '{}'"_cf, group.mirror_from, group.name);
+ group.frames = array(arrayView(it->frames));
+ for (anim_frame& f : group.frames)
+ f.ground = Vector2i((Int)f.size[0] - f.ground[0], f.ground[1]);
+ }
+ }
+
+ auto tex = texture(""_s, path);
+
+ fm_soft_assert(!anim_info.object_name.isEmpty());
+ fm_soft_assert(anim_info.pixel_size.product() > 0);
+ fm_soft_assert(!anim_info.groups.isEmpty());
+ fm_soft_assert(anim_info.nframes > 0);
+ fm_soft_assert(anim_info.nframes == 1 || anim_info.fps > 0);
+ const auto size = tex.pixels().size();
+ const auto width = size[1], height = size[0];
+ fm_soft_assert(anim_info.pixel_size[0] == width && anim_info.pixel_size[1] == height);
+
+ auto atlas = std::make_shared<class anim_atlas>(path, tex, std::move(anim_info));
+ return atlas;
+}
+
} // namespace floormat
+
+
namespace floormat::loader_detail {
ArrayView<const String> loader_impl::anim_atlas_list()
@@ -56,6 +93,7 @@ ArrayView<const String> loader_impl::anim_atlas_list()
std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView dir) noexcept(false)
{
+ fm_soft_assert(check_atlas_name(name));
fm_soft_assert(!dir || dir[dir.size()-1] == '/');
char buf[FILENAME_MAX];
auto path = make_atlas_path(buf, dir, name);
@@ -64,35 +102,7 @@ std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView
return it->second;
else
{
- fm_soft_assert(check_atlas_name(name));
- auto anim_info = deserialize_anim(path + ".json");
-
- for (anim_group& group : anim_info.groups)
- {
- if (!group.mirror_from.isEmpty())
- {
- auto it = std::find_if(anim_info.groups.cbegin(), anim_info.groups.cend(),
- [&](const anim_group& x) { return x.name == group.mirror_from; });
- if (it == anim_info.groups.cend())
- fm_throw("can't find group '{}' to mirror from '{}'"_cf, group.mirror_from, group.name);
- group.frames = array(arrayView(it->frames));
- for (anim_frame& f : group.frames)
- f.ground = Vector2i((Int)f.size[0] - f.ground[0], f.ground[1]);
- }
- }
-
- auto tex = texture(""_s, path);
-
- fm_soft_assert(!anim_info.object_name.isEmpty());
- fm_soft_assert(anim_info.pixel_size.product() > 0);
- fm_soft_assert(!anim_info.groups.isEmpty());
- fm_soft_assert(anim_info.nframes > 0);
- fm_soft_assert(anim_info.nframes == 1 || anim_info.fps > 0);
- const auto size = tex.pixels().size();
- const auto width = size[1], height = size[0];
- fm_soft_assert(anim_info.pixel_size[0] == width && anim_info.pixel_size[1] == height);
-
- auto atlas = std::make_shared<class anim_atlas>(path, tex, std::move(anim_info));
+ auto atlas = get_anim_atlas(path);
return anim_atlas_map[atlas->name()] = atlas;
}
}
diff --git a/loader/ground-atlas.cpp b/loader/ground-atlas.cpp
index 1a0d3905..974d6fa8 100644
--- a/loader/ground-atlas.cpp
+++ b/loader/ground-atlas.cpp
@@ -12,11 +12,9 @@
namespace floormat {
using loader_detail::loader_impl;
-} // namespace floormat
-
-namespace floormat::loader_detail {
-std::shared_ptr<ground_atlas> loader_impl::get_ground_atlas(StringView name, Vector2ub size, pass_mode pass)
+std::shared_ptr<ground_atlas>
+loader_::get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false)
{
fm_assert(name != "<invalid>"_s);
@@ -29,6 +27,10 @@ std::shared_ptr<ground_atlas> loader_impl::get_ground_atlas(StringView name, Vec
return atlas;
}
+} // namespace floormat
+
+namespace floormat::loader_detail {
+
// todo copypasta from wall-atlas.cpp
std::shared_ptr<class ground_atlas> loader_impl::ground_atlas(StringView name, loader_policy policy) noexcept(false)
{
diff --git a/loader/impl.hpp b/loader/impl.hpp
index 9308baba..b376503b 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -54,7 +54,6 @@ struct loader_impl final : loader_
ArrayView<const wall_info> wall_atlas_list() override;
void get_wall_atlas_list();
const wall_info& make_invalid_wall_atlas();
- std::shared_ptr<class wall_atlas> get_wall_atlas(StringView name, StringView dir);
// >-----> tile >----->
tsl::robin_map<StringView, ground_info*> ground_atlas_map;
@@ -65,7 +64,6 @@ struct loader_impl final : loader_
ArrayView<const ground_info> ground_atlas_list() noexcept(false) override;
void get_ground_atlas_list();
const ground_info& make_invalid_ground_atlas();
- std::shared_ptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) override;
// >-----> anim >----->
tsl::robin_map<StringView, std::shared_ptr<class anim_atlas>> anim_atlas_map;
diff --git a/loader/json.cpp b/loader/json.cpp
index 7b12b784..756f8151 100644
--- a/loader/json.cpp
+++ b/loader/json.cpp
@@ -9,13 +9,17 @@
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Utility/Path.h>
-namespace floormat::loader_detail {
+namespace floormat {
-anim_def loader_impl::deserialize_anim(StringView filename)
+anim_def loader_::deserialize_anim_def(StringView filename) noexcept(false)
{
return json_helper::from_json<anim_def>(filename);
}
+} // namespace floormat
+
+namespace floormat::loader_detail {
+
void loader_impl::get_scenery_list()
{
sceneries_array.clear();
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 63740aa7..5c72a719 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -14,6 +14,7 @@ using ImageData2D = ImageData<2>;
namespace floormat {
+struct anim_def;
class anim_atlas;
struct scenery_proto;
struct vobj_info;
@@ -37,7 +38,6 @@ struct loader_
{
virtual StringView shader(StringView filename) noexcept = 0;
virtual Trade::ImageData2D texture(StringView prefix, StringView filename) noexcept(false) = 0;
- virtual std::shared_ptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) = 0;
virtual std::shared_ptr<class ground_atlas> ground_atlas(StringView filename, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0;
virtual ArrayView<const String> anim_atlas_list() = 0;
virtual std::shared_ptr<class anim_atlas> anim_atlas(StringView name, StringView dir = ANIM_PATH) noexcept(false) = 0;
@@ -55,6 +55,10 @@ struct loader_
static StringView make_atlas_path(char(&buf)[FILENAME_MAX], StringView dir, StringView name);
[[nodiscard]] static bool check_atlas_name(StringView name) noexcept;
+ /** \deprecated{internal use only}*/ [[nodiscard]] std::shared_ptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false);
+ /** \deprecated{internal use only}*/ [[nodiscard]] std::shared_ptr<class wall_atlas> get_wall_atlas(StringView name) noexcept(false);
+ /** \deprecated{internal use only}*/ [[nodiscard]] std::shared_ptr<class anim_atlas> get_anim_atlas(StringView path) noexcept(false);
+
virtual ~loader_() noexcept;
fm_DECLARE_DELETED_COPY_ASSIGNMENT(loader_);
fm_DECLARE_DELETED_MOVE_ASSIGNMENT(loader_);
@@ -69,6 +73,8 @@ struct loader_
static const StringView WALL_TILESET_PATH;
protected:
+ static anim_def deserialize_anim_def(StringView filename) noexcept(false);
+
loader_();
};
diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp
index 6e66478b..fa8aabc4 100644
--- a/loader/wall-atlas.cpp
+++ b/loader/wall-atlas.cpp
@@ -30,24 +30,24 @@ using loader_detail::loader_impl;
j["name"] = val.name;
}
-} // namespace floormat
-
-namespace floormat::loader_detail {
-
-std::shared_ptr<wall_atlas> loader_impl::get_wall_atlas(StringView name, StringView dir)
+std::shared_ptr<wall_atlas> loader_::get_wall_atlas(StringView name) noexcept(false)
{
fm_assert(name != "<invalid>"_s);
char buf[FILENAME_MAX];
- auto filename = make_atlas_path(buf, dir, name);
+ auto filename = make_atlas_path(buf, loader.WALL_TILESET_PATH, name);
auto def = wall_atlas_def::deserialize(""_s.join({filename, ".json"_s}));
auto tex = texture(""_s, filename);
fm_soft_assert(name == def.header.name);
fm_soft_assert(!def.frames.isEmpty());
- auto atlas = std::make_shared<class wall_atlas>(std::move(def), dir, tex);
+ auto atlas = std::make_shared<class wall_atlas>(std::move(def), loader.WALL_TILESET_PATH, tex);
return atlas;
}
+} // namespace floormat
+
+namespace floormat::loader_detail {
+
const wall_info& loader_impl::make_invalid_wall_atlas()
{
if (invalid_wall_atlas) [[likely]]
@@ -102,7 +102,7 @@ std::shared_ptr<class wall_atlas> loader_impl::wall_atlas(StringView name, loade
std::unreachable();
}
else if (!it->second->atlas)
- return it->second->atlas = get_wall_atlas(name, loader.WALL_TILESET_PATH);
+ return it->second->atlas = get_wall_atlas(name);
else
return it->second->atlas;
}