Subversion Repositories eduke32

Rev

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

Rev 5000 Rev 5066
Line 18... Line 18...
18
#include "menus.h"
18
#include "menus.h"
19
19
20
#ifdef __cplusplus
20
#ifdef __cplusplus
21
extern "C" {
21
extern "C" {
22
#endif
22
#endif
23
// #include "../src/video/android/SDL_androidkeyboard.h" // FIXME: include header locally if necessary
-
 
24
//#include "../src/events/SDL_mouse_c.h"
-
 
25
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
23
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
26
extern int SDL_SendKeyboardText(const char *text);
24
extern int SDL_SendKeyboardText(const char *text);
27
extern int SDL_SendMouseMotion(SDL_Window * window, Uint32 mouseID, int relative, int x, int y);
25
extern int SDL_SendMouseMotion(SDL_Window * window, Uint32 mouseID, int relative, int x, int y);
28
extern int SDL_SendMouseButton(SDL_Window * window, Uint32 mouseID, Uint8 state, Uint8 button);
26
extern int SDL_SendMouseButton(SDL_Window * window, Uint32 mouseID, Uint8 state, Uint8 button);
29
27
Line 169... Line 167...
169
167
170
        // LOGI("PortableAction state = 0x%016llX", CONTROL_ButtonState);
168
        // LOGI("PortableAction state = 0x%016llX", CONTROL_ButtonState);
171
    }
169
    }
172
}
170
}
173
171
-
 
172
int const deadRegion = 0.3;
-
 
173
-
 
174
float analogCalibrate(float v)
-
 
175
{
-
 
176
    float rv = 0;
-
 
177
-
 
178
    if (v > deadRegion) rv = (v - deadRegion) * (v - deadRegion);
-
 
179
    else if (-v > deadRegion) rv = -(-v - deadRegion) * (-v - deadRegion);
-
 
180
-
 
181
    return rv;
-
 
182
}
-
 
183
174
//Need these NAN check as not cumulative.
184
//Need these NAN check as not cumulative.
175
void PortableMove(float fwd, float strafe)
185
void PortableMove(float fwd, float strafe)
176
{
186
{
177
    if (!ud.auto_run)
187
    if (!ud.auto_run)
178
    {
188
    {
179
        fwd *= 0.5f;
189
        fwd *= 0.5f;
180
        strafe *= 0.5f;
190
        strafe *= 0.5f;
181
    }
191
    }
182
192
183
    if (!isnan(fwd))
193
    if (!isnan(fwd))
184
        droidinput.forwardmove = fclamp2(fwd, -1.f, 1.f);
194
        droidinput.forwardmove = fclamp2(analogCalibrate(fwd), -1.f, 1.f);
185
195
186
    if (!isnan(strafe))
196
    if (!isnan(strafe))
187
        droidinput.sidemove    = fclamp2(strafe,    -1.f, 1.f);
197
        droidinput.sidemove    = fclamp2(analogCalibrate(strafe),    -1.f, 1.f);
188
}
198
}
189
199
190
void PortableLook(double yaw, double pitch)
200
void PortableLook(float yaw, float pitch)
191
{
201
{
192
    // LOGI("PortableLookPitch %f %f",yaw, pitch);
-
 
193
    droidinput.pitch += pitch;
202
    droidinput.pitch += pitch;
194
    droidinput.yaw   += yaw;
203
    droidinput.yaw   += yaw;
195
}
204
}
196
205
197
void PortableLookJoystick(double yaw, double pitch)
206
void PortableLookJoystick(float yaw, float pitch)
198
{
207
{
199
    if (!isnan(pitch))
208
    if (!isnan(pitch))
200
        droidinput.pitch_joystick = pitch;
209
        droidinput.pitch_joystick = analogCalibrate(pitch);
201
210
202
    if (!isnan(yaw))
211
    if (!isnan(yaw))
203
        droidinput.yaw_joystick   = yaw;
212
        droidinput.yaw_joystick   = analogCalibrate(yaw);
204
}
213
}
205
214
206
void PortableCommand(const char * cmd)
215
void PortableCommand(const char * cmd)
207
{
216
{
208
    OSD_Dispatch(cmd);
217
    OSD_Dispatch(cmd);
Line 231... Line 240...
231
            rv = TOUCH_SCREEN_BLANK_TAP;
240
            rv = TOUCH_SCREEN_BLANK_TAP;
232
        else if (consoleShown)
241
        else if (consoleShown)
233
            rv = TOUCH_SCREEN_CONSOLE;
242
            rv = TOUCH_SCREEN_CONSOLE;
234
        else if ((g_player[myconnectindex].ps->gm & MODE_MENU) == MODE_MENU)
243
        else if ((g_player[myconnectindex].ps->gm & MODE_MENU) == MODE_MENU)
235
            rv = (m_currentMenu->type == Verify) ? TOUCH_SCREEN_YES_NO : TOUCH_SCREEN_MENU;
244
            rv = (m_currentMenu->type == Verify) ? TOUCH_SCREEN_YES_NO : TOUCH_SCREEN_MENU;
-
 
245
/*
236
        else if (ud.overhead_on == 2)
246
        else if (ud.overhead_on == 2)
237
            rv = TOUCH_SCREEN_AUTOMAP;
247
            rv = TOUCH_SCREEN_AUTOMAP;
-
 
248
*/
238
        else if ((g_player[myconnectindex].ps->gm & MODE_GAME))
249
        else if ((g_player[myconnectindex].ps->gm & MODE_GAME))
239
            if (PortableRead(READ_IS_DEAD))
250
            if (PortableRead(READ_IS_DEAD))
240
                rv = TOUCH_SCREEN_BLANK_TAP;
251
                rv = TOUCH_SCREEN_BLANK_TAP;
241
            else
252
            else
242
                rv = TOUCH_SCREEN_GAME;
253
                rv = TOUCH_SCREEN_GAME;
Line 244... Line 255...
244
            rv = TOUCH_SCREEN_BLANK_TAP;
255
            rv = TOUCH_SCREEN_BLANK_TAP;
245
         break;
256
         break;
246
    case READ_WEAPONS:
257
    case READ_WEAPONS:
247
        rv = g_player[myconnectindex].ps->gotweapon; break;
258
        rv = g_player[myconnectindex].ps->gotweapon; break;
248
    case READ_AUTOMAP:
259
    case READ_AUTOMAP:
249
        rv = ud.overhead_on != 0;  break;// ud.overhead_on ranges from 0-2
260
        rv = 0; break;//ud.overhead_on != 0;  break;// ud.overhead_on ranges from 0-2
250
    case READ_MAPFOLLOWMODE:
261
    case READ_MAPFOLLOWMODE:
251
        rv = ud.scrollmode; break;
262
        rv = ud.scrollmode; break;
252
    case READ_RENDERER:
263
    case READ_RENDERER:
253
        rv = getrendermode(); break;
264
        rv = getrendermode(); break;
254
    case READ_LASTWEAPON:
265
    case READ_LASTWEAPON:
Line 300... Line 311...
300
    map_dx = map_dy = map_zoom = 0;
311
    map_dx = map_dy = map_zoom = 0;
301
}
312
}
302
313
303
void CONTROL_Android_SetLastWeapon(int w)
314
void CONTROL_Android_SetLastWeapon(int w)
304
{
315
{
305
    LOGI("setLastWeapon %d",w);
-
 
306
    droidinput.lastWeapon = w;
316
    droidinput.lastWeapon = w;
307
}
317
}
308
318
309
void CONTROL_Android_ClearButton(int32_t whichbutton)
319
void CONTROL_Android_ClearButton(int32_t whichbutton)
310
{
320
{
311
    BUTTONCLEAR(whichbutton);
321
    BUTTONCLEAR(whichbutton);
312
    droidinput.functionHeld  &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
322
    droidinput.functionHeld  &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
313
}
323
}
314
324
315
int clearCtrl=1;
-
 
316
void CONTROL_Android_PollDevices(ControlInfo *info)
325
void CONTROL_Android_PollDevices(ControlInfo *info)
317
{
326
{
318
    //LOGI("CONTROL_Android_PollDevices %f %f",forwardmove,sidemove);
327
    //LOGI("CONTROL_Android_PollDevices %f %f",forwardmove,sidemove);
319
    //LOGI("CONTROL_Android_PollDevices %f %f",droidinput.pitch,droidinput.yaw);
328
    //LOGI("CONTROL_Android_PollDevices %f %f",droidinput.pitch,droidinput.yaw);
320
329
321
    info->dz     = (int32_t)nearbyintf(-droidinput.forwardmove * ANDROIDFORWARDMOVEFACTOR);
330
    info->dz = (int32_t)nearbyintf(-droidinput.forwardmove * ANDROIDMOVEFACTOR);
322
    info->dx     = (int32_t)nearbyintf(droidinput.sidemove * ANDROIDSIDEMOVEFACTOR);
331
    info->dx = (int32_t)nearbyintf(droidinput.sidemove * ANDROIDMOVEFACTOR) >> 5;
323
    info->dpitch = (int32_t)nearbyint(droidinput.pitch * ANDROIDPITCHFACTOR +
332
    info->dpitch =
324
            droidinput.pitch_joystick * ANDROIDPITCHFACTORJOYSTICK);
333
    (int32_t)nearbyint(droidinput.pitch * ANDROIDLOOKFACTOR + droidinput.pitch_joystick * ANDROIDPITCHFACTORJOYSTICK);
325
    info->dyaw   = (int32_t)nearbyint(-droidinput.yaw * ANDROIDYAWFACTOR -
334
    info->dyaw =
326
            droidinput.yaw_joystick * ANDROIDYAWFACTORJOYSTICK);
335
    (int32_t)nearbyint(-droidinput.yaw * ANDROIDLOOKFACTOR - droidinput.yaw_joystick * ANDROIDYAWFACTORJOYSTICK);
327
-
 
328
    /*
-
 
329
    if (clearCtrl == 0)
-
 
330
        clearCtrl = 1;
-
 
331

-
 
332
    LOGI("ctrl = %d",clearCtrl);
-
 
333
    info->dpitch *= clearCtrl;
-
 
334
    info->dyaw  *= clearCtrl;
-
 
335
     */
-
 
336
336
337
    droidinput.pitch = droidinput.yaw = 0.f;
337
    droidinput.pitch = droidinput.yaw = 0.f;
338
-
 
339
    clearCtrl = 0;
-
 
340
-
 
341
    CONTROL_ButtonState = 0;
-
 
342
    CONTROL_ButtonState |= droidinput.functionSticky;
338
    CONTROL_ButtonState = droidinput.functionSticky | droidinput.functionHeld;
343
    CONTROL_ButtonState |= droidinput.functionHeld;
-
 
344
-
 
345
    droidinput.functionSticky = 0;
339
    droidinput.functionSticky = 0;
346
340
347
    //LOGI("poll state = 0x%016llX",CONTROL_ButtonState);
341
    //LOGI("poll state = 0x%016llX",CONTROL_ButtonState);
348
}
342
}
349
343