diff options
Diffstat (limited to 'loader')
-rw-r--r-- | loader/anim-atlas.cpp | 6 | ||||
-rw-r--r-- | loader/anim-cell.hpp | 4 | ||||
-rw-r--r-- | loader/anim-traits.cpp | 11 | ||||
-rw-r--r-- | loader/anim-traits.hpp | 8 | ||||
-rw-r--r-- | loader/atlas-loader.hpp | 1 | ||||
-rw-r--r-- | loader/atlas-loader.inl | 1 | ||||
-rw-r--r-- | loader/ground-atlas.cpp | 7 | ||||
-rw-r--r-- | loader/ground-cell.cpp | 1 | ||||
-rw-r--r-- | loader/ground-cell.hpp | 4 | ||||
-rw-r--r-- | loader/ground-traits.cpp | 13 | ||||
-rw-r--r-- | loader/ground-traits.hpp | 8 | ||||
-rw-r--r-- | loader/impl.cpp | 1 | ||||
-rw-r--r-- | loader/impl.hpp | 18 | ||||
-rw-r--r-- | loader/loader.hpp | 14 | ||||
-rw-r--r-- | loader/scenery-traits.hpp | 2 | ||||
-rw-r--r-- | loader/vobj-cell.hpp | 4 | ||||
-rw-r--r-- | loader/vobj.cpp | 5 | ||||
-rw-r--r-- | loader/wall-atlas.cpp | 6 | ||||
-rw-r--r-- | loader/wall-cell.cpp | 1 | ||||
-rw-r--r-- | loader/wall-cell.hpp | 4 | ||||
-rw-r--r-- | loader/wall-traits.cpp | 11 | ||||
-rw-r--r-- | loader/wall-traits.hpp | 8 |
22 files changed, 71 insertions, 67 deletions
diff --git a/loader/anim-atlas.cpp b/loader/anim-atlas.cpp index 76a656e4..cfbe7245 100644 --- a/loader/anim-atlas.cpp +++ b/loader/anim-atlas.cpp @@ -2,13 +2,13 @@ #include "atlas-loader.inl" #include "anim-cell.hpp" #include "anim-traits.hpp" -#include "compat/exception.hpp" +#include "compat/borrowed-ptr.inl" namespace floormat::loader_detail { template class atlas_loader<anim_atlas>; -std::shared_ptr<class anim_atlas> loader_impl::get_anim_atlas(StringView path) noexcept(false) +bptr<class anim_atlas> loader_impl::get_anim_atlas(StringView path) noexcept(false) { return _anim_loader->make_atlas(path, {}); } @@ -23,7 +23,7 @@ ArrayView<const anim_cell> loader_impl::anim_atlas_list() return _anim_loader->atlas_list(); } -std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView dir, loader_policy p) noexcept(false) +bptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView dir, loader_policy p) noexcept(false) { char buf[fm_FILENAME_MAX]; auto path = make_atlas_path(buf, dir, name); diff --git a/loader/anim-cell.hpp b/loader/anim-cell.hpp index 37bbb7d8..ce3f6d54 100644 --- a/loader/anim-cell.hpp +++ b/loader/anim-cell.hpp @@ -1,5 +1,5 @@ #pragma once -#include <memory> +#include "compat/borrowed-ptr.hpp" #include <Corrade/Containers/String.h> namespace floormat { @@ -8,7 +8,7 @@ class anim_atlas; struct anim_cell { - std::shared_ptr<anim_atlas> atlas; + bptr<anim_atlas> atlas; String name; }; diff --git a/loader/anim-traits.cpp b/loader/anim-traits.cpp index 524f4c24..09da71e8 100644 --- a/loader/anim-traits.cpp +++ b/loader/anim-traits.cpp @@ -7,6 +7,7 @@ #include "serialize/json-helper.hpp" #include "serialize/anim.hpp" #include "compat/exception.hpp" +#include "compat/borrowed-ptr.inl" #include <cr/StringView.h> #include <cr/GrowableArray.h> #include <cr/StridedArrayView.h> @@ -19,8 +20,8 @@ namespace floormat::loader_detail { using anim_traits = atlas_loader_traits<anim_atlas>; StringView anim_traits::loader_name() { return "anim_atlas"_s; } -auto anim_traits::atlas_of(const Cell& x) -> const std::shared_ptr<Atlas>& { return x.atlas; } -auto anim_traits::atlas_of(Cell& x) -> std::shared_ptr<Atlas>& { return x.atlas; } +auto anim_traits::atlas_of(const Cell& x) -> const bptr<Atlas>& { return x.atlas; } +auto anim_traits::atlas_of(Cell& x) -> bptr<Atlas>& { return x.atlas; } StringView anim_traits::name_of(const Cell& x) { return x.name; } String& anim_traits::name_of(Cell& x) { return x.name; } @@ -57,7 +58,7 @@ auto anim_traits::make_invalid_atlas(Storage& s) -> Cell .scale = anim_scale::fixed{size.x(), true}, .nframes = 1, }; - auto atlas = std::make_shared<class anim_atlas>(loader.INVALID, loader.make_error_texture(size), move(def)); + auto atlas = bptr<class anim_atlas>{InPlace, loader.INVALID, loader.make_error_texture(size), move(def)}; auto info = anim_cell { .atlas = atlas, .name = loader.INVALID, @@ -65,7 +66,7 @@ auto anim_traits::make_invalid_atlas(Storage& s) -> Cell return info; } -auto anim_traits::make_atlas(StringView name, const Cell&) -> std::shared_ptr<Atlas> +auto anim_traits::make_atlas(StringView name, const Cell&) -> bptr<Atlas> { char buf[fm_FILENAME_MAX]; auto json_path = loader.make_atlas_path(buf, {}, name, ".json"_s); @@ -96,7 +97,7 @@ auto anim_traits::make_atlas(StringView name, const Cell&) -> std::shared_ptr<At const auto width = size[1], height = size[0]; fm_soft_assert(anim_info.pixel_size[0] == width && anim_info.pixel_size[1] == height); - auto atlas = std::make_shared<class anim_atlas>(name, tex, move(anim_info)); + auto atlas = bptr<class anim_atlas>{InPlace, name, tex, move(anim_info)}; return atlas; } diff --git a/loader/anim-traits.hpp b/loader/anim-traits.hpp index 517a3097..85c71612 100644 --- a/loader/anim-traits.hpp +++ b/loader/anim-traits.hpp @@ -1,6 +1,6 @@ #pragma once #include "atlas-loader-fwd.hpp" -#include <memory> +#include "compat/borrowed-ptr.hpp" #include <cr/Optional.h> namespace floormat { struct anim_cell; class anim_atlas; } @@ -15,13 +15,13 @@ template<> struct atlas_loader_traits<anim_atlas> using Storage = atlas_storage<Atlas, Self>; static StringView loader_name(); - static const std::shared_ptr<Atlas>& atlas_of(const Cell& x); - static std::shared_ptr<Atlas>& atlas_of(Cell& x); + static const bptr<Atlas>& atlas_of(const Cell& x); + static bptr<Atlas>& atlas_of(Cell& x); static StringView name_of(const Cell& x); static String& name_of(Cell& x); static void atlas_list(Storage& st); static Cell make_invalid_atlas(Storage& st); - static std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& c); + static bptr<Atlas> make_atlas(StringView name, const Cell& c); static Optional<Cell> make_cell(StringView name); }; diff --git a/loader/atlas-loader.hpp b/loader/atlas-loader.hpp index 226918f0..e56297c1 100644 --- a/loader/atlas-loader.hpp +++ b/loader/atlas-loader.hpp @@ -2,7 +2,6 @@ #include "compat/defs.hpp" #include "atlas-loader-fwd.hpp" #include "policy.hpp" -#include <memory> namespace floormat::loader_detail { diff --git a/loader/atlas-loader.inl b/loader/atlas-loader.inl index 8f1d1db6..6c5fedd4 100644 --- a/loader/atlas-loader.inl +++ b/loader/atlas-loader.inl @@ -5,7 +5,6 @@ #include "atlas-loader.hpp" #include "atlas-loader-storage.hpp" #include "loader/loader.hpp" -#include <memory> #include <cr/ArrayView.h> #include <cr/Optional.h> #include <cr/GrowableArray.h> diff --git a/loader/ground-atlas.cpp b/loader/ground-atlas.cpp index d46b0dfc..4b3495a0 100644 --- a/loader/ground-atlas.cpp +++ b/loader/ground-atlas.cpp @@ -2,14 +2,14 @@ #include "atlas-loader.inl" #include "ground-traits.hpp" #include "ground-cell.hpp" +#include "compat/borrowed-ptr.inl" #include <Magnum/Math/Vector2.h> namespace floormat::loader_detail { template class atlas_loader<ground_atlas>; -std::shared_ptr<ground_atlas> -loader_impl::get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) +bptr<ground_atlas> loader_impl::get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) { return _ground_loader->make_atlas(name, { .atlas = {}, .name = {}, .size = size, .pass = pass, @@ -31,8 +31,7 @@ const ground_cell& loader_impl::invalid_ground_atlas() return _ground_loader->get_invalid_atlas(); } -const std::shared_ptr<class ground_atlas>& -loader_impl::ground_atlas(StringView filename, loader_policy policy) noexcept(false) +const bptr<class ground_atlas>& loader_impl::ground_atlas(StringView filename, loader_policy policy) noexcept(false) { return _ground_loader->get_atlas(filename, policy); } diff --git a/loader/ground-cell.cpp b/loader/ground-cell.cpp index 21982bd0..33696cd6 100644 --- a/loader/ground-cell.cpp +++ b/loader/ground-cell.cpp @@ -4,6 +4,7 @@ //#include "serialize/corrade-string.hpp" #include "serialize/ground-atlas.hpp" #include "serialize/corrade-array.hpp" +#include "compat/borrowed-ptr.inl" #include <cr/Array.h> namespace floormat { diff --git a/loader/ground-cell.hpp b/loader/ground-cell.hpp index 9326cb9c..d96132a0 100644 --- a/loader/ground-cell.hpp +++ b/loader/ground-cell.hpp @@ -1,6 +1,6 @@ #pragma once #include "src/pass-mode.hpp" -#include <memory> +#include "compat/borrowed-ptr.hpp" #include <Corrade/Containers/String.h> #include <Magnum/Math/Vector2.h> @@ -10,7 +10,7 @@ class ground_atlas; struct ground_cell { - std::shared_ptr<ground_atlas> atlas; + bptr<ground_atlas> atlas; String name; Vector2ub size; pass_mode pass = pass_mode::pass; diff --git a/loader/ground-traits.cpp b/loader/ground-traits.cpp index fd3b2dc1..3061ef4c 100644 --- a/loader/ground-traits.cpp +++ b/loader/ground-traits.cpp @@ -5,6 +5,7 @@ #include "src/tile-defs.hpp" #include "src/ground-atlas.hpp" #include "compat/assert.hpp" +#include "compat/borrowed-ptr.inl" #include <cr/Optional.h> #include <Corrade/Containers/StringView.h> #include <Corrade/Containers/Pointer.h> @@ -15,8 +16,8 @@ namespace floormat::loader_detail { using ground_traits = atlas_loader_traits<ground_atlas>; StringView ground_traits::loader_name() { return "ground_atlas"_s; } -auto ground_traits::atlas_of(const Cell& x) -> const std::shared_ptr<Atlas>& { return x.atlas; } -auto ground_traits::atlas_of(Cell& x) -> std::shared_ptr<Atlas>& { return x.atlas; } +auto ground_traits::atlas_of(const Cell& x) -> const bptr<Atlas>& { return x.atlas; } +auto ground_traits::atlas_of(Cell& x) -> bptr<Atlas>& { return x.atlas; } StringView ground_traits::name_of(const Cell& x) { return x.name; } String& ground_traits::name_of(Cell& x) { return x.name; } @@ -30,17 +31,17 @@ void ground_traits::atlas_list(Storage& s) auto ground_traits::make_invalid_atlas(Storage& s) -> Cell { fm_debug_assert(!s.invalid_atlas); - auto atlas = std::make_shared<Atlas>( + auto atlas = bptr<Atlas>{InPlace, ground_def{loader.INVALID, Vector2ub{1,1}, pass_mode::pass}, - loader.make_error_texture(Vector2ui(tile_size_xy))); + loader.make_error_texture(Vector2ui(tile_size_xy))}; return ground_cell{ atlas, atlas->name(), atlas->num_tiles2(), atlas->pass_mode() }; } -auto ground_traits::make_atlas(StringView name, const Cell& c) -> std::shared_ptr<Atlas> +auto ground_traits::make_atlas(StringView name, const Cell& c) -> bptr<Atlas> { auto def = ground_def{name, c.size, c.pass}; auto tex = loader.texture(loader.GROUND_TILESET_PATH, name); - auto atlas = std::make_shared<Atlas>(def, tex); + auto atlas = bptr<Atlas>{InPlace, def, tex}; return atlas; } diff --git a/loader/ground-traits.hpp b/loader/ground-traits.hpp index f3fff4ee..c4d9b905 100644 --- a/loader/ground-traits.hpp +++ b/loader/ground-traits.hpp @@ -1,6 +1,6 @@ #pragma once #include "atlas-loader-fwd.hpp" -#include <memory> +#include "compat/borrowed-ptr.hpp" namespace floormat { struct ground_cell; class ground_atlas; } @@ -14,13 +14,13 @@ template<> struct atlas_loader_traits<ground_atlas> using Storage = atlas_storage<ground_atlas, Self>; static StringView loader_name(); - static const std::shared_ptr<Atlas>& atlas_of(const Cell& x); - static std::shared_ptr<Atlas>& atlas_of(Cell& x); + static const bptr<Atlas>& atlas_of(const Cell& x); + static bptr<Atlas>& atlas_of(Cell& x); static StringView name_of(const Cell& x); static String& name_of(Cell& x); static void atlas_list(Storage& s); static Cell make_invalid_atlas(Storage& st); - static std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& c); + static bptr<Atlas> make_atlas(StringView name, const Cell& c); static Optional<Cell> make_cell(StringView name); }; diff --git a/loader/impl.cpp b/loader/impl.cpp index cc37e8c8..86bd76d5 100644 --- a/loader/impl.cpp +++ b/loader/impl.cpp @@ -1,5 +1,6 @@ #include "impl.hpp" #include "compat/assert.hpp" +#include "compat/borrowed-ptr.inl" #include "ground-traits.hpp" #include "ground-cell.hpp" #include "wall-traits.hpp" diff --git a/loader/impl.hpp b/loader/impl.hpp index b873ba82..9b3ab1c0 100644 --- a/loader/impl.hpp +++ b/loader/impl.hpp @@ -1,9 +1,9 @@ #pragma once -#include "compat/safe-ptr.hpp" #include "loader/loader.hpp" +#include "compat/safe-ptr.hpp" +#include "compat/borrowed-ptr-fwd.hpp" #include "atlas-loader-fwd.hpp" #include <tsl/robin_map.h> -#include <memory> #include <vector> #include <Corrade/Containers/Optional.h> #include <Corrade/Containers/StringView.h> @@ -45,26 +45,26 @@ struct loader_impl final : loader_ // >-----> ground >-----> [[nodiscard]] static atlas_loader<class ground_atlas>* make_ground_atlas_loader(); safe_ptr<atlas_loader<class ground_atlas>> _ground_loader{ make_ground_atlas_loader() }; - const std::shared_ptr<class ground_atlas>& ground_atlas(StringView filename, loader_policy policy) noexcept(false) override; + const bptr<class ground_atlas>& ground_atlas(StringView filename, loader_policy policy) noexcept(false) override; ArrayView<const ground_cell> ground_atlas_list() noexcept(false) override; const ground_cell& invalid_ground_atlas() override; - std::shared_ptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) override; + bptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) override; // >-----> walls >-----> [[nodiscard]] static atlas_loader<class wall_atlas>* make_wall_atlas_loader(); safe_ptr<atlas_loader<class wall_atlas>> _wall_loader{ make_wall_atlas_loader() }; - const std::shared_ptr<class wall_atlas>& wall_atlas(StringView name, loader_policy policy) override; + const bptr<class wall_atlas>& wall_atlas(StringView name, loader_policy policy) override; ArrayView<const wall_cell> wall_atlas_list() override; - std::shared_ptr<class wall_atlas> get_wall_atlas(StringView filename) noexcept(false) override; + bptr<class wall_atlas> get_wall_atlas(StringView filename) noexcept(false) override; const wall_cell& invalid_wall_atlas() override; // >-----> anim >-----> [[nodiscard]] static atlas_loader<class anim_atlas>* make_anim_atlas_loader(); safe_ptr<atlas_loader<class anim_atlas>> _anim_loader{ make_anim_atlas_loader() }; ArrayView<const anim_cell> anim_atlas_list() override; - std::shared_ptr<class anim_atlas> anim_atlas(StringView name, StringView dir, loader_policy policy) noexcept(false) override; + bptr<class anim_atlas> anim_atlas(StringView name, StringView dir, loader_policy policy) noexcept(false) override; const anim_cell& invalid_anim_atlas() override; - std::shared_ptr<class anim_atlas> get_anim_atlas(StringView path) noexcept(false) override; + bptr<class anim_atlas> get_anim_atlas(StringView path) noexcept(false) override; // >-----> scenery >-----> [[nodiscard]] static atlas_loader<struct scenery_proto>* make_scenery_atlas_loader(); @@ -77,7 +77,7 @@ struct loader_impl final : loader_ // >-----> vobjs >-----> tsl::robin_map<StringView, const struct vobj_cell*> vobj_atlas_map; std::vector<struct vobj_cell> vobjs; - std::shared_ptr<class anim_atlas> make_vobj_anim_atlas(StringView name, StringView image_filename); + bptr<class anim_atlas> make_vobj_anim_atlas(StringView name, StringView image_filename); const struct vobj_cell& vobj(StringView name) override; ArrayView<const struct vobj_cell> vobj_list() override; void get_vobj_list(); diff --git a/loader/loader.hpp b/loader/loader.hpp index cf2bbc8a..0ee08148 100644 --- a/loader/loader.hpp +++ b/loader/loader.hpp @@ -1,8 +1,8 @@ #pragma once #include "compat/defs.hpp" +#include "compat/borrowed-ptr-fwd.hpp" #include "src/pass-mode.hpp" #include "loader/policy.hpp" -#include <memory> #include <cr/StringView.h> //namespace Magnum { using Vector2ub = Math::Vector2<unsigned char>; } @@ -35,9 +35,9 @@ struct loader_ virtual Trade::ImageData2D make_error_texture(Vector2ui size, Vector4ub color) = 0; virtual Trade::ImageData2D texture(StringView prefix, StringView filename) noexcept(false) = 0; - virtual const std::shared_ptr<class ground_atlas>& ground_atlas(StringView filename, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0; - virtual const std::shared_ptr<class wall_atlas>& wall_atlas(StringView name, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0; - virtual std::shared_ptr<class anim_atlas> anim_atlas(StringView name, StringView dir, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0; + virtual const bptr<class ground_atlas>& ground_atlas(StringView filename, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0; + virtual const bptr<class wall_atlas>& wall_atlas(StringView name, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0; + virtual bptr<class anim_atlas> anim_atlas(StringView name, StringView dir, loader_policy policy = loader_policy::DEFAULT) noexcept(false) = 0; virtual const struct scenery_proto& scenery(StringView name, loader_policy policy = loader_policy::DEFAULT) = 0; virtual ArrayView<const ground_cell> ground_atlas_list() noexcept(false) = 0; @@ -58,11 +58,11 @@ struct loader_ virtual const scenery_cell& invalid_scenery_atlas() = 0; /** \deprecated{internal use only}*/ [[nodiscard]] - virtual std::shared_ptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) = 0; + virtual bptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) = 0; /** \deprecated{internal use only}*/ [[nodiscard]] - virtual std::shared_ptr<class wall_atlas> get_wall_atlas(StringView name) noexcept(false) = 0; + virtual bptr<class wall_atlas> get_wall_atlas(StringView name) noexcept(false) = 0; /** \deprecated{internal use only}*/ [[nodiscard]] - virtual std::shared_ptr<class anim_atlas> get_anim_atlas(StringView path) noexcept(false) = 0; + virtual bptr<class anim_atlas> get_anim_atlas(StringView path) noexcept(false) = 0; /** \deprecated{internal use only}*/ [[nodiscard]] virtual struct scenery_proto get_scenery(StringView filename, const scenery_cell& c) noexcept(false) = 0; diff --git a/loader/scenery-traits.hpp b/loader/scenery-traits.hpp index 37aaa199..0d7387c7 100644 --- a/loader/scenery-traits.hpp +++ b/loader/scenery-traits.hpp @@ -1,6 +1,6 @@ #pragma once #include "atlas-loader-fwd.hpp" -#include <memory> +#include "compat/borrowed-ptr.hpp" namespace floormat { struct scenery_cell; struct scenery_proto; } diff --git a/loader/vobj-cell.hpp b/loader/vobj-cell.hpp index 1fa22ea2..c5882624 100644 --- a/loader/vobj-cell.hpp +++ b/loader/vobj-cell.hpp @@ -1,6 +1,6 @@ #pragma once #include <cr/String.h> -#include <memory> +#include "compat/borrowed-ptr.hpp" namespace floormat { @@ -9,7 +9,7 @@ class anim_atlas; struct vobj_cell final { String name, descr; - std::shared_ptr<class anim_atlas> atlas; + bptr<class anim_atlas> atlas; }; } // namespace floormat diff --git a/loader/vobj.cpp b/loader/vobj.cpp index f09c9581..789854a4 100644 --- a/loader/vobj.cpp +++ b/loader/vobj.cpp @@ -4,6 +4,7 @@ #include "src/anim-atlas.hpp" #include "src/anim.hpp" #include "compat/exception.hpp" +#include "compat/borrowed-ptr.inl" #include "loader/vobj-cell.hpp" #include <Corrade/Containers/ArrayViewStl.h> #include <Corrade/Containers/StridedArrayView.h> @@ -49,7 +50,7 @@ void adl_serializer<vobj>::from_json(const json& j, vobj& val) namespace floormat::loader_detail { -std::shared_ptr<class anim_atlas> loader_impl::make_vobj_anim_atlas(StringView name, StringView image_filename) +bptr<class anim_atlas> loader_impl::make_vobj_anim_atlas(StringView name, StringView image_filename) { auto tex = texture(VOBJ_PATH, image_filename); anim_def def; @@ -72,7 +73,7 @@ std::shared_ptr<class anim_atlas> loader_impl::make_vobj_anim_atlas(StringView n def.groups = Array<anim_group>{1}; def.groups[0] = move(group); } - auto atlas = std::make_shared<class anim_atlas>(name, tex, move(def)); + auto atlas = bptr<class anim_atlas>(InPlace, name, tex, move(def)); return atlas; } diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp index 8b2acb09..dbf71c47 100644 --- a/loader/wall-atlas.cpp +++ b/loader/wall-atlas.cpp @@ -3,6 +3,7 @@ #include "loader/wall-cell.hpp" #include "loader/wall-traits.hpp" #include "loader/atlas-loader.inl" +#include "compat/borrowed-ptr.inl" #include <Corrade/Containers/Array.h> #include <Corrade/Containers/StringIterable.h> #include <Magnum/Trade/ImageData.h> @@ -12,8 +13,7 @@ namespace floormat::loader_detail { template class atlas_loader<class wall_atlas>; -std::shared_ptr<class wall_atlas> -loader_impl::get_wall_atlas(StringView name) noexcept(false) +bptr<class wall_atlas> loader_impl::get_wall_atlas(StringView name) noexcept(false) { return _wall_loader->make_atlas(name, {}); } @@ -33,7 +33,7 @@ const wall_cell& loader_impl::invalid_wall_atlas() return _wall_loader->get_invalid_atlas(); } -const std::shared_ptr<class wall_atlas>& +const bptr<class wall_atlas>& loader_impl::wall_atlas(StringView filename, loader_policy policy) noexcept(false) { return _wall_loader->get_atlas(filename, policy); diff --git a/loader/wall-cell.cpp b/loader/wall-cell.cpp index 8870b891..a385163b 100644 --- a/loader/wall-cell.cpp +++ b/loader/wall-cell.cpp @@ -1,5 +1,6 @@ #include "wall-cell.hpp" #include "compat/exception.hpp" +#include "compat/borrowed-ptr.inl" #include "serialize/json-helper.hpp" #include "serialize/corrade-string.hpp" #include "serialize/corrade-array.hpp" diff --git a/loader/wall-cell.hpp b/loader/wall-cell.hpp index 541a8339..690896c2 100644 --- a/loader/wall-cell.hpp +++ b/loader/wall-cell.hpp @@ -1,5 +1,5 @@ #pragma once -#include <memory> +#include "compat/borrowed-ptr.hpp" #include <Corrade/Containers/String.h> namespace floormat { @@ -8,7 +8,7 @@ class wall_atlas; struct wall_cell { - std::shared_ptr<wall_atlas> atlas; + bptr<wall_atlas> atlas; String name; static Array<wall_cell> load_atlases_from_json(); diff --git a/loader/wall-traits.cpp b/loader/wall-traits.cpp index 07ff7d9c..e5cd7f40 100644 --- a/loader/wall-traits.cpp +++ b/loader/wall-traits.cpp @@ -6,6 +6,7 @@ #include "src/wall-atlas.hpp" #include "compat/array-size.hpp" #include "compat/exception.hpp" +#include "compat/borrowed-ptr.inl" #include <cr/StringView.h> #include <cr/Optional.h> #include <mg/ImageData.h> @@ -15,8 +16,8 @@ namespace floormat::loader_detail { using wall_traits = atlas_loader_traits<wall_atlas>; StringView wall_traits::loader_name() { return "wall_atlas"_s; } -auto wall_traits::atlas_of(const Cell& x) -> const std::shared_ptr<Atlas>& { return x.atlas; } -auto wall_traits::atlas_of(Cell& x) -> std::shared_ptr<Atlas>& { return x.atlas; } +auto wall_traits::atlas_of(const Cell& x) -> const bptr<Atlas>& { return x.atlas; } +auto wall_traits::atlas_of(Cell& x) -> bptr<Atlas>& { return x.atlas; } StringView wall_traits::name_of(const Cell& x) { return x.name; } String& wall_traits::name_of(Cell& x) { return x.name; } @@ -33,7 +34,7 @@ auto wall_traits::make_invalid_atlas(Storage& s) -> Cell constexpr auto name = loader_::INVALID; constexpr auto frame_size = Vector2ui{tile_size_xy, tile_size_z}; - auto a = std::make_shared<class wall_atlas>( + auto a = bptr<class wall_atlas>(InPlace, wall_atlas_def { Wall::Info{.name = name, .depth = 8}, array<Wall::Frame>({{ {}, frame_size}, }), @@ -46,7 +47,7 @@ auto wall_traits::make_invalid_atlas(Storage& s) -> Cell return { .atlas = move(a), .name = name, }; } -auto wall_traits::make_atlas(StringView name, const Cell&) -> std::shared_ptr<Atlas> +auto wall_traits::make_atlas(StringView name, const Cell&) -> bptr<Atlas> { char file_buf[fm_FILENAME_MAX], json_buf[fm_FILENAME_MAX]; auto file = loader.make_atlas_path(file_buf, loader.WALL_TILESET_PATH, name); @@ -57,7 +58,7 @@ auto wall_traits::make_atlas(StringView name, const Cell&) -> std::shared_ptr<At fm_soft_assert(name == def.header.name); fm_soft_assert(!def.frames.isEmpty()); auto tex = loader.texture(""_s, file); - auto atlas = std::make_shared<class wall_atlas>(move(def), file, tex); + auto atlas = bptr<class wall_atlas>(InPlace, move(def), file, tex); return atlas; } diff --git a/loader/wall-traits.hpp b/loader/wall-traits.hpp index 9233cb97..587555ef 100644 --- a/loader/wall-traits.hpp +++ b/loader/wall-traits.hpp @@ -1,6 +1,6 @@ #pragma once #include "atlas-loader-fwd.hpp" -#include <memory> +#include "compat/borrowed-ptr.hpp" namespace floormat { struct wall_cell; class wall_atlas; } @@ -14,13 +14,13 @@ template<> struct atlas_loader_traits<wall_atlas> using Storage = atlas_storage<wall_atlas, Self>; static StringView loader_name(); - static const std::shared_ptr<Atlas>& atlas_of(const Cell& x); - static std::shared_ptr<Atlas>& atlas_of(Cell& x); + static const bptr<Atlas>& atlas_of(const Cell& x); + static bptr<Atlas>& atlas_of(Cell& x); static StringView name_of(const Cell& x); static String& name_of(Cell& x); static void atlas_list(Storage& st); static Cell make_invalid_atlas(Storage& st); - static std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& c); + static bptr<Atlas> make_atlas(StringView name, const Cell& c); static Optional<Cell> make_cell(StringView name); }; |