Rev 4439 | Rev 4529 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4386 | terminx | 1 | /* |
2 | * |
||
3 | * Designed by Emile Belanger |
||
4 | * |
||
5 | */ |
||
6 | |||
7 | #include <stdlib.h> |
||
8 | #include <stdio.h> |
||
9 | #include <string.h> |
||
10 | #include <jni.h> |
||
11 | #include <android/log.h> |
||
12 | |||
13 | #include "SDL_scancode.h" |
||
4434 | terminx | 14 | #include "SDL_main.h" |
4386 | terminx | 15 | |
16 | #include "TouchControlsContainer.h" |
||
4434 | terminx | 17 | #include "JNITouchControlsUtils.h" |
18 | |||
4440 | terminx | 19 | #ifdef GP_LIC |
20 | #include "s-setup/s-setup.h" |
||
21 | #endif |
||
22 | |||
4386 | terminx | 23 | extern "C" |
24 | { |
||
25 | |||
4434 | terminx | 26 | extern void SDL_Android_Init(JNIEnv* env, jclass cls); |
4386 | terminx | 27 | //This is a new function I put into SDL2, file SDL_androidgl.c |
28 | extern void SDL_SetSwapBufferCallBack(void (*pt2Func)(void)); |
||
29 | |||
30 | #include "in_android.h" |
||
4433 | terminx | 31 | #include "../function.h" |
4386 | terminx | 32 | |
33 | #include "../GL/gl.h" |
||
34 | #include "../GL/nano_gl.h" |
||
35 | |||
4440 | terminx | 36 | //Copied from build.h, which didnt include here |
37 | enum rendmode_t { |
||
38 | REND_CLASSIC, |
||
39 | REND_POLYMOST = 3, |
||
40 | REND_POLYMER |
||
41 | }; |
||
42 | |||
4386 | terminx | 43 | #ifndef LOGI |
44 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__)) |
||
45 | #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "DUKE", __VA_ARGS__)) |
||
46 | #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR,"DUKE", __VA_ARGS__)) |
||
47 | #endif |
||
48 | |||
49 | #define REND_SOFT 0 |
||
50 | #define REND_GL 1 |
||
51 | |||
4436 | terminx | 52 | droidsysinfo_t droidinfo; |
53 | |||
4386 | terminx | 54 | static int curRenderer; |
55 | |||
4434 | terminx | 56 | float gameControlsAlpha = 0.5; |
4386 | terminx | 57 | |
58 | bool invertLook = false; |
||
59 | bool precisionShoot = false; |
||
60 | bool showSticks = true; |
||
61 | bool hideTouchControls = true; |
||
4440 | terminx | 62 | char toggleCrouch = true; |
4386 | terminx | 63 | |
64 | bool shooting = false; |
||
65 | |||
66 | static int controlsCreated = 0; |
||
67 | touchcontrols::TouchControlsContainer controlsContainer; |
||
68 | |||
69 | touchcontrols::TouchControls *tcMenuMain=0; |
||
70 | touchcontrols::TouchControls *tcGameMain=0; |
||
71 | touchcontrols::TouchControls *tcGameWeapons=0; |
||
72 | touchcontrols::TouchControls *tcAutomap=0; |
||
73 | touchcontrols::TouchControls *tcInventory=0; |
||
74 | touchcontrols::TouchControls *tcGameLook=0; //Just used for whole screen look mode |
||
75 | |||
76 | |||
77 | touchcontrols::TouchJoy *touchJoyLeft; |
||
78 | touchcontrols::TouchJoy *touchJoyRight; |
||
79 | touchcontrols::WheelSelect *weaponWheel; |
||
80 | |||
81 | extern JNIEnv* env_; |
||
4434 | terminx | 82 | JavaVM* jvm_; |
4386 | terminx | 83 | |
84 | void openGLStart() |
||
85 | { |
||
4434 | terminx | 86 | if (curRenderer == REND_GL) |
87 | { |
||
88 | glPushMatrix(); |
||
4386 | terminx | 89 | |
4434 | terminx | 90 | glMatrixMode(GL_PROJECTION); |
91 | glLoadIdentity(); |
||
4436 | terminx | 92 | glOrthof (0, droidinfo.screen_width, droidinfo.screen_height, 0, 0, 1); |
4386 | terminx | 93 | |
4434 | terminx | 94 | //glClearColor(1.0f, 1.0f, 0.0f, 1.0f); |
95 | //glClear(GL_COLOR_BUFFER_BIT); |
||
96 | //LOGI("openGLStart"); |
||
97 | glDisable(GL_ALPHA_TEST); |
||
98 | glDisable(GL_DEPTH_TEST); |
||
99 | glDisable(GL_FOG); |
||
100 | glEnable(GL_TEXTURE_2D); |
||
101 | glEnable (GL_BLEND); |
||
4386 | terminx | 102 | |
4434 | terminx | 103 | glColor4f(1,1,1,1); |
4386 | terminx | 104 | |
4434 | terminx | 105 | glDisableClientState(GL_COLOR_ARRAY); |
106 | glEnableClientState(GL_VERTEX_ARRAY); |
||
107 | glEnableClientState(GL_TEXTURE_COORD_ARRAY ); |
||
4386 | terminx | 108 | |
4434 | terminx | 109 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
4386 | terminx | 110 | |
4434 | terminx | 111 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
4386 | terminx | 112 | |
4434 | terminx | 113 | glDisable(GL_CULL_FACE); |
4386 | terminx | 114 | |
4434 | terminx | 115 | glMatrixMode(GL_MODELVIEW); |
4386 | terminx | 116 | |
4434 | terminx | 117 | nanoPushState(); |
118 | } |
||
119 | else //software mode |
||
120 | { |
||
121 | glDisable(GL_ALPHA_TEST); |
||
122 | glDisableClientState(GL_COLOR_ARRAY); |
||
123 | glEnableClientState(GL_VERTEX_ARRAY); |
||
124 | glEnableClientState(GL_TEXTURE_COORD_ARRAY ); |
||
125 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
||
126 | glEnable (GL_BLEND); |
||
127 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
||
128 | glEnable(GL_TEXTURE_2D); |
||
129 | glDisable(GL_CULL_FACE); |
||
130 | glMatrixMode(GL_MODELVIEW); |
||
131 | } |
||
4386 | terminx | 132 | } |
133 | |||
134 | void openGLEnd() |
||
135 | { |
||
4434 | terminx | 136 | if (curRenderer == REND_GL) |
137 | { |
||
138 | //glPopMatrix(); |
||
139 | nanoPopState(); |
||
140 | glPopMatrix(); |
||
141 | } |
||
142 | else// Software mode |
||
143 | { |
||
144 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
||
145 | glMatrixMode(GL_MODELVIEW); |
||
146 | } |
||
4386 | terminx | 147 | } |
148 | |||
149 | void gameSettingsButton(int state) |
||
150 | { |
||
4434 | terminx | 151 | if (state == 1) |
152 | { |
||
153 | showTouchSettings(); |
||
154 | } |
||
4386 | terminx | 155 | } |
156 | |||
157 | //Because there is no Frame(), we need to check back to java each frame to see if the app hase paused |
||
158 | |||
159 | static jclass NativeLibClass = 0; |
||
160 | static jmethodID checkPauseMethod = 0; |
||
4434 | terminx | 161 | |
4386 | terminx | 162 | void swapBuffers() |
163 | { |
||
4434 | terminx | 164 | if (NativeLibClass == 0) |
165 | { |
||
166 | NativeLibClass = env_->FindClass("com/beloko/duke/engine/NativeLib"); |
||
167 | checkPauseMethod = env_->GetStaticMethodID(NativeLibClass, "swapBuffers", "()V"); |
||
168 | } |
||
169 | env_->CallStaticVoidMethod(NativeLibClass, checkPauseMethod); |
||
4386 | terminx | 170 | } |
171 | |||
4433 | terminx | 172 | void gameButton(int state, int code) |
4386 | terminx | 173 | { |
4433 | terminx | 174 | switch (code) |
175 | { |
||
176 | case gamefunc_Fire: |
||
177 | shooting = state; |
||
178 | PortableAction(state, code); |
||
179 | break; |
||
4386 | terminx | 180 | |
4433 | terminx | 181 | case KEY_SHOW_KBRD: |
182 | if (state) |
||
183 | toggleKeyboard(); |
||
184 | |||
185 | PortableKeyEvent(state, SDL_SCANCODE_GRAVE, 0); |
||
186 | break; |
||
187 | |||
188 | case KEY_QUICK_CMD: |
||
189 | if (state == 1) |
||
190 | showCustomCommands(); |
||
191 | break; |
||
192 | |||
193 | case KEY_SHOW_INVEN: |
||
194 | if (state != 1) |
||
195 | break; |
||
196 | |||
197 | if (!tcInventory->isEnabled()) |
||
198 | { |
||
199 | tcInventory->setEnabled(true); |
||
200 | tcInventory->fade(0, 5); |
||
201 | //disable weapon wheel so it does not show, enabled again after inventory cleared |
||
202 | tcGameWeapons->setEnabled(false); |
||
203 | } |
||
204 | else |
||
205 | { |
||
206 | tcInventory->setEnabled(false); |
||
207 | tcGameWeapons->setEnabled(true); |
||
208 | } |
||
209 | |||
210 | break; |
||
211 | |||
212 | case KEY_QUICK_SAVE: |
||
213 | LOGI("QUICK SAVE"); |
||
214 | PortableKeyEvent(state, SDL_SCANCODE_F6, 0); |
||
215 | break; |
||
216 | |||
217 | case KEY_QUICK_LOAD: |
||
218 | LOGI("QUICK LOAD"); |
||
219 | PortableKeyEvent(state, SDL_SCANCODE_F9, 0); |
||
220 | break; |
||
221 | |||
222 | default: |
||
223 | PortableAction(state, code); |
||
224 | break; |
||
225 | } |
||
4386 | terminx | 226 | } |
227 | |||
228 | void automapButton(int state,int code) |
||
229 | { |
||
4434 | terminx | 230 | PortableAction(state,code); |
4386 | terminx | 231 | } |
232 | |||
233 | void inventoryButton(int state,int code) |
||
234 | { |
||
4434 | terminx | 235 | PortableAction(state,code); |
236 | if (state == 0) |
||
237 | { |
||
238 | tcGameWeapons->setEnabled(true); |
||
239 | tcInventory->setEnabled(false); |
||
240 | } |
||
4386 | terminx | 241 | } |
242 | |||
243 | void menuButton(int state,int code) |
||
244 | { |
||
4434 | terminx | 245 | PortableKeyEvent(state, code,code); |
4386 | terminx | 246 | } |
247 | |||
248 | static int weaponWheelVisible = false; |
||
4433 | terminx | 249 | |
4386 | terminx | 250 | void weaponWheelSelected(int enabled) |
251 | { |
||
4434 | terminx | 252 | if (!enabled) |
4433 | terminx | 253 | { |
254 | tcGameWeapons->fade(1, 5); |
||
255 | weaponWheelVisible = false; |
||
256 | return; |
||
257 | } |
||
4386 | terminx | 258 | |
4433 | terminx | 259 | for (int n=0; n<10; n++) |
260 | { |
||
261 | weaponWheel->setSegmentEnabled(n, (PortableRead(READ_WEAPONS) >> n) & 0x1); |
||
262 | } |
||
263 | |||
264 | tcGameWeapons->fade(0, 5); //fade in |
||
265 | weaponWheelVisible = true; |
||
4386 | terminx | 266 | } |
4433 | terminx | 267 | |
4386 | terminx | 268 | void weaponWheelChosen(int segment) |
269 | { |
||
4434 | terminx | 270 | LOGI("weaponWheel %d",segment); |
4433 | terminx | 271 | |
272 | if (segment == -1) //Nothing was selected |
||
273 | { |
||
274 | int32_t lw = PortableRead(READ_LASTWEAPON); |
||
275 | |||
276 | if (lw != -1) |
||
4434 | terminx | 277 | PortableAction(2, gamefunc_Weapon_1 + lw); |
4433 | terminx | 278 | |
279 | return; |
||
280 | } |
||
281 | |||
4434 | terminx | 282 | PortableAction(2, gamefunc_Weapon_1 + segment); |
4386 | terminx | 283 | } |
284 | |||
285 | void left_double_tap(int state) |
||
286 | { |
||
4434 | terminx | 287 | //LOGTOUCH("L double %d",state); |
4439 | terminx | 288 | if (droidinput.left_double_action != -1) |
289 | PortableAction(state, droidinput.left_double_action); |
||
4386 | terminx | 290 | } |
291 | |||
292 | void right_double_tap(int state) |
||
293 | { |
||
4434 | terminx | 294 | //LOGTOUCH("R double %d",state); |
4439 | terminx | 295 | if (droidinput.right_double_action != -1) |
296 | PortableAction(state, droidinput.right_double_action); |
||
4386 | terminx | 297 | } |
298 | |||
4434 | terminx | 299 | void mouseMove(int action, float x, float y, float dx, float dy) |
4386 | terminx | 300 | { |
4440 | terminx | 301 | //LOGI(" mouse dx = %f, dy = %f",dx,dy); |
4386 | terminx | 302 | |
4434 | terminx | 303 | if (weaponWheelVisible) |
304 | return; |
||
305 | |||
306 | double scale = (shooting && precisionShoot) ? PRECISIONSHOOTFACTOR : 1.f; |
||
307 | |||
4440 | terminx | 308 | PortableLook(dx * droidinput.yaw_sens * scale, |
309 | -dy * droidinput.pitch_sens * scale * (invertLook ? -1.f : 1.f)); |
||
4386 | terminx | 310 | } |
311 | |||
4434 | terminx | 312 | void left_stick(float joy_x, float joy_y, float mouse_x, float mouse_y) |
4386 | terminx | 313 | { |
4440 | terminx | 314 | //LOGI("left_stick joy_x = %f, joy_y = %f",joy_x,joy_y); |
315 | |||
4434 | terminx | 316 | joy_x *=10; |
317 | float strafe = joy_x*joy_x; |
||
318 | //float strafe = joy_x; |
||
319 | if (joy_x < 0) |
||
320 | strafe *= -1; |
||
4386 | terminx | 321 | |
4439 | terminx | 322 | PortableMove(joy_y * 15 * droidinput.forward_sens, -strafe * droidinput.strafe_sens); |
4386 | terminx | 323 | } |
324 | |||
4434 | terminx | 325 | void right_stick(float joy_x, float joy_y, float mouse_x, float mouse_y) |
4386 | terminx | 326 | { |
4434 | terminx | 327 | //LOGI(" mouse x = %f",mouse_x); |
4386 | terminx | 328 | |
4434 | terminx | 329 | mouseMove(0, joy_x, joy_y, mouse_x, mouse_y); |
4386 | terminx | 330 | } |
331 | |||
332 | void setHideSticks(bool v) |
||
333 | { |
||
4434 | terminx | 334 | if (touchJoyLeft) touchJoyLeft->setHideGraphics(v); |
335 | if (touchJoyRight) touchJoyRight->setHideGraphics(v); |
||
4386 | terminx | 336 | } |
337 | |||
338 | void touchSettingsButton(int state) |
||
339 | { |
||
4433 | terminx | 340 | int32_t paused = PortableRead(READ_PAUSED); |
341 | |||
4434 | terminx | 342 | //We wanna pause the game when doing settings |
343 | if (state && !paused || !state && paused) |
||
344 | { |
||
4436 | terminx | 345 | PortableKeyEvent(2, SDL_SCANCODE_PAUSE, 0); |
4434 | terminx | 346 | } |
4386 | terminx | 347 | } |
348 | |||
4434 | terminx | 349 | void initControls(int width, int height, const char * graphics_path, const char *settings_file) |
4386 | terminx | 350 | { |
4434 | terminx | 351 | touchcontrols::GLScaleWidth = (float)width; |
352 | touchcontrols::GLScaleHeight = (float)height; |
||
4386 | terminx | 353 | |
4434 | terminx | 354 | LOGI("initControls %d x %d,x path = %s, settings = %s",width,height,graphics_path,settings_file); |
4386 | terminx | 355 | |
4434 | terminx | 356 | if (!controlsCreated) |
357 | { |
||
358 | LOGI("creating controls"); |
||
4386 | terminx | 359 | |
4434 | terminx | 360 | touchcontrols::setGraphicsBasePath(graphics_path); |
4386 | terminx | 361 | |
4434 | terminx | 362 | controlsContainer.openGL_start.connect( sigc::ptr_fun(&openGLStart)); |
363 | controlsContainer.openGL_end.connect( sigc::ptr_fun(&openGLEnd)); |
||
364 | controlsContainer.signal_settings.connect( sigc::ptr_fun(&touchSettingsButton)); |
||
4386 | terminx | 365 | |
366 | |||
4434 | terminx | 367 | tcMenuMain = new touchcontrols::TouchControls("menu",true,false); |
368 | tcGameMain = new touchcontrols::TouchControls("game",false,true,1,true); |
||
369 | tcGameWeapons = new touchcontrols::TouchControls("weapons",false,true,1,false); |
||
370 | tcAutomap = new touchcontrols::TouchControls("automap",false,true,1,false); |
||
371 | tcInventory = new touchcontrols::TouchControls("inventory",false,true,1,false); |
||
372 | tcGameLook = new touchcontrols::TouchControls("mouse",true,false); |
||
373 | //controlsContainer.dukeHack = 1; |
||
4386 | terminx | 374 | |
4440 | terminx | 375 | tcGameMain->signal_settingsButton.connect( sigc::ptr_fun(&gameSettingsButton) ); |
376 | //tcMenuMain->signal_settingsButton.connect( sigc::ptr_fun(&gameSettingsButton) ); |
||
4386 | terminx | 377 | |
4434 | terminx | 378 | //Menu |
4436 | terminx | 379 | tcMenuMain->addControl(new touchcontrols::Button("down_arrow", touchcontrols::RectF(20,13,23,16), "arrow_down", SDL_SCANCODE_DOWN, true)); //Repeating buttons |
380 | tcMenuMain->addControl(new touchcontrols::Button("up_arrow", touchcontrols::RectF(20,10,23,13), "arrow_up", SDL_SCANCODE_UP, true)); |
||
381 | tcMenuMain->addControl(new touchcontrols::Button("left_arrow", touchcontrols::RectF(17,13,20,16), "arrow_left", SDL_SCANCODE_LEFT, true)); |
||
382 | tcMenuMain->addControl(new touchcontrols::Button("right_arrow", touchcontrols::RectF(23,13,26,16), "arrow_right", SDL_SCANCODE_RIGHT, true)); |
||
383 | tcMenuMain->addControl(new touchcontrols::Button("enter", touchcontrols::RectF(0,13,3,16), "enter", SDL_SCANCODE_RETURN)); |
||
4440 | terminx | 384 | tcMenuMain->addControl(new touchcontrols::Button("esc", touchcontrols::RectF(0,10,3,13), "esc", SDL_SCANCODE_ESCAPE)); |
4386 | terminx | 385 | |
386 | |||
4434 | terminx | 387 | tcMenuMain->signal_button.connect( sigc::ptr_fun(&menuButton) ); |
388 | tcMenuMain->setAlpha(0.5); |
||
4386 | terminx | 389 | |
390 | |||
4434 | terminx | 391 | tcInventory->addControl(new touchcontrols::Button("jetpack", touchcontrols::RectF(4,3,7,6),"jetpack",gamefunc_Jetpack)); |
392 | tcInventory->addControl(new touchcontrols::Button("medkit", touchcontrols::RectF(7,3,10,6),"medkit",gamefunc_MedKit)); |
||
393 | tcInventory->addControl(new touchcontrols::Button("nightv", touchcontrols::RectF(4,6,7,9),"nightvision",gamefunc_NightVision)); |
||
394 | tcInventory->addControl(new touchcontrols::Button("holoduke",touchcontrols::RectF(7,6,10,9),"holoduke",gamefunc_Holo_Duke)); |
||
395 | tcInventory->addControl(new touchcontrols::Button("steroids",touchcontrols::RectF(4,9,7,12),"steroids",gamefunc_Steroids)); |
||
396 | tcMenuMain->setAlpha(1); |
||
4386 | terminx | 397 | |
398 | |||
4434 | terminx | 399 | tcInventory->signal_button.connect( sigc::ptr_fun(&inventoryButton)); |
4386 | terminx | 400 | |
4436 | terminx | 401 | /* FIXME: definitely hook this up |
4434 | terminx | 402 | //Automap |
403 | tcAutomap->addControl(new touchcontrols::Button("down_arrow",touchcontrols::RectF(2,14,4,16),"arrow_down",PORT_ACT_MAP_DOWN)); |
||
404 | tcAutomap->addControl(new touchcontrols::Button("up_arrow",touchcontrols::RectF(2,10,4,12),"arrow_up",PORT_ACT_MAP_UP)); |
||
405 | tcAutomap->addControl(new touchcontrols::Button("left_arrow",touchcontrols::RectF(0,12,2,14),"arrow_left",PORT_ACT_MAP_LEFT)); |
||
406 | tcAutomap->addControl(new touchcontrols::Button("right_arrow",touchcontrols::RectF(4,12,6,14),"arrow_right",PORT_ACT_MAP_RIGHT)); |
||
407 | tcAutomap->addControl(new touchcontrols::Button("zoom_in",touchcontrols::RectF(4,10,6,12),"zoom_in",PORT_ACT_MAP_ZOOM_IN)); |
||
408 | tcAutomap->addControl(new touchcontrols::Button("zoom_out",touchcontrols::RectF(4,14,6,16),"zoom_out",PORT_ACT_MAP_ZOOM_OUT)); |
||
4386 | terminx | 409 | |
4434 | terminx | 410 | tcAutomap->signal_button.connect( sigc::ptr_fun(&automapButton) ); |
411 | tcAutomap->setAlpha(0.5); |
||
412 | */ |
||
4386 | terminx | 413 | |
4434 | terminx | 414 | //Game |
415 | tcGameMain->setAlpha(gameControlsAlpha); |
||
416 | controlsContainer.editButtonAlpha = gameControlsAlpha; |
||
4440 | terminx | 417 | tcGameMain->addControl(new touchcontrols::Button("use", touchcontrols::RectF(23,3,26,6), "use", gamefunc_Open)); |
4436 | terminx | 418 | tcGameMain->addControl(new touchcontrols::Button("attack", touchcontrols::RectF(20,7,23,10), "fire2", gamefunc_Fire)); |
4440 | terminx | 419 | tcGameMain->addControl(new touchcontrols::Button("jump", touchcontrols::RectF(23,6,26,9), "jump", gamefunc_Jump)); |
4436 | terminx | 420 | tcGameMain->addControl(new touchcontrols::Button("crouch", touchcontrols::RectF(24,12,26,14), "crouch", gamefunc_Crouch)); |
421 | tcGameMain->addControl(new touchcontrols::Button("kick", touchcontrols::RectF(20,4,23,7), "boot", gamefunc_Quick_Kick,false,true)); |
||
4386 | terminx | 422 | |
4440 | terminx | 423 | tcGameMain->addControl(new touchcontrols::Button("quick_save", touchcontrols::RectF(24,0,26,2), "save", KEY_QUICK_SAVE,false,true)); |
424 | tcGameMain->addControl(new touchcontrols::Button("quick_load", touchcontrols::RectF(20,0,22,2), "load", KEY_QUICK_LOAD,false,true)); |
||
4436 | terminx | 425 | tcGameMain->addControl(new touchcontrols::Button("map", touchcontrols::RectF(4,0,6,2), "map", gamefunc_Map, false,true)); |
426 | tcGameMain->addControl(new touchcontrols::Button("keyboard", touchcontrols::RectF(8,0,10,2), "keyboard", KEY_SHOW_KBRD, false,true)); |
||
4386 | terminx | 427 | |
4436 | terminx | 428 | tcGameMain->addControl(new touchcontrols::Button("show_inventory",touchcontrols::RectF(2,0,4,2), "inv", KEY_SHOW_INVEN)); |
4386 | terminx | 429 | |
4440 | terminx | 430 | tcGameMain->addControl(new touchcontrols::Button("next_weapon", touchcontrols::RectF(0,3,3,5), "next_weap",gamefunc_Next_Weapon,false,true)); |
431 | tcGameMain->addControl(new touchcontrols::Button("prev_weapon", touchcontrols::RectF(0,5,3,7), "prev_weap",gamefunc_Previous_Weapon,false,true)); |
||
4434 | terminx | 432 | /* |
433 | //quick actions binds |
||
434 | tcGameMain->addControl(new touchcontrols::Button("quick_key_1",touchcontrols::RectF(4,3,6,5),"quick_key_1",KEY_QUICK_KEY1,false,true)); |
||
435 | tcGameMain->addControl(new touchcontrols::Button("quick_key_2",touchcontrols::RectF(6,3,8,5),"quick_key_2",KEY_QUICK_KEY2,false,true)); |
||
436 | tcGameMain->addControl(new touchcontrols::Button("quick_key_3",touchcontrols::RectF(8,3,10,5),"quick_key_3",KEY_QUICK_KEY3,false,true)); |
||
437 | tcGameMain->addControl(new touchcontrols::Button("quick_key_4",touchcontrols::RectF(10,3,12,5),"quick_key_4",KEY_QUICK_KEY4,false,true)); |
||
438 | */ |
||
439 | //Left stick |
||
440 | touchJoyLeft = new touchcontrols::TouchJoy("stick",touchcontrols::RectF(0,7,8,16),"strafe_arrow"); |
||
441 | tcGameMain->addControl(touchJoyLeft); |
||
442 | touchJoyLeft->signal_move.connect(sigc::ptr_fun(&left_stick) ); |
||
443 | touchJoyLeft->signal_double_tap.connect(sigc::ptr_fun(&left_double_tap) ); |
||
4386 | terminx | 444 | |
4434 | terminx | 445 | //Right stick |
446 | touchJoyRight = new touchcontrols::TouchJoy("touch",touchcontrols::RectF(17,7,26,16),"look_arrow"); |
||
447 | tcGameMain->addControl(touchJoyRight); |
||
448 | touchJoyRight->signal_move.connect(sigc::ptr_fun(&right_stick) ); |
||
449 | touchJoyRight->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) ); |
||
450 | touchJoyRight->setEnabled(false); |
||
4386 | terminx | 451 | |
4434 | terminx | 452 | tcGameMain->signal_button.connect( sigc::ptr_fun(&gameButton) ); |
4386 | terminx | 453 | |
454 | |||
4434 | terminx | 455 | //Mouse look for whole screen |
456 | touchcontrols::Mouse *mouse = new touchcontrols::Mouse("mouse",touchcontrols::RectF(3,0,26,16),""); |
||
457 | mouse->signal_action.connect(sigc::ptr_fun(&mouseMove)); |
||
458 | mouse->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) ); |
||
4386 | terminx | 459 | |
4434 | terminx | 460 | mouse->setHideGraphics(true); |
461 | tcGameMain->addControl(mouse); |
||
462 | //tcGameLook->addControl(mouse); |
||
4386 | terminx | 463 | |
464 | |||
465 | |||
4434 | terminx | 466 | //Weapons |
467 | weaponWheel = new touchcontrols::WheelSelect("weapon_wheel",touchcontrols::RectF(7,2,19,14),"weapon_wheel_orange_blank",10); |
||
468 | weaponWheel->signal_selected.connect(sigc::ptr_fun(&weaponWheelChosen) ); |
||
469 | weaponWheel->signal_enabled.connect(sigc::ptr_fun(&weaponWheelSelected)); |
||
470 | tcGameWeapons->addControl(weaponWheel); |
||
4386 | terminx | 471 | |
472 | |||
4434 | terminx | 473 | tcGameWeapons->setAlpha(0.9); |
4386 | terminx | 474 | |
4434 | terminx | 475 | controlsContainer.addControlGroup(tcMenuMain); |
476 | controlsContainer.addControlGroup(tcGameMain); |
||
477 | controlsContainer.addControlGroup(tcInventory);//Need to be above tcGameMain incase buttons over stick |
||
478 | controlsContainer.addControlGroup(tcGameWeapons); |
||
479 | //controlsContainer.addControlGroup(tcAutomap); |
||
480 | //controlsContainer.addControlGroup(tcGameLook); |
||
481 | controlsCreated = 1; |
||
4386 | terminx | 482 | |
4434 | terminx | 483 | tcGameMain->setXMLFile((std::string)graphics_path + "/game.xml"); |
484 | tcGameWeapons->setXMLFile((std::string)graphics_path + "/weapons.xml"); |
||
485 | tcAutomap->setXMLFile((std::string)graphics_path + "/automap.xml"); |
||
486 | tcInventory->setXMLFile((std::string)graphics_path + "/inventory.xml"); |
||
4386 | terminx | 487 | |
4434 | terminx | 488 | } |
489 | else |
||
490 | LOGI("NOT creating controls"); |
||
4386 | terminx | 491 | |
4434 | terminx | 492 | //controlsContainer.initGL(); |
4386 | terminx | 493 | } |
494 | |||
4440 | terminx | 495 | |
496 | #ifdef GP_LIC |
||
497 | #define GP_LIC_INC 1 |
||
498 | #include "s-setup/gp_lic_include.h" |
||
499 | #endif |
||
500 | |||
4386 | terminx | 501 | void frameControls() |
502 | { |
||
4433 | terminx | 503 | static int loadedGLImages = 0; |
504 | static int inMenuLast = 1; |
||
505 | static int inAutomapLast = 0; |
||
506 | |||
4434 | terminx | 507 | //LOGI("frameControls"); |
508 | //We need to do this here now because duke loads a new gl context |
||
509 | if (!loadedGLImages) |
||
510 | { |
||
511 | touchJoyRight->setEnabled(false); |
||
4386 | terminx | 512 | |
4434 | terminx | 513 | controlsContainer.initGL(); |
514 | loadedGLImages = 1; |
||
515 | } |
||
4386 | terminx | 516 | |
4434 | terminx | 517 | //LOGI("frameControls"); |
518 | curRenderer = (PortableRead(READ_RENDERER) != REND_CLASSIC); |
||
4386 | terminx | 519 | |
4434 | terminx | 520 | int inMenuNew = PortableRead(READ_MENU); |
521 | if (inMenuLast != inMenuNew) |
||
522 | { |
||
523 | inMenuLast = inMenuNew; |
||
524 | if (!inMenuNew) |
||
525 | { |
||
526 | tcGameMain->setEnabled(true); |
||
527 | tcGameWeapons->setEnabled(true); |
||
528 | tcGameWeapons->fade(1,5); |
||
529 | tcMenuMain->setEnabled(false); |
||
530 | } |
||
531 | else |
||
532 | { |
||
533 | tcGameMain->setEnabled(false); |
||
534 | tcGameWeapons->setEnabled(false); |
||
535 | tcMenuMain->setEnabled(true); |
||
536 | } |
||
537 | } |
||
4386 | terminx | 538 | |
4434 | terminx | 539 | int inAutomapNew = PortableRead(READ_AUTOMAP) && !inMenuLast; //Dont show if menu comes up |
540 | if (inAutomapLast != inAutomapNew) |
||
541 | { |
||
542 | inAutomapLast = inAutomapNew; |
||
543 | if (inAutomapNew) |
||
544 | { |
||
545 | tcAutomap->animateIn(5); |
||
546 | } |
||
547 | else |
||
548 | { |
||
549 | tcAutomap->animateOut(5); |
||
550 | } |
||
551 | } |
||
4386 | terminx | 552 | |
4434 | terminx | 553 | setHideSticks(!showSticks); |
554 | controlsContainer.draw(); |
||
4440 | terminx | 555 | |
556 | #ifdef GP_LIC |
||
557 | #define GP_LIC_INC 2 |
||
558 | #include "s-setup/gp_lic_include.h" |
||
559 | #endif |
||
560 | |||
4386 | terminx | 561 | } |
562 | |||
563 | void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,int other) |
||
564 | { |
||
4436 | terminx | 565 | gameControlsAlpha = MINCONTROLALPHA + (alpha * (1.0f - MINCONTROLALPHA)); |
4386 | terminx | 566 | |
4434 | terminx | 567 | if (tcGameMain) |
568 | { |
||
569 | tcGameMain->setAlpha(gameControlsAlpha); |
||
570 | controlsContainer.editButtonAlpha = gameControlsAlpha; |
||
571 | tcGameWeapons->setAlpha(gameControlsAlpha); |
||
572 | tcInventory->setAlpha(gameControlsAlpha); |
||
573 | } |
||
4386 | terminx | 574 | |
4436 | terminx | 575 | // TODO: defined names for these values |
576 | toggleCrouch = other & 0x2 ? true : false; |
||
577 | invertLook = other & 0x4 ? true : false; |
||
578 | precisionShoot = other & 0x8 ? true : false; |
||
579 | showSticks = other & 0x1000 ? true : false; |
||
4386 | terminx | 580 | |
4436 | terminx | 581 | hideTouchControls = other & 0x80000000 ? true : false; |
582 | |||
4434 | terminx | 583 | switch ((other>>4) & 0xF) |
584 | { |
||
585 | case 1: |
||
4439 | terminx | 586 | droidinput.left_double_action = gamefunc_Fire; |
4434 | terminx | 587 | break; |
588 | case 2: |
||
4439 | terminx | 589 | droidinput.left_double_action = gamefunc_Jump; |
4434 | terminx | 590 | break; |
591 | default: |
||
4439 | terminx | 592 | droidinput.left_double_action = -1; |
4434 | terminx | 593 | } |
4386 | terminx | 594 | |
4434 | terminx | 595 | switch ((other>>8) & 0xF) |
596 | { |
||
597 | case 1: |
||
4439 | terminx | 598 | droidinput.right_double_action = gamefunc_Fire; |
4434 | terminx | 599 | break; |
600 | case 2: |
||
4439 | terminx | 601 | droidinput.right_double_action = gamefunc_Jump; |
4434 | terminx | 602 | break; |
603 | default: |
||
4439 | terminx | 604 | droidinput.right_double_action = -1; |
4434 | terminx | 605 | } |
4386 | terminx | 606 | |
4439 | terminx | 607 | droidinput.strafe_sens = strafe; |
608 | droidinput.forward_sens = fwd; |
||
609 | droidinput.pitch_sens = pitch; |
||
610 | droidinput.yaw_sens = yaw; |
||
4386 | terminx | 611 | } |
612 | |||
613 | #define EXPORT_ME __attribute__ ((visibility("default"))) |
||
614 | |||
615 | JNIEnv* env_; |
||
616 | |||
617 | int argc=1; |
||
618 | const char * argv[32]; |
||
619 | std::string graphicpath; |
||
620 | std::string doom_path; |
||
621 | |||
4434 | terminx | 622 | static const char * getGamePath() |
4386 | terminx | 623 | { |
4434 | terminx | 624 | return doom_path.c_str(); |
4386 | terminx | 625 | } |
626 | |||
627 | jint EXPORT_ME |
||
628 | Java_com_beloko_duke_engine_NativeLib_init( JNIEnv* env, |
||
4434 | terminx | 629 | jobject thiz,jstring graphics_dir,jint audio_rate,jint audio_buffer_size,jobjectArray argsArray,jint renderer,jstring doom_path_ ) |
4386 | terminx | 630 | { |
4434 | terminx | 631 | env_ = env; |
4386 | terminx | 632 | |
4440 | terminx | 633 | #ifdef GP_LIC |
634 | getGlobalClasses(env_); |
||
635 | #endif |
||
636 | |||
4436 | terminx | 637 | droidinfo.audio_sample_rate = audio_rate; |
638 | droidinfo.audio_buffer_size = audio_buffer_size; |
||
4386 | terminx | 639 | |
4434 | terminx | 640 | curRenderer = renderer; |
641 | //curRenderer = REND_SOFT; |
||
642 | curRenderer = REND_GL; |
||
4386 | terminx | 643 | |
4434 | terminx | 644 | argv[0] = "eduke32"; |
645 | int argCount = (env)->GetArrayLength( argsArray); |
||
646 | LOGI("argCount = %d",argCount); |
||
647 | for (int i=0; i<argCount; i++) { |
||
648 | jstring string = (jstring) (env)->GetObjectArrayElement( argsArray, i); |
||
649 | argv[argc] = (char *)(env)->GetStringUTFChars( string, 0); |
||
650 | LOGI("arg = %s",argv[argc]); |
||
651 | argc++; |
||
652 | } |
||
4386 | terminx | 653 | |
4434 | terminx | 654 | doom_path = (char *)(env)->GetStringUTFChars( doom_path_, 0); |
4386 | terminx | 655 | |
4434 | terminx | 656 | //Change working dir, save games etc |
657 | // FIXME: potentially conflicts with chdirs in -game_dir support |
||
658 | chdir(getGamePath()); |
||
659 | char timidity_env[512]; |
||
4386 | terminx | 660 | |
4434 | terminx | 661 | sprintf(timidity_env,"TIMIDITY_CFG=%s/../timidity.cfg",getGamePath()); |
662 | //putenv("TIMIDITY_CFG=../timidity.cfg"); |
||
663 | putenv(timidity_env); |
||
4386 | terminx | 664 | |
4434 | terminx | 665 | LOGI("doom_path = %s",getGamePath()); |
4386 | terminx | 666 | |
4434 | terminx | 667 | const char * p = env->GetStringUTFChars(graphics_dir,NULL); |
668 | graphicpath = std::string(p); |
||
4386 | terminx | 669 | |
4436 | terminx | 670 | initControls(droidinfo.screen_width, -droidinfo.screen_height, |
671 | graphicpath.c_str(),(graphicpath + "/touch_controls.xml").c_str()); |
||
4386 | terminx | 672 | |
4434 | terminx | 673 | /* |
674 | if (renderer != REND_SOFT) |
||
675 | SDL_SetSwapBufferCallBack(frameControls); |
||
4386 | terminx | 676 | |
4434 | terminx | 677 | if (renderer == REND_SOFT)// In soft mode SDL calls swap buffer, disable so it does not flicker |
678 | SDL_SwapBufferPerformsSwap(false); |
||
679 | */ |
||
4386 | terminx | 680 | |
681 | |||
4434 | terminx | 682 | SDL_SetSwapBufferCallBack(frameControls); |
4386 | terminx | 683 | |
4434 | terminx | 684 | //Now doen in java to keep context etc |
685 | //SDL_SwapBufferPerformsSwap(false); |
||
4436 | terminx | 686 | |
4434 | terminx | 687 | PortableInit(argc, argv); |
4436 | terminx | 688 | |
4434 | terminx | 689 | return 0; |
4386 | terminx | 690 | } |
691 | |||
692 | |||
693 | jint EXPORT_ME |
||
694 | Java_com_beloko_duke_engine_NativeLib_frame( JNIEnv* env, |
||
4434 | terminx | 695 | jobject thiz ) |
4386 | terminx | 696 | { |
4434 | terminx | 697 | LOGI("Java_com_beloko_duke_engine_NativeLib_frame"); |
4386 | terminx | 698 | |
4434 | terminx | 699 | frameControls(); |
700 | return 0; |
||
4386 | terminx | 701 | } |
702 | |||
703 | __attribute__((visibility("default"))) jint JNI_OnLoad(JavaVM* vm, void* reserved) |
||
704 | { |
||
4434 | terminx | 705 | LOGI("JNI_OnLoad"); |
706 | setTCJNIEnv(vm); |
||
707 | jvm_ = vm; |
||
708 | return JNI_VERSION_1_4; |
||
4386 | terminx | 709 | } |
710 | |||
711 | |||
712 | void EXPORT_ME |
||
713 | Java_com_beloko_duke_engine_NativeLib_keypress(JNIEnv *env, jobject obj, |
||
4434 | terminx | 714 | jint down, jint keycode, jint unicode) |
4386 | terminx | 715 | { |
4434 | terminx | 716 | LOGI("keypress %d",keycode); |
717 | if (controlsContainer.isEditing()) |
||
718 | { |
||
719 | if (down && (keycode == SDL_SCANCODE_ESCAPE )) |
||
720 | controlsContainer.finishEditing(); |
||
4436 | terminx | 721 | return; |
4434 | terminx | 722 | } |
4436 | terminx | 723 | |
724 | PortableKeyEvent(down,keycode,unicode); |
||
4386 | terminx | 725 | } |
726 | |||
727 | |||
728 | void EXPORT_ME |
||
729 | Java_com_beloko_duke_engine_NativeLib_touchEvent(JNIEnv *env, jobject obj, |
||
4440 | terminx | 730 | jint action, jint pid, jdouble x, jdouble y) |
4386 | terminx | 731 | { |
4434 | terminx | 732 | //LOGI("TOUCHED"); |
733 | controlsContainer.processPointer(action,pid,x,y); |
||
4386 | terminx | 734 | } |
735 | |||
736 | |||
737 | void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_doAction(JNIEnv *env, jobject obj, |
||
4434 | terminx | 738 | jint state, jint action) |
4386 | terminx | 739 | { |
4434 | terminx | 740 | LOGI("doAction %d %d",state,action); |
741 | |||
742 | //gamepadButtonPressed(); |
||
743 | if (hideTouchControls && tcGameMain) |
||
744 | { |
||
745 | if (tcGameMain->isEnabled()) |
||
746 | tcGameMain->animateOut(30); |
||
747 | |||
748 | if (tcGameWeapons->isEnabled()) |
||
749 | tcGameWeapons->animateOut(30); |
||
750 | } |
||
751 | |||
752 | PortableAction(state,action); |
||
4386 | terminx | 753 | } |
754 | |||
755 | void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogFwd(JNIEnv *env, jobject obj, |
||
4434 | terminx | 756 | jfloat v) |
4386 | terminx | 757 | { |
4440 | terminx | 758 | PortableMove(v, NAN); |
4386 | terminx | 759 | } |
760 | |||
761 | void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogSide(JNIEnv *env, jobject obj, |
||
4434 | terminx | 762 | jfloat v) |
4386 | terminx | 763 | { |
4440 | terminx | 764 | PortableMove(NAN, v); |
4386 | terminx | 765 | } |
766 | |||
767 | void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogPitch(JNIEnv *env, jobject obj, |
||
4434 | terminx | 768 | jint mode,jfloat v) |
4386 | terminx | 769 | { |
4440 | terminx | 770 | PortableLookJoystick(NAN, v); |
4386 | terminx | 771 | } |
772 | |||
773 | void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogYaw(JNIEnv *env, jobject obj, |
||
4434 | terminx | 774 | jint mode,jfloat v) |
4386 | terminx | 775 | { |
4440 | terminx | 776 | PortableLookJoystick(v, NAN); |
4386 | terminx | 777 | } |
778 | |||
779 | void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_setTouchSettings(JNIEnv *env, jobject obj, |
||
4434 | terminx | 780 | jfloat alpha,jfloat strafe,jfloat fwd,jfloat pitch,jfloat yaw,int other) |
4386 | terminx | 781 | { |
4434 | terminx | 782 | setTouchSettings(alpha,strafe,fwd,pitch,yaw,other); |
4386 | terminx | 783 | } |
784 | |||
785 | void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_resetTouchSettings(JNIEnv *env, jobject obj) |
||
786 | { |
||
4434 | terminx | 787 | controlsContainer.resetDefaults(); |
4386 | terminx | 788 | } |
789 | |||
790 | std::string quickCommandString; |
||
791 | jint EXPORT_ME |
||
792 | Java_com_beloko_duke_engine_NativeLib_quickCommand(JNIEnv *env, jobject obj, |
||
4434 | terminx | 793 | jstring command) |
4386 | terminx | 794 | { |
4434 | terminx | 795 | const char * p = env->GetStringUTFChars(command,NULL); |
796 | quickCommandString = std::string(p) + "\n"; |
||
797 | env->ReleaseStringUTFChars(command, p); |
||
798 | PortableCommand(quickCommandString.c_str()); |
||
4386 | terminx | 799 | } |
800 | |||
801 | void EXPORT_ME |
||
802 | Java_com_beloko_duke_engine_NativeLib_setScreenSize( JNIEnv* env, |
||
4434 | terminx | 803 | jobject thiz, jint width, jint height) |
4386 | terminx | 804 | { |
4436 | terminx | 805 | droidinfo.screen_width = width; |
806 | droidinfo.screen_height = height; |
||
4386 | terminx | 807 | } |
808 | |||
4434 | terminx | 809 | void EXPORT_ME Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls) |
4386 | terminx | 810 | { |
4434 | terminx | 811 | /* This interface could expand with ABI negotiation, calbacks, etc. */ |
812 | SDL_Android_Init(env, cls); |
||
813 | SDL_SetMainReady(); |
||
814 | // SDL_EventState(SDL_TEXTINPUT,SDL_ENABLE); |
||
4386 | terminx | 815 | } |
816 | |||
4440 | terminx | 817 | #ifdef GP_LIC |
818 | #define GP_LIC_INC 3 |
||
819 | #include "s-setup/gp_lic_include.h" |
||
820 | #endif |
||
4386 | terminx | 821 | } |