From 49d8e7dbebf0abc2817ec87a551ea344b03809fe Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Tue, 7 Aug 2012 14:03:20 +0200 Subject: [PATCH] Initial commit of handling of onPause() onPause() is called on ICS when the back button is pressed before the task lists is shown. With this commit, opentyrian pauses an ongoing level and waits for a key before continuing it. It does however not silence the music, which may be desirable as well (to be added with the next commit) --- project/AndroidManifestTemplate.xml | 3 ++- project/java/MainActivity.java | 11 +++++++++++ .../jni/application/opentyrian/src/keyboard.cpp | 13 +++++++++++++ project/jni/application/opentyrian/src/keyboard.h | 10 ++++++++++ .../jni/application/opentyrian/src/mainint.cpp | 15 ++++++++------- .../jni/application/opentyrian/src/tyrian2.cpp | 2 +- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/project/AndroidManifestTemplate.xml b/project/AndroidManifestTemplate.xml index 9cf1e248a..cdec4d025 100644 --- a/project/AndroidManifestTemplate.xml +++ b/project/AndroidManifestTemplate.xml @@ -2,7 +2,7 @@ emergency kill */ diff --git a/project/jni/application/opentyrian/src/keyboard.h b/project/jni/application/opentyrian/src/keyboard.h index 4cd826f1d..74e4e44d7 100644 --- a/project/jni/application/opentyrian/src/keyboard.h +++ b/project/jni/application/opentyrian/src/keyboard.h @@ -50,6 +50,16 @@ void set_mouse_position( int x, int y ); void service_SDL_events( JE_boolean clear_new ); +extern JE_boolean handle_pause_key; + +static inline +void service_SDL_events_ignore_pause( JE_boolean clear_new ) +{ + handle_pause_key = false; + service_SDL_events( clear_new ); + handle_pause_key = true; +} + void sleep_game( void ); void JE_clearKeyboard( void ); diff --git a/project/jni/application/opentyrian/src/mainint.cpp b/project/jni/application/opentyrian/src/mainint.cpp index ef5206503..1435f7af1 100644 --- a/project/jni/application/opentyrian/src/mainint.cpp +++ b/project/jni/application/opentyrian/src/mainint.cpp @@ -2783,7 +2783,7 @@ void JE_mainKeyboardInput( void ) } /* pause game */ - pause_pressed = pause_pressed || keysactive[SDLK_p]; + pause_pressed = pause_pressed || keysactive[SDLK_p] || keysactive[SDLK_PAUSE]; /* in-game setup */ ingamemenu_pressed = ingamemenu_pressed || keysactive[SDLK_ESCAPE]; @@ -2915,6 +2915,7 @@ void JE_pauseGame( void ) push_joysticks_as_keyboard(); service_SDL_events(true); + JE_showVGA(); if ((newkey && lastkey_sym != SDLK_LCTRL && lastkey_sym != SDLK_RCTRL && lastkey_sym != SDLK_LALT && lastkey_sym != SDLK_RALT) || JE_mousePosition(&mouseX, &mouseY) > 0) @@ -2938,6 +2939,8 @@ void JE_pauseGame( void ) done = true; } } + else + SDL_Delay(300); wait_delay(); } while (!done); @@ -3172,10 +3175,10 @@ redo: } } - service_SDL_events(false); + service_SDL_events_ignore_pause(false); - /* mouse input */ - /* + /* mouse input algorithm which is not suitable for touch-emulated mouse */ +#ifndef ANDROID if ((inputDevice == 0 || inputDevice == 2) && has_mouse) { button[0] |= mouse_pressed[0]; @@ -3194,9 +3197,7 @@ redo: set_mouse_position(159, 100); } } - */ - - +#endif /* keyboard input */ if ((inputDevice == 0 || inputDevice == 1 || inputDevice == 2) && !play_demo) { diff --git a/project/jni/application/opentyrian/src/tyrian2.cpp b/project/jni/application/opentyrian/src/tyrian2.cpp index bb274131c..2a84ba4cf 100644 --- a/project/jni/application/opentyrian/src/tyrian2.cpp +++ b/project/jni/application/opentyrian/src/tyrian2.cpp @@ -2377,7 +2377,7 @@ draw_player_shot_loop_end: } else // input handling for pausing, menu, cheats { - service_SDL_events(false); + service_SDL_events_ignore_pause(false); if (newkey) {