summaryrefslogtreecommitdiffhomepage
path: root/loader
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-11 01:58:39 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-11 08:49:51 +0100
commitc6abddc2349685a9476b6838a59893a17e443d2f (patch)
treea80d75e8c9510ecb2281bb90489d672d8120a52f /loader
parent636db6c8e51a72e106347024793fadd63761aeb0 (diff)
wip anim atlas loader
Diffstat (limited to 'loader')
-rw-r--r--loader/anim-atlas.cpp1
-rw-r--r--loader/anim-traits.cpp62
-rw-r--r--loader/anim-traits.hpp2
-rw-r--r--loader/atlas-loader-storage.hpp1
-rw-r--r--loader/atlas-loader.inl6
-rw-r--r--loader/ground-traits.cpp1
6 files changed, 68 insertions, 5 deletions
diff --git a/loader/anim-atlas.cpp b/loader/anim-atlas.cpp
index 3ca61256..6fca5a49 100644
--- a/loader/anim-atlas.cpp
+++ b/loader/anim-atlas.cpp
@@ -60,6 +60,7 @@ std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView
if (name == INVALID) return make_invalid_anim_atlas().atlas; // todo! hack
fm_soft_assert(check_atlas_name(name));
+ fm_soft_assert(!dir || dir[dir.size()-1] == '/');
char buf[fm_FILENAME_MAX];
auto path = make_atlas_path(buf, dir, name);
diff --git a/loader/anim-traits.cpp b/loader/anim-traits.cpp
index 9741f62e..9ff7e6b5 100644
--- a/loader/anim-traits.cpp
+++ b/loader/anim-traits.cpp
@@ -1,13 +1,73 @@
#include "anim-traits.hpp"
-#include "compat/exception.hpp"
+#include "atlas-loader-storage.hpp"
+#include "anim-cell.hpp"
+#include "src/anim-atlas.hpp"
+#include "src/tile-defs.hpp"
#include "loader.hpp"
+#include "compat/exception.hpp"
#include <cr/StringView.h>
+#include <cr/Pointer.h>
#include <cr/Optional.h>
#include <mg/ImageData.h>
#include <mg/ImageView.h>
namespace floormat::loader_detail {
+using anim_traits = atlas_loader_traits<anim_atlas>;
+StringView anim_traits::loader_name() { return "anim_atlas"_s; }
+auto anim_traits::atlas_of(const Cell& x) -> const std::shared_ptr<Atlas>& { return x.atlas; }
+auto anim_traits::atlas_of(Cell& x) -> std::shared_ptr<Atlas>& { return x.atlas; }
+StringView anim_traits::name_of(const Cell& x) { return x.name; }
+StringView anim_traits::name_of(const Atlas& x) { return x.name(); }
+String& anim_traits::name_of(Cell& x) { return x.name; }
+
+void anim_traits::ensure_atlases_loaded(Storage& s)
+{
+ fm_assert(s.name_map.empty());
+ s.cell_array = {};
+ s.cell_array.reserve(16);
+ s.name_map[loader.INVALID] = -1uz;
+}
+
+auto anim_traits::make_invalid_atlas(Storage& s) -> Pointer<Cell>
+{
+ fm_debug_assert(!s.invalid_atlas);
+ constexpr auto size = Vector2ui{16};
+
+ auto frame = anim_frame {
+ .ground = Vector2i(size/2),
+ .offset = {},
+ .size = size,
+ };
+ auto groups = Array<anim_group>{ValueInit, 1};
+ groups[0] = anim_group {
+ .name = "n"_s,
+ .frames = array({ frame }),
+ };
+ auto def = anim_def {
+ .object_name = loader.INVALID,
+ .anim_name = loader.INVALID,
+ .groups = Utility::move(groups),
+ .pixel_size = size,
+ .scale = anim_scale::fixed{size.x(), true},
+ .nframes = 1,
+ };
+ auto atlas = std::make_shared<class anim_atlas>(loader.INVALID, loader.make_error_texture(size), std::move(def));
+ auto info = anim_cell{
+ .name = loader.INVALID,
+ .atlas = atlas,
+ };
+ return Pointer<anim_cell>{ InPlace, std::move(info) };
+}
+
+auto anim_traits::make_atlas(StringView name, const Cell&) -> std::shared_ptr<Atlas>
+{
+ return {}; // todo
+}
+auto anim_traits::make_cell(StringView) -> Optional<Cell>
+{
+ return {};
+}
} // namespace floormat::loader_detail
diff --git a/loader/anim-traits.hpp b/loader/anim-traits.hpp
index 3c4a43af..8eef8b89 100644
--- a/loader/anim-traits.hpp
+++ b/loader/anim-traits.hpp
@@ -20,7 +20,7 @@ template<> struct atlas_loader_traits<anim_atlas>
static StringView name_of(const Atlas& x);
static String& name_of(Cell& x);
static void ensure_atlases_loaded(Storage& st);
- static const Cell& make_invalid_atlas(Storage& st);
+ static Pointer<Cell> make_invalid_atlas(Storage& st);
static std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& c);
static Optional<Cell> make_cell(StringView name);
};
diff --git a/loader/atlas-loader-storage.hpp b/loader/atlas-loader-storage.hpp
index c8bd3261..c5e45cc2 100644
--- a/loader/atlas-loader-storage.hpp
+++ b/loader/atlas-loader-storage.hpp
@@ -2,6 +2,7 @@
#include "compat/int-hash.hpp"
#include "atlas-loader-fwd.hpp"
#include <vector>
+#include <cr/StringView.h>
#include <tsl/robin_map.h>
namespace floormat::loader_detail {
diff --git a/loader/atlas-loader.inl b/loader/atlas-loader.inl
index f5cd39ea..c1093f82 100644
--- a/loader/atlas-loader.inl
+++ b/loader/atlas-loader.inl
@@ -50,12 +50,12 @@ auto atlas_loader<ATLAS, TRAITS>::ensure_atlas_list() -> ArrayView<const Cell>
s.name_map[loader.INVALID] = sz;
}
- fm_assert(!s.name_map.empty());
- fm_assert(!s.cell_array.empty());
-
for (const auto& [name, index] : s.name_map)
fm_assert(index < s.cell_array.size() || index == -1uz);
+ fm_debug_assert(!s.name_map.empty());
+ fm_debug_assert(!s.cell_array.empty());
+
return { s.cell_array.data(), s.cell_array.size() };
}
diff --git a/loader/ground-traits.cpp b/loader/ground-traits.cpp
index e56f0692..f1795f4e 100644
--- a/loader/ground-traits.cpp
+++ b/loader/ground-traits.cpp
@@ -32,6 +32,7 @@ void ground_traits::ensure_atlases_loaded(Storage& s)
auto ground_traits::make_invalid_atlas(Storage& s) -> Pointer<Cell>
{
+ fm_debug_assert(!s.invalid_atlas);
fm_assert(!s.invalid_atlas);
auto atlas = std::make_shared<Atlas>(
ground_def{loader.INVALID, Vector2ub{1,1}, pass_mode::pass},