Lifecycle tweaks that get Android building again

This commit is contained in:
Aaron Culliney 2015-09-12 15:33:22 -07:00
parent 0321c27de6
commit b2cb35c182
4 changed files with 39 additions and 26 deletions

View File

@ -560,13 +560,18 @@ public class Apple2Activity extends Activity {
public void onClick(DialogInterface dialog, int which) {
nativeOnQuit();
Apple2Activity.this.finish();
new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
Thread.sleep(2000);
} catch (InterruptedException ex) {
// ...
}
System.exit(0);
}
}.run();
}
}).setNegativeButton(R.string.no, null).create();
/*mQuitDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override

View File

@ -30,6 +30,8 @@ enum {
ANDROID_ACTION_POINTER_UP = 0x6,
};
static bool shuttingDown = false;
#if TESTING
static void _run_tests(void) {
char *local_argv[] = {
@ -134,7 +136,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobje
_run_tests();
// CPU thread is started from testsuite (if needed)
#else
timing_startCPU();
emulator_start();
#endif
}
@ -145,13 +147,8 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsChanged(JNIEnv *env
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsInitialized(JNIEnv *env, jobject obj, jint width, jint height) {
LOG("width:%d height:%d", width, height);
static bool graphicsPreviouslyInitialized = false;
if (graphicsPreviouslyInitialized) {
LOG("shutting down previous context");
video_shutdown();
}
graphicsPreviouslyInitialized = true;
video_shutdown();
video_backend->reshape(width, height);
video_backend->init((void *)0);
}
@ -171,6 +168,9 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnResume(JNIEnv *env, jobje
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobject obj, jboolean isSystemPause) {
if (shuttingDown) {
return;
}
if (cpu_isPaused()) {
return;
}
@ -192,7 +192,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobjec
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeRender(JNIEnv *env, jobject obj) {
if (UNLIKELY(emulator_shutting_down)) {
if (UNLIKELY(shuttingDown)) {
return;
}
@ -225,17 +225,16 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jobject
#if TESTING
// test driver thread is managing CPU
#else
shuttingDown = true;
LOG("%s", "");
c_eject_6(0);
c_eject_6(1);
emulator_shutting_down = true;
cpu_resume();
if (pthread_join(cpu_thread_id, NULL)) {
ERRLOG("OOPS: pthread_join of CPU thread ...");
}
emulator_shutdown();
#endif
}
@ -276,17 +275,22 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnUncaughtException(JNIEnv
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyDown(JNIEnv *env, jobject obj, jint keyCode, jint metaState) {
if (UNLIKELY(shuttingDown)) {
return;
}
android_keycode_to_emulator(keyCode, metaState, true);
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyUp(JNIEnv *env, jobject obj, jint keyCode, jint metaState) {
if (UNLIKELY(shuttingDown)) {
return;
}
android_keycode_to_emulator(keyCode, metaState, false);
}
jlong Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnTouch(JNIEnv *env, jobject obj, jint action, jint pointerCount, jint pointerIndex, jfloatArray xCoords, jfloatArray yCoords) {
//LOG(": %d/%d/%d :", action, pointerCount, pointerIndex);
if (UNLIKELY(emulator_shutting_down)) {
video_shutdown();
if (UNLIKELY(shuttingDown)) {
return 0x0LL;
}

View File

@ -47,7 +47,7 @@ void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetSpeakerVolume(JNIEnv
assert(goesToTen >= 0);
sound_volume = goesToTen;
#warning FIXME TODO refactor/remove sound_volume ?
speaker_setVolumeZeroToTen(goesToTen);
vm_reinitializeAudio();
}
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetAudioLatency(JNIEnv *env, jclass cls, jfloat latencySecs) {

View File

@ -38,10 +38,8 @@ static void _init_common() {
static void _shutdown_threads(void) {
#if !TESTING
# if defined(__linux__) && !defined(ANDROID)
LOG("Emulator waiting for other threads to clean up...");
# if !__linux__
# error FIXME TODO on Darwin ...
# else
do {
DIR *dir = opendir("/proc/self/task");
if (!dir) {
@ -71,6 +69,8 @@ static void _shutdown_threads(void) {
static struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
nanosleep(&ts, NULL); // 30Hz framerate
} while (1);
# elif defined(__APPLE__)
# error TODO FIXME ... verify leaks-n-things with instruments on Darwin
# endif
#endif
}
@ -96,9 +96,13 @@ int main(int _argc, char **_argv) {
argv = _argv;
emulator_start();
video_main_loop();
// main loop ...
emulator_shutdown();
LOG("Emulator exit ...");
return 0;
}
#endif