use libuv event loop in the glfw view

Integrates libuv's default loop with GLFW's glfwWaitEvents() call. See https://github.com/joyent/libuv/issues/1246 for more details on integrating event loops.

fixes #149
This commit is contained in:
Konstantin Käfer
2014-04-22 16:54:55 +02:00
parent 9ff9d0edb5
commit 1ecff57829
9 changed files with 108 additions and 281 deletions

View File

@@ -6,15 +6,8 @@
#include "settings.hpp"
#include "../common/glfw_view.hpp"
#include "request.hpp"
MapView *mapView = nullptr;
std::forward_list<std::shared_ptr<llmr::platform::Request>> requests;
void quit_handler(int s) {
if (mapView) {
@@ -26,10 +19,6 @@ void quit_handler(int s) {
}
}
int main(int argc, char *argv[]) {
int fullscreen_flag = 0;
@@ -51,13 +40,6 @@ int main(int argc, char *argv[]) {
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
// curl init
curl_global_init(CURL_GLOBAL_ALL);
llmr::platform::Request::initialize();
// main loop
llmr::Settings_JSON settings;
mapView = new MapView(settings, fullscreen_flag);
@@ -66,49 +48,5 @@ int main(int argc, char *argv[]) {
mapView->settings.sync();
delete mapView;
llmr::platform::Request::finish();
curl_global_cleanup();
return ret;
}
namespace llmr {
void platform::cleanup() {
bool& dirty = mapView->dirty;
requests.remove_if([&dirty](std::shared_ptr<llmr::platform::Request> &req) {
if (req->done) {
req->foreground_callback();
dirty = true;
return true;
} else {
return false;
}
});
}
void platform::restart() {
if (mapView) {
mapView->dirty = true;
}
}
std::shared_ptr<platform::Request>
platform::request_http(const std::string &url, std::function<void(Response *)> background_function,
std::function<void()> foreground_callback) {
std::shared_ptr<Request> req =
std::make_shared<Request>(url, background_function, foreground_callback);
requests.push_front(req);
return req;
}
// Cancels an HTTP request.
void platform::cancel_request_http(const std::shared_ptr<Request> &req) {
if (req) {
req->cancel();
}
}
}