summaryrefslogtreecommitdiffhomepage
path: root/loader
diff options
context:
space:
mode:
Diffstat (limited to 'loader')
-rw-r--r--loader/error-tex.cpp15
-rw-r--r--loader/impl.hpp5
-rw-r--r--loader/loader.hpp2
-rw-r--r--loader/texture.cpp7
-rw-r--r--loader/wall-atlas.cpp6
5 files changed, 27 insertions, 8 deletions
diff --git a/loader/error-tex.cpp b/loader/error-tex.cpp
new file mode 100644
index 00000000..4cc64f91
--- /dev/null
+++ b/loader/error-tex.cpp
@@ -0,0 +1,15 @@
+#include "impl.hpp"
+#include <Magnum/Math/Vector4.h>
+#include <Magnum/PixelFormat.h>
+#include <Magnum/Trade/ImageData.h>
+
+namespace floormat::loader_detail {
+
+Trade::ImageData2D loader_impl::make_error_texture()
+{
+ static const Vector4ub data[] = { {255, 0, 255, 255} }; // magenta
+ return Trade::ImageData2D{PixelFormat::RGBA8Unorm, {1, 1}, {},
+ Containers::arrayView(data, 1), {}, {}};
+}
+
+} // namespace floormat::loader_detail
diff --git a/loader/impl.hpp b/loader/impl.hpp
index 1ff3f421..a5a197c9 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -39,9 +39,10 @@ struct loader_impl final : loader_
// >-----> resources >----->
Optional<Utility::Resource> shader_res;
-
StringView shader(StringView filename) noexcept override;
- Trade::ImageData2D texture(StringView prefix, StringView filename) noexcept(false) override;
+
+ Trade::ImageData2D make_error_texture();
+ Trade::ImageData2D texture(StringView prefix, StringView filename, bool fail_ok = true) noexcept(false) override;
// >-----> walls >----->
struct wall_index { uint32_t val = (uint32_t)-1; };
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 072d0f06..ac99cfb5 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -27,7 +27,7 @@ struct wall_info;
struct loader_
{
virtual StringView shader(StringView filename) noexcept = 0;
- virtual Trade::ImageData2D texture(StringView prefix, StringView filename) noexcept(false) = 0;
+ virtual Trade::ImageData2D texture(StringView prefix, StringView filename, bool fail_ok = true) noexcept(false) = 0;
// todo remove Optional when wall_atlas is fully implemented -sh 20231122
virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename, Vector2ub size, Optional<pass_mode> pass) noexcept(false) = 0;
virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename) noexcept(false) = 0;
diff --git a/loader/texture.cpp b/loader/texture.cpp
index 28b903c2..1e4ac709 100644
--- a/loader/texture.cpp
+++ b/loader/texture.cpp
@@ -12,7 +12,7 @@
namespace floormat::loader_detail {
fm_noinline
-Trade::ImageData2D loader_impl::texture(StringView prefix, StringView filename_) noexcept(false)
+Trade::ImageData2D loader_impl::texture(StringView prefix, StringView filename_, bool fail_ok) noexcept(false)
{
ensure_plugins();
@@ -48,7 +48,10 @@ Trade::ImageData2D loader_impl::texture(StringView prefix, StringView filename_)
const auto path = Path::currentDirectory();
buf[len] = '\0';
char errbuf[128];
- fm_throw("can't open image '{}' (cwd '{}'): {}"_cf, buf, path ? StringView{*path} : "(null)"_s, get_error_string(errbuf));
+ if (!fail_ok)
+ fm_throw("can't open image '{}' (cwd '{}'): {}"_cf, buf, path ? StringView{*path} : "(null)"_s, get_error_string(errbuf));
+ else
+ return make_error_texture();
}
} // namespace floormat::loader_detail
diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp
index 1ba46ee7..1b10740c 100644
--- a/loader/wall-atlas.cpp
+++ b/loader/wall-atlas.cpp
@@ -24,15 +24,15 @@ using nlohmann::json;
val = {};
val.name = j["name"];
fm_soft_assert(loader.check_atlas_name(val.name));
- if (j.contains("descr"))
- val.descr = j["descr"];
+ if (j.contains("description"))
+ val.descr = j["description"];
}
[[maybe_unused]] static void to_json(json& j, const wall_info& val)
{
j["name"] = val.name;
if (val.descr)
- j["descr"] = val.descr;
+ j["description"] = val.descr;
}
} // namespace floormat