update android project

This commit is contained in:
2019-07-11 13:34:21 +02:00
parent d453e854b1
commit 92dd00d910
3 changed files with 49 additions and 40 deletions

View File

@@ -560,7 +560,6 @@ static int engine_init_display(struct engine* engine) {
} }
} }
FILE* file = popen("getprop", "r"); FILE* file = popen("getprop", "r");
std::map<std::string, std::string> os_props; std::map<std::string, std::string> os_props;
if (file) 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 Maker: %s", os_props["ro.product.manufacturer"].c_str());
LOG("PROP Mode: %s", os_props["ro.product.model"].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; Asset::m_am = engine->app->activity->assetManager;
App::I.and_app = engine->app; App::I.and_app = engine->app;
App::I.and_engine = engine; App::I.and_engine = engine;
@@ -630,13 +620,16 @@ static int engine_init_display(struct engine* engine) {
App::I.width = w; App::I.width = w;
App::I.height = h; App::I.height = h;
App::I.redraw = true; 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 #endif
LOG("All ready");
engine->animating = 1;
android_async_unlock(engine);
return 0; return 0;
} }
@@ -644,6 +637,7 @@ static int engine_init_display(struct engine* engine) {
* Just the current frame in the display. * Just the current frame in the display.
*/ */
static void engine_draw_frame(struct engine* engine) { static void engine_draw_frame(struct engine* engine) {
return;
static auto start = std::chrono::high_resolution_clock::now(); static auto start = std::chrono::high_resolution_clock::now();
static float elapsed = 0; static float elapsed = 0;
static float elapsed_1s = 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); int32_t eventType = AInputEvent_getType(event);
//LOG("event type: %d", eventType); //LOG("event type: %d", eventType);
locker _locker{engine}; //locker _locker{engine};
App::I.redraw = true; App::I.redraw = true;
switch (eventType) { switch (eventType) {
@@ -769,7 +763,9 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
float pressure = AMotionEvent_getPressure(event, 0); float pressure = AMotionEvent_getPressure(event, 0);
kEventSource source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ? kEventSource source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ?
kEventSource::Stylus : kEventSource::Touch; 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; tracked = 1;
//LOG("first down"); //LOG("first down");
return 1; 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.x = AMotionEvent_getX(event, 0);
p0.pos.y = AMotionEvent_getY(event, 0); p0.pos.y = AMotionEvent_getY(event, 0);
//LOG("second down"); //LOG("second down");
if (tracked == 1) App::I.ui_task_async([=] {
App::I.mouse_cancel(0); if (tracked == 1)
App::I.gesture_start(p0.pos, p1.pos); App::I.mouse_cancel(0);
App::I.gesture_start(p0.pos, p1.pos);
});
tracked = 2; tracked = 2;
} }
return 1; 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 source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ?
kEventSource::Stylus : kEventSource::Touch; kEventSource::Stylus : kEventSource::Touch;
if (tracked == 1) 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; tracked = 0;
//LOG("first up"); //LOG("first up");
return 1; return 1;
@@ -815,14 +817,18 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
{ {
p1.id = -1; p1.id = -1;
//LOG("second up"); //LOG("second up");
App::I.gesture_end(); App::I.ui_task_async([=] {
App::I.gesture_end();
});
} }
return 1; return 1;
case AMOTION_EVENT_ACTION_HOVER_MOVE: // pen move before touching case AMOTION_EVENT_ACTION_HOVER_MOVE: // pen move before touching
{ {
float y = AMotionEvent_getY(event, 0); float y = AMotionEvent_getY(event, 0);
float x = AMotionEvent_getX(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"); //LOG("single move");
return 1; return 1;
} }
@@ -835,7 +841,9 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
float pressure = AMotionEvent_getPressure(event, 0); float pressure = AMotionEvent_getPressure(event, 0);
kEventSource source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ? kEventSource source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ?
kEventSource::Stylus : kEventSource::Touch; 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"); //LOG("single move");
} }
else if (count == 2) 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); float y = AMotionEvent_getY(event, 1);
p1.pos = {x, y}; 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; return 1;
default: default:
@@ -879,17 +889,23 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
case AKEY_EVENT_ACTION_MULTIPLE: case AKEY_EVENT_ACTION_MULTIPLE:
LOG("Received key multi event: %d\n", key_val); LOG("Received key multi event: %d\n", key_val);
if (uniValue > 32 && uniValue < 127) //printable ascii range if (uniValue > 32 && uniValue < 127) //printable ascii range
App::I.key_char(uniValue); App::I.ui_task_async([=] {
App::I.key_char(uniValue);
});
break; break;
case AKEY_EVENT_ACTION_DOWN: case AKEY_EVENT_ACTION_DOWN:
LOG("Received key down event: %d\n", key_val); 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; break;
case AKEY_EVENT_ACTION_UP: case AKEY_EVENT_ACTION_UP:
LOG("Received key up event: %d\n", key_val); LOG("Received key up event: %d\n", key_val);
App::I.key_up(convert_key(key_val)); App::I.ui_task_async([=] {
if (uniValue > 32 && uniValue < 127) //printable ascii range App::I.key_up(convert_key(key_val));
App::I.key_char(uniValue); if (uniValue > 32 && uniValue < 127) //printable ascii range
App::I.key_char(uniValue);
});
break; break;
} }
return 1; return 1;

View File

@@ -276,7 +276,6 @@ public:
template<typename T, typename R = void> template<typename T, typename R = void>
std::future<R> render_task_async(T task) std::future<R> render_task_async(T task)
{ {
#ifdef _WIN32
std::packaged_task<R()> pt(task); std::packaged_task<R()> pt(task);
std::future<R> f = pt.get_future(); std::future<R> f = pt.get_future();
if (is_render_thread()) if (is_render_thread())
@@ -292,13 +291,11 @@ public:
render_cv.notify_all(); render_cv.notify_all();
} }
return f; return f;
#endif // _WIN32
} }
template<typename T, typename R = void> template<typename T, typename R = void>
R render_task(T task) R render_task(T task)
{ {
#ifdef _WIN32
std::packaged_task<R()> pt(task); std::packaged_task<R()> pt(task);
std::future<R> f = pt.get_future(); std::future<R> f = pt.get_future();
if (is_render_thread()) if (is_render_thread())
@@ -314,7 +311,6 @@ public:
render_cv.notify_all(); render_cv.notify_all();
} }
return render_running ? f.get() : R(); return render_running ? f.get() : R();
#endif // _WIN32
} }
void render_sync() void render_sync()

View File

@@ -144,11 +144,8 @@ Texture2D::~Texture2D()
{ {
if (auto_destroy) if (auto_destroy)
{ {
App::I.render_task_async([this] LOG("Texture2D auto destroy");
{ destroy();
LOG("Texture2D auto destroy");
destroy();
});
} }
} }