summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-02 20:52:56 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-02 21:11:55 +0100
commitb83f447ff6978509fdf23e9813eff6d7b5a6ffa2 (patch)
treefc279e69a8335a452f4913960c55c6289a1c4d10
parent128e76192e7bc3cc12c01f67b36a54509433d893 (diff)
main: set collect threshold depending on screen resolution
-rw-r--r--main/draw.cpp12
-rw-r--r--main/main-impl.hpp1
-rw-r--r--src/world.cpp2
-rw-r--r--src/world.hpp5
4 files changed, 18 insertions, 2 deletions
diff --git a/main/draw.cpp b/main/draw.cpp
index 28bd1fdd..2c8ebc7b 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -1,8 +1,10 @@
+#include "Magnum/GL/Context.h"
#include "main-impl.hpp"
#include "floormat/app.hpp"
#include "src/camera-offset.hpp"
#include "src/anim-atlas.hpp"
#include "main/clickable.hpp"
+#include "world.hpp"
#include <Corrade/Containers/ArrayView.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Renderer.h>
@@ -35,6 +37,7 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept
// -- user--
app.on_viewport_event(fb_size);
+ update_collect_threshold();
}
global_coords main_impl::pixel_to_tile(Vector2d position) const noexcept
@@ -76,6 +79,15 @@ auto main_impl::get_draw_bounds() const noexcept -> draw_bounds
return {x0, x1, y0, y1};
}
+void main_impl::update_collect_threshold()
+{
+ const auto [minx, maxx, miny, maxy] = get_draw_bounds();
+ const auto value = std::max(64_uz, (std::size_t)(maxx-minx+4)*(std::size_t)(maxy-minx+4));
+ if (!(GL::Context::current().configurationFlags() & GL::Implementation::ContextConfigurationFlag::QuietLog))
+ fm_debug("collect threshold is now %zu", value);
+ _world.set_collect_threshold(value);
+}
+
void main_impl::draw_world() noexcept
{
const auto [minx, maxx, miny, maxy] = get_draw_bounds();
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index deb5d73e..997b4980 100644
--- a/main/main-impl.hpp
+++ b/main/main-impl.hpp
@@ -91,6 +91,7 @@ private:
void recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept;
void draw_world() noexcept;
+ void update_collect_threshold();
draw_bounds get_draw_bounds() const noexcept override;
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);