Subversion Repositories eduke32

Rev

Rev 4439 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4386 terminx 1
#include "sdl_inc.h"
2
#include "baselayer.h"
3
#include "keys.h"
4
#include "duke3d.h"
5
#include "common_game.h"
6
#include "osd.h"
7
#include "player.h"
4433 terminx 8
#include "game.h"
9
#include "build.h"
4386 terminx 10
 
11
#include "jmact/keyboard.h"
12
#include "jmact/control.h"
13
 
4433 terminx 14
#include "../src/video/android/SDL_androidkeyboard.h" // FIXME: include header locally if necessary
4386 terminx 15
 
16
#include "in_android.h"
17
 
18
#include <android/log.h>
19
 
20
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__))
21
 
4433 terminx 22
extern int32_t main(int32_t argc, char *argv []);
4386 terminx 23
 
24
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
25
extern int SDL_SendKeyboardText(const char *text);
26
 
4433 terminx 27
static char sdl_text[2];
4386 terminx 28
 
4439 terminx 29
droidinput_t droidinput;
4434 terminx 30
 
4433 terminx 31
int PortableKeyEvent(int state, int code,int unicode)
32
{
4434 terminx 33
    LOGI("PortableKeyEvent %d %d %d",state,code,unicode);
4386 terminx 34
 
4433 terminx 35
    SDL_SendKeyboardKey(state ? SDL_PRESSED : SDL_RELEASED, code);
4434 terminx 36
    SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
4386 terminx 37
 
4434 terminx 38
    if (code == 42)
39
        unicode = 42;
4386 terminx 40
 
4434 terminx 41
    if (state)
42
    {
43
        //if (unicode < 128)
44
        {
45
            sdl_text[0] = unicode;
46
            sdl_text[1] = 0;
4386 terminx 47
 
4434 terminx 48
            int posted = SDL_SendKeyboardText((const char*)sdl_text);
49
            LOGI("posted = %d",posted);
50
        }
4386 terminx 51
 
4434 terminx 52
        if (state == 2)
53
            PortableKeyEvent(0, code, unicode);
54
    }
4386 terminx 55
 
4434 terminx 56
    return 0;
4386 terminx 57
}
58
 
59
void changeActionState(int state, int action)
60
{
4434 terminx 61
    if (state)
62
    {
63
        //BUTTONSET(action,1);
64
        droidinput.functionSticky  |= ((uint64_t)1<<((uint64_t)(action)));
65
        droidinput.functionHeld    |= ((uint64_t)1<<((uint64_t)(action)));
4433 terminx 66
        return;
67
    }
68
 
69
    //BUTTONCLEAR(action);
4434 terminx 70
    droidinput.functionHeld  &= ~((uint64_t) 1<<((uint64_t) (action)));
4386 terminx 71
}
72
 
4440 terminx 73
#ifdef GP_LIC
74
#define GP_LIC_INC 4
75
#include "s-setup/gp_lic_include.h"
76
#endif
77
 
4386 terminx 78
void PortableAction(int state, int action)
79
{
4434 terminx 80
    LOGI("PortableAction action = %d, state = %d", action, state);
4386 terminx 81
 
4436 terminx 82
    if (action >= MENU_UP && action <= MENU_BACK)
4434 terminx 83
    {
84
        if (PortableRead(READ_MENU))
85
        {
4436 terminx 86
            int sdl_code [] = { SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT,
4440 terminx 87
                    SDL_SCANCODE_RIGHT, SDL_SCANCODE_RETURN, SDL_SCANCODE_ESCAPE };
4436 terminx 88
            PortableKeyEvent(state, sdl_code[action-MENU_UP], 0);
4434 terminx 89
            return;
90
        }
91
    }
92
    else
4433 terminx 93
    {
4434 terminx 94
        if (PortableRead(READ_MENU)) //If in the menu, dont do any game actions
95
            return;
4433 terminx 96
 
4440 terminx 97
#ifdef GP_LIC
98
#define GP_LIC_INC 5
99
#include "s-setup/gp_lic_include.h"
100
#endif
101
 
4434 terminx 102
        //Special toggle for crouch, NOT when using jetpack or in water
103
        if (!g_player[myconnectindex].ps->jetpack_on &&
104
                g_player[myconnectindex].ps->on_ground &&
105
                (sector[g_player[myconnectindex].ps->cursectnum].lotag != ST_2_UNDERWATER))
106
        {
107
            if (toggleCrouch)
108
            {
109
                if (action == gamefunc_Crouch)
110
                {
111
                    if (state)
112
                        droidinput.crouchToggleState = !droidinput.crouchToggleState;
4386 terminx 113
 
4434 terminx 114
                    state = droidinput.crouchToggleState;
115
                }
116
            }
117
        }
4386 terminx 118
 
4434 terminx 119
        //Check if jumping while crouched
120
        if (action == gamefunc_Jump)
121
        {
4440 terminx 122
            droidinput.crouchToggleState = 0;
4434 terminx 123
            changeActionState(0, gamefunc_Crouch);
124
        }
4386 terminx 125
 
4434 terminx 126
        changeActionState(state, action);
127
 
4440 terminx 128
        if (state == 2)
129
            PortableAction(0,action);
130
 
131
        // LOGI("PortableAction state = 0x%016llX", CONTROL_ButtonState);
4434 terminx 132
    }
4386 terminx 133
}
134
 
4440 terminx 135
//Need these NAN check as not cumulative.
4386 terminx 136
void PortableMove(float fwd, float strafe)
137
{
4440 terminx 138
    if (!isnan(fwd))
139
        droidinput.forwardmove = fclamp2(fwd, -1.f, 1.f);
140
 
141
    if (!isnan(strafe))
142
        droidinput.sidemove    = fclamp2(strafe,    -1.f, 1.f);
4386 terminx 143
}
144
 
4434 terminx 145
void PortableLook(double yaw, double pitch)
4386 terminx 146
{
4440 terminx 147
    // LOGI("PortableLookPitch %f %f",yaw, pitch);
4434 terminx 148
    droidinput.pitch += pitch;
149
    droidinput.yaw   += yaw;
4386 terminx 150
}
151
 
4440 terminx 152
void PortableLookJoystick(double yaw, double pitch)
153
{
154
    if (!isnan(pitch))
155
        droidinput.pitch_joystick = pitch;
156
 
157
    if (!isnan(yaw))
158
        droidinput.yaw_joystick   = yaw;
159
}
160
 
4433 terminx 161
void PortableCommand(const char * cmd)
162
{
163
    OSD_Dispatch(cmd);
4386 terminx 164
}
165
 
4436 terminx 166
void PortableInit(int argc, const char ** argv)
4386 terminx 167
{
4439 terminx 168
    droidinput.left_double_action = -1;
169
    droidinput.right_double_action = -1;
170
 
4434 terminx 171
    main(argc, argv);
4386 terminx 172
}
173
 
4433 terminx 174
int32_t PortableRead(portableread_t r)
4386 terminx 175
{
4433 terminx 176
    switch (r)
177
    {
178
    case READ_MENU:
179
        return (g_player[myconnectindex].ps->gm & MODE_MENU) == MODE_MENU || (g_player[myconnectindex].ps->gm & MODE_GAME) != MODE_GAME;
180
    case READ_WEAPONS:
181
        return g_player[myconnectindex].ps->gotweapon;
182
    case READ_AUTOMAP:
4440 terminx 183
        return ud.overhead_on != 0; // ud.overhead_on ranges from 0-2
4436 terminx 184
    case READ_MAPFOLLOWMODE:
185
        return ud.scrollmode;
4433 terminx 186
    case READ_RENDERER:
187
        return getrendermode();
188
    case READ_LASTWEAPON:
4434 terminx 189
        return droidinput.lastWeapon;
4433 terminx 190
    case READ_PAUSED:
191
        return ud.pause_on != 0;
192
    default:
193
        return 0;
194
    }
4386 terminx 195
}
196
 
197
///This stuff is called from the game/engine
198
 
4433 terminx 199
void CONTROL_Android_SetLastWeapon(int w)
4386 terminx 200
{
4434 terminx 201
    LOGI("setLastWeapon %d",w);
202
    droidinput.lastWeapon = w;
4386 terminx 203
}
204
 
205
void CONTROL_Android_ClearButton(int32_t whichbutton)
206
{
4434 terminx 207
    BUTTONCLEAR(whichbutton);
208
    droidinput.functionHeld  &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
4386 terminx 209
}
210
 
4436 terminx 211
void CONTROL_Android_PollDevices(ControlInfo *info)
4386 terminx 212
{
4434 terminx 213
    //LOGI("CONTROL_Android_PollDevices %f %f",forwardmove,sidemove);
4440 terminx 214
    //LOGI("CONTROL_Android_PollDevices %f %f",droidinput.pitch,droidinput.yaw);
4386 terminx 215
 
4439 terminx 216
    info->dz     = (int32_t)nearbyintf(-droidinput.forwardmove * ANDROIDFORWARDMOVEFACTOR);
217
    info->dx     = (int32_t)nearbyintf(droidinput.sidemove * ANDROIDSIDEMOVEFACTOR);
4440 terminx 218
    info->dpitch = (int32_t)nearbyint(droidinput.pitch * ANDROIDPITCHFACTOR +
219
            droidinput.pitch_joystick * ANDROIDPITCHFACTORJOYSTICK);
220
    info->dyaw   = (int32_t)nearbyint(-droidinput.yaw * ANDROIDYAWFACTOR -
221
            droidinput.yaw_joystick * ANDROIDYAWFACTORJOYSTICK);
4386 terminx 222
 
4440 terminx 223
    //droidinput.forwardmove = droidinput.sidemove = 0.f;
4434 terminx 224
    droidinput.pitch = droidinput.yaw = 0.f;
4386 terminx 225
 
4434 terminx 226
    CONTROL_ButtonState = 0;
227
    CONTROL_ButtonState |= droidinput.functionSticky;
228
    CONTROL_ButtonState |= droidinput.functionHeld;
4386 terminx 229
 
4434 terminx 230
    droidinput.functionSticky = 0;
4386 terminx 231
 
4434 terminx 232
    //LOGI("poll state = 0x%016llX",CONTROL_ButtonState);
4386 terminx 233
}
234
 
235