comparison android/testproject/jni/app-android.cpp @ 4722:faa228f7ce5b

- Cleaned up a bunch of code - Added 'feature' enable/disable so we're not running accel/sound/whatever in Java when we don't need to be - More work on the sound system. But it still crashes pretty horribly, not sure why yet.
author Paul Hunkin <paul@bieh.net>
date Tue, 27 Jul 2010 21:21:24 +0200
parents f2c2a33a1a38
children 74da47b2f5b7
comparison
equal deleted inserted replaced
4721:7bb9d3a3f257 4722:faa228f7ce5b
32 jclass mActivityInstance; 32 jclass mActivityInstance;
33 33
34 //method signatures 34 //method signatures
35 jmethodID midCreateGLContext; 35 jmethodID midCreateGLContext;
36 jmethodID midFlipBuffers; 36 jmethodID midFlipBuffers;
37 jmethodID midEnableFeature;
37 38
38 extern "C" int SDL_main(); 39 extern "C" int SDL_main();
39 extern "C" int Android_OnKeyDown(int keycode); 40 extern "C" int Android_OnKeyDown(int keycode);
40 extern "C" int Android_OnKeyUp(int keycode); 41 extern "C" int Android_OnKeyUp(int keycode);
41 extern "C" void Android_SetScreenResolution(int width, int height); 42 extern "C" void Android_SetScreenResolution(int width, int height);
42 extern "C" void Android_OnResize(int width, int height, int format); 43 extern "C" void Android_OnResize(int width, int height, int format);
43 extern "C" int SDL_SendQuit(); 44 extern "C" int SDL_SendQuit();
45 extern "C" void Android_EnableFeature(int featureid, bool enabled);
44 46
45 //If we're not the active app, don't try to render 47 //If we're not the active app, don't try to render
46 bool bRenderingEnabled = false; 48 bool bRenderingEnabled = false;
49
50 //Feature IDs
51 static const int FEATURE_SOUND = 1;
52 static const int FEATURE_ACCEL = 2;
53
54 //Accelerometer data storage
55 float fLastAccelerometer[3];
47 56
48 /******************************************************************************* 57 /*******************************************************************************
49 Functions called by JNI 58 Functions called by JNI
50 *******************************************************************************/ 59 *******************************************************************************/
51 60
65 74
66 jclass cls = mEnv->FindClass ("org/libsdl/android/SDLActivity"); 75 jclass cls = mEnv->FindClass ("org/libsdl/android/SDLActivity");
67 mActivityInstance = cls; 76 mActivityInstance = cls;
68 midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V"); 77 midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
69 midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V"); 78 midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
70 79 midEnableFeature = mEnv->GetStaticMethodID(cls,"enableFeature","(I, I)V");
71 if(!midCreateGLContext || !midFlipBuffers){ 80
81 if(!midCreateGLContext || !midFlipBuffers || !midEnableFeature){
72 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n"); 82 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n");
73 }else{ 83 }else{
74 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Good mids\n"); 84 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Good mids\n");
75 } 85 }
76 86
82 jobject obj ){ 92 jobject obj ){
83 93
84 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native Init"); 94 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native Init");
85 95
86 mEnv = env; 96 mEnv = env;
87
88 bRenderingEnabled = true; 97 bRenderingEnabled = true;
98
99 Android_EnableFeature(FEATURE_ACCEL, true);
89 100
90 SDL_main(); 101 SDL_main();
91 } 102 }
92 103
93 //Keydown 104 //Keydown
150 JNIEnv* env, jobject obj, jint width, 161 JNIEnv* env, jobject obj, jint width,
151 jint height, jint format){ 162 jint height, jint format){
152 Android_OnResize(width, height, format); 163 Android_OnResize(width, height, format);
153 } 164 }
154 165
155 166 extern "C" void Java_org_libsdl_android_SDLActivity_onNativeAccel(
156 167 JNIEnv* env, jobject obj,
157 /******************************************************************************* 168 jfloat x, jfloat y, jfloat z){
158 Functions called by SDL 169 fLastAccelerometer[0] = x;
170 fLastAccelerometer[1] = y;
171 fLastAccelerometer[2] = z;
172 }
173
174
175
176 /*******************************************************************************
177 Functions called by SDL into Java
159 *******************************************************************************/ 178 *******************************************************************************/
160 extern "C" void sdl_create_context(){ 179 extern "C" void Android_CreateContext(){
161 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context()\n"); 180 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context()\n");
162 181
163 bRenderingEnabled = true; 182 bRenderingEnabled = true;
164 183
165 mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext ); 184 mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext );
166 } 185 }
167 186
168 extern "C" void sdl_render(){ 187 extern "C" void Android_Render(){
169 188
170 if(!bRenderingEnabled){ 189 if(!bRenderingEnabled){
171 return; 190 return;
172 } 191 }
173 192
174 //When we get here, we've accumulated a full frame 193 //When we get here, we've accumulated a full frame
175 mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers ); 194 mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers );
176 } 195 }
177 196
197 extern "C" void Android_EnableFeature(int featureid, bool enabled){
198
199 mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers,
200 featureid, (int)enabled);
201 }
202