summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-14 19:40:18 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-14 19:40:18 +0100
commit07018b1d1247f4fb558a2b551dd8d4ca35346377 (patch)
tree51ee528771fbb77ee1f62adf38a1d8cca1c8ac8c
parent626e49662839a1ecd505547a5671d1ab8ac5b4aa (diff)
switch back to using StringView in atlas loader
-rw-r--r--editor/ground-editor.cpp1
m---------external/magnum0
-rw-r--r--loader/anim-traits.cpp3
-rw-r--r--loader/atlas-loader-storage.hpp8
-rw-r--r--loader/atlas-loader.inl27
-rw-r--r--loader/ground-cell.cpp6
-rw-r--r--loader/ground-cell.hpp3
-rw-r--r--loader/ground-traits.cpp3
-rw-r--r--loader/impl.cpp1
-rw-r--r--loader/scenery-cell.cpp6
-rw-r--r--loader/scenery-cell.hpp13
-rw-r--r--loader/scenery-traits.cpp3
-rw-r--r--loader/wall-cell.cpp7
-rw-r--r--loader/wall-cell.hpp3
-rw-r--r--loader/wall-traits.cpp3
-rw-r--r--serialize/scenery.cpp11
-rw-r--r--src/scenery.cpp6
-rw-r--r--src/scenery.hpp6
18 files changed, 50 insertions, 60 deletions
diff --git a/editor/ground-editor.cpp b/editor/ground-editor.cpp
index 55b779b5..b1239b02 100644
--- a/editor/ground-editor.cpp
+++ b/editor/ground-editor.cpp
@@ -28,6 +28,7 @@ ground_editor::~ground_editor() noexcept = default;
void ground_editor::load_atlases()
{
fm_assert(_atlases.empty());
+
for (const auto& g : loader.ground_atlas_list())
{
if (g.name != loader.INVALID) [[likely]]
diff --git a/external/magnum b/external/magnum
-Subproject cb51358646dca9d6e7b8113d3d10e4c04725f5b
+Subproject e0a12bdc0b744ced20e0442ded6cd3f95b4677c
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 <cr/Move.h>
#include <cr/StringView.h>
-#include <cr/Array.h>
+#include <cr/GrowableArray.h>
#include <cr/StridedArrayView.h>
#include <cr/Pointer.h>
#include <cr/Optional.h>
@@ -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 <vector>
#include <cr/StringView.h>
+#include <cr/Array.h>
#include <cr/Optional.h>
#include <tsl/robin_map.h>
@@ -19,9 +19,9 @@ struct atlas_storage
using Atlas = typename Traits::Atlas;
using Cell = typename Traits::Cell;
- tsl::robin_map<String, size_t, hash_string_view, string_equals> name_map;
- std::vector<Cell> cell_array;
- std::vector<String> missing_atlas_names;
+ tsl::robin_map<StringView, size_t, hash_string_view, string_equals> name_map;
+ Array<Cell> cell_array;
+ Array<String> missing_atlas_names;
Optional<Cell> 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 <cr/ArrayView.h>
#include <cr/Optional.h>
#include <cr/Move.h>
+#include <cr/GrowableArray.h>
namespace floormat::loader_detail {
template<typename ATLAS, typename TRAITS>
atlas_loader<ATLAS, TRAITS>::atlas_loader(TRAITS&& traits): // NOLINT(*-rvalue-reference-param-not-moved)
t{Utility::move(traits)}
-{}
+{
+ arrayReserve(s.missing_atlas_names, 8);
+}
template<typename ATLAS, typename TRAITS>
atlas_loader<ATLAS, TRAITS>::atlas_loader() requires std::is_default_constructible_v<TRAITS>: atlas_loader{TRAITS{}} {}
@@ -36,17 +39,18 @@ auto atlas_loader<ATLAS, TRAITS>::atlas_list() -> ArrayView<const Cell>
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, TRAITS>::atlas_list() -> ArrayView<const Cell>
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<ATLAS, TRAITS>::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<typename ATLAS, typename TRAITS>
void atlas_loader<ATLAS, TRAITS>::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 <cr/Array.h>
namespace floormat {
-vector_wrapper<const ground_cell> ground_cell::load_atlases_from_json()
+Array<ground_cell> 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<std::vector<ground_cell>>(s)};
+ return json_helper::from_json<Array<ground_cell>>(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 <memory>
#include <Corrade/Containers/String.h>
@@ -16,7 +15,7 @@ struct ground_cell
Vector2ub size;
pass_mode pass = pass_mode::pass;
- static vector_wrapper<const ground_cell> load_atlases_from_json();
+ static Array<ground_cell> 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 <cr/Optional.h>
#include <Corrade/Containers/StringView.h>
#include <Corrade/Containers/Pointer.h>
@@ -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<const scenery_cell> scenery_cell::load_atlases_from_json()
+Array<scenery_cell> 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<std::vector<scenery_cell>>(path) };
+ return json_helper::from_json<Array<scenery_cell>>(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 <memory>
@@ -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<json_wrapper> data{make_json_wrapper()};
Optional<scenery_proto> proto;
- ~scenery_cell() noexcept;
- static vector_wrapper<const scenery_cell> load_atlases_from_json();
+ static Array<scenery_cell> 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 <cr/Array.h>
namespace floormat {
@@ -20,11 +21,11 @@ using nlohmann::json;
j["name"] = val.name;
}
-vector_wrapper<const wall_cell> wall_cell::load_atlases_from_json()
+Array<wall_cell> 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<std::vector<wall_cell>>(s)};
+ return {json_helper::from_json<Array<wall_cell>>(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 <memory>
#include <Corrade/Containers/String.h>
@@ -12,7 +11,7 @@ struct wall_cell
std::shared_ptr<wall_atlas> atlas;
String name;
- static vector_wrapper<const wall_cell> load_atlases_from_json();
+ static Array<wall_cell> 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 <cr/StringView.h>
#include <cr/Optional.h>
#include <mg/ImageData.h>
@@ -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;
}
diff --git a/serialize/scenery.cpp b/serialize/scenery.cpp
index ff20d3d3..80f99d32 100644
--- a/serialize/scenery.cpp
+++ b/serialize/scenery.cpp
@@ -13,17 +13,6 @@
namespace floormat {
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-copy-with-user-provided-dtor"
-#endif
-
-scenery_cell::~scenery_cell() noexcept = default;
-
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-
auto scenery_cell::make_json_wrapper() -> json_wrapper* { return new json_wrapper; }
} // namespace floormat
diff --git a/src/scenery.cpp b/src/scenery.cpp
index 1e13d2df..ed5b643f 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -40,10 +40,10 @@ template<typename T> using scenery_to_proto = typename scenery_to_proto_<T>::typ
} // namespace
-scenery_proto::scenery_proto() { type = object_type::scenery; }
+scenery_proto::scenery_proto() noexcept { type = object_type::scenery; }
-scenery_proto& scenery_proto::operator=(const scenery_proto&) = default;
-scenery_proto::scenery_proto(const scenery_proto&) = default;
+scenery_proto& scenery_proto::operator=(const scenery_proto&) noexcept = default;
+scenery_proto::scenery_proto(const scenery_proto&) noexcept = default;
scenery_proto::~scenery_proto() noexcept = default;
scenery_proto::operator bool() const { return atlas != nullptr; }
diff --git a/src/scenery.hpp b/src/scenery.hpp
index e6e483fa..8b003e73 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -47,10 +47,10 @@ struct scenery_proto : object_proto
{
scenery_proto_variants subtype;
- scenery_proto();
- scenery_proto(const scenery_proto&);
+ scenery_proto() noexcept;
+ scenery_proto(const scenery_proto&) noexcept;
~scenery_proto() noexcept override;
- scenery_proto& operator=(const scenery_proto&);
+ scenery_proto& operator=(const scenery_proto&) noexcept;
bool operator==(const object_proto& proto) const override;
explicit operator bool() const;
enum scenery_type scenery_type() const;