Skip to content

Commit

Permalink
Apply LOVE 11.x-specific patch to SDL2.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikuAuahDark committed Sep 26, 2023
1 parent eac9c7d commit 8b77791
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ public enum NativeState {
public static NativeState mNextNativeState;
public static NativeState mCurrentNativeState;

public static boolean mExitCalledFromJava; // love2d-mod: allow restarting of the native thread

/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
public static boolean mBrokenLibraries = true;

Expand Down Expand Up @@ -306,6 +308,7 @@ public static void initialize() {
mCursors = new Hashtable<Integer, PointerIcon>();
mLastCursorID = 0;
mSDLThread = null;
mExitCalledFromJava = false; // love2d-mod: allow restarting of the native thread
mIsResumedCalled = false;
mHasFocus = true;
mNextNativeState = NativeState.INIT;
Expand Down Expand Up @@ -378,6 +381,13 @@ public void onClick(DialogInterface dialog,int id) {
return;
}

startNative(); // love2d-mod: allow restarting of the native thread
}

// love2d-mod-start: allow restarting of the native thread
public void startNative() {
boolean hadSDLThread = SDLActivity.mSDLThread != null;

// Set up JNI
SDL.setupJNI();

Expand Down Expand Up @@ -427,7 +437,12 @@ public void onClick(DialogInterface dialog,int id) {
SDLActivity.onNativeDropFile(filename);
}
}

if (hadSDLThread) {
resumeNativeThread();
}
}
// love2d-mod-end: allow restarting of the native thread

protected void pauseNativeThread() {
mNextNativeState = NativeState.PAUSED;
Expand Down Expand Up @@ -595,6 +610,20 @@ protected void onDestroy() {
return;
}

appQuitFinish(); // love2d-mod: allow restarting of the native thread
super.onDestroy();
}

// love2d-mod-start: allow restarting of the native thread
public void resetNative() {
Log.v("SDL", "resetNative()");

SDLActivity.mExitCalledFromJava = true; // love2d-mod: allow restarting of the native thread

appQuitFinish();
}

private void appQuitFinish() {
if (SDLActivity.mSDLThread != null) {

// Send Quit event to "SDLThread" thread
Expand All @@ -609,9 +638,8 @@ protected void onDestroy() {
}

SDLActivity.nativeQuit();

super.onDestroy();
}
// love2d-mod-end: allow restarting of the native thread

@Override
public void onBackPressed() {
Expand Down Expand Up @@ -1885,12 +1913,15 @@ public void run() {

Log.v("SDL", "Finished main function");

if (SDLActivity.mSingleton != null && !SDLActivity.mSingleton.isFinishing()) {
// Let's finish the Activity
SDLActivity.mSDLThread = null;
SDLActivity.mSingleton.finish();
} // else: Activity is already being destroyed

// love2d-mod-start: allow restarting of the native thread
if (!SDLActivity.mExitCalledFromJava) {
if (SDLActivity.mSingleton != null && !SDLActivity.mSingleton.isFinishing()) {
// Let's finish the Activity
SDLActivity.mSDLThread = null;
SDLActivity.mSingleton.finish();
} // else: Activity is already being destroyed
}
// love2d-mod-end: allow restarting of the native thread
}
}

Expand Down
7 changes: 4 additions & 3 deletions love/src/jni/SDL2/include/SDL_config_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@
#endif

/* Enable various audio drivers */
#define SDL_AUDIO_DRIVER_ANDROID 1
#define SDL_AUDIO_DRIVER_OPENSLES 1
#define SDL_AUDIO_DRIVER_AAUDIO 1
/* love2d-mod: Audio is handled by OpenAL */
#define SDL_AUDIO_DRIVER_ANDROID 0
#define SDL_AUDIO_DRIVER_OPENSLES 0
#define SDL_AUDIO_DRIVER_AAUDIO 0
#define SDL_AUDIO_DRIVER_DUMMY 1

/* Enable various input drivers */
Expand Down

0 comments on commit 8b77791

Please sign in to comment.