From 1216a061d3e46eae983a38e42e71115e5c9faef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 30 Apr 2014 12:01:26 +0200 Subject: move to libuv for the rendering loop --- common/glfw_view.cpp | 66 +++++++++++----------------------------------------- 1 file changed, 14 insertions(+), 52 deletions(-) (limited to 'common/glfw_view.cpp') diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp index d3034016fc..cfa1156a1c 100644 --- a/common/glfw_view.cpp +++ b/common/glfw_view.cpp @@ -1,39 +1,7 @@ #include "glfw_view.hpp" - -#ifndef HAVE_KQUEUE -# if defined(__APPLE__) || \ - defined(__DragonFly__) || \ - defined(__FreeBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) -# define HAVE_KQUEUE 1 -# endif -#endif - -#ifndef HAVE_EPOLL -# if defined(__linux__) -# define HAVE_EPOLL 1 -# endif -#endif - -#if defined(HAVE_KQUEUE) || defined(HAVE_EPOLL) - -#if defined(HAVE_KQUEUE) -# include -# include -# include -#endif - -#if defined(HAVE_EPOLL) -# include -#endif - -#endif - - MapView::MapView(llmr::Settings &settings, bool fullscreen) - : fullscreen(fullscreen), settings(settings), map(settings) {} + : fullscreen(fullscreen), settings(settings), map(*this) {} MapView::~MapView() { glfwTerminate(); } @@ -77,20 +45,17 @@ void MapView::init() { glfwGetFramebufferSize(window, &fb_width, &fb_height); settings.load(); - map.setup(); resize(window, 0, 0); - glfwSwapInterval(1); - - map.loadSettings(); - glfwSetCursorPosCallback(window, mousemove); glfwSetMouseButtonCallback(window, mouseclick); glfwSetWindowSizeCallback(window, resize); glfwSetFramebufferSizeCallback(window, resize); glfwSetScrollCallback(window, scroll); glfwSetKeyCallback(window, key); + + glfwMakeContextCurrent(nullptr); } void MapView::key(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) { @@ -152,7 +117,6 @@ void MapView::resize(GLFWwindow *window, int, int) { glfwGetFramebufferSize(window, &fb_width, &fb_height); mapView->map.resize(width, height, (float)fb_width / (float)width, fb_width, fb_height); - mapView->map.update(); } void MapView::mouseclick(GLFWwindow *window, int button, int action, int modifiers) { @@ -199,17 +163,11 @@ int MapView::run() { map.start(); while (!glfwWindowShouldClose(window)) { - if (map.clean.test_and_set() == false) { - // This branch is executed when the previous value of the "clean" - // flag is false (i.e. it is unclean == dirty). - try { - map.render(); - } - catch (std::exception &ex) { - fprintf(stderr, "exception: %s\n", ex.what()); - } + if (map.swapped.test_and_set() == false) { glfwSwapBuffers(window); + map.rendered.clear(); fps(); + map.rerender(); } glfwWaitEvents(); @@ -220,6 +178,14 @@ int MapView::run() { return 0; } +void MapView::make_active() { + glfwMakeContextCurrent(window); +} + +void MapView::swap() { + glfwPostEmptyEvent(); +} + void MapView::fps() { static int frames = 0; static double time_elapsed = 0; @@ -267,9 +233,5 @@ void show_debug_image(std::string name, const char *data, size_t width, size_t h glfwMakeContextCurrent(current_window); } -void restart() { - glfwPostEmptyEvent(); -} - } } -- cgit v1.2.1