Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added requested_exit function to module interface to exit mainloop if…

… the game requests it
  • Loading branch information...
commit bf72f4d0cb8e7866fe7f9d69c8cf7f52e8f5eb81 1 parent 0cae281
@crowriot authored
View
6 modules/angrybirds.c
@@ -257,5 +257,11 @@ angrybirds_resume(struct SupportModule *self)
self->priv->native_resume(ENV_M, GLOBAL_M);
}
+static int
+angrybirds_requests_exit(struct SupportModule *self)
+{
+ return 0;
+}
+
APKENV_MODULE(angrybirds, MODULE_PRIORITY_GAME)
View
1  modules/common.h
@@ -60,6 +60,7 @@
module->deinit = modulename ## _deinit; \
module->pause = modulename ## _pause; \
module->resume = modulename ## _resume; \
+ module->requests_exit = modulename ## _requests_exit; \
return APKENV_MODULE_VERSION; \
}
View
79 modules/fruitninja.c
@@ -30,7 +30,7 @@
/**
* Fruit Ninja support module 0.5 - By: Arto Rusanen
- *
+ *
**/
#ifdef APKENV_DEBUG
@@ -58,6 +58,7 @@ typedef void (*fruitninja_saveonexit_t)(JNIEnv *env, jobject obj) SOFTFP;
typedef void (*fruitninja_gamerequestedquit_t)(JNIEnv *env, jobject obj) SOFTFP;
typedef void (*fruitninja_setapplicensed_t)(JNIEnv *env, jobject obj, jboolean value) SOFTFP;
typedef void (*fruitninja_initfilemanager_t)(JNIEnv *env, jobject obj, jstring paramString1, jstring paramString2, jboolean paramBoolean) SOFTFP;
+typedef void (*fruitninja_initjavasoundmanager_t)(JNIEnv *env, jobject obj) SOFTFP;
struct SupportModulePriv {
jni_onload_t JNI_OnLoad;
@@ -70,6 +71,7 @@ struct SupportModulePriv {
fruitninja_gamerequestedquit_t native_gamerequestedquit;
fruitninja_setapplicensed_t native_setapplicensed;
fruitninja_initfilemanager_t native_initfilemanager;
+ fruitninja_initjavasoundmanager_t native_initjavasoundmanager;
const char *myHome;
};
static struct SupportModulePriv fruitninja_priv;
@@ -115,7 +117,7 @@ JNIEnv_CallStaticObjectMethodV(JNIEnv* p0, jclass p1, jmethodID p2, va_list p3)
struct dummy_jstring *str = va_arg(p3,struct dummy_jstring*); //Sound file?
char* soundname = strdup(str->data);
int i;
- for(i = 0; soundname[i]; i++) {
+ for(i = 0; soundname[i]; i++) {
soundname[i] = tolower(soundname[i]); // LowerCase soundname
}
@@ -130,7 +132,7 @@ JNIEnv_CallStaticObjectMethodV(JNIEnv* p0, jclass p1, jmethodID p2, va_list p3)
}
}
MODULE_DEBUG_PRINTF("module: Sound not found: %s\n", soundname);
-
+
}
else
{
@@ -144,15 +146,17 @@ JNIEnv_CallStaticObjectMethodV(JNIEnv* p0, jclass p1, jmethodID p2, va_list p3)
/* Backround music support. I didn't find documentation about playing
music from memory buffer. So extract music and play it from there */
void
-extract_music_callback(const char *filename, char *buffer, size_t size)
+extract_files_callback(const char *filename, char *buffer, size_t size)
{
- char* fname = strrchr (filename, '/') + 1;
+ char* fname = strchr (filename, '/') + 1;
char tmp[PATH_MAX];
strcpy(tmp, fruitninja_priv.myHome);
strcat(tmp, fname);
- MODULE_DEBUG_PRINTF("module: Extract music to: %s\n", tmp);
+ MODULE_DEBUG_PRINTF("module: Extract file to: %s\n", tmp);
+
+ global->recursive_mkdir(tmp);
FILE *my_file = fopen(tmp, "wb");
fwrite(buffer, size, 1, my_file);
@@ -162,7 +166,7 @@ extract_music_callback(const char *filename, char *buffer, size_t size)
/* If music is started with Mix_PlayMusic( music, -1 ) it should loop right?
At least for me it did not so reload music and start again... */
void
-musicFinished()
+musicFinished()
{
MODULE_DEBUG_PRINTF("module: Music finished, trying to restart...\n");
music = Mix_LoadMUS( Music_Path );
@@ -183,7 +187,7 @@ JNIEnv_CallStaticVoidMethodV(JNIEnv* p0, jclass p1, jmethodID p2, va_list p3)
char* musicname = strdup(str->data);
int i;
- for(i = 0; musicname[i]; i++) {
+ for(i = 0; musicname[i]; i++) {
musicname[i] = tolower(musicname[i]); // LowerCase musicname
}
@@ -196,7 +200,7 @@ JNIEnv_CallStaticVoidMethodV(JNIEnv* p0, jclass p1, jmethodID p2, va_list p3)
music = Mix_LoadMUS( Music_Path );
Mix_PlayMusic( music, 0 ); // -1 should loop music? Not for me?
Mix_HookMusicFinished(musicFinished);
- } else if( strcmp( p2->name, "SetMusicVolume" ) == 0 ){
+ } else if( strcmp( p2->name, "SetMusicVolume" ) == 0 ){
int musicvol = va_arg(p3, double) * MIX_MAX_VOLUME;
MODULE_DEBUG_PRINTF("module: SetMusicVolume: %i\n", musicvol);
Mix_VolumeMusic(musicvol);
@@ -251,10 +255,7 @@ JNIEnv_FindClass(JNIEnv* p0, const char* p1)
jmethodID
JNIEnv_GetStaticMethodID(JNIEnv* p0, jclass clazz, const char* name, const char* sig)
{
- if( !strcmp( name, "isNetworkConnected" ) == 0 &&
- !strcmp( name, "SetMusicVolume" ) == 0 &&
- !strcmp( name, "SFXPlayInternal" ) == 0)
- MODULE_DEBUG_PRINTF("module_JNIEnv_GetStaticMethodID(%x, %s, %s)\n", clazz, name, sig);
+ MODULE_DEBUG_PRINTF("module_JNIEnv_GetStaticMethodID(%x, %s, %s)\n", clazz, name, sig);
jmethodID id = malloc(sizeof(struct _jmethodID));
id->clazz = clazz;
id->name = strdup(name);
@@ -269,6 +270,14 @@ JNIEnv_CallStaticBooleanMethodV(JNIEnv* p0, jclass p1, jmethodID p2, va_list p3)
MODULE_DEBUG_PRINTF("module_JNIEnv_CallStaticBooleanMethodV(%x, %s, %s)\n", p2->clazz, p2->name, p2->sig);
return 0;
}
+jboolean
+JNIEnv_CallStaticIntMethodMethodV(JNIEnv* p0, jclass p1, jmethodID p2, va_list p3)
+{
+ MODULE_DEBUG_PRINTF("module_JNIEnv_CallStaticIntMethodMethodV(%x, %s, %s)\n", p2->clazz, p2->name, p2->sig);
+ if (strcmp(p2->name,"GetWifi")==0) return 0;
+ if (strcmp(p2->name,"GetTouchscreenCapabilities")==0) return 0;
+ return 0;
+}
void
JNIEnv_ExceptionClear(JNIEnv* p0)
{
@@ -284,16 +293,20 @@ JNIEnv_ExceptionOccurred(JNIEnv* p0)
static int
fruitninja_try_init(struct SupportModule *self)
{
+ // Java_com_halfbrick_fruitninja_ < prefix in 1.5.4
+ // Java_com_halfbrick_mortar_ < prefix in 1.7.6
+
//self->priv->JNI_OnLoad = (jni_onload_t)LOOKUP_M("JNI_OnLoad"); //No JNI_Onload function in fruitninja
- self->priv->native_init = (fruitninja_init_t)LOOKUP_M("NativeGameLib_native_1init");
- self->priv->native_touchevent = (fruitninja_touchevent_t)LOOKUP_M("NativeGameLib_native_1touchEvent");
- self->priv->native_step = (fruitninja_step_t)LOOKUP_M("NativeGameLib_native_1step");
- self->priv->native_pause = (fruitninja_pause_t)LOOKUP_M("NativeGameLib_native_1onPause");
- self->priv->native_resume = (fruitninja_resume_t)LOOKUP_M("NativeGameLib_native_1onResume");
- self->priv->native_saveonexit = (fruitninja_saveonexit_t)LOOKUP_M("NativeGameLib_native_1saveOnExit");
- self->priv->native_gamerequestedquit = (fruitninja_gamerequestedquit_t)LOOKUP_M("NativeGameLib_native_1gameRequestedQuit");
- self->priv->native_setapplicensed = (fruitninja_setapplicensed_t)LOOKUP_M("NativeGameLib_native_1SetAppLicensed");
- self->priv->native_initfilemanager = (fruitninja_initfilemanager_t)LOOKUP_M("NativeGameLib_native_1InitFileManager");
+ self->priv->native_init = (fruitninja_init_t)LOOKUP_M("_NativeGameLib_native_1init");
+ self->priv->native_touchevent = (fruitninja_touchevent_t)LOOKUP_M("_NativeGameLib_native_1touchEvent");
+ self->priv->native_step = (fruitninja_step_t)LOOKUP_M("_NativeGameLib_native_1step");
+ self->priv->native_pause = (fruitninja_pause_t)LOOKUP_M("_NativeGameLib_native_1onPause");
+ self->priv->native_resume = (fruitninja_resume_t)LOOKUP_M("_NativeGameLib_native_1onResume");
+ self->priv->native_saveonexit = (fruitninja_saveonexit_t)LOOKUP_M("_NativeGameLib_native_1saveOnExit");
+ self->priv->native_gamerequestedquit = (fruitninja_gamerequestedquit_t)LOOKUP_M("_NativeGameLib_native_1gameRequestedQuit");
+ self->priv->native_setapplicensed = (fruitninja_setapplicensed_t)LOOKUP_M("_NativeGameLib_native_1SetAppLicensed");
+ self->priv->native_initfilemanager = (fruitninja_initfilemanager_t)LOOKUP_M("_NativeGameLib_native_1InitFileManager");
+ self->priv->native_initjavasoundmanager = (fruitninja_initjavasoundmanager_t)LOOKUP_M("_NativeGameLib_native_1InitJavaSoundManager");
/* override for JNIEnv_ */
self->override_env.CallStaticObjectMethodV = JNIEnv_CallStaticObjectMethodV;
@@ -306,6 +319,7 @@ fruitninja_try_init(struct SupportModule *self)
self->override_env.CallStaticBooleanMethodV = JNIEnv_CallStaticBooleanMethodV;
self->override_env.CallStaticVoidMethodV = JNIEnv_CallStaticVoidMethodV;
self->override_env.ExceptionOccurred = JNIEnv_ExceptionOccurred;
+ self->override_env.CallStaticIntMethodV = JNIEnv_CallStaticIntMethodMethodV;
return (//self->priv->JNI_OnLoad != NULL &&
self->priv->native_init != NULL &&
@@ -325,13 +339,13 @@ fruitninja_init(struct SupportModule *self, int width, int height, const char *h
global = GLOBAL_M;
self->priv->myHome = strdup(home);
- /* Init audio. I am too lazy to find out if fruitninja reports right
+ /* Init audio. I am too lazy to find out if fruitninja reports right
settings so I just hardcode these into here... */
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16SYS;
int audio_channels = 2;
int audio_buffers = 1024;
-
+
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) {
fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError());
exit(1);
@@ -341,12 +355,19 @@ fruitninja_init(struct SupportModule *self, int width, int height, const char *h
/* Load sounds */
global->foreach_file("assets/sound", load_sound_callback);
- /* Extract backround music */
- global->foreach_file("assets/music", extract_music_callback);
+ /* Extract files */
+ //global->foreach_file("assets/", extract_files_callback);
+
+#ifdef PANDORA
+ sync();
+#endif
+
jstring jSource = GLOBAL_M->env->NewStringUTF(ENV_M, global->apk_filename); //APK path & filename
jstring jHome = GLOBAL_M->env->NewStringUTF(ENV_M, home); // Save file location
self->priv->native_initfilemanager(ENV_M, GLOBAL_M, jSource, jHome, 0);
+ if (self->priv->native_initjavasoundmanager!=0)
+ self->priv->native_initjavasoundmanager(ENV_M, GLOBAL_M);
self->priv->native_init(ENV_M, GLOBAL_M, width, height, GLOBAL_M->env->NewStringUTF(ENV_M, "en"));
self->priv->native_setapplicensed(ENV_M, GLOBAL_M, 1);
}
@@ -391,5 +412,11 @@ fruitninja_resume(struct SupportModule *self)
self->priv->native_resume(ENV_M, GLOBAL_M);
}
+static int
+fruitninja_requests_exit(struct SupportModule *self)
+{
+ return 0;
+}
+
APKENV_MODULE(fruitninja, MODULE_PRIORITY_GAME)
View
9 modules/fruitninja.cbp
@@ -7,17 +7,18 @@
<Option compiler="pandora_compiler" />
<Build>
<Target title="Debug">
- <Option output="../bin/Debug/fruitninja.apkenv" prefix_auto="0" extension_auto="1" />
- <Option object_output="../obj/Debug/" />
+ <Option output="../bin/Debug/fruitninja.apkenv.so" prefix_auto="0" extension_auto="0" />
+ <Option object_output="./obj/Debug/" />
<Option type="3" />
<Option compiler="pandora_compiler" />
<Compiler>
<Add option="-g" />
+ <Add option="-DAPKENV_DEBUG" />
</Compiler>
</Target>
<Target title="Release">
- <Option output="../bin/Release/fruitninja.apkenv" prefix_auto="0" extension_auto="1" />
- <Option object_output="../obj/Release/" />
+ <Option output="../bin/Release/fruitninja.apkenv.so" prefix_auto="0" extension_auto="0" />
+ <Option object_output="./obj/Release/" />
<Option type="3" />
<Option compiler="pandora_compiler" />
<Compiler>
View
6 modules/trg2.c
@@ -119,5 +119,11 @@ trg2_resume(struct SupportModule *self)
{
}
+static int
+trg2_requests_exit()
+{
+ return 0;
+}
+
APKENV_MODULE(trg2, MODULE_PRIORITY_GAME)
View
94 modules/unity.c
@@ -42,8 +42,6 @@
# define MODULE_DEBUG_PRINTF(...)
#endif
-#define UNITYPLAYER_CLASS_NAME "com/unity3d/player/UnityPlayer"
-
struct GlobalState* global;
@@ -116,9 +114,42 @@ jobject JNIEnv_CallObjectMethod(JNIEnv* env, jobject p1, jmethodID p2, ...) SOFT
}
jobject
+JNIEnv_CallStaticObjectMethod(JNIEnv* env, jclass p1, jmethodID p2, ...) SOFTFP
+{
+ struct dummy_jclass* clazz = p1;
+ jmethodID method = p2;
+
+ MODULE_DEBUG_PRINTF("JNIEnv_CallStaticObjectMethod(%s,%s)\n",clazz->name,method->name);
+
+ if (strcmp(method->name,"getProperty")==0) {
+ //jstring property = va_arg(p3,jstring);
+ //const char* prop = (*env)->
+ //dummy_jobject* obj = malloc(sizeof(dummy_jobject));
+ //return obj;
+ return (*env)->NewStringUTF(env, GLOBAL_J(env)->apk_filename);
+ }
+ else
+ if (strcmp(method->name,"getPackageCodePath")==0) {
+ return (*env)->NewStringUTF(env, GLOBAL_J(env)->apk_filename);
+ }
+
+ return NULL;
+}
+
+jobject
JNIEnv_NewGlobalRef(JNIEnv* p0, jobject p1)
{
MODULE_DEBUG_PRINTF("JNIEnv_NewGlobalRef(%x)\n", p1);
+ if (p1==NULL) {
+ struct dummy_jclass* cls = malloc(sizeof(struct dummy_jclass));
+ cls->name = "null";
+
+ dummy_jobject* obj = malloc(sizeof(dummy_jobject));
+ obj->clazz = cls;
+ obj->field = NULL;
+ MODULE_DEBUG_PRINTF("JNIEnv_NewGlobalRef(%x) -> %x\n", p1, obj);
+ return obj;
+ }
//dummy_jobject
return NULL;
}
@@ -130,20 +161,27 @@ JNIEnv_NewGlobalRef(JNIEnv* p0, jobject p1)
native calls
*/
-typedef void (*unity_nativeInit_t)(JNIEnv* env, jint p1, jint p2);
-typedef void (*unity_nativeFile_t)(JNIEnv* env, jstring p1);
-typedef jboolean (*unity_nativeRender_t)(JNIEnv* env);
-typedef void (*unity_initJni_t)(JNIEnv* env);
+typedef void (*unity_nativeInit_t)(JNIEnv* env, jobject p0, jint p1, jint p2);
+typedef void (*unity_nativeFile_t)(JNIEnv* env, jobject p0, jstring p1);
+typedef jboolean (*unity_nativeRender_t)(JNIEnv* env, jobject p0);
+typedef void (*unity_initJni_t)(JNIEnv* env, jobject p0);
+typedef void (*unity_InitPlayerPrefs_t)(JNIEnv*, jobject p0);
+typedef jboolean (*unity_androidinit_t)(JNIEnv*, jobject p0, jstring p1, jstring p2);
+typedef void (*unity_androidpreparegameloop_t)(JNIEnv*, jobject);
/* -------- */
struct SupportModulePriv {
jni_onload_t JNI_OnLoad_libunity;
+ jni_onload_t JNI_OnLoad_libmono;
unity_initJni_t initJni;
unity_nativeInit_t nativeInit;
unity_nativeFile_t nativeFile;
unity_nativeRender_t nativeRender;
+ unity_InitPlayerPrefs_t InitPlayerPrefs;
+ unity_androidinit_t unityAndroidInit;
+ unity_androidpreparegameloop_t unityAndroidPrepareGameLoop;
};
static struct SupportModulePriv unity_priv;
@@ -151,21 +189,23 @@ static int
unity_try_init(struct SupportModule *self)
{
self->priv->JNI_OnLoad_libunity = (jni_onload_t)LOOKUP_LIBM("libunity","JNI_OnLoad");
-
- void* fmodGetInfo = LOOKUP_M("Java_org_fmod_FMODAudioDevice_fmodGetInfo");
+ self->priv->JNI_OnLoad_libmono = (jni_onload_t)LOOKUP_LIBM("libmono","JNI_OnLoad");
self->override_env.GetStaticFieldID = JNIEnv_GetStaticFieldID;
self->override_env.GetStaticObjectField = JNIEnv_GetStaticObjectField;
self->override_env.GetObjectClass = JNIEnv_GetObjectClass;
self->override_env.CallObjectMethod = JNIEnv_CallObjectMethod;
+ self->override_env.CallStaticObjectMethod = JNIEnv_CallStaticObjectMethod;
self->override_env.RegisterNatives = JNIEnv_RegisterNatives;
self->override_env.GetStringUTFChars = JNIEnv_GetStringUTFChars;
self->override_env.NewGlobalRef = JNIEnv_NewGlobalRef;
- return (self->priv->JNI_OnLoad_libunity !=NULL && fmodGetInfo!=NULL);
+ return (self->priv->JNI_OnLoad_libunity!=NULL);
}
+#define UNITYPLAYER_CLASS_NAME "com/unity3d/player/UnityPlayer"
+#define PLAYERPREFS_CLASS_NAME "com/unity3d/player/PlayerPrefs"
#define method_is(native) (strcmp(method->name,#native)==0)
jint
@@ -177,6 +217,7 @@ JNIEnv_RegisterNatives(JNIEnv* p0, jclass p1, const JNINativeMethod* p2, jint p3
MODULE_DEBUG_PRINTF("\n\tClass: %s\n", clazz->name);
int is_unity_player = strcmp(clazz->name,UNITYPLAYER_CLASS_NAME)==0;
+ int is_player_prefs = strcmp(clazz->name,PLAYERPREFS_CLASS_NAME)==0;
int i=0;
const JNINativeMethod *method = p2;
@@ -187,8 +228,14 @@ JNIEnv_RegisterNatives(JNIEnv* p0, jclass p1, const JNINativeMethod* p2, jint p3
if (method_is(nativeInit)) { unity_priv.nativeInit = (unity_nativeInit_t)method->fnPtr;} else
if (method_is(nativeFile)) { unity_priv.nativeFile = (unity_nativeFile_t)method->fnPtr;} else
- if (method_is(nativeRender)) { unity_priv.nativeRender = (unity_nativeRender_t)method->fnPtr;} else
- if (method_is(initJni)) { unity_priv.initJni = (unity_initJni_t)method->fnPtr;} else
+ if (method_is(nativeRender)) { unity_priv.nativeRender = (unity_nativeRender_t)method->fnPtr;} else
+ if (method_is(initJni)) { unity_priv.initJni = (unity_initJni_t)method->fnPtr;} else
+ if (method_is(unityAndroidInit)) { unity_priv.unityAndroidInit = (unity_androidinit_t)method->fnPtr;} else
+ if (method_is(unityAndroidPrepareGameLoop)) {unity_priv.unityAndroidPrepareGameLoop = (unity_androidpreparegameloop_t)method->fnPtr;} else
+ ;
+ } else if (is_player_prefs) {
+
+ if (method_is(InitPlayerPrefs)) { unity_priv.InitPlayerPrefs = (unity_InitPlayerPrefs_t)method->fnPtr;} else
;
}
@@ -225,14 +272,26 @@ unity_init(struct SupportModule *self, int width, int height, const char *home)
system("export MALLOC_CHECK_=0"); //<unit? or who? does something weird on the pandora ...
+ MODULE_DEBUG_PRINTF("JNI_OnLoad\n");
self->priv->JNI_OnLoad_libunity(VM_M,0);
+ MODULE_DEBUG_PRINTF("JNI_OnLoad done.\n");
+
- self->priv->initJni(ENV_M);
+ MODULE_DEBUG_PRINTF("nativeInit\n");
+ self->priv->nativeInit(ENV_M,GLOBAL_M,width,height);
+ MODULE_DEBUG_PRINTF("nativeInit done\n");
- jstring file = GLOBAL_M->env->NewStringUTF(ENV_M, global->apk_filename);
+ MODULE_DEBUG_PRINTF("unityAndroidInit\n");
+ jstring bin = GLOBAL_M->env->NewStringUTF(ENV_M,"assets/bin/");
+ jstring lib = GLOBAL_M->env->NewStringUTF(ENV_M,"./lib/");//strcat(home,"lib/"));
+ self->priv->unityAndroidInit(ENV_M,GLOBAL_M,bin,lib);
+ MODULE_DEBUG_PRINTF("unityAndroidInitDone\n");
- self->priv->nativeFile(ENV_M,file);
+ MODULE_DEBUG_PRINTF("nativeFile\n");
+ jstring file = GLOBAL_M->env->NewStringUTF(ENV_M,global->apk_filename);
+ self->priv->nativeFile(ENV_M,GLOBAL_M,file);
+ MODULE_DEBUG_PRINTF("nativeFile done\n");
}
@@ -244,7 +303,7 @@ unity_input(struct SupportModule *self, int event, int x, int y, int finger)
static void
unity_update(struct SupportModule *self)
{
- self->priv->nativeRender(ENV_M);
+ if (self->priv->nativeRender) self->priv->nativeRender(ENV_M,GLOBAL_M);
}
static void
@@ -262,6 +321,11 @@ unity_resume(struct SupportModule *self)
{
}
+static int
+unity_requests_exit(struct SupportModule *self)
+{
+ return 0;
+}
APKENV_MODULE(unity, MODULE_PRIORITY_ENGINE)
Please sign in to comment.
Something went wrong with that request. Please try again.