Mercurial > sdl-ios-xcode
annotate android/testproject/jni/app-android.c @ 4706:12c9d4532b49
Testing out pthread support in android. Appears to work.
author | Paul Hunkin <paul@bieh.net> |
---|---|
date | Fri, 18 Jun 2010 00:02:13 +1200 |
parents | 190f043af37d |
children | f3f65cb6a382 |
rev | line source |
---|---|
4704 | 1 /******************************************************************************* |
2 Headers | |
3 *******************************************************************************/ | |
4 #include <jni.h> | |
5 #include <sys/time.h> | |
6 #include <time.h> | |
7 #include <android/log.h> | |
8 #include <stdint.h> | |
9 | |
4705 | 10 #include <stdio.h> |
11 #include <stdlib.h> | |
12 #include <math.h> | |
13 | |
4706
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
14 #include <pthread.h> |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
15 |
4705 | 16 #include "importgl.h" |
17 | |
4704 | 18 /******************************************************************************* |
19 Globals | |
20 *******************************************************************************/ | |
21 int gAppAlive = 1; | |
22 | |
23 static int sWindowWidth = 320; | |
24 static int sWindowHeight = 480; | |
25 static int sDemoStopped = 0; | |
26 | |
27 static long _getTime(void){ | |
28 struct timeval now; | |
29 gettimeofday(&now, NULL); | |
30 return (long)(now.tv_sec*1000 + now.tv_usec/1000); | |
31 } | |
32 | |
4705 | 33 |
34 | |
4706
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
35 /******************************************************************************* |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
36 SDL thread |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
37 *******************************************************************************/ |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
38 pthread_t mSDLThread = 0; |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
39 |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
40 void* sdlThreadProc(void* args){ |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
41 __android_log_print(ANDROID_LOG_INFO, "SDL", "Thread Entry"); |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
42 return 0; |
4705 | 43 } |
4706
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
44 |
4704 | 45 /******************************************************************************* |
46 Initialize the graphics state | |
47 *******************************************************************************/ | |
48 void Java_org_libsdl_android_TestRenderer_nativeInit( JNIEnv* env ) | |
49 { | |
50 importGLInit(); | |
51 | |
52 gAppAlive = 1; | |
53 sDemoStopped = 0; | |
4705 | 54 |
55 __android_log_print(ANDROID_LOG_INFO, "SDL", "Entry point"); | |
56 | |
4706
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
57 //Spin up the SDL thread |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
58 int r = pthread_create(&mSDLThread, NULL, sdlThreadProc, NULL); |
4705 | 59 |
4706
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
60 if(r != 0){ |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
61 __android_log_print(ANDROID_LOG_INFO, "SDL", "Couldn't spawn thread: %d", r); |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
62 }else{ |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
63 __android_log_print(ANDROID_LOG_INFO, "SDL", "Started SDL thread"); |
12c9d4532b49
Testing out pthread support in android. Appears to work.
Paul Hunkin <paul@bieh.net>
parents:
4705
diff
changeset
|
64 } |
4705 | 65 |
4704 | 66 } |
67 | |
68 /******************************************************************************* | |
69 Resize | |
70 *******************************************************************************/ | |
71 void Java_org_libsdl_android_TestRenderer_nativeResize( JNIEnv* env, | |
72 jobject thiz, | |
73 jint w, | |
74 jint h ) | |
75 { | |
76 sWindowWidth = w; | |
77 sWindowHeight = h; | |
78 __android_log_print(ANDROID_LOG_INFO, "SDL", "resize w=%d h=%d", w, h); | |
4705 | 79 |
4704 | 80 } |
81 | |
82 /******************************************************************************* | |
83 Finalize (ie: shutdown) | |
84 *******************************************************************************/ | |
85 void Java_org_libsdl_android_TestRenderer_nativeDone( JNIEnv* env ) | |
86 { | |
87 | |
88 //shut down the app | |
89 | |
90 importGLDeinit(); | |
4705 | 91 |
92 __android_log_print(ANDROID_LOG_INFO, "SDL", "Finalize"); | |
4704 | 93 } |
94 | |
95 /******************************************************************************* | |
96 Pause (ie: stop as soon as possible) | |
97 *******************************************************************************/ | |
98 void Java_org_libsdl_android_TestGLSurfaceView_nativePause( JNIEnv* env ) | |
99 { | |
100 sDemoStopped = !sDemoStopped; | |
101 if (sDemoStopped) { | |
102 //we paused | |
4705 | 103 __android_log_print(ANDROID_LOG_INFO, "SDL", "Pause"); |
4704 | 104 } else { |
105 //we resumed | |
4705 | 106 __android_log_print(ANDROID_LOG_INFO, "SDL", "Resume"); |
4704 | 107 } |
108 } | |
109 | |
110 /******************************************************************************* | |
111 Render the next frame | |
112 *******************************************************************************/ | |
4705 | 113 |
4704 | 114 void Java_org_libsdl_android_TestRenderer_nativeRender( JNIEnv* env ) |
115 { | |
116 //TODO: Render here | |
4705 | 117 |
4704 | 118 } |