(Android) Get rid of unused width/height/animated in g_android struct

This commit is contained in:
twinaphex 2012-10-31 17:12:18 +01:00
parent 291280670d
commit cbcffbb5cf
3 changed files with 36 additions and 65 deletions

View File

@ -22,9 +22,6 @@ struct droid
bool init_quit; bool init_quit;
bool window_inited; bool window_inited;
unsigned animating;
unsigned width;
unsigned height;
struct saved_state state; struct saved_state state;
}; };

View File

@ -39,15 +39,15 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd)
RARCH_LOG("engine_handle_cmd: APP_CMD_SAVE_STATE.\n"); RARCH_LOG("engine_handle_cmd: APP_CMD_SAVE_STATE.\n");
// The system has asked us to save our current state. Do so. // The system has asked us to save our current state. Do so.
g_android.app->savedState = malloc(sizeof(struct saved_state)); g_android.app->savedState = malloc(sizeof(struct saved_state));
*((struct saved_state*)g_android.app->savedState) = g_android.state; *((struct saved_state*)g_android.app->savedState) = g_android.state;
g_android.app->savedStateSize = sizeof(struct saved_state); g_android.app->savedStateSize = sizeof(struct saved_state);
break; break;
case APP_CMD_INIT_WINDOW: case APP_CMD_INIT_WINDOW:
RARCH_LOG("engine_handle_cmd: APP_CMD_INIT_WINDOW.\n"); RARCH_LOG("engine_handle_cmd: APP_CMD_INIT_WINDOW.\n");
// The window is being shown, get it ready. // The window is being shown, get it ready.
if (g_android.app->window != NULL) if (g_android.app->window != NULL)
g_android.window_inited = true; g_android.window_inited = true;
break; break;
case APP_CMD_START: case APP_CMD_START:
RARCH_LOG("engine_handle_cmd: APP_CMD_START.\n"); RARCH_LOG("engine_handle_cmd: APP_CMD_START.\n");
break; break;
@ -59,43 +59,40 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd)
break; break;
case APP_CMD_PAUSE: case APP_CMD_PAUSE:
RARCH_LOG("engine_handle_cmd: APP_CMD_PAUSE.\n"); RARCH_LOG("engine_handle_cmd: APP_CMD_PAUSE.\n");
g_android.init_quit = true; g_android.init_quit = true;
break; break;
case APP_CMD_TERM_WINDOW: case APP_CMD_TERM_WINDOW:
RARCH_LOG("engine_handle_cmd: APP_CMD_TERM_WINDOW.\n"); RARCH_LOG("engine_handle_cmd: APP_CMD_TERM_WINDOW.\n");
// The window is being hidden or closed, clean it up. // The window is being hidden or closed, clean it up.
break; break;
case APP_CMD_GAINED_FOCUS: case APP_CMD_GAINED_FOCUS:
RARCH_LOG("engine_handle_cmd: APP_CMD_GAINED_FOCUS.\n"); RARCH_LOG("engine_handle_cmd: APP_CMD_GAINED_FOCUS.\n");
// When our app gains focus, we start monitoring the accelerometer. // When our app gains focus, we start monitoring the accelerometer.
#if 0 #if 0
if (g_android.accelerometerSensor != NULL) if (g_android.accelerometerSensor != NULL)
{ {
ASensorEventQueue_enableSensor(g_android.sensorEventQueue, ASensorEventQueue_enableSensor(g_android.sensorEventQueue,
g_android.accelerometerSensor); g_android.accelerometerSensor);
// We'd like to get 60 events per second (in us). // We'd like to get 60 events per second (in us).
ASensorEventQueue_setEventRate(g_android.sensorEventQueue, ASensorEventQueue_setEventRate(g_android.sensorEventQueue,
g_android.accelerometerSensor, (1000L/60)*1000); g_android.accelerometerSensor, (1000L/60)*1000);
} }
#endif #endif
break; break;
case APP_CMD_LOST_FOCUS: case APP_CMD_LOST_FOCUS:
RARCH_LOG("engine_handle_cmd: APP_CMD_LOST_FOCUS.\n"); RARCH_LOG("engine_handle_cmd: APP_CMD_LOST_FOCUS.\n");
// When our app loses focus, we stop monitoring the accelerometer. // When our app loses focus, we stop monitoring the accelerometer.
// This is to avoid consuming battery while not being used. // This is to avoid consuming battery while not being used.
if (!g_android.window_inited) if (!g_android.window_inited)
{ {
#if 0 #if 0
if (g_android.accelerometerSensor != NULL) if (g_android.accelerometerSensor != NULL)
ASensorEventQueue_disableSensor(g_android.sensorEventQueue, ASensorEventQueue_disableSensor(g_android.sensorEventQueue,
g_android.accelerometerSensor); g_android.accelerometerSensor);
#endif #endif
// Also stop animating.
g_android.animating = 0;
} }
break; break;
} }
} }
@ -178,45 +175,28 @@ void android_main(struct android_app* state)
argv[argc++] = strdup(libretro_path); argv[argc++] = strdup(libretro_path);
argv[argc++] = strdup("-v"); argv[argc++] = strdup("-v");
g_android.animating = 1;
g_extern.verbose = true; g_extern.verbose = true;
while(!g_android.window_inited) while(!g_android.window_inited)
{ {
// Read all pending events. // Read all pending events.
int ident; int ident;
int events;
struct android_poll_source* source; struct android_poll_source* source;
// If not animating, we will block forever waiting for events. // Block forever waiting for events.
// If animating, we loop until all events are read, then continue while ((ident=ALooper_pollAll(0, NULL, 0, (void**)&source)) >= 0)
// to draw the next frame of animation.
while ((ident=ALooper_pollAll(g_android.animating ? 0 : -1, NULL, &events,
(void**)&source)) >= 0)
{ {
// Process this event. // Process this event.
if (source != NULL) if (source != NULL)
source->process(g_android.app, source); source->process(g_android.app, source);
// If a sensor has data, process it now. // Check if we are exiting.
if (ident == LOOPER_ID_USER && g_android.accelerometerSensor != NULL) if (g_android.app->destroyRequested != 0)
{ return;
ASensorEvent event;
while (ASensorEventQueue_getEvents(g_android.sensorEventQueue, &event, 1) > 0)
{
//RARCH_LOG("accelerometer: x=%f y=%f z=%f.\n", event.acceleration.x,
//event.acceleration.y, event.acceleration.z);
}
}
// Check if we are exiting.
if (g_android.app->destroyRequested != 0)
return;
} }
} }
RARCH_LOG("Start RetroArch...\n"); RARCH_LOG("Starting RetroArch...\n");
rarch_main(argc, argv); rarch_main(argc, argv);
exit(0); exit(0);

View File

@ -57,22 +57,18 @@ static void gfx_ctx_destroy(void)
g_egl_surf = EGL_NO_SURFACE; g_egl_surf = EGL_NO_SURFACE;
g_egl_ctx = EGL_NO_CONTEXT; g_egl_ctx = EGL_NO_CONTEXT;
g_config = 0; g_config = 0;
g_android.width = 0;
g_android.height = 0;
g_android.animating = 0;
} }
static bool gfx_ctx_init(void) static bool gfx_ctx_init(void)
{ {
RARCH_LOG("gfx_ctx_init().\n"); RARCH_LOG("gfx_ctx_init().\n");
const EGLint attribs[] = { const EGLint attribs[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8, EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8, EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8, EGL_RED_SIZE, 8,
EGL_NONE EGL_NONE
}; };
EGLConfig config; EGLConfig config;
EGLint num_config; EGLint num_config;
@ -88,7 +84,7 @@ static bool gfx_ctx_init(void)
}; };
RARCH_LOG("Initializing context\n"); RARCH_LOG("Initializing context\n");
if ((g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) if ((g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY)
goto error; goto error;
@ -115,11 +111,9 @@ static bool gfx_ctx_init(void)
goto error; goto error;
if (!eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_WIDTH, &width) || if (!eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_WIDTH, &width) ||
!eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_HEIGHT, &height)) !eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_HEIGHT, &height))
goto error; goto error;
g_android.width = width;
g_android.height = height;
g_android.state.angle = 0; g_android.state.angle = 0;
return true; return true;