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