summaryrefslogtreecommitdiffhomepage
path: root/loader
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-01-11 03:18:00 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-01-11 03:18:00 +0100
commitf3d870a400395e75f601f32a3bbb3e68502d9000 (patch)
tree3735b14eaa74d4a80d9197ac973b5dbffbd675d6 /loader
parentb91deae59c69ca41d5feffaf4f16b29ee47af64d (diff)
fix some todo's
Diffstat (limited to 'loader')
-rw-r--r--loader/impl.hpp4
-rw-r--r--loader/json.cpp22
-rw-r--r--loader/loader.hpp7
-rw-r--r--loader/wall-atlas.cpp1
4 files changed, 17 insertions, 17 deletions
diff --git a/loader/impl.hpp b/loader/impl.hpp
index 37a00304..d88174ba 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -60,7 +60,9 @@ struct loader_impl final : loader_
// >-----> tile >----->
tsl::robin_map<StringView, std::shared_ptr<class tile_atlas>> tile_atlas_map;
+ std::vector<std::shared_ptr<class tile_atlas>> tile_atlas_array;
+ ArrayView<const std::shared_ptr<class tile_atlas>> tile_atlases(StringView filename) noexcept(false) override;
std::shared_ptr<class tile_atlas> tile_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) override;
std::shared_ptr<class tile_atlas> tile_atlas(StringView filename) noexcept(false) override;
@@ -77,7 +79,7 @@ struct loader_impl final : loader_
std::vector<serialized_scenery> sceneries_array;
tsl::robin_map<StringView, const serialized_scenery*> sceneries_map;
- const std::vector<serialized_scenery>& sceneries() override;
+ ArrayView<const serialized_scenery> sceneries() override;
const scenery_proto& scenery(StringView name) noexcept(false) override;
void get_scenery_list();
diff --git a/loader/json.cpp b/loader/json.cpp
index e9da0339..7cf24015 100644
--- a/loader/json.cpp
+++ b/loader/json.cpp
@@ -7,6 +7,7 @@
#include "serialize/tile-atlas.hpp"
#include "serialize/scenery.hpp"
#include "loader/scenery.hpp"
+#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/StringStlView.h>
#include <Corrade/Utility/Path.h>
@@ -32,10 +33,11 @@ void loader_impl::get_scenery_list()
fm_assert(!sceneries_map.empty());
}
-const std::vector<serialized_scenery>& loader_impl::sceneries()
+ArrayView<const serialized_scenery> loader_impl::sceneries()
{
- if (sceneries_array.empty())
+ if (sceneries_array.empty()) [[likely]]
get_scenery_list();
+ fm_assert(!sceneries_array.empty());
return sceneries_array;
}
@@ -44,21 +46,21 @@ const scenery_proto& loader_impl::scenery(StringView name) noexcept(false)
fm_soft_assert(check_atlas_name(name));
if (sceneries_array.empty())
get_scenery_list();
+ fm_assert(!sceneries_array.empty());
auto it = sceneries_map.find(name);
if (it == sceneries_map.end())
fm_throw("no such scenery: '{}'"_cf, name);
return it->second->proto;
}
-} // namespace floormat::loader_detail
-
-namespace floormat {
-
-std::vector<std::shared_ptr<class tile_atlas>> loader_::tile_atlases(StringView filename)
+ArrayView<const std::shared_ptr<class tile_atlas>> loader_impl::tile_atlases(StringView filename)
{
- auto vec = json_helper::from_json<std::vector<std::shared_ptr<class tile_atlas>>>(
+ if (!tile_atlas_array.empty()) [[likely]]
+ return tile_atlas_array;
+ tile_atlas_array = json_helper::from_json<std::vector<std::shared_ptr<class tile_atlas>>>(
Path::join(loader_::IMAGE_PATH, filename));
- return vec;
+ fm_assert(!tile_atlas_array.empty());
+ return tile_atlas_array;
}
-} // namespace floormat
+} // namespace floormat::loader_detail
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 9b2d1c3c..f93e6967 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -2,7 +2,6 @@
#include "src/pass-mode.hpp"
#include <stdio.h>
#include <memory>
-#include <vector>
#include <Corrade/Containers/StringView.h>
namespace Magnum { using Vector2ub = Math::Vector2<unsigned char>; }
@@ -25,7 +24,6 @@ struct loader_
{
virtual StringView shader(StringView filename) noexcept = 0;
virtual Trade::ImageData2D texture(StringView prefix, StringView filename, bool fail_ok = true) noexcept(false) = 0;
- // todo remove Optional when wall_atlas is fully implemented -sh 20231122
virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) = 0;
virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename) noexcept(false) = 0;
virtual ArrayView<const String> anim_atlas_list() = 0;
@@ -34,9 +32,8 @@ struct loader_
virtual ArrayView<const wall_info> wall_atlas_list() = 0;
static void destroy();
static loader_& default_loader() noexcept;
- // todo move to ArrayView later, make non-static, and remove pass_mode
- static std::vector<std::shared_ptr<class tile_atlas>> tile_atlases(StringView filename);
- virtual const std::vector<serialized_scenery>& sceneries() = 0;
+ virtual ArrayView<const std::shared_ptr<class tile_atlas>> tile_atlases(StringView filename) noexcept(false) = 0;
+ virtual ArrayView<const serialized_scenery> sceneries() = 0;
virtual const scenery_proto& scenery(StringView name) noexcept(false) = 0;
virtual StringView startup_directory() noexcept = 0;
static StringView strip_prefix(StringView name);
diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp
index 242702e3..66dc3ba5 100644
--- a/loader/wall-atlas.cpp
+++ b/loader/wall-atlas.cpp
@@ -104,7 +104,6 @@ std::shared_ptr<class wall_atlas> loader_impl::wall_atlas(StringView name, bool
missing:
{
- // todo allocate wall_info instead
missing_wall_atlases.push_back(String { AllocatedInit, name });
auto string_view = StringView{missing_wall_atlases.back()};
wall_atlas_map[string_view] = (wall_info*)-1;