save and restore layers image when context is lost in Android

This commit is contained in:
2017-04-29 21:30:40 +01:00
parent 2e47ccb0c6
commit fa49d9ee09
17 changed files with 210 additions and 69 deletions

View File

@@ -3,8 +3,10 @@
package="com.omigamedev"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="@string/app_name"
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:allowBackup="false"
android:hasCode="false"

View File

@@ -313,6 +313,7 @@ static int engine_init_display(struct engine* engine) {
glDisable(GL_DEPTH_TEST);
//glEnableClientState(GL_VERTEX_ARRAY);
Asset::m_am = engine->app->activity->assetManager;
App::I.data_path = engine->app->activity->externalDataPath;
App::I.width = w;
App::I.height = h;
App::I.init();
@@ -357,7 +358,6 @@ static void engine_term_display(struct engine* engine) {
engine->display = EGL_NO_DISPLAY;
engine->context = EGL_NO_CONTEXT;
engine->surface = EGL_NO_SURFACE;
App::I.terminate();
}
/**
@@ -366,7 +366,7 @@ static void engine_term_display(struct engine* engine) {
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
struct engine* engine = (struct engine*)app->userData;
int32_t eventType = AInputEvent_getType(event);
LOG("event type: %d", eventType);
//LOG("event type: %d", eventType);
switch (eventType) {
case AINPUT_EVENT_TYPE_MOTION:
// switch (AInputEvent_getSource(event)) {
@@ -384,7 +384,7 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
int ret = -1;
for (int i = 0; i < count; i++)
{
LOG("pointer %d id %d == %d", i, id, AMotionEvent_getPointerId(event, i));
//LOG("pointer %d id %d == %d", i, id, AMotionEvent_getPointerId(event, i));
if (AMotionEvent_getPointerId(event, i) == id)
ret = i;
}
@@ -400,7 +400,7 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
static Pointer p0, p1;
static int tracked = 0;
//LOG("event source: %d", AInputEvent_getSource(event));
LOG("pointer id %d count %d", pointer_id, count);
//LOG("pointer id %d count %d", pointer_id, count);
MouseEvent e;
switch (action) {
case AMOTION_EVENT_ACTION_DOWN:
@@ -412,12 +412,12 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
p0.idx = index;
App::I.mouse_down(0, x, y);
tracked = 1;
LOG("first down");
//LOG("first down");
return 1;
}
case AMOTION_EVENT_ACTION_POINTER_DOWN:
{
LOG("pointer down index %d", index);
//LOG("pointer down index %d", index);
if (count == 2)
{
float y = AMotionEvent_getY(event, 1);
@@ -426,7 +426,7 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
p1.idx = index;
p1.pos = {x, y};
tracked = 2;
LOG("second down");
//LOG("second down");
App::I.mouse_cancel(0);
App::I.gesture_start(p0.pos, p1.pos);
}
@@ -440,14 +440,14 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
p0.id = -1;
p1.id = -1;
App::I.mouse_up(0, x, y);
LOG("first up");
//LOG("first up");
return 1;
}
case AMOTION_EVENT_ACTION_POINTER_UP:
if (p1.id == AMotionEvent_getPointerId(event, 1))
{
p1.id = -1;
LOG("second up");
//LOG("second up");
App::I.gesture_end();
}
return 1;
@@ -456,7 +456,7 @@ 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.mouse_move(x, y);
LOG("single move");
//LOG("single move");
return 1;
}
case AMOTION_EVENT_ACTION_MOVE:
@@ -465,22 +465,22 @@ 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.mouse_move(x, y);
LOG("single move");
//LOG("single move");
}
else if (count == 2)
{
int idx = findPointer(pointer_id, event);
LOG("pointer move index %d", idx);
//LOG("pointer move index %d", idx);
if (p0.idx == idx)
{
LOG("first move");
//LOG("first move");
float y = AMotionEvent_getY(event, 0);
float x = AMotionEvent_getX(event, 0);
p0.pos = {x, y};
}
if (p1.idx == idx)
{
LOG("second move");
//LOG("second move");
float x = AMotionEvent_getX(event, 1);
float y = AMotionEvent_getY(event, 1);
p1.pos = {x, y};
@@ -528,6 +528,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();
engine_term_display(engine);
//exit(0);
break;