diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-11 00:39:28 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-11 08:49:51 +0100 |
commit | 5267d7b5b52fb8112dc4001b3b8f7985521af5ba (patch) | |
tree | 32952992edee1144841b1cb8d69965ee981fe870 /loader/wall-traits.cpp | |
parent | b8c538bcdfdcc7f2739934ea96fe98ae61b565dc (diff) |
wip atlas loader
Diffstat (limited to 'loader/wall-traits.cpp')
-rw-r--r-- | loader/wall-traits.cpp | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/loader/wall-traits.cpp b/loader/wall-traits.cpp index d31aba4e..70d729c0 100644 --- a/loader/wall-traits.cpp +++ b/loader/wall-traits.cpp @@ -22,35 +22,17 @@ StringView wall_traits::name_of(const Cell& x) { return x.name; } StringView wall_traits::name_of(const Atlas& x) { return x.name(); } String& wall_traits::name_of(Cell& x) { return x.name; } -void wall_traits::ensure_atlases_loaded(Storage& st) +void wall_traits::ensure_atlases_loaded(Storage& s) { - if (!st.name_map.empty()) [[likely]] - return; + fm_assert(s.name_map.empty()); - st.cell_array = wall_cell::load_atlases_from_json().vec; - st.name_map.max_load_factor(0.4f); - st.name_map.reserve((st.cell_array.size()+1)*3/2); - st.name_map[loader.INVALID] = -1uz; - - for (auto& c : st.cell_array) - if (c.name.isSmall()) - c.name = String{AllocatedInit, c.name}; - - for (auto i = 0uz; const auto& c : st.cell_array) - { - fm_soft_assert(c.name != loader.INVALID); - fm_soft_assert(loader.check_atlas_name(c.name)); - fm_soft_assert(!c.atlas); - fm_assert(!c.name.isSmall()); - st.name_map[c.name] = i++; - } + s.cell_array = wall_cell::load_atlases_from_json().vec; + s.name_map[loader.INVALID] = -1uz; } -auto wall_traits::make_invalid_atlas(Storage& st) -> const Cell& +auto wall_traits::make_invalid_atlas(Storage& s) -> Pointer<Cell> { - if (st.invalid_atlas) [[likely]] - return *st.invalid_atlas; - + fm_assert(!s.invalid_atlas); constexpr auto name = loader_::INVALID; constexpr auto frame_size = Vector2ui{tile_size_xy, tile_size_z}; @@ -64,8 +46,7 @@ auto wall_traits::make_invalid_atlas(Storage& st) -> const Cell& {{ {.val = 0}, {}, }}, {1u}, }, name, loader.make_error_texture(frame_size)); - st.invalid_atlas = Pointer<wall_cell>{InPlaceInit, wall_cell{ .atlas = std::move(a), .name = name, } }; - return *st.invalid_atlas; + return Pointer<wall_cell>{InPlaceInit, wall_cell{ .atlas = std::move(a), .name = name, } }; } auto wall_traits::make_atlas(StringView name, const Cell&) -> std::shared_ptr<Atlas> |