trying to load game from apk

This commit is contained in:
fysx
2013-12-21 00:36:55 +01:00
parent fe7195c840
commit 7758fc2412
4 changed files with 56 additions and 12 deletions
@@ -22,12 +22,21 @@ void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject
SDL_SetMainReady(); SDL_SetMainReady();
jboolean isCopy;
const char* str = (*env)->GetStringUTFChars(env, obj, &isCopy);
/* Run the application code! */ /* Run the application code! */
int status; int status;
char *argv[2]; char *argv[4];
argv[0] = SDL_strdup("SDL_app"); argv[0] = SDL_strdup("SDL_app");
argv[1] = NULL; argv[1] = SDL_strdup("--package-path");
status = SDL_main(1, argv); 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 */ /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
/* exit(status); */ /* exit(status); */
+6 -2
View File
@@ -244,10 +244,14 @@ function love.boot()
local o = love.arg.options local o = love.arg.options
local arg0 = love.arg.getLow(arg) local arg0 = love.arg.getLow(arg)
SDL.log("trying to load lovegame") -- SDL.log("trying to load lovegame")
arg0 = "/sdcard/lovegame/" -- arg0 = "/sdcard/lovegame/"
love.filesystem.init(arg0) 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? -- Is this one of those fancy "fused" games?
local can_has_game = pcall(love.filesystem.setSource, arg0) local can_has_game = pcall(love.filesystem.setSource, arg0)
is_fused_game = can_has_game is_fused_game = can_has_game
+13 -4
View File
@@ -433,12 +433,21 @@ const unsigned char boot_lua[] =
0x67, 0x2e, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x0a, 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, 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, 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, 0x2d, 0x2d, 0x09, 0x53, 0x44, 0x4c, 0x2e, 0x6c, 0x6f, 0x67, 0x28, 0x22, 0x74, 0x72, 0x79, 0x69, 0x6e, 0x67,
0x6f, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x67, 0x61, 0x6d, 0x65, 0x22, 0x29, 0x0a, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x67, 0x61, 0x6d, 0x65, 0x22,
0x09, 0x61, 0x72, 0x67, 0x30, 0x20, 0x3d, 0x20, 0x22, 0x2f, 0x73, 0x64, 0x63, 0x61, 0x72, 0x64, 0x2f, 0x6c, 0x29, 0x0a,
0x6f, 0x76, 0x65, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x22, 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, 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, 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, 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, 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, 0x64, 0x22, 0x20, 0x67, 0x61, 0x6d, 0x65, 0x73, 0x3f, 0x0a,
+25 -3
View File
@@ -4,6 +4,9 @@ import java.util.Arrays;
import android.app.*; import android.app.*;
import android.content.*; 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.*;
import android.view.inputmethod.BaseInputConnection; import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
@@ -231,7 +234,7 @@ public class SDLActivity extends Activity {
} }
// C functions we call // 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 nativeLowMemory();
public static native void nativeQuit(); public static native void nativeQuit();
public static native void nativePause(); public static native void nativePause();
@@ -413,10 +416,17 @@ public class SDLActivity extends Activity {
Simple nativeInit() runnable Simple nativeInit() runnable
*/ */
class SDLMain implements Runnable { class SDLMain implements Runnable {
public String path;
public SDLMain (String path) {
this.path = path;
}
@Override @Override
public void run() { public void run() {
// Runs SDL_main() // Runs SDL_main()
SDLActivity.nativeInit(); Log.v("Java", "calling with arg " + this.path);
SDLActivity.nativeInit(this.path);
//Log.v("SDL", "SDL thread terminated"); //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. // This is the entry point to the C app.
// Start up the C app thread and enable sensor input for the first time // 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); enableSensor(Sensor.TYPE_ACCELEROMETER, true);
SDLActivity.mSDLThread.start(); SDLActivity.mSDLThread.start();
} }