From e7b6d72cd12aae845f56c92db53dad608217726a Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Thu, 19 Nov 2015 13:56:16 +0200 Subject: [render] Add a RunLoop to `render` main thread Also simplified the code making the logic more linear. --- bin/render.cpp | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'bin') diff --git a/bin/render.cpp b/bin/render.cpp index 6762d28c1b..71f74b043c 100644 --- a/bin/render.cpp +++ b/bin/render.cpp @@ -1,10 +1,10 @@ #include #include #include +#include #include #include -#include #include #include @@ -17,18 +17,9 @@ namespace po = boost::program_options; -#include - -#include #include #include -#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 -#define UV_ASYNC_PARAMS(handle) uv_async_t *handle, int -#else -#define UV_ASYNC_PARAMS(handle) uv_async_t *handle -#endif - int main(int argc, char *argv[]) { std::string style_path; double lat = 0, lon = 0; @@ -73,8 +64,9 @@ int main(int argc, char *argv[]) { using namespace mbgl; - mbgl::SQLiteCache cache(cache_file); - mbgl::DefaultFileSource fileSource(&cache); + util::RunLoop loop; + SQLiteCache cache(cache_file); + DefaultFileSource fileSource(&cache); // Try to load the token from the environment. if (!token.size()) { @@ -102,16 +94,7 @@ int main(int argc, char *argv[]) { map.setDebug(debug ? mbgl::MapDebugOptions::TileBorders | mbgl::MapDebugOptions::ParseStatus : mbgl::MapDebugOptions::NoDebug); } - uv_async_t *async = new uv_async_t; - uv_async_init(uv_default_loop(), async, [](UV_ASYNC_PARAMS(as)) { - std::unique_ptr image(reinterpret_cast(as->data)); - uv_close(reinterpret_cast(as), [](uv_handle_t *handle) { - delete reinterpret_cast(handle); - }); - util::write_file(output, encodePNG(*image)); - }); - - map.renderStill([async](std::exception_ptr error, PremultipliedImage&& image) { + map.renderStill([&](std::exception_ptr error, PremultipliedImage&& image) { try { if (error) { std::rethrow_exception(error); @@ -121,10 +104,11 @@ int main(int argc, char *argv[]) { exit(1); } - async->data = new PremultipliedImage(std::move(image)); - uv_async_send(async); + util::write_file(output, encodePNG(image)); + loop.stop(); }); - // This loop will terminate once the async was fired. - uv_run(uv_default_loop(), UV_RUN_DEFAULT); + loop.run(); + + return 0; } -- cgit v1.2.1