summaryrefslogtreecommitdiffhomepage
path: root/loader
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-01-17 11:45:27 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-01-17 11:45:27 +0100
commitdba1218fe0ed78d5b264538f2f4553900e9fd1eb (patch)
tree5253eb2f20484f100a0c40b10efb3babcfe9db17 /loader
parent0e94c1acc5ed8d44ce26eb4b4cef8070442d10a4 (diff)
a
Diffstat (limited to 'loader')
-rw-r--r--loader/ground-atlas.cpp41
-rw-r--r--loader/impl.hpp2
-rw-r--r--loader/loader.hpp7
3 files changed, 39 insertions, 11 deletions
diff --git a/loader/ground-atlas.cpp b/loader/ground-atlas.cpp
index feae0ac5..1a0d3905 100644
--- a/loader/ground-atlas.cpp
+++ b/loader/ground-atlas.cpp
@@ -30,10 +30,22 @@ std::shared_ptr<ground_atlas> loader_impl::get_ground_atlas(StringView name, Vec
}
// todo copypasta from wall-atlas.cpp
-std::shared_ptr<class ground_atlas> loader_impl::ground_atlas(StringView name, bool fail_ok) noexcept(false)
+std::shared_ptr<class ground_atlas> loader_impl::ground_atlas(StringView name, loader_policy policy) noexcept(false)
{
(void)ground_atlas_list();
- fm_assert(fail_ok || name != INVALID);
+
+ switch (policy)
+ {
+ case loader_policy::error:
+ fm_assert(name != INVALID);
+ break;
+ case loader_policy::ignore:
+ case loader_policy::warn:
+ break;
+ default:
+ fm_abort("invalid loader_policy");
+ }
+
fm_soft_assert(check_atlas_name(name));
auto it = ground_atlas_map.find(name);
@@ -41,10 +53,15 @@ std::shared_ptr<class ground_atlas> loader_impl::ground_atlas(StringView name, b
{
if (it->second == (ground_info*)-1) [[unlikely]]
{
- if (fail_ok) [[likely]]
- goto missing_ok;
- else
+ switch (policy)
+ {
+ case loader_policy::error:
goto error;
+ case loader_policy::warn:
+ case loader_policy::ignore:
+ goto missing_ok;
+ }
+ std::unreachable();
}
else if (!it->second->atlas)
return it->second->atlas = get_ground_atlas(name, it->second->size, it->second->pass);
@@ -53,13 +70,19 @@ std::shared_ptr<class ground_atlas> loader_impl::ground_atlas(StringView name, b
}
else
{
- if (fail_ok) [[likely]]
- goto missing;
- else
+ switch (policy)
+ {
+ case loader_policy::error:
goto error;
+ case loader_policy::warn:
+ goto missing_warn;
+ case loader_policy::ignore:
+ goto missing_ok;
+ }
+ std::unreachable();
}
-missing:
+missing_warn:
{
missing_ground_atlases.push_back(String { AllocatedInit, name });
auto string_view = StringView{missing_ground_atlases.back()};
diff --git a/loader/impl.hpp b/loader/impl.hpp
index a4a33747..fd51b4f3 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -61,7 +61,7 @@ struct loader_impl final : loader_
std::vector<ground_info> ground_atlas_array;
std::vector<String> missing_ground_atlases;
Pointer<ground_info> invalid_ground_atlas;
- std::shared_ptr<class ground_atlas> ground_atlas(StringView filename, bool fail_ok) noexcept(false) override;
+ std::shared_ptr<class ground_atlas> ground_atlas(StringView filename, loader_policy policy) noexcept(false) override;
ArrayView<const ground_info> ground_atlas_list() noexcept(false) override;
void get_ground_atlas_list();
const ground_info& make_invalid_ground_atlas();
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 51a15b14..be132751 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -28,12 +28,17 @@ struct vobj_info final
std::shared_ptr<anim_atlas> atlas;
};
+enum class loader_policy : uint8_t
+{
+ error, warn, ignore, DEFAULT = error,
+};
+
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, bool fail_ok = false) 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;
virtual std::shared_ptr<class wall_atlas> wall_atlas(StringView name, bool fail_ok = false) noexcept(false) = 0;