Subversion Repositories eduke32

Rev

Rev 4439 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4439 Rev 4440
Line 14... Line 14...
14
#include "SDL_main.h"
14
#include "SDL_main.h"
15
15
16
#include "TouchControlsContainer.h"
16
#include "TouchControlsContainer.h"
17
#include "JNITouchControlsUtils.h"
17
#include "JNITouchControlsUtils.h"
18
18
-
 
19
#ifdef GP_LIC
-
 
20
#include "s-setup/s-setup.h"
-
 
21
#endif
-
 
22
19
extern "C"
23
extern "C"
20
{
24
{
21
25
22
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
26
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
23
//This is a new function I put into SDL2, file SDL_androidgl.c
27
//This is a new function I put into SDL2, file SDL_androidgl.c
Line 27... Line 31...
27
#include "../function.h"
31
#include "../function.h"
28
32
29
#include "../GL/gl.h"
33
#include "../GL/gl.h"
30
#include "../GL/nano_gl.h"
34
#include "../GL/nano_gl.h"
31
35
-
 
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
32
#ifndef LOGI
43
#ifndef LOGI
33
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__))
44
#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__))
45
#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__))
46
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR,"DUKE", __VA_ARGS__))
36
#endif
47
#endif
Line 46... Line 57...
46
57
47
bool invertLook = false;
58
bool invertLook = false;
48
bool precisionShoot = false;
59
bool precisionShoot = false;
49
bool showSticks = true;
60
bool showSticks = true;
50
bool hideTouchControls = true;
61
bool hideTouchControls = true;
51
bool toggleCrouch = true;
62
char toggleCrouch = true;
52
63
53
bool shooting = false;
64
bool shooting = false;
54
65
55
static int controlsCreated = 0;
66
static int controlsCreated = 0;
56
touchcontrols::TouchControlsContainer controlsContainer;
67
touchcontrols::TouchControlsContainer controlsContainer;
Line 285... Line 296...
285
        PortableAction(state, droidinput.right_double_action);
296
        PortableAction(state, droidinput.right_double_action);
286
}
297
}
287
298
288
void mouseMove(int action, float x, float y, float dx, float dy)
299
void mouseMove(int action, float x, float y, float dx, float dy)
289
{
300
{
290
    //LOGI(" mouse dx = %f",dx);
301
    //LOGI(" mouse dx = %f, dy = %f",dx,dy);
291
302
292
    if (weaponWheelVisible)
303
    if (weaponWheelVisible)
293
        return;
304
        return;
294
305
295
    double scale = (shooting && precisionShoot) ? PRECISIONSHOOTFACTOR : 1.f;
306
    double scale = (shooting && precisionShoot) ? PRECISIONSHOOTFACTOR : 1.f;
296
307
297
    PortableLook(dx * 2 * droidinput.yaw_sens * scale,
308
    PortableLook(dx * droidinput.yaw_sens * scale,
298
        -dy * droidinput.pitch_sens * scale * invertLook ? -1 : 1);
309
        -dy * droidinput.pitch_sens * scale * (invertLook ? -1.f : 1.f));
299
}
310
}
300
311
301
void left_stick(float joy_x, float joy_y, float mouse_x, float mouse_y)
312
void left_stick(float joy_x, float joy_y, float mouse_x, float mouse_y)
302
{
313
{
-
 
314
        //LOGI("left_stick joy_x = %f, joy_y = %f",joy_x,joy_y);
-
 
315
303
    joy_x *=10;
316
    joy_x *=10;
304
    float strafe = joy_x*joy_x;
317
    float strafe = joy_x*joy_x;
305
    //float strafe = joy_x;
318
    //float strafe = joy_x;
306
    if (joy_x < 0)
319
    if (joy_x < 0)
307
        strafe *= -1;
320
        strafe *= -1;
Line 357... Line 370...
357
        tcAutomap  = new touchcontrols::TouchControls("automap",false,true,1,false);
370
        tcAutomap  = new touchcontrols::TouchControls("automap",false,true,1,false);
358
        tcInventory = new touchcontrols::TouchControls("inventory",false,true,1,false);
371
        tcInventory = new touchcontrols::TouchControls("inventory",false,true,1,false);
359
        tcGameLook = new touchcontrols::TouchControls("mouse",true,false);
372
        tcGameLook = new touchcontrols::TouchControls("mouse",true,false);
360
        //controlsContainer.dukeHack = 1;
373
        //controlsContainer.dukeHack = 1;
361
374
362
//        tcGameMain->signal_settingsButton.connect(  sigc::ptr_fun(&gameSettingsButton) );
375
        tcGameMain->signal_settingsButton.connect(  sigc::ptr_fun(&gameSettingsButton) );
363
        tcMenuMain->signal_settingsButton.connect(  sigc::ptr_fun(&gameSettingsButton) );
376
        //tcMenuMain->signal_settingsButton.connect(  sigc::ptr_fun(&gameSettingsButton) );
364
377
365
        //Menu
378
        //Menu
366
        tcMenuMain->addControl(new touchcontrols::Button("down_arrow",  touchcontrols::RectF(20,13,23,16),  "arrow_down",   SDL_SCANCODE_DOWN,  true)); //Repeating buttons
379
        tcMenuMain->addControl(new touchcontrols::Button("down_arrow",  touchcontrols::RectF(20,13,23,16),  "arrow_down",   SDL_SCANCODE_DOWN,  true)); //Repeating buttons
367
        tcMenuMain->addControl(new touchcontrols::Button("up_arrow",    touchcontrols::RectF(20,10,23,13),  "arrow_up",     SDL_SCANCODE_UP,    true));
380
        tcMenuMain->addControl(new touchcontrols::Button("up_arrow",    touchcontrols::RectF(20,10,23,13),  "arrow_up",     SDL_SCANCODE_UP,    true));
368
        tcMenuMain->addControl(new touchcontrols::Button("left_arrow",  touchcontrols::RectF(17,13,20,16),  "arrow_left",   SDL_SCANCODE_LEFT,  true));
381
        tcMenuMain->addControl(new touchcontrols::Button("left_arrow",  touchcontrols::RectF(17,13,20,16),  "arrow_left",   SDL_SCANCODE_LEFT,  true));
369
        tcMenuMain->addControl(new touchcontrols::Button("right_arrow", touchcontrols::RectF(23,13,26,16),  "arrow_right",  SDL_SCANCODE_RIGHT, true));
382
        tcMenuMain->addControl(new touchcontrols::Button("right_arrow", touchcontrols::RectF(23,13,26,16),  "arrow_right",  SDL_SCANCODE_RIGHT, true));
370
        tcMenuMain->addControl(new touchcontrols::Button("enter",       touchcontrols::RectF(0,13,3,16),    "enter",        SDL_SCANCODE_RETURN));
383
        tcMenuMain->addControl(new touchcontrols::Button("enter",       touchcontrols::RectF(0,13,3,16),    "enter",        SDL_SCANCODE_RETURN));
371
        tcMenuMain->addControl(new touchcontrols::Button("esc",         touchcontrols::RectF(0,9,3,12),     "esc",          SDL_SCANCODE_ESCAPE));
384
        tcMenuMain->addControl(new touchcontrols::Button("esc",         touchcontrols::RectF(0,10,3,13),    "esc",          SDL_SCANCODE_ESCAPE));
372
385
373
386
374
        tcMenuMain->signal_button.connect(  sigc::ptr_fun(&menuButton) );
387
        tcMenuMain->signal_button.connect(  sigc::ptr_fun(&menuButton) );
375
        tcMenuMain->setAlpha(0.5);
388
        tcMenuMain->setAlpha(0.5);
376
389
Line 399... Line 412...
399
            */
412
            */
400
413
401
        //Game
414
        //Game
402
        tcGameMain->setAlpha(gameControlsAlpha);
415
        tcGameMain->setAlpha(gameControlsAlpha);
403
        controlsContainer.editButtonAlpha = gameControlsAlpha;
416
        controlsContainer.editButtonAlpha = gameControlsAlpha;
404
        tcGameMain->addControl(new touchcontrols::Button("use",         touchcontrols::RectF(23,4,26,7),    "use",      gamefunc_Open));
417
        tcGameMain->addControl(new touchcontrols::Button("use",         touchcontrols::RectF(23,3,26,6),    "use",      gamefunc_Open));
405
        tcGameMain->addControl(new touchcontrols::Button("attack",      touchcontrols::RectF(20,7,23,10),   "fire2",    gamefunc_Fire));
418
        tcGameMain->addControl(new touchcontrols::Button("attack",      touchcontrols::RectF(20,7,23,10),   "fire2",    gamefunc_Fire));
406
        tcGameMain->addControl(new touchcontrols::Button("jump",        touchcontrols::RectF(23,7,26,10),   "jump",     gamefunc_Jump));
419
        tcGameMain->addControl(new touchcontrols::Button("jump",        touchcontrols::RectF(23,6,26,9),   "jump",     gamefunc_Jump));
407
        tcGameMain->addControl(new touchcontrols::Button("crouch",      touchcontrols::RectF(24,12,26,14),  "crouch",   gamefunc_Crouch));
420
        tcGameMain->addControl(new touchcontrols::Button("crouch",      touchcontrols::RectF(24,12,26,14),  "crouch",   gamefunc_Crouch));
408
        tcGameMain->addControl(new touchcontrols::Button("kick",        touchcontrols::RectF(20,4,23,7),    "boot",     gamefunc_Quick_Kick,false,true));
421
        tcGameMain->addControl(new touchcontrols::Button("kick",        touchcontrols::RectF(20,4,23,7),    "boot",     gamefunc_Quick_Kick,false,true));
409
422
410
        tcGameMain->addControl(new touchcontrols::Button("quick_save",  touchcontrols::RectF(24,0,26,2),    "save",     KEY_QUICK_SAVE));
423
        tcGameMain->addControl(new touchcontrols::Button("quick_save",  touchcontrols::RectF(24,0,26,2),    "save",     KEY_QUICK_SAVE,false,true));
411
        tcGameMain->addControl(new touchcontrols::Button("quick_load",  touchcontrols::RectF(20,0,22,2),    "load",     KEY_QUICK_LOAD));
424
        tcGameMain->addControl(new touchcontrols::Button("quick_load",  touchcontrols::RectF(20,0,22,2),    "load",     KEY_QUICK_LOAD,false,true));
412
        tcGameMain->addControl(new touchcontrols::Button("map",         touchcontrols::RectF(4,0,6,2),      "map",      gamefunc_Map,       false,true));
425
        tcGameMain->addControl(new touchcontrols::Button("map",         touchcontrols::RectF(4,0,6,2),      "map",      gamefunc_Map,       false,true));
413
        tcGameMain->addControl(new touchcontrols::Button("keyboard",    touchcontrols::RectF(8,0,10,2),     "keyboard", KEY_SHOW_KBRD,      false,true));
426
        tcGameMain->addControl(new touchcontrols::Button("keyboard",    touchcontrols::RectF(8,0,10,2),     "keyboard", KEY_SHOW_KBRD,      false,true));
414
427
415
        tcGameMain->addControl(new touchcontrols::Button("show_inventory",touchcontrols::RectF(2,0,4,2),    "inv",      KEY_SHOW_INVEN));
428
        tcGameMain->addControl(new touchcontrols::Button("show_inventory",touchcontrols::RectF(2,0,4,2),    "inv",      KEY_SHOW_INVEN));
416
429
417
        tcGameMain->addControl(new touchcontrols::Button("next_weapon", touchcontrols::RectF(0,3,3,5),      "next_weap",gamefunc_Next_Weapon));
430
        tcGameMain->addControl(new touchcontrols::Button("next_weapon", touchcontrols::RectF(0,3,3,5),      "next_weap",gamefunc_Next_Weapon,false,true));
418
        tcGameMain->addControl(new touchcontrols::Button("prev_weapon", touchcontrols::RectF(0,7,3,9),      "prev_weap",gamefunc_Previous_Weapon));
431
        tcGameMain->addControl(new touchcontrols::Button("prev_weapon", touchcontrols::RectF(0,5,3,7),      "prev_weap",gamefunc_Previous_Weapon,false,true));
419
        /*
432
        /*
420
                //quick actions binds
433
                //quick actions binds
421
                tcGameMain->addControl(new touchcontrols::Button("quick_key_1",touchcontrols::RectF(4,3,6,5),"quick_key_1",KEY_QUICK_KEY1,false,true));
434
                tcGameMain->addControl(new touchcontrols::Button("quick_key_1",touchcontrols::RectF(4,3,6,5),"quick_key_1",KEY_QUICK_KEY1,false,true));
422
                tcGameMain->addControl(new touchcontrols::Button("quick_key_2",touchcontrols::RectF(6,3,8,5),"quick_key_2",KEY_QUICK_KEY2,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));
423
                tcGameMain->addControl(new touchcontrols::Button("quick_key_3",touchcontrols::RectF(8,3,10,5),"quick_key_3",KEY_QUICK_KEY3,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));
Line 477... Line 490...
477
        LOGI("NOT creating controls");
490
        LOGI("NOT creating controls");
478
491
479
    //controlsContainer.initGL();
492
    //controlsContainer.initGL();
480
}
493
}
481
494
-
 
495
-
 
496
#ifdef GP_LIC
-
 
497
#define GP_LIC_INC 1
-
 
498
#include "s-setup/gp_lic_include.h"
-
 
499
#endif
-
 
500
482
void frameControls()
501
void frameControls()
483
{
502
{
484
    static int loadedGLImages = 0;
503
    static int loadedGLImages = 0;
485
    static int inMenuLast = 1;
504
    static int inMenuLast = 1;
486
    static int inAutomapLast = 0;
505
    static int inAutomapLast = 0;
Line 531... Line 550...
531
        }
550
        }
532
    }
551
    }
533
552
534
    setHideSticks(!showSticks);
553
    setHideSticks(!showSticks);
535
    controlsContainer.draw();
554
    controlsContainer.draw();
-
 
555
-
 
556
#ifdef GP_LIC
-
 
557
#define GP_LIC_INC 2
-
 
558
#include "s-setup/gp_lic_include.h"
-
 
559
#endif
-
 
560
536
}
561
}
537
562
538
void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,int other)
563
void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,int other)
539
{
564
{
540
    gameControlsAlpha = MINCONTROLALPHA + (alpha * (1.0f - MINCONTROLALPHA));
565
    gameControlsAlpha = MINCONTROLALPHA + (alpha * (1.0f - MINCONTROLALPHA));
Line 603... Line 628...
603
Java_com_beloko_duke_engine_NativeLib_init( JNIEnv* env,
628
Java_com_beloko_duke_engine_NativeLib_init( JNIEnv* env,
604
        jobject thiz,jstring graphics_dir,jint audio_rate,jint audio_buffer_size,jobjectArray argsArray,jint renderer,jstring doom_path_ )
629
        jobject thiz,jstring graphics_dir,jint audio_rate,jint audio_buffer_size,jobjectArray argsArray,jint renderer,jstring doom_path_ )
605
{
630
{
606
    env_ = env;
631
    env_ = env;
607
632
-
 
633
#ifdef GP_LIC
-
 
634
        getGlobalClasses(env_);
-
 
635
#endif
-
 
636
608
    droidinfo.audio_sample_rate = audio_rate;
637
    droidinfo.audio_sample_rate = audio_rate;
609
    droidinfo.audio_buffer_size = audio_buffer_size;
638
    droidinfo.audio_buffer_size = audio_buffer_size;
610
639
611
    curRenderer = renderer;
640
    curRenderer = renderer;
612
    //curRenderer = REND_SOFT;
641
    //curRenderer = REND_SOFT;
Line 696... Line 725...
696
}
725
}
697
726
698
727
699
void EXPORT_ME
728
void EXPORT_ME
700
Java_com_beloko_duke_engine_NativeLib_touchEvent(JNIEnv *env, jobject obj,
729
Java_com_beloko_duke_engine_NativeLib_touchEvent(JNIEnv *env, jobject obj,
701
        jint action, jint pid, jfloat x, jfloat y)
730
        jint action, jint pid, jdouble x, jdouble y)
702
{
731
{
703
    //LOGI("TOUCHED");
732
    //LOGI("TOUCHED");
704
    controlsContainer.processPointer(action,pid,x,y);
733
    controlsContainer.processPointer(action,pid,x,y);
705
}
734
}
706
735
Line 724... Line 753...
724
}
753
}
725
754
726
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogFwd(JNIEnv *env, jobject obj,
755
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogFwd(JNIEnv *env, jobject obj,
727
        jfloat v)
756
        jfloat v)
728
{
757
{
729
    PortableMove(v, 0.f);
758
    PortableMove(v, NAN);
730
}
759
}
731
760
732
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogSide(JNIEnv *env, jobject obj,
761
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogSide(JNIEnv *env, jobject obj,
733
        jfloat v)
762
        jfloat v)
734
{
763
{
735
    PortableMove(0.f, v);
764
    PortableMove(NAN, v);
736
}
765
}
737
766
738
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogPitch(JNIEnv *env, jobject obj,
767
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogPitch(JNIEnv *env, jobject obj,
739
        jint mode,jfloat v)
768
        jint mode,jfloat v)
740
{
769
{
741
    PortableLook(0.f, v);
770
    PortableLookJoystick(NAN, v);
742
}
771
}
743
772
744
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogYaw(JNIEnv *env, jobject obj,
773
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogYaw(JNIEnv *env, jobject obj,
745
        jint mode,jfloat v)
774
        jint mode,jfloat v)
746
{
775
{
747
    PortableLook(v, 0.f);
776
    PortableLookJoystick(v, NAN);
748
}
777
}
749
778
750
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_setTouchSettings(JNIEnv *env, jobject obj,
779
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_setTouchSettings(JNIEnv *env, jobject obj,
751
        jfloat alpha,jfloat strafe,jfloat fwd,jfloat pitch,jfloat yaw,int other)
780
        jfloat alpha,jfloat strafe,jfloat fwd,jfloat pitch,jfloat yaw,int other)
752
{
781
{
Line 783... Line 812...
783
    SDL_Android_Init(env, cls);
812
    SDL_Android_Init(env, cls);
784
    SDL_SetMainReady();
813
    SDL_SetMainReady();
785
    // SDL_EventState(SDL_TEXTINPUT,SDL_ENABLE);
814
    // SDL_EventState(SDL_TEXTINPUT,SDL_ENABLE);
786
}
815
}
787
816
-
 
817
#ifdef GP_LIC
-
 
818
#define GP_LIC_INC 3
-
 
819
#include "s-setup/gp_lic_include.h"
-
 
820
#endif
788
}
821
}