summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/glfw_view.cpp5
-rw-r--r--include/llmr/map/map.hpp12
-rw-r--r--ios/MBXViewController.mm5
-rw-r--r--src/map/map.cpp25
4 files changed, 29 insertions, 18 deletions
diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp
index cfa1156a1c..321670b664 100644
--- a/common/glfw_view.cpp
+++ b/common/glfw_view.cpp
@@ -163,11 +163,10 @@ int MapView::run() {
map.start();
while (!glfwWindowShouldClose(window)) {
- if (map.swapped.test_and_set() == false) {
+ if (map.needsSwap()) {
glfwSwapBuffers(window);
- map.rendered.clear();
+ map.swapped();
fps();
- map.rerender();
}
glfwWaitEvents();
diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp
index c1cc7c370d..3dfc830a30 100644
--- a/include/llmr/map/map.hpp
+++ b/include/llmr/map/map.hpp
@@ -39,6 +39,10 @@ public:
// Forces a map update: always triggers a rerender.
void update();
+ // Controls buffer swapping.
+ bool needsSwap();
+ void swapped();
+
// Size
void resize(uint16_t width, uint16_t height, float ratio = 1);
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height);
@@ -105,18 +109,18 @@ private:
// Unconditionally performs a render with the current map state.
void render();
-public:
+private:
// If cleared, the next time the render thread attempts to render the map, it will *actually*
// render the map.
- std::atomic_flag clean = ATOMIC_FLAG_INIT;
+ std::atomic_flag is_clean = ATOMIC_FLAG_INIT;
// If this flag is cleared, the current back buffer is ready for being swapped with the front
// buffer (i.e. it has rendered data).
- std::atomic_flag swapped = ATOMIC_FLAG_INIT;
+ std::atomic_flag is_swapped = ATOMIC_FLAG_INIT;
// This is cleared once the current front buffer has been presented and the back buffer is
// ready for rendering.
- std::atomic_flag rendered = ATOMIC_FLAG_INIT;
+ std::atomic_flag is_rendered = ATOMIC_FLAG_INIT;
private:
View &view;
diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm
index c6f3b1bc41..ca3b65621a 100644
--- a/ios/MBXViewController.mm
+++ b/ios/MBXViewController.mm
@@ -153,11 +153,10 @@ MBXViewController *viewController = nullptr;
- (void)swap
{
- if (map->swapped.test_and_set() == false)
+ if (map->needsSwap())
{
[(GLKView *)self.view display];
- map->rendered.clear();
- map->rerender();
+ map->swapped();
}
}
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 861c373bdd..df1e5ac38c 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -21,9 +21,9 @@ Map::Map(View& view)
loop(uv_loop_new()) {
// Make sure that we're doing an initial drawing in all cases.
- clean.clear();
- rendered.clear();
- swapped.test_and_set();
+ is_clean.clear();
+ is_rendered.clear();
+ is_swapped.test_and_set();
}
Map::~Map() {
@@ -91,7 +91,16 @@ void Map::rerender() {
}
void Map::update() {
- clean.clear();
+ is_clean.clear();
+ rerender();
+}
+
+bool Map::needsSwap() {
+ return is_swapped.test_and_set() == false;
+}
+
+void Map::swapped() {
+ is_rendered.clear();
rerender();
}
@@ -100,15 +109,15 @@ void Map::render(uv_async_t *async) {
map->prepare();
- if (map->rendered.test_and_set() == false) {
- if (map->clean.test_and_set() == false) {
+ if (map->is_rendered.test_and_set() == false) {
+ if (map->is_clean.test_and_set() == false) {
map->render();
- map->swapped.clear();
+ map->is_swapped.clear();
map->view.swap();
} else {
// We set the rendered flag in the test above, so we have to reset it
// now that we're not actually rendering because the map is clean.
- map->rendered.clear();
+ map->is_rendered.clear();
}
}
}