diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-02 20:52:56 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-02 21:11:55 +0100 |
commit | b83f447ff6978509fdf23e9813eff6d7b5a6ffa2 (patch) | |
tree | fc279e69a8335a452f4913960c55c6289a1c4d10 /src | |
parent | 128e76192e7bc3cc12c01f67b36a54509433d893 (diff) |
main: set collect threshold depending on screen resolution
Diffstat (limited to 'src')
-rw-r--r-- | src/world.cpp | 2 | ||||
-rw-r--r-- | src/world.hpp | 5 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/world.cpp b/src/world.cpp index 20805905..1fcee1d8 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -44,7 +44,7 @@ void world::clear() void world::maybe_collect() { - if (_chunks.size() > _last_collection + collect_every) + if (_chunks.size() > _last_collection + _collect_every) collect(); } diff --git a/src/world.hpp b/src/world.hpp index 3bfcf702..36703fd3 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -18,13 +18,14 @@ private: chunk_coords pos = invalid_coords; } _last_chunk; - static constexpr std::size_t initial_capacity = 64, collect_every = 64; + static constexpr std::size_t initial_capacity = 64; static constexpr float max_load_factor = .5; static constexpr auto hasher = [](chunk_coords c) constexpr -> std::size_t { return int_hash((std::size_t)c.y << 16 | (std::size_t)c.x); }; std::unordered_map<chunk_coords, chunk, decltype(hasher)> _chunks; std::size_t _last_collection = 0; + std::size_t _collect_every = 64; explicit world(std::size_t capacity); @@ -48,6 +49,8 @@ public: void serialize(StringView filename); static world deserialize(StringView filename); + void set_collect_threshold(std::size_t value) { _collect_every = value; } + std::size_t collect_threshold() const noexcept { return _collect_every; } fm_DECLARE_DEPRECATED_COPY_ASSIGNMENT(world); fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(world); |