From 92dd00d910e2f12e5058668456d7e7ccc420ca7c Mon Sep 17 00:00:00 2001 From: omigamedev Date: Thu, 11 Jul 2019 13:34:21 +0200 Subject: [PATCH] update android project --- android/src/cpp/main.cpp | 78 ++++++++++++++++++++++++---------------- src/app.h | 4 --- src/texture.cpp | 7 ++-- 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/android/src/cpp/main.cpp b/android/src/cpp/main.cpp index c0af210..3bcec00 100644 --- a/android/src/cpp/main.cpp +++ b/android/src/cpp/main.cpp @@ -560,7 +560,6 @@ static int engine_init_display(struct engine* engine) { } } - FILE* file = popen("getprop", "r"); std::map os_props; if (file) @@ -593,15 +592,6 @@ static int engine_init_display(struct engine* engine) { LOG("PROP Maker: %s", os_props["ro.product.manufacturer"].c_str()); LOG("PROP Mode: %s", os_props["ro.product.model"].c_str()); - // Initialize GL state. - - android_async_lock(engine); - - //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); - //glEnable(GL_CULL_FACE); - //glShadeModel(GL_SMOOTH); - glDisable(GL_DEPTH_TEST); - //glEnableClientState(GL_VERTEX_ARRAY); Asset::m_am = engine->app->activity->assetManager; App::I.and_app = engine->app; App::I.and_engine = engine; @@ -630,13 +620,16 @@ static int engine_init_display(struct engine* engine) { App::I.width = w; App::I.height = h; App::I.redraw = true; - App::I.init(); + + // give control to the render thread + LOG("release egl context"); + eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + LOG("start render threads"); + App::I.render_thread_start(); + LOG("start ui thread"); + App::I.ui_thread_start(); #endif - - LOG("All ready"); - engine->animating = 1; - - android_async_unlock(engine); return 0; } @@ -644,6 +637,7 @@ static int engine_init_display(struct engine* engine) { * Just the current frame in the display. */ static void engine_draw_frame(struct engine* engine) { + return; static auto start = std::chrono::high_resolution_clock::now(); static float elapsed = 0; static float elapsed_1s = 0; @@ -719,7 +713,7 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) int32_t eventType = AInputEvent_getType(event); //LOG("event type: %d", eventType); - locker _locker{engine}; + //locker _locker{engine}; App::I.redraw = true; switch (eventType) { @@ -769,7 +763,9 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) float pressure = AMotionEvent_getPressure(event, 0); kEventSource source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ? kEventSource::Stylus : kEventSource::Touch; - App::I.mouse_down(0, x, y, pressure, source, 0); + App::I.ui_task_async([=]{ + App::I.mouse_down(0, x, y, pressure, source, 0); + }); tracked = 1; //LOG("first down"); return 1; @@ -787,9 +783,11 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) p0.pos.x = AMotionEvent_getX(event, 0); p0.pos.y = AMotionEvent_getY(event, 0); //LOG("second down"); - if (tracked == 1) - App::I.mouse_cancel(0); - App::I.gesture_start(p0.pos, p1.pos); + App::I.ui_task_async([=] { + if (tracked == 1) + App::I.mouse_cancel(0); + App::I.gesture_start(p0.pos, p1.pos); + }); tracked = 2; } return 1; @@ -805,7 +803,11 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) kEventSource source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ? kEventSource::Stylus : kEventSource::Touch; if (tracked == 1) - App::I.mouse_up(0, x, y, source, 0); + { + App::I.ui_task_async([=] { + App::I.mouse_up(0, x, y, source, 0); + }); + } tracked = 0; //LOG("first up"); return 1; @@ -815,14 +817,18 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) { p1.id = -1; //LOG("second up"); - App::I.gesture_end(); + App::I.ui_task_async([=] { + App::I.gesture_end(); + }); } return 1; case AMOTION_EVENT_ACTION_HOVER_MOVE: // pen move before touching { float y = AMotionEvent_getY(event, 0); float x = AMotionEvent_getX(event, 0); - App::I.mouse_move(x, y, 0, kEventSource::Stylus, 0); + App::I.ui_task_async([=] { + App::I.mouse_move(x, y, 0, kEventSource::Stylus, 0); + }); //LOG("single move"); return 1; } @@ -835,7 +841,9 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) float pressure = AMotionEvent_getPressure(event, 0); kEventSource source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ? kEventSource::Stylus : kEventSource::Touch; - App::I.mouse_move(x, y, pressure, source, 0); + App::I.ui_task_async([=] { + App::I.mouse_move(x, y, pressure, source, 0); + }); //LOG("single move"); } else if (count == 2) @@ -856,7 +864,9 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) float y = AMotionEvent_getY(event, 1); p1.pos = {x, y}; } - App::I.gesture_move(p0.pos, p1.pos); + App::I.ui_task_async([=] { + App::I.gesture_move(p0.pos, p1.pos); + }); } return 1; default: @@ -879,17 +889,23 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) case AKEY_EVENT_ACTION_MULTIPLE: LOG("Received key multi event: %d\n", key_val); if (uniValue > 32 && uniValue < 127) //printable ascii range - App::I.key_char(uniValue); + App::I.ui_task_async([=] { + App::I.key_char(uniValue); + }); break; case AKEY_EVENT_ACTION_DOWN: LOG("Received key down event: %d\n", key_val); - App::I.key_down(convert_key(key_val)); + App::I.ui_task_async([=] { + App::I.key_down(convert_key(key_val)); + }); break; case AKEY_EVENT_ACTION_UP: LOG("Received key up event: %d\n", key_val); - App::I.key_up(convert_key(key_val)); - if (uniValue > 32 && uniValue < 127) //printable ascii range - App::I.key_char(uniValue); + App::I.ui_task_async([=] { + App::I.key_up(convert_key(key_val)); + if (uniValue > 32 && uniValue < 127) //printable ascii range + App::I.key_char(uniValue); + }); break; } return 1; diff --git a/src/app.h b/src/app.h index 3d98f5a..eb3497a 100644 --- a/src/app.h +++ b/src/app.h @@ -276,7 +276,6 @@ public: template std::future render_task_async(T task) { -#ifdef _WIN32 std::packaged_task pt(task); std::future f = pt.get_future(); if (is_render_thread()) @@ -292,13 +291,11 @@ public: render_cv.notify_all(); } return f; -#endif // _WIN32 } template R render_task(T task) { -#ifdef _WIN32 std::packaged_task pt(task); std::future f = pt.get_future(); if (is_render_thread()) @@ -314,7 +311,6 @@ public: render_cv.notify_all(); } return render_running ? f.get() : R(); -#endif // _WIN32 } void render_sync() diff --git a/src/texture.cpp b/src/texture.cpp index aaa4575..15d23be 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -144,11 +144,8 @@ Texture2D::~Texture2D() { if (auto_destroy) { - App::I.render_task_async([this] - { - LOG("Texture2D auto destroy"); - destroy(); - }); + LOG("Texture2D auto destroy"); + destroy(); } }