1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#include "java_glue.h"
#include "os_android.h"
#include "main/main.h"
#include <unistd.h>
#include "file_access_jandroid.h"
#include "dir_access_jandroid.h"
static OS_Android *os_android=NULL;
struct TST {
int a;
TST() {
a=5;
}
};
TST tst;
struct JAndroidPointerEvent {
Vector<OS_Android::TouchPos> points;
int pointer;
int what;
};
static List<JAndroidPointerEvent> pointer_events;
static bool initialized=false;
static Mutex *input_mutex=NULL;
JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_init(JNIEnv * env, jobject obj, jint width, jint height)
{
if (initialized) // wtf
return;
__android_log_print(ANDROID_LOG_INFO,"godot","**INIT EVENT! - %p\n",env);
initialized=true;
__android_log_print(ANDROID_LOG_INFO,"godot","***************** HELLO FROM JNI!!!!!!!!");
{
//setup IO Object
jclass cls = env->FindClass("com/android/godot/Godot");
if (cls) {
cls=(jclass)env->NewGlobalRef(cls);
__android_log_print(ANDROID_LOG_INFO,"godot","*******CLASS FOUND!!!");
}
__android_log_print(ANDROID_LOG_INFO,"godot","STEP2, %p",cls);
jfieldID fid = env->GetStaticFieldID(cls, "io", "Lcom/android/godot/GodotIO;");
__android_log_print(ANDROID_LOG_INFO,"godot","STEP3 %i",fid);
jobject ob = env->GetStaticObjectField(cls,fid);
__android_log_print(ANDROID_LOG_INFO,"godot","STEP4, %p",ob);
jobject gob = env->NewGlobalRef(ob);
FileAccessJAndroid::setup(env,gob);
DirAccessJAndroid::setup(env,gob);
}
os_android = new OS_Android(width,height);
char wd[500];
getcwd(wd,500);
__android_log_print(ANDROID_LOG_INFO,"godot","test construction %i\n",tst.a);
__android_log_print(ANDROID_LOG_INFO,"godot","running from dir %s\n",wd);
__android_log_print(ANDROID_LOG_INFO,"godot","**SETUP");
#if 0
char *args[]={"-test","render",NULL};
__android_log_print(ANDROID_LOG_INFO,"godot","pre asdasd setup...");
Error err = Main::setup("apk",2,args);
#else
Error err = Main::setup("apk",0,NULL);
#endif
if (err!=OK) {
__android_log_print(ANDROID_LOG_INFO,"godot","*****UNABLE TO SETUP");
return; //should exit instead and print the error
}
__android_log_print(ANDROID_LOG_INFO,"godot","**START");
if (!Main::start()) {
return; //should exit instead and print the error
}
input_mutex=Mutex::create();
os_android->main_loop_begin();
}
JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_step(JNIEnv * env, jobject obj)
{
__android_log_print(ANDROID_LOG_INFO,"godot","**STEP EVENT! - %p-%i\n",env,Thread::get_caller_ID());
{
FileAccessJAndroid::update_env(env);
DirAccessJAndroid::update_env(env);
}
input_mutex->lock();
while(pointer_events.size()) {
JAndroidPointerEvent jpe=pointer_events.front()->get();
os_android->process_touch(jpe.what,jpe.pointer,jpe.points);
pointer_events.pop_front();
}
input_mutex->unlock();
if (os_android->main_loop_iterate()==true) {
return; //should exit instead
}
}
JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_touch(JNIEnv * env, jobject obj, jint ev,jint pointer, jint count, jintArray positions) {
__android_log_print(ANDROID_LOG_INFO,"godot","**TOUCH EVENT! - %p-%i\n",env,Thread::get_caller_ID());
Vector<OS_Android::TouchPos> points;
for(int i=0;i<count;i++) {
jint p[3];
env->GetIntArrayRegion(positions,i*3,3,p);
OS_Android::TouchPos tp;
tp.pos=Point2(p[1],p[2]);
tp.id=p[0];
points.push_back(tp);
}
JAndroidPointerEvent jpe;
jpe.pointer=pointer;
jpe.points=points;
jpe.what=ev;
input_mutex->lock();
pointer_events.push_back(jpe);
input_mutex->unlock();
//if (os_android)
// os_android->process_touch(ev,pointer,points);
}
//Main::cleanup();
//return os.get_exit_code();
|