diff options
Diffstat (limited to 'src/world.hpp')
-rw-r--r-- | src/world.hpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/world.hpp b/src/world.hpp index 75e05bd8..1e8469d9 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -1,8 +1,25 @@ #pragma once +#include "compat/int-hash.hpp" #include "global-coords.hpp" #include <unordered_map> #include <memory> +namespace std { + +template<typename> struct hash; + +template<> +struct hash<floormat::chunk_coords> final +{ + constexpr + std::size_t operator()(floormat::chunk_coords c) const noexcept + { + return floormat::int_hash((std::size_t)c.y << 16 | (std::size_t)c.x); + } +}; + +} // namespace std + namespace floormat { struct chunk; @@ -18,14 +35,13 @@ struct world final void collect(); private: - static constexpr std::size_t initial_capacity = 64, collect_every = 100; + static constexpr std::size_t initial_capacity = 64, collect_every = 32; static constexpr float max_load_factor = .5; std::size_t _last_collection = 0; void maybe_collect(); - struct hasher final { std::size_t operator()(chunk_coords c) const noexcept; }; - std::unordered_map<chunk_coords, std::shared_ptr<chunk>, hasher> _chunks{initial_capacity}; + std::unordered_map<chunk_coords, std::shared_ptr<chunk>> _chunks{initial_capacity}; }; } // namespace floormat |