android: stop the emulator thread ASAP, don't wait for activity finish

Disable VJoy editor button when touched, to avoid launching it twice
This commit is contained in:
Flyinghead 2019-02-18 16:16:54 +01:00
parent e426bc8058
commit 737dd83855
7 changed files with 32 additions and 56 deletions

View File

@ -47,6 +47,10 @@ public class BaseNativeGLActivity extends Activity implements SurfaceHolder.Call
@Override
protected void onDestroy() {
super.onDestroy();
stopEmulator();
}
protected void stopEmulator() {
if (mView != null) {
mView.stop();
}

View File

@ -71,6 +71,7 @@ public class EditVJoyActivity extends BaseNativeGLActivity {
hlay.addView(addbut(R.drawable.apply, new OnClickListener() {
public void onClick(View v) {
stopEmulator();
Intent inte = new Intent(EditVJoyActivity.this, MainActivity.class);
startActivity(inte);
finish();

View File

@ -79,9 +79,10 @@ public class InputFragment extends Fragment {
Config.vibrationDuration = mPrefs.getInt(Config.pref_vibrationDuration, 20);
vib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
Button buttonLaunchEditor = (Button) getView().findViewById(R.id.buttonLaunchEditor);
final Button buttonLaunchEditor = (Button) getView().findViewById(R.id.buttonLaunchEditor);
buttonLaunchEditor.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
buttonLaunchEditor.setEnabled(false);
mCallback.onEditorSelected(Uri.EMPTY);
}
});
@ -137,6 +138,13 @@ public class InputFragment extends Fragment {
updateVibration();
}
@Override
public void onResume() {
super.onResume();
Button buttonLaunchEditor = (Button) getView().findViewById(R.id.buttonLaunchEditor);
buttonLaunchEditor.setEnabled(isBIOSAvailable());
}
private boolean isBIOSAvailable() {
String home_directory = mPrefs.getString(Config.pref_home,
Environment.getExternalStorageDirectory().getAbsolutePath());

View File

@ -135,7 +135,6 @@ public class NativeGLView extends SurfaceView {
handler.post(new Runnable() {
@Override
public void run() {
// FIXME STOP AT SOME POINT!!
if (ethd.getState() == Thread.State.TERMINATED)
((Activity)getContext()).finish();
else {
@ -516,6 +515,7 @@ public class NativeGLView extends SurfaceView {
Player.play();
}
Log.i("NativeGLView", "Running emulator");
JNIdc.run(this);
}
@ -584,6 +584,7 @@ public class NativeGLView extends SurfaceView {
}
public void stop() {
Log.i("NativeGLView", "Stopping emulator");
//JNIdc.destroy();
JNIdc.stop();
try {
@ -591,6 +592,7 @@ public class NativeGLView extends SurfaceView {
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.i("NativeGLView", "Stopping emulator completed");
}
@TargetApi(19)

View File

@ -47,7 +47,6 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
@Override
public void onInputDeviceRemoved(int i) {
if (maple_port > 0)
// TODO The removed device might not be a gamepad/joystick
maple_port--;
joystickRemoved(i);
}

View File

@ -119,12 +119,14 @@ void dc_pause_emu();
void dc_resume_emu(bool continue_running);
void dc_stop();
void dc_term();
bool dc_is_running();
bool VramLockedWrite(u8* address);
bool rend_single_frame();
void rend_init_renderer();
void rend_term_renderer();
void rend_cancel_emu_wait();
bool egl_makecurrent();
//extern cResetEvent rs,re;
@ -411,13 +413,10 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_run(JNIEnv *env,jobje
dc_run();
env->DeleteGlobalRef(emu);
emu = NULL;
}
int msgboxf(const wchar* text,unsigned int type,...) {
JVMAttacher attacher;
if (attacher.failed())
return 0;
va_list args;
wchar temp[2048];
@ -426,6 +425,12 @@ int msgboxf(const wchar* text,unsigned int type,...) {
va_end(args);
LOGE("%s", temp);
if (emu == NULL)
return 0;
JVMAttacher attacher;
if (attacher.failed())
return 0;
int byteCount = strlen(temp);
jbyteArray bytes = attacher.env->NewByteArray(byteCount);
attacher.env->SetByteArrayRegion(bytes, 0, byteCount, (jbyte *) temp);
@ -460,7 +465,10 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_resume(JNIEnv *env,jo
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_stop(JNIEnv *env,jobject obj)
{
if (dc_is_running()) {
dc_stop();
rend_cancel_emu_wait();
}
}
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_destroy(JNIEnv *env,jobject obj)
@ -636,11 +644,6 @@ void androidaudio_term()
// Move along, there is nothing to see here!
}
bool os_IsAudioBuffered()
{
return jenv->CallIntMethod(emu,writemid,jsamples,-1)==0;
}
audiobackend_t audiobackend_android = {
"android", // Slug
"Android Audio", // Name
@ -686,47 +689,6 @@ void os_DebugBreak()
// Attach debugger here to figure out what went wrong
for(;;) ;
}
/*
void SaveSettings()
{
JVMAttacher attacher;
if (attacher.failed())
return;
attacher.env->CallVoidMethod(g_emulator, saveSettingsMid);
}
void LoadSpecialSettings();
void LoadCustom()
{
JVMAttacher attacher;
if (attacher.failed())
return;
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST
char *reios_id = reios_disk_id();
char *p = reios_id + strlen(reios_id) - 1;
while (p >= reios_id && *p == ' ')
*p-- = '\0';
if (*p == '\0')
return;
#elif DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE
char *reios_id = naomi_game_id;
char *reios_software_name = naomi_game_id;
#endif
LoadSpecialSettings(); // Default per-game settings
jmethodID loadGameConfigurationMid = attacher.env->GetMethodID(attacher.env->GetObjectClass(g_emulator), "loadGameConfiguration", "(Ljava/lang/String;)V");
char *id = (char*)malloc(11);
strcpy(id, reios_id);
jstring jreios_id = attacher.env->NewStringUTF(id);
attacher.env->CallVoidMethod(g_emulator, loadGameConfigurationMid, jreios_id);
}
*/
JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickAdded(JNIEnv *env, jobject obj, jint id, jstring name, jint maple_port)
{

View File

@ -5,7 +5,7 @@
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:fitsSystemWindows="false"
tools:openDrawer="start">
<include
@ -18,7 +18,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:fitsSystemWindows="false"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main"/>