summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-09 19:34:15 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-09 20:08:55 +0100
commitd0395f8468b33817a79a0fd625ae52cdff06ae19 (patch)
tree1751e2e0771cb231fc143aebd7df3c1e72334beb
parentd30921ac0b361639c10ae9d337cbf16cc3b7d359 (diff)
loader: move vobj_cell to its own file
-rw-r--r--editor/vobj-editor.cpp37
-rw-r--r--editor/vobj-editor.hpp4
-rw-r--r--loader/atlas-loader.inl7
-rw-r--r--loader/ground-atlas.cpp3
-rw-r--r--loader/ground-traits.cpp20
-rw-r--r--loader/impl.cpp9
-rw-r--r--loader/impl.hpp8
-rw-r--r--loader/loader.hpp12
-rw-r--r--loader/vobj-cell.hpp15
-rw-r--r--loader/vobj.cpp7
-rw-r--r--serialize/savegame.cpp1
-rw-r--r--src/light.cpp1
12 files changed, 70 insertions, 54 deletions
diff --git a/editor/vobj-editor.cpp b/editor/vobj-editor.cpp
index ea9b8659..bfe88d71 100644
--- a/editor/vobj-editor.cpp
+++ b/editor/vobj-editor.cpp
@@ -1,7 +1,8 @@
#include "vobj-editor.hpp"
-#include "loader/loader.hpp"
#include "src/world.hpp"
#include "src/light.hpp"
+#include "loader/loader.hpp"
+#include "loader/vobj-cell.hpp"
#include "app.hpp"
#include <array>
#include <utility>
@@ -68,23 +69,27 @@ start: while (auto id = a.get_object_colliding_with_cursor())
struct light_factory final : vobj_factory
{
- object_type type() const override { return object_type::light; }
+ object_type type() const override;
+ const vobj_cell& info() const override;
+ std::shared_ptr<object> make(world& w, object_id id, global_coords pos) const override;
+};
- const vobj_info& info() const override
- {
- constexpr auto NAME = "light"_s;
- static const vobj_info& ret = loader.vobj(NAME);
- fm_debug_assert(ret.name == NAME);
- fm_debug_assert(ret.atlas != nullptr);
- return ret;
- }
+object_type light_factory::type() const { return object_type::light; }
- std::shared_ptr<object> make(world& w, object_id id, global_coords pos) const override
- {
- auto ret = w.make_object<light>(id, pos, light_proto{});
- return ret;
- }
-};
+const vobj_cell& light_factory::info() const
+{
+ constexpr auto NAME = "light"_s;
+ static const vobj_cell& ret = loader.vobj(NAME);
+ fm_debug_assert(ret.name == NAME);
+ fm_debug_assert(ret.atlas != nullptr);
+ return ret;
+}
+
+std::shared_ptr<object> light_factory::make(world& w, object_id id, global_coords pos) const
+{
+ auto ret = w.make_object<light>(id, pos, light_proto{});
+ return ret;
+}
auto vobj_editor::make_vobj_type_map() -> std::map<StringView, vobj_>
{
diff --git a/editor/vobj-editor.hpp b/editor/vobj-editor.hpp
index 962212c7..7bcc32b6 100644
--- a/editor/vobj-editor.hpp
+++ b/editor/vobj-editor.hpp
@@ -11,14 +11,14 @@ class world;
struct global_coords;
struct object;
class anim_atlas;
-struct vobj_info;
+struct vobj_cell;
struct app;
struct vobj_factory
{
vobj_factory();
virtual ~vobj_factory() noexcept;
- virtual const vobj_info& info() const = 0;
+ virtual const vobj_cell& info() const = 0;
virtual object_type type() const = 0;
virtual std::shared_ptr<object> make(world& w, object_id id, global_coords pos) const = 0;
diff --git a/loader/atlas-loader.inl b/loader/atlas-loader.inl
index dcd6ba27..5488cad1 100644
--- a/loader/atlas-loader.inl
+++ b/loader/atlas-loader.inl
@@ -110,9 +110,12 @@ missing_warn:
}
template<typename ATLAS, typename TRAITS>
-auto atlas_loader<ATLAS, TRAITS>::make_atlas(StringView name, const Cell& cell) -> std::shared_ptr<Atlas>
+auto atlas_loader<ATLAS, TRAITS>::make_atlas(StringView name, const Cell& c) -> std::shared_ptr<Atlas>
{
- return t.make_atlas(name, cell);
+ fm_assert(name != "<invalid>"_s);
+ fm_soft_assert(!c.name || t.name_of(c) == name);
+ fm_soft_assert(loader.check_atlas_name(name));
+ return t.make_atlas(name, c);
}
template<typename ATLAS, typename TRAITS>
diff --git a/loader/ground-atlas.cpp b/loader/ground-atlas.cpp
index 0ea4f768..9ca9cb9b 100644
--- a/loader/ground-atlas.cpp
+++ b/loader/ground-atlas.cpp
@@ -11,9 +11,8 @@ template class atlas_loader<ground_atlas>;
std::shared_ptr<ground_atlas>
loader_impl::get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false)
{
- fm_assert(name != loader.INVALID);
auto atlas = _ground_loader->make_atlas(name, {
- .atlas = {}, .name = name, .size = size, .pass = pass,
+ .atlas = {}, .name = {}, .size = size, .pass = pass,
});
return atlas;
}
diff --git a/loader/ground-traits.cpp b/loader/ground-traits.cpp
index 5cb8d29e..0ec42f0e 100644
--- a/loader/ground-traits.cpp
+++ b/loader/ground-traits.cpp
@@ -14,15 +14,15 @@
namespace floormat::loader_detail {
-using traits = atlas_loader_traits<ground_atlas>;
+using ground_traits = atlas_loader_traits<ground_atlas>;
-StringView traits::loader_name() { return "ground_atlas"_s; }
-auto traits::atlas_of(const Cell& x) -> const std::shared_ptr<Atlas>& { return x.atlas; }
-auto traits::atlas_of(Cell& x) -> std::shared_ptr<Atlas>& { return x.atlas; }
-StringView traits::name_of(const Cell& x) { return x.name; }
-StringView traits::name_of(const Atlas& x) { return x.name(); }
+StringView ground_traits::loader_name() { return "ground_atlas"_s; }
+auto ground_traits::atlas_of(const Cell& x) -> const std::shared_ptr<Atlas>& { return x.atlas; }
+auto ground_traits::atlas_of(Cell& x) -> std::shared_ptr<Atlas>& { return x.atlas; }
+StringView ground_traits::name_of(const Cell& x) { return x.name; }
+StringView ground_traits::name_of(const Atlas& x) { return x.name(); }
-void traits::ensure_atlases_loaded(Storage& st)
+void ground_traits::ensure_atlases_loaded(Storage& st)
{
if (!st.is_empty()) [[likely]]
return;
@@ -58,7 +58,7 @@ void traits::ensure_atlases_loaded(Storage& st)
fm_debug_assert(!st.is_empty());
}
-auto traits::make_invalid_atlas(Storage& s) -> const Cell&
+auto ground_traits::make_invalid_atlas(Storage& s) -> const Cell&
{
if (!s.invalid_atlas) [[unlikely]]
{
@@ -70,9 +70,9 @@ auto traits::make_invalid_atlas(Storage& s) -> const Cell&
return *s.invalid_atlas;
}
-auto traits::make_atlas(StringView name, const Cell& cell) -> std::shared_ptr<Atlas>
+auto ground_traits::make_atlas(StringView name, const Cell& c) -> std::shared_ptr<Atlas>
{
- auto def = ground_def{name, cell.size, cell.pass};
+ auto def = ground_def{name, c.size, c.pass};
auto tex = loader.texture(loader.GROUND_TILESET_PATH, name);
auto atlas = std::make_shared<Atlas>(def, tex);
return atlas;
diff --git a/loader/impl.cpp b/loader/impl.cpp
index 543f0794..1b6e80e3 100644
--- a/loader/impl.cpp
+++ b/loader/impl.cpp
@@ -3,14 +3,12 @@
#include "scenery.hpp"
#include "wall-cell.hpp"
#include "anim-cell.hpp"
-#include "ground-cell.hpp"
#include "ground-traits.hpp"
+#include "ground-cell.hpp"
+#include "vobj-cell.hpp"
#include "atlas-loader.hpp"
#include "atlas-loader-storage.hpp"
-#include <Corrade/Containers/Pair.h>
-#include <Magnum/Trade/ImageData.h>
-
#ifdef __GNUG__
#pragma GCC diagnostic ignored "-Walloca"
#endif
@@ -31,8 +29,7 @@ StringView loader_impl::shader(StringView filename) noexcept
return ret;
}
-loader_impl::loader_impl() :
- _ground_loader{ make_ground_atlas_loader() }
+loader_impl::loader_impl()
{
missing_wall_atlases.reserve(32);
system_init();
diff --git a/loader/impl.hpp b/loader/impl.hpp
index a1ea4d88..e119ba13 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -76,11 +76,11 @@ struct loader_impl final : loader_
void get_scenery_list();
// >-----> vobjs >----->
- tsl::robin_map<StringView, const struct vobj_info*> vobj_atlas_map;
- std::vector<struct vobj_info> vobjs;
+ tsl::robin_map<StringView, const struct vobj_cell*> vobj_atlas_map;
+ std::vector<struct vobj_cell> vobjs;
std::shared_ptr<class anim_atlas> make_vobj_anim_atlas(StringView name, StringView image_filename);
- const struct vobj_info& vobj(StringView name) override;
- ArrayView<const struct vobj_info> vobj_list() override;
+ const struct vobj_cell& vobj(StringView name) override;
+ ArrayView<const struct vobj_cell> vobj_list() override;
void get_vobj_list();
};
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 452b6fcc..23a9ddf3 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -18,19 +18,13 @@ struct anim_def;
class anim_atlas;
struct anim_cell;
struct scenery_proto;
-struct vobj_info;
+struct vobj_cell;
class ground_atlas;
struct ground_cell;
struct wall_cell;
class wall_atlas;
struct scenery_proto;
-struct vobj_info final
-{
- String name, descr;
- std::shared_ptr<anim_atlas> atlas;
-};
-
struct loader_
{
virtual StringView shader(StringView filename) noexcept = 0;
@@ -48,8 +42,8 @@ struct loader_
virtual const scenery_proto& scenery(StringView name) noexcept(false) = 0;
virtual StringView startup_directory() noexcept = 0;
static StringView strip_prefix(StringView name);
- virtual const vobj_info& vobj(StringView name) = 0;
- virtual ArrayView<const struct vobj_info> vobj_list() = 0;
+ virtual const vobj_cell& vobj(StringView name) = 0;
+ virtual ArrayView<const struct vobj_cell> vobj_list() = 0;
static StringView make_atlas_path(char(&buf)[fm_FILENAME_MAX], StringView dir, StringView name);
[[nodiscard]] static bool check_atlas_name(StringView name) noexcept;
diff --git a/loader/vobj-cell.hpp b/loader/vobj-cell.hpp
new file mode 100644
index 00000000..1fa22ea2
--- /dev/null
+++ b/loader/vobj-cell.hpp
@@ -0,0 +1,15 @@
+#pragma once
+#include <cr/String.h>
+#include <memory>
+
+namespace floormat {
+
+class anim_atlas;
+
+struct vobj_cell final
+{
+ String name, descr;
+ std::shared_ptr<class anim_atlas> atlas;
+};
+
+} // namespace floormat
diff --git a/loader/vobj.cpp b/loader/vobj.cpp
index 5f7fc2fe..d437df69 100644
--- a/loader/vobj.cpp
+++ b/loader/vobj.cpp
@@ -4,6 +4,7 @@
#include "src/anim-atlas.hpp"
#include "src/anim.hpp"
#include "compat/exception.hpp"
+#include "loader/vobj-cell.hpp"
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/StridedArrayView.h>
#include <Corrade/Utility/Path.h>
@@ -89,7 +90,7 @@ void loader_impl::get_vobj_list()
for (const auto& [name, descr, img_name] : vec)
{
auto atlas = make_vobj_anim_atlas(name, img_name);
- auto info = vobj_info{name, descr, atlas};
+ auto info = vobj_cell{name, descr, atlas};
vobjs.push_back(std::move(info));
const auto& x = vobjs.back();
vobj_atlas_map[x.atlas->name()] = &x;
@@ -98,7 +99,7 @@ void loader_impl::get_vobj_list()
fm_assert(!vobjs.empty());
}
-ArrayView<const vobj_info> loader_impl::vobj_list()
+ArrayView<const vobj_cell> loader_impl::vobj_list()
{
if (vobjs.empty())
get_vobj_list();
@@ -106,7 +107,7 @@ ArrayView<const vobj_info> loader_impl::vobj_list()
return vobjs;
}
-const struct vobj_info& loader_impl::vobj(StringView name)
+const struct vobj_cell& loader_impl::vobj(StringView name)
{
if (vobjs.empty())
get_vobj_list();
diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp
index a68be2db..e54b0067 100644
--- a/serialize/savegame.cpp
+++ b/serialize/savegame.cpp
@@ -17,6 +17,7 @@
#include "src/scenery.hpp"
#include "src/critter.hpp"
#include "src/light.hpp"
+#include "loader/vobj-cell.hpp"
#include <cstring>
#include <cstdio>
diff --git a/src/light.cpp b/src/light.cpp
index 675646eb..3de02885 100644
--- a/src/light.cpp
+++ b/src/light.cpp
@@ -2,6 +2,7 @@
#include "tile-constants.hpp"
#include "shaders/shader.hpp"
#include "loader/loader.hpp"
+#include "loader/vobj-cell.hpp"
#include <cmath>
namespace floormat {