ANDROID: Implement pause/resume

Don't just kill the whole process when the Activity is stopped. Instead,
use its events to pause or resume audio and the running engine (if any).
Of course not every engines implements that... but at least an incoming
call doesn't kill the game now (lol).
This commit is contained in:
dhewg 2011-03-02 20:25:47 +01:00
parent ccfe427eb5
commit 25ef065a41
4 changed files with 52 additions and 18 deletions

View file

@ -27,6 +27,7 @@
#include "base/main.h"
#include "common/config-manager.h"
#include "engines/engine.h"
#include "backends/platform/android/android.h"
#include "backends/platform/android/asset-archive.h"
@ -93,6 +94,8 @@ const JNINativeMethod JNI::_natives[] = {
(void *)JNI::pushEvent },
{ "enableZoning", "(Z)V",
(void *)JNI::enableZoning },
{ "pauseEngine", "(Z)V",
(void *)JNI::pauseEngine }
};
JNI::JNI() {
@ -613,5 +616,15 @@ void JNI::enableZoning(JNIEnv *env, jobject self, jboolean enable) {
_system->enableZoning(enable);
}
void JNI::pauseEngine(JNIEnv *env, jobject self, jboolean pause) {
if (!_system || !g_engine)
return;
if ((pause && !g_engine->isPaused()) || (!pause && g_engine->isPaused())) {
LOGD("pauseEngine: %d", pause);
g_engine->pauseEngine(pause);
}
}
#endif

View file

@ -129,6 +129,8 @@ private:
static void pushEvent(JNIEnv *env, jobject self, jobject java_event);
static void enableZoning(JNIEnv *env, jobject self, jboolean enable);
static void pauseEngine(JNIEnv *env, jobject self, jboolean pause);
};
inline bool JNI::haveSurface() {

View file

@ -44,6 +44,7 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
final private native void destroy();
final private native void setSurface(int width, int height);
final private native int main(String[] args);
final private native void pauseEngine(boolean pause);
// Set scummvm config options
final public native void enableZoning(boolean enable);
@ -134,12 +135,14 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
System.exit(res);
}
public void pause() {
// TODO
}
public void pause(boolean pause) {
if (audio_track != null && !pause)
audio_track.play();
public void resume() {
// TODO
pauseEngine(pause);
if (audio_track != null && pause)
audio_track.stop();
}
final private void initEGL() throws Exception {

View file

@ -161,30 +161,46 @@ public class ScummVMActivity extends Activity {
scummvm_thread.start();
}
private boolean was_paused = false;
@Override
public void onPause() {
if (scummvm != null) {
was_paused = true;
scummvm.pause();
}
public void onStart() {
Log.d(ScummVM.LOG_TAG, "onStart");
super.onPause();
super.onStart();
}
@Override
public void onResume() {
Log.d(ScummVM.LOG_TAG, "onResume");
super.onResume();
if (scummvm != null && was_paused)
scummvm.resume();
if (scummvm != null)
scummvm.pause(false);
}
was_paused = false;
@Override
public void onPause() {
Log.d(ScummVM.LOG_TAG, "onPause");
super.onPause();
if (scummvm != null)
scummvm.pause(true);
}
@Override
public void onStop() {
Log.d(ScummVM.LOG_TAG, "onStop");
super.onStop();
}
@Override
public void onDestroy() {
Log.d(ScummVM.LOG_TAG, "onDestroy");
super.onDestroy();
if (scummvm != null) {
scummvm.pushEvent(new Event(Event.EVENT_QUIT));
@ -194,9 +210,9 @@ public class ScummVMActivity extends Activity {
} catch (InterruptedException e) {
Log.i(ScummVM.LOG_TAG, "Error while joining ScummVM thread", e);
}
}
super.onStop();
scummvm = null;
}
}
static final int MSG_MENU_LONG_PRESS = 1;