App::I static singleton to pointer
This commit is contained in:
@@ -255,19 +255,21 @@ JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_pickExternalCal
|
||||
env->ReleaseStringUTFChars(path, path_utf);
|
||||
|
||||
LOG("data_path %s", file_path.c_str());
|
||||
App::I.data_path = file_path;
|
||||
App::I.work_path = file_path;
|
||||
App::I.rec_path = file_path + "/frames";
|
||||
App::I->data_path = file_path;
|
||||
App::I->work_path = file_path;
|
||||
App::I->rec_path = file_path + "/frames";
|
||||
|
||||
App::I->initLog();
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_contentRectChanged(JNIEnv *end, jobject,
|
||||
jint wnd_w, jint wnd_h, jint rect_left, jint rect_top, jint rect_right, jint rect_bottom)
|
||||
{
|
||||
#ifndef __QUEST__
|
||||
LOG("resize wnd [%d %d] rect [%d %d %d %d]", wnd_w, wnd_h, rect_left, rect_top, rect_right, rect_bottom);
|
||||
App::I.width = wnd_w;
|
||||
App::I.height = (rect_bottom - rect_top);
|
||||
App::I.off_x = 0;
|
||||
App::I.off_y = wnd_h - (rect_bottom - rect_top);
|
||||
App::I->width = wnd_w;
|
||||
App::I->height = (rect_bottom - rect_top);
|
||||
App::I->off_x = 0;
|
||||
App::I->off_y = wnd_h - (rect_bottom - rect_top);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -315,7 +317,6 @@ std::string get_data_path(android_app* mApplication)
|
||||
*/
|
||||
static int engine_init_display(struct engine* engine) {
|
||||
// initialize OpenGL ES and EGL
|
||||
App::I.initLog();
|
||||
|
||||
/*
|
||||
* Here specify the attributes of the desired configuration.
|
||||
@@ -499,7 +500,7 @@ static int engine_init_display(struct engine* engine) {
|
||||
if (resuming_context)
|
||||
{
|
||||
LOG("RESUME APP");
|
||||
App::I.and_app = engine->app;
|
||||
App::I->and_app = engine->app;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -593,42 +594,42 @@ static int engine_init_display(struct engine* engine) {
|
||||
LOG("PROP Mode: %s", os_props["ro.product.model"].c_str());
|
||||
|
||||
Asset::m_am = engine->app->activity->assetManager;
|
||||
App::I.and_app = engine->app;
|
||||
App::I.and_engine = engine;
|
||||
App::I->and_app = engine->app;
|
||||
App::I->and_engine = engine;
|
||||
|
||||
//std::string base_path = engine->app->activity->externalDataPath ?
|
||||
// engine->app->activity->externalDataPath : get_data_path(engine->app);
|
||||
if (App::I.data_path.empty() || App::I.data_path == ".")
|
||||
App::I.data_path = get_data_path(engine->app);
|
||||
LOG("data_path %s", App::I.data_path.c_str());
|
||||
if (App::I->data_path.empty() || App::I->data_path == ".")
|
||||
App::I->data_path = get_data_path(engine->app);
|
||||
LOG("data_path %s", App::I->data_path.c_str());
|
||||
|
||||
|
||||
#ifdef __QUEST__
|
||||
App::I.zoom = 1.f;
|
||||
App::I.width = 1024;
|
||||
App::I.height = 1024;
|
||||
App::I.redraw = true;
|
||||
App::I.init();
|
||||
App::I.resize(1024, 1024);
|
||||
App::I.vr_active = true;
|
||||
App::I.has_vr = true;
|
||||
App::I.vr_only = true;
|
||||
App::I->zoom = 1.f;
|
||||
App::I->width = 1024;
|
||||
App::I->height = 1024;
|
||||
App::I->redraw = true;
|
||||
App::I->init();
|
||||
App::I->resize(1024, 1024);
|
||||
App::I->vr_active = true;
|
||||
App::I->has_vr = true;
|
||||
App::I->vr_only = true;
|
||||
#else
|
||||
float density = get_display_density(engine->app);
|
||||
LOG("density %f", density);
|
||||
App::I.zoom = density;// / 1.5;
|
||||
App::I.width = w;
|
||||
App::I.height = h;
|
||||
App::I.redraw = true;
|
||||
App::I->zoom = density;// / 1.5;
|
||||
App::I->width = w;
|
||||
App::I->height = h;
|
||||
App::I->redraw = true;
|
||||
|
||||
// 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();
|
||||
App::I->render_thread_start();
|
||||
LOG("start ui thread");
|
||||
App::I.ui_thread_start();
|
||||
App::I->ui_thread_start();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -652,7 +653,7 @@ static void engine_draw_frame(struct engine* engine) {
|
||||
start = now;
|
||||
elapsed += dt.count();
|
||||
elapsed_1s += dt.count();
|
||||
App::I.tick(dt.count());
|
||||
App::I->tick(dt.count());
|
||||
|
||||
if (elapsed_1s > 1.f)
|
||||
{
|
||||
@@ -668,14 +669,14 @@ static void engine_draw_frame(struct engine* engine) {
|
||||
rendered_frames++;
|
||||
|
||||
#ifdef __QUEST__
|
||||
App::I.update(elapsed);
|
||||
App::I->update(elapsed);
|
||||
oculus_draw(dt.count());
|
||||
#else
|
||||
if (!(App::I.redraw || App::I.animate))
|
||||
if (!(App::I->redraw || App::I->animate))
|
||||
return;
|
||||
|
||||
App::I.clear();
|
||||
App::I.update(elapsed);
|
||||
App::I->clear();
|
||||
App::I->update(elapsed);
|
||||
|
||||
eglSwapBuffers(engine->display, engine->surface);
|
||||
#endif
|
||||
@@ -714,7 +715,7 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
||||
//LOG("event type: %d", eventType);
|
||||
|
||||
//locker _locker{engine};
|
||||
App::I.redraw = true;
|
||||
App::I->redraw = true;
|
||||
|
||||
switch (eventType) {
|
||||
case AINPUT_EVENT_TYPE_MOTION:
|
||||
@@ -763,8 +764,8 @@ 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.ui_task_async([=]{
|
||||
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");
|
||||
@@ -783,10 +784,10 @@ 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");
|
||||
App::I.ui_task_async([=] {
|
||||
App::I->ui_task_async([=] {
|
||||
if (tracked == 1)
|
||||
App::I.mouse_cancel(0);
|
||||
App::I.gesture_start(p0.pos, p1.pos);
|
||||
App::I->mouse_cancel(0);
|
||||
App::I->gesture_start(p0.pos, p1.pos);
|
||||
});
|
||||
tracked = 2;
|
||||
}
|
||||
@@ -804,8 +805,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
||||
kEventSource::Stylus : kEventSource::Touch;
|
||||
if (tracked == 1)
|
||||
{
|
||||
App::I.ui_task_async([=] {
|
||||
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;
|
||||
@@ -817,8 +818,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
||||
{
|
||||
p1.id = -1;
|
||||
//LOG("second up");
|
||||
App::I.ui_task_async([=] {
|
||||
App::I.gesture_end();
|
||||
App::I->ui_task_async([=] {
|
||||
App::I->gesture_end();
|
||||
});
|
||||
}
|
||||
return 1;
|
||||
@@ -826,8 +827,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
||||
{
|
||||
float y = AMotionEvent_getY(event, 0);
|
||||
float x = AMotionEvent_getX(event, 0);
|
||||
App::I.ui_task_async([=] {
|
||||
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;
|
||||
@@ -841,8 +842,8 @@ 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.ui_task_async([=] {
|
||||
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");
|
||||
}
|
||||
@@ -864,8 +865,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
||||
float y = AMotionEvent_getY(event, 1);
|
||||
p1.pos = {x, y};
|
||||
}
|
||||
App::I.ui_task_async([=] {
|
||||
App::I.gesture_move(p0.pos, p1.pos);
|
||||
App::I->ui_task_async([=] {
|
||||
App::I->gesture_move(p0.pos, p1.pos);
|
||||
});
|
||||
}
|
||||
return 1;
|
||||
@@ -889,22 +890,22 @@ 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.ui_task_async([=] {
|
||||
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.ui_task_async([=] {
|
||||
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.ui_task_async([=] {
|
||||
App::I.key_up(convert_key(key_val));
|
||||
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);
|
||||
App::I->key_char(uniValue);
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -922,7 +923,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
switch (cmd) {
|
||||
case APP_CMD_RESUME:
|
||||
LOG("APP_CMD_RESUME");
|
||||
App::I.redraw = true;
|
||||
App::I->redraw = true;
|
||||
ALooper_wake(engine->app->looper);
|
||||
break;
|
||||
case APP_CMD_SAVE_STATE:
|
||||
@@ -941,7 +942,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
break;
|
||||
case APP_CMD_TERM_WINDOW:
|
||||
// The window is being hidden or closed, clean it up.
|
||||
//App::I.terminate();
|
||||
//App::I->terminate();
|
||||
engine_term_display(engine);
|
||||
//exit(0);
|
||||
break;
|
||||
@@ -974,20 +975,20 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
break;
|
||||
case APP_CMD_WINDOW_REDRAW_NEEDED:
|
||||
LOG("APP_CMD_WINDOW_REDRAW_NEEDED");
|
||||
App::I.redraw = true;
|
||||
App::I->redraw = true;
|
||||
ALooper_wake(engine->app->looper);
|
||||
break;
|
||||
case APP_CMD_WINDOW_RESIZED:
|
||||
LOG("APP_CMD_WINDOW_RESIZED");
|
||||
App::I.redraw = true;
|
||||
App::I->redraw = true;
|
||||
ALooper_wake(engine->app->looper);
|
||||
break;
|
||||
case APP_CMD_CONTENT_RECT_CHANGED:
|
||||
LOG("APP_CMD_CONTENT_RECT_CHANGED");
|
||||
//App::I.width = engine->app->contentRect.right - engine->app->contentRect.left;
|
||||
//App::I.height = engine->app->contentRect.bottom - engine->app->contentRect.top;
|
||||
//LOG("content rect %f %f", App::I.width, App::I.height);
|
||||
App::I.redraw = true;
|
||||
//App::I->width = engine->app->contentRect.right - engine->app->contentRect.left;
|
||||
//App::I->height = engine->app->contentRect.bottom - engine->app->contentRect.top;
|
||||
//LOG("content rect %f %f", App::I->width, App::I->height);
|
||||
App::I->redraw = true;
|
||||
ALooper_wake(engine->app->looper);
|
||||
break;
|
||||
}
|
||||
@@ -1003,6 +1004,8 @@ void android_main(struct android_app* state) {
|
||||
// DON'T REMOVE, even if the compiler say it's deprecated
|
||||
app_dummy();
|
||||
|
||||
App::I = new App;
|
||||
|
||||
memset(&g_engine, 0, sizeof(g_engine));
|
||||
state->userData = &g_engine;
|
||||
state->onAppCmd = engine_handle_cmd;
|
||||
@@ -1036,8 +1039,8 @@ void android_main(struct android_app* state) {
|
||||
g_engine.state = *(struct saved_state*)state->savedState;
|
||||
}
|
||||
|
||||
//App::I.create();
|
||||
App::I.redraw = true;
|
||||
//App::I->create();
|
||||
App::I->redraw = true;
|
||||
|
||||
// loop waiting for stuff to do.
|
||||
|
||||
@@ -1079,7 +1082,7 @@ void android_main(struct android_app* state) {
|
||||
continue;
|
||||
|
||||
if (ident == ALOOPER_POLL_TIMEOUT){
|
||||
App::I.redraw = true;
|
||||
App::I->redraw = true;
|
||||
engine_draw_frame(&g_engine);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user