Mercurial > sdl-ios-xcode
annotate 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 |
rev | line source |
---|---|
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
1 /******************************************************************************* |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
2 Headers |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
3 *******************************************************************************/ |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
4 #include <jni.h> |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
5 #include <sys/time.h> |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
6 #include <time.h> |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
7 #include <android/log.h> |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
8 #include <stdint.h> |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
9 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
10 #include <stdio.h> |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
11 #include <stdlib.h> |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
12 #include <math.h> |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
13 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
14 #include <pthread.h> |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
15 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
16 #include "importgl.h" |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
17 #include "egl.h" |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
18 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
19 /******************************************************************************* |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
20 Globals |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
21 *******************************************************************************/ |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
22 static long _getTime(void){ |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
23 struct timeval now; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
24 gettimeofday(&now, NULL); |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
25 return (long)(now.tv_sec*1000 + now.tv_usec/1000); |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
26 } |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
27 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
28 JNIEnv* mEnv = NULL; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
29 JavaVM* mVM = NULL; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
30 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
31 //Main activity |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
32 jclass mActivityInstance; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
33 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
34 //method signatures |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
35 jmethodID midCreateGLContext; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
36 jmethodID midFlipBuffers; |
4722 | 37 jmethodID midEnableFeature; |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
38 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
39 extern "C" int SDL_main(); |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
40 extern "C" int Android_OnKeyDown(int keycode); |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
41 extern "C" int Android_OnKeyUp(int keycode); |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
42 extern "C" void Android_SetScreenResolution(int width, int height); |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
43 extern "C" void Android_OnResize(int width, int height, int format); |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
44 extern "C" int SDL_SendQuit(); |
4722 | 45 extern "C" void Android_EnableFeature(int featureid, bool enabled); |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
46 |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
47 //If we're not the active app, don't try to render |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
48 bool bRenderingEnabled = false; |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
49 |
4722 | 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]; | |
56 | |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
57 /******************************************************************************* |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
58 Functions called by JNI |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
59 *******************************************************************************/ |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
60 |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
61 //Library init |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
62 extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved){ |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
63 |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
64 JNIEnv* env = NULL; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
65 jint result = -1; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
66 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
67 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
68 return result; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
69 } |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
70 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
71 mEnv = env; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
72 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
73 __android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: OnLoad"); |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
74 |
4712 | 75 jclass cls = mEnv->FindClass ("org/libsdl/android/SDLActivity"); |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
76 mActivityInstance = cls; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
77 midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V"); |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
78 midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V"); |
4722 | 79 midEnableFeature = mEnv->GetStaticMethodID(cls,"enableFeature","(I, I)V"); |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
80 |
4722 | 81 if(!midCreateGLContext || !midFlipBuffers || !midEnableFeature){ |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
82 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n"); |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
83 }else{ |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
84 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Good mids\n"); |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
85 } |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
86 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
87 return JNI_VERSION_1_4; |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
88 } |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
89 |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
90 //Start up the SDL app |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
91 extern "C" void Java_org_libsdl_android_SDLActivity_nativeInit( JNIEnv* env, |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
92 jobject obj ){ |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
93 |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
94 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native Init"); |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
95 |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
96 mEnv = env; |
4722 | 97 bRenderingEnabled = true; |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
98 |
4722 | 99 Android_EnableFeature(FEATURE_ACCEL, true); |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
100 |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
101 SDL_main(); |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
102 } |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
103 |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
104 //Keydown |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
105 extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyDown(JNIEnv* env, |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
106 jobject obj, jint keycode){ |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
107 |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
108 int r = Android_OnKeyDown(keycode); |
4714 | 109 __android_log_print(ANDROID_LOG_INFO, "SDL", |
110 "SDL: native key down %d, %d\n", keycode, r); | |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
111 |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
112 } |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
113 |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
114 //Keyup |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
115 extern "C" void Java_org_libsdl_android_SDLActivity_onNativeKeyUp(JNIEnv* env, |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
116 jobject obj, jint keycode){ |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
117 |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
118 int r = Android_OnKeyUp(keycode); |
4714 | 119 __android_log_print(ANDROID_LOG_INFO, "SDL", |
120 "SDL: native key up %d, %d\n", keycode, r); | |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
121 |
4714 | 122 } |
123 | |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
124 //Touch |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
125 extern "C" void Java_org_libsdl_android_SDLActivity_onNativeTouch(JNIEnv* env, |
4714 | 126 jobject obj, jint action, jfloat x, jfloat y, jfloat p){ |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
127 |
4714 | 128 __android_log_print(ANDROID_LOG_INFO, "SDL", |
129 "SDL: native touch event %d @ %f/%f, pressure %f\n", | |
130 action, x, y, p); | |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
131 |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
132 //TODO: Pass this off to the SDL multitouch stuff |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
133 |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
134 } |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
135 |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
136 //Quit |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
137 extern "C" void Java_org_libsdl_android_SDLActivity_nativeQuit( JNIEnv* env, |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
138 jobject obj ){ |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
139 |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
140 //Stop rendering as we're no longer in the foreground |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
141 bRenderingEnabled = false; |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
142 |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
143 //Inject a SDL_QUIT event |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
144 int r = SDL_SendQuit(); |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
145 |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
146 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native quit %d", r); |
4713
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
147 } |
ba38983b10c2
Added preliminary keyboard event support
Paul Hunkin <paul@bieh.net>
parents:
4712
diff
changeset
|
148 |
4716
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
149 //Screen size |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
150 extern "C" void Java_org_libsdl_android_SDLActivity_nativeSetScreenSize( |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
151 JNIEnv* env, jobject obj, jint width, jint height){ |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
152 |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
153 __android_log_print(ANDROID_LOG_INFO, "SDL", |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
154 "SDL: Set screen size on init: %d/%d\n", width, height); |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
155 Android_SetScreenResolution(width, height); |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
156 |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
157 } |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
158 |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
159 //Resize |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
160 extern "C" void Java_org_libsdl_android_SDLActivity_onNativeResize( |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
161 JNIEnv* env, jobject obj, jint width, |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
162 jint height, jint format){ |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
163 Android_OnResize(width, height, format); |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
164 } |
f2c2a33a1a38
Added resize hander stub and initial screen size setter
Paul Hunkin <paul@bieh.net>
parents:
4715
diff
changeset
|
165 |
4722 | 166 extern "C" void Java_org_libsdl_android_SDLActivity_onNativeAccel( |
167 JNIEnv* env, jobject obj, | |
168 jfloat x, jfloat y, jfloat z){ | |
169 fLastAccelerometer[0] = x; | |
170 fLastAccelerometer[1] = y; | |
171 fLastAccelerometer[2] = z; | |
172 } | |
173 | |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
174 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
175 |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
176 /******************************************************************************* |
4722 | 177 Functions called by SDL into Java |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
178 *******************************************************************************/ |
4722 | 179 extern "C" void Android_CreateContext(){ |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
180 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context()\n"); |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
181 |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
182 bRenderingEnabled = true; |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
183 |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
184 mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext ); |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
185 } |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
186 |
4722 | 187 extern "C" void Android_Render(){ |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
188 |
4715
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
189 if(!bRenderingEnabled){ |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
190 return; |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
191 } |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
192 |
9bb98766eed0
Shut down the C application properly on quit instead of crashing in the most horrible way possible
Paul Hunkin <paul@bieh.net>
parents:
4714
diff
changeset
|
193 //When we get here, we've accumulated a full frame |
4711
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
194 mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers ); |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
195 } |
ed040b480a9f
- Restructured threads and application structure.
Paul Hunkin <paul@bieh.net>
parents:
diff
changeset
|
196 |
4722 | 197 extern "C" void Android_EnableFeature(int featureid, bool enabled){ |
198 | |
199 mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers, | |
200 featureid, (int)enabled); | |
201 } | |
202 |