diff options
-rw-r--r-- | loader/ground-atlas.cpp | 41 | ||||
-rw-r--r-- | loader/impl.hpp | 2 | ||||
-rw-r--r-- | loader/loader.hpp | 7 | ||||
-rw-r--r-- | serialize/world-reader.cpp | 2 |
4 files changed, 40 insertions, 12 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; diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index ac247553..68da2537 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -223,7 +223,7 @@ void reader_state::read_chunks(reader_t& s) auto name = lookup_atlas(id); if constexpr(std::is_same_v<ground_atlas, T>) { - auto atlas = loader.ground_atlas(name, true); + auto atlas = loader.ground_atlas(name, loader_policy::warn); fm_soft_assert(v < atlas->num_tiles()); return { atlas, v }; } |