diff --git a/jni/SDL2-2.0.1/src/main/android/SDL_android_main.c b/jni/SDL2-2.0.1/src/main/android/SDL_android_main.c index 8f00f39d..76e5d9f4 100644 --- a/jni/SDL2-2.0.1/src/main/android/SDL_android_main.c +++ b/jni/SDL2-2.0.1/src/main/android/SDL_android_main.c @@ -22,12 +22,21 @@ void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject SDL_SetMainReady(); + jboolean isCopy; + const char* str = (*env)->GetStringUTFChars(env, obj, &isCopy); + /* Run the application code! */ int status; - char *argv[2]; + char *argv[4]; argv[0] = SDL_strdup("SDL_app"); - argv[1] = NULL; - status = SDL_main(1, argv); + argv[1] = SDL_strdup("--package-path"); + argv[2] = SDL_strdup(str); + argv[3] = NULL; + + if (isCopy == JNI_TRUE) + (*env)->ReleaseStringUTFChars(env, obj, str); + + status = SDL_main(3, argv); /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */ /* exit(status); */ diff --git a/jni/love/src/scripts/boot.lua b/jni/love/src/scripts/boot.lua index ba44d1a7..ab88f00d 100644 --- a/jni/love/src/scripts/boot.lua +++ b/jni/love/src/scripts/boot.lua @@ -244,10 +244,14 @@ function love.boot() local o = love.arg.options local arg0 = love.arg.getLow(arg) - SDL.log("trying to load lovegame") - arg0 = "/sdcard/lovegame/" +-- SDL.log("trying to load lovegame") +-- arg0 = "/sdcard/lovegame/" love.filesystem.init(arg0) + for i,a in ipairs (o.game.arg) do + SDL.log("arg " .. tostring(i) .. " = " .. tostring(a)) + end + -- Is this one of those fancy "fused" games? local can_has_game = pcall(love.filesystem.setSource, arg0) is_fused_game = can_has_game diff --git a/jni/love/src/scripts/boot.lua.h b/jni/love/src/scripts/boot.lua.h index 386b3f1d..4a0e768c 100644 --- a/jni/love/src/scripts/boot.lua.h +++ b/jni/love/src/scripts/boot.lua.h @@ -433,12 +433,21 @@ const unsigned char boot_lua[] = 0x67, 0x2e, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x61, 0x72, 0x67, 0x30, 0x20, 0x3d, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x61, 0x72, 0x67, 0x2e, 0x67, 0x65, 0x74, 0x4c, 0x6f, 0x77, 0x28, 0x61, 0x72, 0x67, 0x29, 0x0a, - 0x09, 0x53, 0x44, 0x4c, 0x2e, 0x6c, 0x6f, 0x67, 0x28, 0x22, 0x74, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x74, - 0x6f, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x67, 0x61, 0x6d, 0x65, 0x22, 0x29, 0x0a, - 0x09, 0x61, 0x72, 0x67, 0x30, 0x20, 0x3d, 0x20, 0x22, 0x2f, 0x73, 0x64, 0x63, 0x61, 0x72, 0x64, 0x2f, 0x6c, - 0x6f, 0x76, 0x65, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x22, 0x0a, + 0x2d, 0x2d, 0x09, 0x53, 0x44, 0x4c, 0x2e, 0x6c, 0x6f, 0x67, 0x28, 0x22, 0x74, 0x72, 0x79, 0x69, 0x6e, 0x67, + 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x67, 0x61, 0x6d, 0x65, 0x22, + 0x29, 0x0a, + 0x2d, 0x2d, 0x09, 0x61, 0x72, 0x67, 0x30, 0x20, 0x3d, 0x20, 0x22, 0x2f, 0x73, 0x64, 0x63, 0x61, 0x72, 0x64, + 0x2f, 0x6c, 0x6f, 0x76, 0x65, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x22, 0x0a, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x69, 0x6e, 0x69, 0x74, 0x28, 0x61, 0x72, 0x67, 0x30, 0x29, 0x0a, + 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x2c, 0x61, 0x20, 0x69, 0x6e, 0x20, 0x69, 0x70, 0x61, 0x69, 0x72, 0x73, + 0x20, 0x28, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x2e, 0x61, 0x72, 0x67, 0x29, 0x20, 0x64, 0x6f, 0x0a, + 0x09, 0x09, 0x53, 0x44, 0x4c, 0x2e, 0x6c, 0x6f, 0x67, 0x28, 0x22, 0x61, 0x72, 0x67, 0x20, 0x22, 0x20, 0x2e, + 0x2e, 0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x69, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, + 0x20, 0x3d, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x61, + 0x29, 0x29, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x49, 0x73, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, 0x20, 0x66, 0x61, 0x6e, 0x63, 0x79, 0x20, 0x22, 0x66, 0x75, 0x73, 0x65, 0x64, 0x22, 0x20, 0x67, 0x61, 0x6d, 0x65, 0x73, 0x3f, 0x0a, diff --git a/src/org/libsdl/app/SDLActivity.java b/src/org/libsdl/app/SDLActivity.java index 9cb53f98..570b43ba 100644 --- a/src/org/libsdl/app/SDLActivity.java +++ b/src/org/libsdl/app/SDLActivity.java @@ -4,6 +4,9 @@ import java.util.Arrays; import android.app.*; import android.content.*; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.view.*; import android.view.inputmethod.BaseInputConnection; import android.view.inputmethod.EditorInfo; @@ -231,7 +234,7 @@ public class SDLActivity extends Activity { } // C functions we call - public static native void nativeInit(); + public static native void nativeInit(String apkPath); public static native void nativeLowMemory(); public static native void nativeQuit(); public static native void nativePause(); @@ -413,10 +416,17 @@ public class SDLActivity extends Activity { Simple nativeInit() runnable */ class SDLMain implements Runnable { + public String path; + + public SDLMain (String path) { + this.path = path; + } + @Override public void run() { // Runs SDL_main() - SDLActivity.nativeInit(); + Log.v("Java", "calling with arg " + this.path); + SDLActivity.nativeInit(this.path); //Log.v("SDL", "SDL thread terminated"); } @@ -544,7 +554,19 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, // This is the entry point to the C app. // Start up the C app thread and enable sensor input for the first time - SDLActivity.mSDLThread = new Thread(new SDLMain(), "SDLThread"); + String apkFilePath = null; + ApplicationInfo appInfo = null; + Context context = getContext(); + PackageManager packMgmr = context.getPackageManager(); + try { + appInfo = packMgmr.getApplicationInfo("org.love2d.android", 0); + } catch (NameNotFoundException e) { + e.printStackTrace(); + throw new RuntimeException("Unable to locate assets, aborting..."); + } + apkFilePath = appInfo.sourceDir; + + SDLActivity.mSDLThread = new Thread(new SDLMain(apkFilePath), "SDLThread"); enableSensor(Sensor.TYPE_ACCELEROMETER, true); SDLActivity.mSDLThread.start(); }