From 07018b1d1247f4fb558a2b551dd8d4ca35346377 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 14 Feb 2024 19:40:18 +0100 Subject: switch back to using StringView in atlas loader --- loader/anim-traits.cpp | 3 ++- loader/atlas-loader-storage.hpp | 8 ++++---- loader/atlas-loader.inl | 27 +++++++++++++++++++-------- loader/ground-cell.cpp | 6 ++++-- loader/ground-cell.hpp | 3 +-- loader/ground-traits.cpp | 3 +-- loader/impl.cpp | 1 + loader/scenery-cell.cpp | 6 +++--- loader/scenery-cell.hpp | 13 +------------ loader/scenery-traits.cpp | 3 +-- loader/wall-cell.cpp | 7 ++++--- loader/wall-cell.hpp | 3 +-- loader/wall-traits.cpp | 3 +-- 13 files changed, 43 insertions(+), 43 deletions(-) (limited to 'loader') diff --git a/loader/anim-traits.cpp b/loader/anim-traits.cpp index c4139381..bb784de1 100644 --- a/loader/anim-traits.cpp +++ b/loader/anim-traits.cpp @@ -9,7 +9,7 @@ #include "compat/exception.hpp" #include #include -#include +#include #include #include #include @@ -29,6 +29,7 @@ void anim_traits::atlas_list(Storage& s) { fm_debug_assert(s.name_map.empty()); s.cell_array = {}; + arrayReserve(s.cell_array, 16); s.name_map[loader.INVALID] = -1uz; } diff --git a/loader/atlas-loader-storage.hpp b/loader/atlas-loader-storage.hpp index fc540a6e..1cc1e340 100644 --- a/loader/atlas-loader-storage.hpp +++ b/loader/atlas-loader-storage.hpp @@ -1,8 +1,8 @@ #pragma once #include "compat/int-hash.hpp" #include "atlas-loader-fwd.hpp" -#include #include +#include #include #include @@ -19,9 +19,9 @@ struct atlas_storage using Atlas = typename Traits::Atlas; using Cell = typename Traits::Cell; - tsl::robin_map name_map; - std::vector cell_array; - std::vector missing_atlas_names; + tsl::robin_map name_map; + Array cell_array; + Array missing_atlas_names; Optional invalid_atlas; ~atlas_storage() noexcept = default; diff --git a/loader/atlas-loader.inl b/loader/atlas-loader.inl index d307a021..490ff3a4 100644 --- a/loader/atlas-loader.inl +++ b/loader/atlas-loader.inl @@ -9,13 +9,16 @@ #include #include #include +#include namespace floormat::loader_detail { template atlas_loader::atlas_loader(TRAITS&& traits): // NOLINT(*-rvalue-reference-param-not-moved) t{Utility::move(traits)} -{} +{ + arrayReserve(s.missing_atlas_names, 8); +} template atlas_loader::atlas_loader() requires std::is_default_constructible_v: atlas_loader{TRAITS{}} {} @@ -36,17 +39,18 @@ auto atlas_loader::atlas_list() -> ArrayView String& name{t.name_of(c)}; fm_soft_assert(name != loader.INVALID); fm_soft_assert(loader.check_atlas_name(name)); + if (name.isSmall()) name = String{AllocatedInit, name}; } s.name_map.max_load_factor(0.4f); - if (!s.cell_array.empty()) + if (!s.cell_array.isEmpty()) s.name_map.reserve(s.cell_array.size()*5/2 + 1); for (auto i = 0uz; const auto& c : s.cell_array) s.name_map[t.name_of(c)] = i++; { const Cell& invalid_atlas{get_invalid_atlas()}; size_t sz{s.cell_array.size()}; - s.cell_array.push_back(invalid_atlas); + arrayAppend(s.cell_array, invalid_atlas); s.name_map[loader.INVALID] = sz; } @@ -54,7 +58,7 @@ auto atlas_loader::atlas_list() -> ArrayView fm_assert(index < s.cell_array.size() || index == -1uz); fm_debug_assert(!s.name_map.empty()); - fm_debug_assert(!s.cell_array.empty()); + fm_debug_assert(!s.cell_array.isEmpty()); return { s.cell_array.data(), s.cell_array.size() }; } @@ -134,8 +138,10 @@ auto atlas_loader::get_atlas(StringView name, const loader_policy fm_assert(!t.atlas_of(*c_)); fm_assert(t.name_of(*c_) == name); const size_t index{s.cell_array.size()}; - s.cell_array.emplace_back(Utility::move(*c_)); + arrayAppend(s.cell_array, Utility::move(*c_)); Cell& c{s.cell_array.back()}; + String& name_{t.name_of(c)}; + if (name_.isSmall()) name_ = String{AllocatedInit, name_}; t.atlas_of(c) = make_atlas(name, c); fm_debug_assert(t.atlas_of(c)); s.name_map[t.name_of(c)] = index; @@ -162,8 +168,11 @@ error: fm_throw("no such atlas '{}'"_cf, name); missing_warn: - s.missing_atlas_names.push_back(name); - s.name_map[ s.missing_atlas_names.back() ] = -1uz; + arrayAppend(s.missing_atlas_names, name); + if (auto& back = s.missing_atlas_names.back(); back.isSmall()) back = String{AllocatedInit, back}; + String& back{s.missing_atlas_names.back()}; + if (back.isSmall()) back = String{AllocatedInit, back}; + s.name_map[back] = -1uz; if (name != loader.INVALID) DBG_nospace << t.loader_name() << " '" << name << "' doesn't exist"; @@ -210,10 +219,12 @@ template void atlas_loader::register_cell(Cell&& c) { String& name{t.name_of(c)}; + if (name.isSmall()) name = String{AllocatedInit, name}; fm_assert(!s.name_map.contains(name)); fm_soft_assert(loader.check_atlas_name(name)); const size_t index{s.cell_array.size()}; - s.cell_array.push_back(Utility::move(c)); + arrayAppend(s.cell_array, Utility::move(c)); + if (String& name_ = t.name_of(s.cell_array.back()); name_.isSmall()) name_ = String{AllocatedInit, name_}; s.name_map[ t.name_of(s.cell_array.back()) ] = index; } diff --git a/loader/ground-cell.cpp b/loader/ground-cell.cpp index f8373d76..82829b62 100644 --- a/loader/ground-cell.cpp +++ b/loader/ground-cell.cpp @@ -4,14 +4,16 @@ #include "serialize/json-helper.hpp" //#include "serialize/corrade-string.hpp" #include "serialize/ground-atlas.hpp" +#include "serialize/corrade-array.hpp" +#include namespace floormat { -vector_wrapper ground_cell::load_atlases_from_json() +Array ground_cell::load_atlases_from_json() { char buf[fm_FILENAME_MAX]; auto s = loader.make_atlas_path(buf, loader.GROUND_TILESET_PATH, "ground.json"_s); - return {json_helper::from_json>(s)}; + return json_helper::from_json>(s); } } // namespace floormat diff --git a/loader/ground-cell.hpp b/loader/ground-cell.hpp index 0e1e51be..9326cb9c 100644 --- a/loader/ground-cell.hpp +++ b/loader/ground-cell.hpp @@ -1,5 +1,4 @@ #pragma once -#include "compat/vector-wrapper-fwd.hpp" #include "src/pass-mode.hpp" #include #include @@ -16,7 +15,7 @@ struct ground_cell Vector2ub size; pass_mode pass = pass_mode::pass; - static vector_wrapper load_atlases_from_json(); + static Array load_atlases_from_json(); }; } // namespace floormat diff --git a/loader/ground-traits.cpp b/loader/ground-traits.cpp index 869cf214..fd3b2dc1 100644 --- a/loader/ground-traits.cpp +++ b/loader/ground-traits.cpp @@ -5,7 +5,6 @@ #include "src/tile-defs.hpp" #include "src/ground-atlas.hpp" #include "compat/assert.hpp" -#include "compat/vector-wrapper.hpp" #include #include #include @@ -24,7 +23,7 @@ String& ground_traits::name_of(Cell& x) { return x.name; } void ground_traits::atlas_list(Storage& s) { fm_debug_assert(s.name_map.empty()); - s.cell_array = ground_cell::load_atlases_from_json().vec; + s.cell_array = ground_cell::load_atlases_from_json(); s.name_map[loader.INVALID] = -1uz; } diff --git a/loader/impl.cpp b/loader/impl.cpp index 969688ea..cc37e8c8 100644 --- a/loader/impl.cpp +++ b/loader/impl.cpp @@ -12,6 +12,7 @@ #include "vobj-cell.hpp" #include "atlas-loader.hpp" #include "atlas-loader-storage.hpp" +#include "serialize/json-wrapper.hpp" namespace floormat { diff --git a/loader/scenery-cell.cpp b/loader/scenery-cell.cpp index 96b256cb..d8b0f885 100644 --- a/loader/scenery-cell.cpp +++ b/loader/scenery-cell.cpp @@ -1,18 +1,18 @@ #include "scenery-cell.hpp" -#include "compat/vector-wrapper.hpp" #include "src/anim-atlas.hpp" #include "loader/loader.hpp" #include "serialize/json-helper.hpp" #include "serialize/scenery.hpp" #include "serialize/json-wrapper.hpp" +#include "serialize/corrade-array.hpp" namespace floormat { -vector_wrapper scenery_cell::load_atlases_from_json() +Array scenery_cell::load_atlases_from_json() { char buf[fm_FILENAME_MAX]; auto path = loader.make_atlas_path(buf, loader.SCENERY_PATH, "scenery.json"_s); - return { json_helper::from_json>(path) }; + return json_helper::from_json>(path); } } // namespace floormat diff --git a/loader/scenery-cell.hpp b/loader/scenery-cell.hpp index 2b74cfef..b33f9441 100644 --- a/loader/scenery-cell.hpp +++ b/loader/scenery-cell.hpp @@ -1,5 +1,4 @@ #pragma once -#include "compat/vector-wrapper-fwd.hpp" #include "compat/safe-ptr.hpp" #include "src/scenery.hpp" #include @@ -11,24 +10,14 @@ namespace floormat { struct json_wrapper; struct scenery_proto; -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-copy-with-user-provided-dtor" -#endif - struct scenery_cell final { String name; safe_ptr data{make_json_wrapper()}; Optional proto; - ~scenery_cell() noexcept; - static vector_wrapper load_atlases_from_json(); + static Array load_atlases_from_json(); [[nodiscard]] static json_wrapper* make_json_wrapper(); }; -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - } // namespace floormat diff --git a/loader/scenery-traits.cpp b/loader/scenery-traits.cpp index d8add93b..fcc00d02 100644 --- a/loader/scenery-traits.cpp +++ b/loader/scenery-traits.cpp @@ -1,6 +1,5 @@ #include "scenery-traits.hpp" #include "compat/assert.hpp" -#include "compat/vector-wrapper.hpp" #include "atlas-loader-storage.hpp" #include "scenery-cell.hpp" #include "loader.hpp" @@ -27,7 +26,7 @@ String& scenery_traits::name_of(Cell& x) { return x.name; } void scenery_traits::atlas_list(Storage& s) { fm_debug_assert(s.name_map.empty()); - s.cell_array = scenery_cell::load_atlases_from_json().vec; + s.cell_array = scenery_cell::load_atlases_from_json(); s.name_map[loader.INVALID] = -1uz; } diff --git a/loader/wall-cell.cpp b/loader/wall-cell.cpp index 4e12f0be..8870b891 100644 --- a/loader/wall-cell.cpp +++ b/loader/wall-cell.cpp @@ -1,9 +1,10 @@ #include "wall-cell.hpp" -#include "compat/vector-wrapper.hpp" #include "compat/exception.hpp" #include "serialize/json-helper.hpp" #include "serialize/corrade-string.hpp" +#include "serialize/corrade-array.hpp" #include "loader/loader.hpp" +#include namespace floormat { @@ -20,11 +21,11 @@ using nlohmann::json; j["name"] = val.name; } -vector_wrapper wall_cell::load_atlases_from_json() +Array wall_cell::load_atlases_from_json() { char buf[fm_FILENAME_MAX]; auto s = loader.make_atlas_path(buf, loader.WALL_TILESET_PATH, "walls.json"_s); - return {json_helper::from_json>(s)}; + return {json_helper::from_json>(s)}; } } // namespace floormat diff --git a/loader/wall-cell.hpp b/loader/wall-cell.hpp index e8cd15d5..541a8339 100644 --- a/loader/wall-cell.hpp +++ b/loader/wall-cell.hpp @@ -1,5 +1,4 @@ #pragma once -#include "compat/vector-wrapper-fwd.hpp" #include #include @@ -12,7 +11,7 @@ struct wall_cell std::shared_ptr atlas; String name; - static vector_wrapper load_atlases_from_json(); + static Array load_atlases_from_json(); }; } // namespace floormat diff --git a/loader/wall-traits.cpp b/loader/wall-traits.cpp index 0820629a..37056746 100644 --- a/loader/wall-traits.cpp +++ b/loader/wall-traits.cpp @@ -5,7 +5,6 @@ #include "src/tile-defs.hpp" #include "src/wall-atlas.hpp" #include "compat/exception.hpp" -#include "compat/vector-wrapper.hpp" #include #include #include @@ -23,7 +22,7 @@ String& wall_traits::name_of(Cell& x) { return x.name; } void wall_traits::atlas_list(Storage& s) { fm_debug_assert(s.name_map.empty()); - s.cell_array = wall_cell::load_atlases_from_json().vec; + s.cell_array = wall_cell::load_atlases_from_json(); s.name_map[loader.INVALID] = -1uz; } -- cgit v1.2.3