implement multithreading for windows, implement file uploading when saving
This commit is contained in:
@@ -12,6 +12,10 @@
|
||||
void android_async_lock(struct engine* engine);
|
||||
void android_async_swap(struct engine* engine);
|
||||
void android_async_unlock(struct engine* engine);
|
||||
#elif _WIN32
|
||||
void async_lock();
|
||||
void async_swap();
|
||||
void async_unlock();
|
||||
#endif
|
||||
|
||||
using namespace ui;
|
||||
@@ -59,6 +63,43 @@ void App::initLog()
|
||||
LogRemote::I.file_init();
|
||||
}
|
||||
|
||||
static size_t curl_data_handler(void *contents, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
auto buffer = reinterpret_cast<std::string*>(userp);
|
||||
buffer->append((char*)contents, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
void App::upload(std::string filename)
|
||||
{
|
||||
CURL *curl;
|
||||
|
||||
struct curl_httppost *formpost = NULL;
|
||||
struct curl_httppost *lastptr = NULL;
|
||||
|
||||
//curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
curl_formadd(&formpost,
|
||||
&lastptr,
|
||||
CURLFORM_COPYNAME, "fileToUpload",
|
||||
CURLFORM_FILE, filename.c_str(),
|
||||
CURLFORM_END);
|
||||
|
||||
curl = curl_easy_init();
|
||||
std::string res;
|
||||
|
||||
if (curl)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "http://omigamedev.ddns.net:8080/upload/upl.php");
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_handler);
|
||||
auto err = curl_easy_perform(curl); //here it crashes
|
||||
std::cout << "\n\nUPLOAD RESULT\n" << res << "\n\n\n";
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
|
||||
void App::init()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@@ -133,6 +174,9 @@ void App::async_start()
|
||||
[ios_view async_lock];
|
||||
#elif __ANDROID__
|
||||
android_async_lock(and_engine);
|
||||
#elif _WIN32
|
||||
async_lock();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -140,6 +184,8 @@ void App::async_update()
|
||||
{
|
||||
#if __IOS__
|
||||
[ios_view->glview bindDrawable];
|
||||
#elif _WIN32
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
redraw = true;
|
||||
clear();
|
||||
@@ -151,6 +197,8 @@ void App::async_update()
|
||||
[ios_view async_swap];
|
||||
#elif __ANDROID__
|
||||
android_async_swap(and_engine);
|
||||
#elif _WIN32
|
||||
async_swap();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -162,11 +210,16 @@ void App::async_end()
|
||||
[ios_view async_unlock];
|
||||
#elif __ANDROID__
|
||||
android_async_unlock(and_engine);
|
||||
#elif _WIN32
|
||||
async_unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
void App::update(float dt)
|
||||
{
|
||||
static std::mutex m;
|
||||
std::lock_guard<std::mutex> _lock(m);
|
||||
|
||||
// update offscreen stuff
|
||||
if (canvas && canvas->m_canvas)
|
||||
canvas->m_canvas->stroke_draw();
|
||||
|
||||
Reference in New Issue
Block a user