2014-03-22 09:25:51 +00:00
|
|
|
#include "sdl_inc.h"
|
|
|
|
#include "baselayer.h"
|
|
|
|
#include "keys.h"
|
|
|
|
#include "duke3d.h"
|
|
|
|
#include "common_game.h"
|
|
|
|
#include "osd.h"
|
|
|
|
#include "player.h"
|
2014-04-12 08:45:50 +00:00
|
|
|
#include "game.h"
|
|
|
|
#include "build.h"
|
2014-03-22 09:25:51 +00:00
|
|
|
|
|
|
|
#include "jmact/keyboard.h"
|
|
|
|
#include "jmact/control.h"
|
|
|
|
|
2014-07-06 00:10:33 +00:00
|
|
|
#include "menus.h"
|
|
|
|
|
2014-04-12 08:45:50 +00:00
|
|
|
#include "../src/video/android/SDL_androidkeyboard.h" // FIXME: include header locally if necessary
|
2014-03-22 09:25:51 +00:00
|
|
|
|
|
|
|
#include "in_android.h"
|
|
|
|
|
|
|
|
#include <android/log.h>
|
|
|
|
|
|
|
|
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__))
|
|
|
|
|
2014-04-12 08:45:50 +00:00
|
|
|
extern int32_t main(int32_t argc, char *argv []);
|
|
|
|
|
2014-03-22 09:25:51 +00:00
|
|
|
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
|
|
|
|
extern int SDL_SendKeyboardText(const char *text);
|
|
|
|
|
2014-04-12 08:45:50 +00:00
|
|
|
static char sdl_text[2];
|
2014-03-22 09:25:51 +00:00
|
|
|
|
2014-04-14 16:30:23 +00:00
|
|
|
droidinput_t droidinput;
|
2014-04-12 22:10:36 +00:00
|
|
|
|
2014-04-12 08:45:50 +00:00
|
|
|
int PortableKeyEvent(int state, int code,int unicode)
|
|
|
|
{
|
2014-04-12 22:10:36 +00:00
|
|
|
LOGI("PortableKeyEvent %d %d %d",state,code,unicode);
|
2014-03-22 09:25:51 +00:00
|
|
|
|
2014-04-12 08:45:50 +00:00
|
|
|
SDL_SendKeyboardKey(state ? SDL_PRESSED : SDL_RELEASED, code);
|
2014-04-12 22:10:36 +00:00
|
|
|
SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
|
2014-03-22 09:25:51 +00:00
|
|
|
|
2014-10-29 17:03:50 +00:00
|
|
|
// if (code == 42)
|
|
|
|
// unicode = 42;
|
2014-03-22 09:25:51 +00:00
|
|
|
|
2014-04-12 22:10:36 +00:00
|
|
|
if (state)
|
|
|
|
{
|
|
|
|
//if (unicode < 128)
|
|
|
|
{
|
|
|
|
sdl_text[0] = unicode;
|
|
|
|
sdl_text[1] = 0;
|
2014-03-22 09:25:51 +00:00
|
|
|
|
2014-04-12 22:10:36 +00:00
|
|
|
int posted = SDL_SendKeyboardText((const char*)sdl_text);
|
|
|
|
LOGI("posted = %d",posted);
|
|
|
|
}
|
2014-03-22 09:25:51 +00:00
|
|
|
|
2014-04-12 22:10:36 +00:00
|
|
|
if (state == 2)
|
|
|
|
PortableKeyEvent(0, code, unicode);
|
|
|
|
}
|
2014-03-22 09:25:51 +00:00
|
|
|
|
2014-04-12 22:10:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-03-22 09:25:51 +00:00
|
|
|
|
|
|
|
void changeActionState(int state, int action)
|
|
|
|
{
|
2014-04-12 22:10:36 +00:00
|
|
|
if (state)
|
|
|
|
{
|
|
|
|
//BUTTONSET(action,1);
|
|
|
|
droidinput.functionSticky |= ((uint64_t)1<<((uint64_t)(action)));
|
|
|
|
droidinput.functionHeld |= ((uint64_t)1<<((uint64_t)(action)));
|
2014-04-12 08:45:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//BUTTONCLEAR(action);
|
2014-04-12 22:10:36 +00:00
|
|
|
droidinput.functionHeld &= ~((uint64_t) 1<<((uint64_t) (action)));
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 19:02:48 +00:00
|
|
|
#ifdef GP_LIC
|
|
|
|
#define GP_LIC_INC 4
|
|
|
|
#include "s-setup/gp_lic_include.h"
|
|
|
|
#endif
|
|
|
|
|
2014-03-22 09:25:51 +00:00
|
|
|
void PortableAction(int state, int action)
|
|
|
|
{
|
2014-04-12 22:10:36 +00:00
|
|
|
LOGI("PortableAction action = %d, state = %d", action, state);
|
2014-03-22 09:25:51 +00:00
|
|
|
|
2014-04-13 03:20:17 +00:00
|
|
|
if (action >= MENU_UP && action <= MENU_BACK)
|
2014-04-12 08:45:50 +00:00
|
|
|
{
|
2014-07-06 00:10:33 +00:00
|
|
|
if (PortableRead(READ_SCREEN_MODE) == TOUCH_SCREEN_MENU)
|
2014-04-12 22:10:36 +00:00
|
|
|
{
|
2014-04-13 03:20:17 +00:00
|
|
|
int sdl_code [] = { SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT,
|
2014-04-15 19:02:48 +00:00
|
|
|
SDL_SCANCODE_RIGHT, SDL_SCANCODE_RETURN, SDL_SCANCODE_ESCAPE };
|
2014-04-13 03:20:17 +00:00
|
|
|
PortableKeyEvent(state, sdl_code[action-MENU_UP], 0);
|
2014-04-12 22:10:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-06 00:10:33 +00:00
|
|
|
//if (PortableRead(READ_SCREEN_MODE) != TOUCH_SCREEN_GAME) //If not in game don't do any of this
|
2014-10-29 17:03:50 +00:00
|
|
|
/// return;
|
2014-04-12 22:10:36 +00:00
|
|
|
|
2014-04-15 19:02:48 +00:00
|
|
|
#ifdef GP_LIC
|
|
|
|
#define GP_LIC_INC 5
|
|
|
|
#include "s-setup/gp_lic_include.h"
|
|
|
|
#endif
|
|
|
|
|
2014-04-12 22:10:36 +00:00
|
|
|
//Special toggle for crouch, NOT when using jetpack or in water
|
|
|
|
if (!g_player[myconnectindex].ps->jetpack_on &&
|
|
|
|
g_player[myconnectindex].ps->on_ground &&
|
|
|
|
(sector[g_player[myconnectindex].ps->cursectnum].lotag != ST_2_UNDERWATER))
|
|
|
|
{
|
|
|
|
if (toggleCrouch)
|
|
|
|
{
|
|
|
|
if (action == gamefunc_Crouch)
|
|
|
|
{
|
|
|
|
if (state)
|
|
|
|
droidinput.crouchToggleState = !droidinput.crouchToggleState;
|
|
|
|
|
|
|
|
state = droidinput.crouchToggleState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check if jumping while crouched
|
|
|
|
if (action == gamefunc_Jump)
|
|
|
|
{
|
2014-04-15 19:02:48 +00:00
|
|
|
droidinput.crouchToggleState = 0;
|
2014-04-12 22:10:36 +00:00
|
|
|
changeActionState(0, gamefunc_Crouch);
|
|
|
|
}
|
|
|
|
|
|
|
|
changeActionState(state, action);
|
|
|
|
|
2014-04-15 19:02:48 +00:00
|
|
|
if (state == 2)
|
|
|
|
PortableAction(0,action);
|
|
|
|
|
|
|
|
// LOGI("PortableAction state = 0x%016llX", CONTROL_ButtonState);
|
2014-04-12 08:45:50 +00:00
|
|
|
}
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 19:02:48 +00:00
|
|
|
//Need these NAN check as not cumulative.
|
2014-03-22 09:25:51 +00:00
|
|
|
void PortableMove(float fwd, float strafe)
|
|
|
|
{
|
2014-04-15 19:02:48 +00:00
|
|
|
if (!isnan(fwd))
|
|
|
|
droidinput.forwardmove = fclamp2(fwd, -1.f, 1.f);
|
|
|
|
|
|
|
|
if (!isnan(strafe))
|
|
|
|
droidinput.sidemove = fclamp2(strafe, -1.f, 1.f);
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-04-12 22:10:36 +00:00
|
|
|
void PortableLook(double yaw, double pitch)
|
2014-03-22 09:25:51 +00:00
|
|
|
{
|
2014-04-15 19:02:48 +00:00
|
|
|
// LOGI("PortableLookPitch %f %f",yaw, pitch);
|
2014-04-12 22:10:36 +00:00
|
|
|
droidinput.pitch += pitch;
|
|
|
|
droidinput.yaw += yaw;
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 19:02:48 +00:00
|
|
|
void PortableLookJoystick(double yaw, double pitch)
|
|
|
|
{
|
|
|
|
if (!isnan(pitch))
|
|
|
|
droidinput.pitch_joystick = pitch;
|
|
|
|
|
|
|
|
if (!isnan(yaw))
|
|
|
|
droidinput.yaw_joystick = yaw;
|
|
|
|
}
|
|
|
|
|
2014-04-12 08:45:50 +00:00
|
|
|
void PortableCommand(const char * cmd)
|
2014-03-22 09:25:51 +00:00
|
|
|
{
|
2014-04-12 08:45:50 +00:00
|
|
|
OSD_Dispatch(cmd);
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-04-13 03:20:17 +00:00
|
|
|
void PortableInit(int argc, const char ** argv)
|
2014-03-22 09:25:51 +00:00
|
|
|
{
|
2014-07-06 00:10:33 +00:00
|
|
|
//droidinput.left_double_action = -1;
|
|
|
|
//droidinput.right_double_action = -1;
|
2014-04-14 16:30:23 +00:00
|
|
|
|
2014-04-12 22:10:36 +00:00
|
|
|
main(argc, argv);
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 17:03:50 +00:00
|
|
|
int consoleShown = 0;
|
|
|
|
void AndroidSetConsoleShown(int onf)
|
|
|
|
{
|
|
|
|
consoleShown = onf;
|
|
|
|
}
|
2014-07-06 00:10:33 +00:00
|
|
|
|
|
|
|
extern int animation_playing;
|
2014-10-29 17:03:50 +00:00
|
|
|
extern int inExtraScreens; //In game.c
|
2014-04-12 08:45:50 +00:00
|
|
|
int32_t PortableRead(portableread_t r)
|
2014-03-22 09:25:51 +00:00
|
|
|
{
|
2014-04-12 08:45:50 +00:00
|
|
|
switch (r)
|
|
|
|
{
|
2014-07-06 00:10:33 +00:00
|
|
|
case READ_SCREEN_MODE:
|
|
|
|
|
|
|
|
if (animation_playing)
|
|
|
|
return TOUCH_SCREEN_BLANK_TAP;
|
2014-10-29 17:03:50 +00:00
|
|
|
else if (inExtraScreens)
|
|
|
|
return TOUCH_SCREEN_BLANK_TAP;
|
|
|
|
else if (consoleShown)
|
|
|
|
return TOUCH_SCREEN_CONSOLE;
|
2014-07-06 00:10:33 +00:00
|
|
|
else if ((g_player[myconnectindex].ps->gm & MODE_MENU) == MODE_MENU)
|
|
|
|
{
|
|
|
|
//Then check if Yes/No menu
|
|
|
|
if ((g_currentMenu == MENU_QUITTOTITLE) ||
|
|
|
|
(g_currentMenu == MENU_RESETPLAYER ) ||
|
2014-10-29 17:03:50 +00:00
|
|
|
((g_currentMenu == MENU_LOADVERIFY )) ||
|
2014-07-06 00:10:33 +00:00
|
|
|
(g_currentMenu == MENU_NEWVERIFY ) ||
|
2014-10-29 17:03:50 +00:00
|
|
|
((g_currentMenu == MENU_SAVEVERIFY )) ||
|
2014-07-06 00:10:33 +00:00
|
|
|
(g_currentMenu == MENU_QUIT ) ||
|
|
|
|
(g_currentMenu == MENU_QUITTOTITLE )
|
|
|
|
)
|
|
|
|
return TOUCH_SCREEN_YES_NO;
|
|
|
|
else
|
|
|
|
return TOUCH_SCREEN_MENU;
|
|
|
|
}
|
2014-10-29 17:03:50 +00:00
|
|
|
else if (ud.overhead_on == 2)
|
|
|
|
return TOUCH_SCREEN_AUTOMAP;
|
2014-07-06 00:10:33 +00:00
|
|
|
else if ((g_player[myconnectindex].ps->gm & MODE_GAME))
|
2014-10-29 17:03:50 +00:00
|
|
|
if (PortableRead(READ_IS_DEAD))
|
|
|
|
return TOUCH_SCREEN_BLANK_TAP;
|
|
|
|
else
|
|
|
|
return TOUCH_SCREEN_GAME;
|
2014-07-06 00:10:33 +00:00
|
|
|
else
|
|
|
|
return TOUCH_SCREEN_BLANK_TAP;
|
|
|
|
|
2014-04-12 08:45:50 +00:00
|
|
|
case READ_WEAPONS:
|
|
|
|
return g_player[myconnectindex].ps->gotweapon;
|
|
|
|
case READ_AUTOMAP:
|
2014-04-15 19:02:48 +00:00
|
|
|
return ud.overhead_on != 0; // ud.overhead_on ranges from 0-2
|
2014-04-13 03:20:17 +00:00
|
|
|
case READ_MAPFOLLOWMODE:
|
|
|
|
return ud.scrollmode;
|
2014-04-12 08:45:50 +00:00
|
|
|
case READ_RENDERER:
|
|
|
|
return getrendermode();
|
|
|
|
case READ_LASTWEAPON:
|
2014-04-12 22:10:36 +00:00
|
|
|
return droidinput.lastWeapon;
|
2014-04-12 08:45:50 +00:00
|
|
|
case READ_PAUSED:
|
|
|
|
return ud.pause_on != 0;
|
2014-10-29 17:03:50 +00:00
|
|
|
case READ_IS_DEAD:
|
|
|
|
return g_player[myconnectindex].ps->dead_flag;
|
2014-04-12 08:45:50 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 17:03:50 +00:00
|
|
|
static float map_zoom,map_dx,map_dy = 0;
|
|
|
|
|
|
|
|
void PortableAutomapControl(float zoom,float dx,float dy)
|
|
|
|
{
|
|
|
|
map_zoom += zoom;
|
|
|
|
map_dx += dx;
|
|
|
|
map_dy += dy;
|
|
|
|
}
|
|
|
|
|
2014-03-22 09:25:51 +00:00
|
|
|
///This stuff is called from the game/engine
|
|
|
|
|
2014-10-29 17:03:50 +00:00
|
|
|
extern void CONTROL_Android_ScrollMap(int32_t *angle,int32_t *x, int32_t *y, uint16_t *zoom )
|
|
|
|
{
|
|
|
|
|
|
|
|
*x += ((int)(map_dx * -30000)*sintable[(512+2048-*angle)&2047])>>14;
|
|
|
|
*y += ((int)(map_dy * -30000)*sintable[(512+1024-512-*angle)&2047])>>14;
|
|
|
|
|
|
|
|
*zoom += map_zoom * 2000;
|
|
|
|
//*angle = 0;
|
|
|
|
map_dx = map_dy = map_zoom = 0;
|
|
|
|
}
|
|
|
|
|
2014-04-12 08:45:50 +00:00
|
|
|
void CONTROL_Android_SetLastWeapon(int w)
|
2014-03-22 09:25:51 +00:00
|
|
|
{
|
2014-04-12 22:10:36 +00:00
|
|
|
LOGI("setLastWeapon %d",w);
|
|
|
|
droidinput.lastWeapon = w;
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CONTROL_Android_ClearButton(int32_t whichbutton)
|
|
|
|
{
|
2014-04-12 22:10:36 +00:00
|
|
|
BUTTONCLEAR(whichbutton);
|
|
|
|
droidinput.functionHeld &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
2014-07-06 00:10:33 +00:00
|
|
|
int clearCtrl=1;
|
2014-04-13 03:20:17 +00:00
|
|
|
void CONTROL_Android_PollDevices(ControlInfo *info)
|
2014-03-22 09:25:51 +00:00
|
|
|
{
|
2014-04-12 22:10:36 +00:00
|
|
|
//LOGI("CONTROL_Android_PollDevices %f %f",forwardmove,sidemove);
|
2014-04-15 19:02:48 +00:00
|
|
|
//LOGI("CONTROL_Android_PollDevices %f %f",droidinput.pitch,droidinput.yaw);
|
2014-04-12 22:10:36 +00:00
|
|
|
|
2014-10-29 17:03:50 +00:00
|
|
|
info->dz = (int32_t)nearbyintf(-droidinput.forwardmove * ANDROIDFORWARDMOVEFACTOR);
|
|
|
|
info->dx = (int32_t)nearbyintf(droidinput.sidemove * ANDROIDSIDEMOVEFACTOR);
|
|
|
|
info->dpitch = (int32_t)nearbyint(droidinput.pitch * ANDROIDPITCHFACTOR +
|
2014-04-15 19:02:48 +00:00
|
|
|
droidinput.pitch_joystick * ANDROIDPITCHFACTORJOYSTICK);
|
2014-10-29 17:03:50 +00:00
|
|
|
info->dyaw = (int32_t)nearbyint(-droidinput.yaw * ANDROIDYAWFACTOR -
|
2014-04-15 19:02:48 +00:00
|
|
|
droidinput.yaw_joystick * ANDROIDYAWFACTORJOYSTICK);
|
2014-04-12 22:10:36 +00:00
|
|
|
|
2014-07-06 00:10:33 +00:00
|
|
|
/*
|
|
|
|
if (clearCtrl == 0)
|
|
|
|
clearCtrl = 1;
|
|
|
|
|
|
|
|
LOGI("ctrl = %d",clearCtrl);
|
|
|
|
info->dpitch *= clearCtrl;
|
|
|
|
info->dyaw *= clearCtrl;
|
|
|
|
*/
|
|
|
|
|
2014-04-12 22:10:36 +00:00
|
|
|
droidinput.pitch = droidinput.yaw = 0.f;
|
|
|
|
|
2014-07-06 00:10:33 +00:00
|
|
|
clearCtrl = 0;
|
|
|
|
|
2014-04-12 22:10:36 +00:00
|
|
|
CONTROL_ButtonState = 0;
|
|
|
|
CONTROL_ButtonState |= droidinput.functionSticky;
|
|
|
|
CONTROL_ButtonState |= droidinput.functionHeld;
|
|
|
|
|
|
|
|
droidinput.functionSticky = 0;
|
|
|
|
|
|
|
|
//LOGI("poll state = 0x%016llX",CONTROL_ButtonState);
|
2014-03-22 09:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|