summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-22 16:03:10 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-22 16:03:10 +0200
commitb1165d784c446dc505a100d861cb5151bebdda15 (patch)
tree0186179580aa8585f6fb3f3ad9c0ca7207f97607 /src
parentaa03952cb2a889f8d81a70ed4bd0b4ae69e5ab8d (diff)
serializer work
Diffstat (limited to 'src')
-rw-r--r--src/world.hpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/world.hpp b/src/world.hpp
index 6321606e..24a77d11 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -12,15 +12,6 @@ struct chunk;
struct world final
{
- std::shared_ptr<chunk> operator[](chunk_coords c) noexcept;
- std::tuple<std::shared_ptr<chunk>, tile&> operator[](global_coords pt) noexcept;
- bool contains(chunk_coords c) const noexcept;
- void clear();
- void collect();
-
- world();
- fm_DECLARE_DELETED_COPY_ASSIGNMENT(world);
-
private:
void maybe_collect();
@@ -30,10 +21,33 @@ private:
return int_hash((std::size_t)c.y << 16 | (std::size_t)c.x);
};
- std::size_t _last_collection = 0;
-
std::unordered_map<chunk_coords, std::shared_ptr<chunk>, decltype(hasher)> _chunks{initial_capacity, hasher};
mutable std::optional<std::tuple<std::shared_ptr<chunk>, chunk_coords>> _last_chunk;
+ std::size_t _last_collection = 0;
+
+public:
+ explicit world();
+
+ template<typename Hash, typename Alloc, typename Pred>
+ explicit world(std::unordered_map<chunk_coords, std::shared_ptr<chunk>, Hash, Alloc, Pred>&& chunks);
+
+ std::shared_ptr<chunk> operator[](chunk_coords c) noexcept;
+ std::tuple<std::shared_ptr<chunk>, tile&> operator[](global_coords pt) noexcept;
+ bool contains(chunk_coords c) const noexcept;
+ void clear();
+ void collect();
+
+ [[deprecated]] const auto& chunks() const noexcept { return _chunks; } // only for serialization
+
+ fm_DECLARE_DEPRECATED_COPY_ASSIGNMENT(world);
+ fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(world);
};
+template<typename Hash, typename Alloc, typename Pred>
+world::world(std::unordered_map<chunk_coords, std::shared_ptr<chunk>, Hash, Alloc, Pred>&& chunks) :
+ _chunks{chunks.begin(), chunks.end(),
+ std::max(initial_capacity, std::size_t(1/max_load_factor * 2 * chunks.size())),
+ hasher}
+{}
+
} // namespace floormat