Permalink
Browse files

cut the rope module continued: now reaches the main screen on the pan…

…dora (WIP: input and sound)

loadpng added and used by cut the rope
  • Loading branch information...
1 parent bf72f4d commit ce1bf3bb4c0044fb2cb1be5f20c521191061c424 @crowriot committed Jan 16, 2013
Showing with 285 additions and 19 deletions.
  1. +150 −16 modules/cuttherope.c
  2. +4 −3 modules/cuttherope.cbp
  3. +109 −0 png/loadpng.c
  4. +22 −0 png/loadpng.h
View
@@ -37,16 +37,28 @@
**/
#include "common.h"
+#include "../png/loadpng.h"
+#include <linux/limits.h>
+
+
+#ifdef APKENV_DEBUG
+# define MODULE_DEBUG_PRINTF(...) printf(__VA_ARGS__)
+#else
+# define MODULE_DEBUG_PRINTF(...)
+#endif
#include <SDL/SDL.h>
typedef void (*cuttherope_init_t)(JNIEnv *env, jobject obj, jobject resourceLoader, jobject soundManager, jobject preferences,
jobject saveManager, jobject flurry, jobject videoPlayer, jobject scorer,
jobject billingInterface, jobject remoteDataManager, jint x) SOFTFP;
-typedef void (*cuttherope_resize_t)(JNIEnv *env, jobject object, jint width, jint height, jboolean flag) SOFTFP;
+typedef void (*cuttherope_resize_t)(JNIEnv *env, jobject object, jint width, jint height) SOFTFP;
typedef void (*cuttherope_tick_t)(JNIEnv *env, jobject object, jlong tick) SOFTFP;
typedef void (*cuttherope_render_t)(JNIEnv *env, jobject object) SOFTFP;
typedef void (*cuttherope_videobannerfinished_t)(JNIEnv *env, jobject object) SOFTFP;
+typedef void (*cuttherope_resume_t)(JNIEnv*,jobject);
+typedef void (*cuttherope_imageloaded_t)(JNIEnv*,jobject,jint p1, jbyteArray p2, jint p3, jint p4);
+
struct SupportModulePriv {
jni_onload_t JNI_OnLoad;
@@ -55,16 +67,20 @@ struct SupportModulePriv {
cuttherope_tick_t nativeTick;
cuttherope_render_t nativeRender;
cuttherope_videobannerfinished_t videoBannerFinished;
-
+ cuttherope_resume_t nativeResume;
+ cuttherope_imageloaded_t imageLoaded;
struct GlobalState *global;
+ const char* home;
};
static struct SupportModulePriv cuttherope_priv;
static void
cuttherope_video_banner_finished()
{
- cuttherope_priv.videoBannerFinished(ENV(cuttherope_priv.global),
- cuttherope_priv.global);
+ if (cuttherope_priv.videoBannerFinished!=0) {
+ cuttherope_priv.videoBannerFinished(ENV(cuttherope_priv.global),
+ cuttherope_priv.global);
+ }
}
@@ -81,6 +97,8 @@ cuttherope_CallStaticObjectMethodV(JNIEnv *, jclass, jmethodID, va_list) SOFTFP;
static jobject
cuttherope_CallObjectMethodV(JNIEnv *env, jobject p1, jmethodID p2, va_list p3)
{
+ MODULE_DEBUG_PRINTF("CallObjectMethodV %s\n",p2->name);
+
if (strcmp(p2->name, "loadData") == 0) {
struct dummy_jstring *arg;
arg = va_arg(p3, struct dummy_jstring*);
@@ -90,6 +108,8 @@ cuttherope_CallObjectMethodV(JNIEnv *env, jobject p1, jmethodID p2, va_list p3)
char *filename = malloc(strlen(arg->data) + strlen("assets/") + 1);
sprintf(filename, "assets/%s", arg->data);
+ MODULE_DEBUG_PRINTF(" data=%s\n",arg->data);
+
char *buf;
size_t buf_size;
if (GLOBAL_J(env)->read_file(filename, &buf, &buf_size)) {
@@ -98,12 +118,15 @@ cuttherope_CallObjectMethodV(JNIEnv *env, jobject p1, jmethodID p2, va_list p3)
array->data = buf;
array->size = buf_size;
+ MODULE_DEBUG_PRINTF(" data=%s size=%d\n",arg->data, buf_size);
+
// Poll for events here to avoid "not responding" messages
- SDL_Event e;
- while (SDL_PollEvent(&e));
+ SDL_Event e;
+ while (SDL_PollEvent(&e));
return array;
} else {
+ MODULE_DEBUG_PRINTF(" data=%s not found\n",arg->data);
return GLOBAL_J(env);
}
} else if (strcmp(p2->name, "getBytesOfBitmap") == 0) {
@@ -121,9 +144,59 @@ cuttherope_CallObjectMethodV(JNIEnv *env, jobject p1, jmethodID p2, va_list p3)
}
static void
-cuttherope_CallVoidMethodV(JNIEnv* p0, jobject p1, jmethodID p2, va_list p3)
+cuttherope_CallVoidMethodV(JNIEnv* env, jobject p1, jmethodID p2, va_list p3)
{
- if (p2 && strcmp(p2->name, "showVideoBanner") == 0) {
+ if (!p2)
+ return;
+
+ MODULE_DEBUG_PRINTF("CallVoidMethodV %s\n",p2->name);
+
+ if (strcmp(p2->name,"loadImage")==0) {//public void loadImage(String paramString, int paramInt)
+
+ struct dummy_jstring *filename = va_arg(p3, struct dummy_jstring*);
+ jint fileId = va_arg(p3, jint);
+
+ MODULE_DEBUG_PRINTF("CallVoidMethodV(%s): filename=%s fileId=%d\n",p2->name,filename->data,fileId);
+
+ char *buf;
+ size_t buf_size;
+
+ char filepath[PATH_MAX]; sprintf(filepath,"assets/%s",filename->data);
+
+ if (GLOBAL_J(env)->read_file(filepath, &buf, &buf_size)) {
+
+ MODULE_DEBUG_PRINTF("CallVoidMethodV(%s): filename=%s ok\n",p2->name,filename->data);
+
+ sprintf(filepath,"%s/%s",cuttherope_priv.home,filename->data);
+ FILE *fp =fopen(filepath,"wb");
+ if (fp!=0) {
+ fwrite(buf, buf_size, 1, fp);
+ fclose(fp);
+
+ image_t* image = loadpng(filepath,0,1,1);
+ if (image!=0) {
+
+ MODULE_DEBUG_PRINTF("CallVoidMethodV(%s): imageLoaded=%s (%d,%d,%d) (%x)\n",p2->name,filename->data,image->width,image->height,image->bpp,image);
+
+ cuttherope_priv.imageLoaded(ENV(cuttherope_priv.global),cuttherope_priv.global,fileId,image,image->width,image->height);
+
+ //free(raw);
+ //free(image->data);
+ //free(image);
+ }
+ }
+ }
+ }
+ else
+ if (strcmp(p2->name,"loadSound")==0) { //public void loadSound(String paramString, int paramInt)
+ struct dummy_jstring *filename = va_arg(p3, struct dummy_jstring*);
+ jint paramInt = va_arg(p3, jint);
+
+ MODULE_DEBUG_PRINTF("CallVoidMethodV(%s): filename=%s param=%d\n",p2->name,filename->data,paramInt);
+
+ }
+ else
+ if ( strcmp(p2->name, "showBanner") == 0) {
cuttherope_video_banner_finished();
}
}
@@ -132,34 +205,84 @@ static jobject
cuttherope_CallStaticObjectMethodV(JNIEnv *env, jclass p1, jmethodID p2, va_list p3)
{
if (strcmp(p2->name, "getAppVersion") == 0) {
- return (*env)->NewStringUTF(env, "1.0.0");
+ return (*env)->NewStringUTF(env, "1.1.0");
}
return NULL;
}
+static jint
+cuttherope_CallIntMethodV(JNIEnv* p0, jobject p1, jmethodID p2, va_list p3)
+{
+ //MODULE_DEBUG_PRINTF("JNIEnv_CallIntMethodV(%s)\n",p2->name);
+ if (strcmp(p2->name,"getIntForKey")==0) {
+ struct dummy_jstring *arg;
+ arg = va_arg(p3, struct dummy_jstring*);
+ MODULE_DEBUG_PRINTF(" key=%s\n",arg->data);
+ }
+ return 0;
+}
+
+void*
+cuttherope_GetDirectBufferAddress(JNIEnv* p0, jobject p1)
+{
+ MODULE_DEBUG_PRINTF("cuttherope_GetDirectBufferAddress(%x)\n",p1);
+ image_t *img = p1;
+ return img->data;
+}
+
static int
cuttherope_try_init(struct SupportModule *self)
{
+ /*
+ Java_com_zeptolab_ctr_CtrRenderer_nativeResize
+ Java_com_zeptolab_ctr_CtrRenderer_freeDirect
+ Java_com_zeptolab_ctr_CtrRenderer_nativeMenuPressed
+ Java_com_zeptolab_ctr_CtrRenderer_nativeBackPressed
+ Java_com_zeptolab_ctr_CtrRenderer_nativeDrawFps
+ Java_com_zeptolab_ctr_CtrRenderer_nativeCpuIndex
+ Java_com_zeptolab_ctr_CtrRenderer_nativeTouchProcess
+ Java_com_zeptolab_ctr_CtrRenderer_nativeTouchAdd
+ Java_com_zeptolab_ctr_CtrRenderer_nativeRender
+ Java_com_zeptolab_ctr_CtrRenderer_nativeTick
+ Java_com_zeptolab_ctr_CtrRenderer_nativePause
+ Java_com_zeptolab_ctr_CtrRenderer_nativeResume
+ Java_com_zeptolab_ctr_CtrRenderer_nativeDestroy
+ Java_com_zeptolab_ctr_CtrRenderer_allocDirect
+ Java_com_zeptolab_ctr_CtrRenderer_nativeInit
+ JNI_OnLoad
+ JNI_OnUnload
+ Java_com_zeptolab_ctr_CtrRenderer_nativePlaybackFinished
+ Java_com_zeptolab_ctr_CtrResourceLoader_imageLoaded
+ */
+
+
self->priv->JNI_OnLoad = (jni_onload_t)LOOKUP_M("JNI_OnLoad");
- self->priv->nativeInit = (cuttherope_init_t)LOOKUP_M("nativeInit");
- self->priv->nativeResize = (cuttherope_resize_t)LOOKUP_M("nativeResize");
- self->priv->nativeTick = (cuttherope_tick_t)LOOKUP_M("nativeTick");
- self->priv->nativeRender = (cuttherope_render_t)LOOKUP_M("nativeRender");
+ self->priv->nativeInit = (cuttherope_init_t)LOOKUP_M("CtrRenderer_nativeInit");
+ self->priv->nativeResize = (cuttherope_resize_t)LOOKUP_M("CtrRenderer_nativeResize");
+ self->priv->nativeTick = (cuttherope_tick_t)LOOKUP_M("CtrRenderer_nativeTick");
+ self->priv->nativeRender = (cuttherope_render_t)LOOKUP_M("CtrRenderer_nativeRender");
+ self->priv->nativeResume = (cuttherope_resume_t)LOOKUP_M("CtrRenderer_nativeResume");
+ self->priv->imageLoaded = (cuttherope_imageloaded_t)LOOKUP_M("CtrResourceLoader_imageLoaded");
self->priv->videoBannerFinished = (cuttherope_videobannerfinished_t)LOOKUP_M("videoBannerFinished");
+ //self->priv->nativePlaybackFinished;
self->priv->global = GLOBAL_M;
self->override_env.CallObjectMethodV = cuttherope_CallObjectMethodV;
self->override_env.CallVoidMethodV = cuttherope_CallVoidMethodV;
self->override_env.CallStaticObjectMethodV = cuttherope_CallStaticObjectMethodV;
+ self->override_env.CallIntMethodV = cuttherope_CallIntMethodV;
+ self->override_env.GetDirectBufferAddress = cuttherope_GetDirectBufferAddress;
return (self->priv->JNI_OnLoad != NULL &&
self->priv->nativeInit != NULL &&
self->priv->nativeResize != NULL &&
self->priv->nativeTick != NULL &&
- self->priv->videoBannerFinished != NULL);
+ self->priv->nativeRender != NULL &&
+ self->priv->imageLoaded != NULL
+ );
}
static void
@@ -175,12 +298,17 @@ cuttherope_init(struct SupportModule *self, int width, int height, const char *h
void *billingInterface = (void*)0xF07;
void *remoteDataManager = (void*)0xF08;
+ self->priv->home = strdup(home);
+
self->priv->JNI_OnLoad(VM_M, NULL);
+ self->priv->nativeResize(ENV_M, GLOBAL_M, width, height);
+
self->priv->nativeInit(ENV_M, GLOBAL_M, resourceLoader, soundManager, preferences,
saveManager, flurry, videoPlayer, scorer,
billingInterface, remoteDataManager, 0);
- self->priv->nativeResize(ENV_M, GLOBAL_M, width, height, 1);
+
+ self->priv->nativeResume(ENV_M, GLOBAL_M);
}
static void
@@ -191,7 +319,7 @@ cuttherope_input(struct SupportModule *self, int event, int x, int y, int finger
static void
cuttherope_update(struct SupportModule *self)
{
- self->priv->nativeTick(ENV_M, GLOBAL_M, SDL_GetTicks());
+ self->priv->nativeTick(ENV_M, GLOBAL_M, 16);
self->priv->nativeRender(ENV_M, GLOBAL_M);
}
@@ -210,5 +338,11 @@ cuttherope_resume(struct SupportModule *self)
{
}
+static int
+cuttherope_requests_exit(struct SupportModule *self)
+{
+ return 0;
+}
+
APKENV_MODULE(cuttherope, MODULE_PRIORITY_GAME)
View
@@ -8,7 +8,7 @@
<Build>
<Target title="Debug">
<Option output="../bin/Debug/cuttherope.apkenv.so" prefix_auto="1" extension_auto="0" />
- <Option object_output="../obj/Debug/" />
+ <Option object_output="./obj/Debug/" />
<Option type="3" />
<Option compiler="pandora_compiler" />
<Option createDefFile="1" />
@@ -19,7 +19,7 @@
</Target>
<Target title="Release">
<Option output="../bin/Release/cuttherope.apkenv.so" prefix_auto="1" extension_auto="0" />
- <Option object_output="../obj/Release/" />
+ <Option object_output="./obj/Release/" />
<Option type="3" />
<Option compiler="pandora_compiler" />
<Option createDefFile="1" />
@@ -35,8 +35,9 @@
<Compiler>
<Add option="-Wall" />
<Add option="-DPANDORA" />
+ <Add option="-DAPKENV_DEBUG" />
</Compiler>
- <Unit filename="modules/cuttherope.c">
+ <Unit filename="cuttherope.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
Oops, something went wrong.

0 comments on commit ce1bf3b

Please sign in to comment.