summaryrefslogtreecommitdiffhomepage
path: root/loader
diff options
context:
space:
mode:
Diffstat (limited to 'loader')
-rw-r--r--loader/impl.hpp5
-rw-r--r--loader/loader.hpp2
-rw-r--r--loader/wall-atlas.cpp31
-rw-r--r--loader/wall-info.hpp2
4 files changed, 35 insertions, 5 deletions
diff --git a/loader/impl.hpp b/loader/impl.hpp
index a5a197c9..c5fe83b2 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -49,9 +49,12 @@ struct loader_impl final : loader_
tsl::robin_map<StringView, wall_info*> wall_atlas_map;
std::vector<wall_info> wall_atlas_array;
- const wall_info& wall_atlas(StringView name) override;
+ Pointer<wall_info> invalid_wall_atlas;
+
+ const wall_info& wall_atlas(StringView name, bool fail_ok = true) override;
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 path);
// >-----> tile >----->
diff --git a/loader/loader.hpp b/loader/loader.hpp
index ac99cfb5..a7dd8a7f 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -33,7 +33,7 @@ struct loader_
virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename) 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;
- virtual const wall_info& wall_atlas(StringView name) = 0;
+ virtual const wall_info& wall_atlas(StringView name, bool fail_ok = true) = 0;
virtual ArrayView<const wall_info> wall_atlas_list() = 0;
static void destroy();
static loader_& default_loader() noexcept;
diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp
index 1b10740c..23eb6e53 100644
--- a/loader/wall-atlas.cpp
+++ b/loader/wall-atlas.cpp
@@ -7,6 +7,7 @@
#include "wall-info.hpp"
#include "serialize/json-helper.hpp"
#include "serialize/corrade-string.hpp"
+#include "src/tile-defs.hpp"
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/StringIterable.h>
@@ -49,7 +50,28 @@ std::shared_ptr<wall_atlas> loader_impl::get_wall_atlas(StringView name, StringV
return atlas;
}
-const wall_info& loader_impl::wall_atlas(StringView name)
+const wall_info& loader_impl::make_invalid_wall_atlas()
+{
+ if (invalid_wall_atlas) [[likely]]
+ return *invalid_wall_atlas;
+
+ constexpr auto name = "<invalid>"_s;
+ constexpr auto size = Vector3ui{iTILE_SIZE};
+ constexpr auto frame_size = Vector2ui{size.x(), size.z()};
+
+ auto a = std::make_shared<class wall_atlas>(
+ wall_atlas_def {
+ {.name = name, .depth = 8},
+ { {{}, frame_size},},
+ { { {.index = 0, .count = 1, .pixel_size = frame_size, } } },
+ {{ {.val = 0}, {}, {}, {} }},
+ {1u},
+ }, name, make_error_texture());
+ invalid_wall_atlas = Pointer<wall_info>{InPlaceInit, wall_info{ .name = name, .atlas = a } };
+ return *invalid_wall_atlas;
+}
+
+const wall_info& loader_impl::wall_atlas(StringView name, bool fail_ok)
{
fm_soft_assert(check_atlas_name(name));
char buf[FILENAME_MAX];
@@ -57,7 +79,12 @@ const wall_info& loader_impl::wall_atlas(StringView name)
auto it = wall_atlas_map.find(name);
if (it == wall_atlas_map.end())
- fm_throw("no such wall atlas '{}'"_cf, name);
+ {
+ if (!fail_ok)
+ fm_throw("no such wall atlas '{}'"_cf, name);
+ else
+ return make_invalid_wall_atlas();
+ }
fm_assert(it->second != nullptr);
if (!it->second->atlas)
it->second->atlas = get_wall_atlas(it->second->name, path);
diff --git a/loader/wall-info.hpp b/loader/wall-info.hpp
index 570f436d..acd5cdc4 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, descr{};
std::shared_ptr<wall_atlas> atlas;
};