Partial Android support cleanup. I actually have no idea if this even compiles ;)

git-svn-id: https://svn.eduke32.com/eduke32@4433 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2014-04-12 08:45:50 +00:00
parent 45dec87cf0
commit 5645858a64
7 changed files with 210 additions and 252 deletions

View file

@ -32,7 +32,7 @@ extern int android_screen_height;
extern void CONTROL_Android_ClearButton(int32_t whichbutton); extern void CONTROL_Android_ClearButton(int32_t whichbutton);
extern void CONTROL_Android_PollDevices(ControlInfo *info); extern void CONTROL_Android_PollDevices(ControlInfo *info);
extern void setLastWeapon(int w); extern void CONTROL_Android_SetLastWeapon(int w);
#endif #endif
#endif #endif

View file

@ -20,6 +20,7 @@ extern "C"
extern void SDL_SetSwapBufferCallBack(void (*pt2Func)(void)); extern void SDL_SetSwapBufferCallBack(void (*pt2Func)(void));
#include "in_android.h" #include "in_android.h"
#include "../function.h"
#include "../GL/gl.h" #include "../GL/gl.h"
#include "../GL/nano_gl.h" #include "../GL/nano_gl.h"
@ -44,7 +45,6 @@ int android_screen_height;
#define KEY_SHOW_INVEN 0x1009 #define KEY_SHOW_INVEN 0x1009
#define KEY_QUICK_SAVE 0x100A #define KEY_QUICK_SAVE 0x100A
#define KEY_QUICK_LOAD 0x100B #define KEY_QUICK_LOAD 0x100B
#define KEY_SNIPER 0x100C
#define KEY_QUICK_KEY1 0x1011 #define KEY_QUICK_KEY1 0x1011
#define KEY_QUICK_KEY2 0x1012 #define KEY_QUICK_KEY2 0x1012
@ -61,7 +61,6 @@ bool showSticks = true;
bool hideTouchControls = true; bool hideTouchControls = true;
bool shooting = false; bool shooting = false;
bool sniperMode = false;
static int controlsCreated = 0; static int controlsCreated = 0;
touchcontrols::TouchControlsContainer controlsContainer; touchcontrols::TouchControlsContainer controlsContainer;
@ -204,29 +203,29 @@ void swapBuffers()
void gameButton(int state, int code) void gameButton(int state, int code)
{ {
if (code == gamefunc_Fire) switch (code)
{ {
case gamefunc_Fire:
shooting = state; shooting = state;
PortableAction(state, code); PortableAction(state, code);
} break;
if (code == KEY_SNIPER)
{ case KEY_SHOW_KBRD:
sniperMode = state;
}
else if (code == KEY_SHOW_KBRD)
{
if (state) if (state)
toggleKeyboard(); toggleKeyboard();
PortableKeyEvent(state, SDL_SCANCODE_GRAVE, 0); PortableKeyEvent(state, SDL_SCANCODE_GRAVE, 0);
} break;
else if (code == KEY_QUICK_CMD){
case KEY_QUICK_CMD:
if (state == 1) if (state == 1)
showCustomCommands(); showCustomCommands();
} break;
else if (code == KEY_SHOW_INVEN){
if (state == 1) case KEY_SHOW_INVEN:
{ if (state != 1)
break;
if (!tcInventory->isEnabled()) if (!tcInventory->isEnabled())
{ {
tcInventory->setEnabled(true); tcInventory->setEnabled(true);
@ -239,18 +238,23 @@ void gameButton(int state,int code)
tcInventory->setEnabled(false); tcInventory->setEnabled(false);
tcGameWeapons->setEnabled(true); tcGameWeapons->setEnabled(true);
} }
}
} break;
else if (code == KEY_QUICK_SAVE){
case KEY_QUICK_SAVE:
LOGI("QUICK SAVE"); LOGI("QUICK SAVE");
PortableKeyEvent(state, SDL_SCANCODE_F6, 0); PortableKeyEvent(state, SDL_SCANCODE_F6, 0);
} break;
else if (code == KEY_QUICK_LOAD){
case KEY_QUICK_LOAD:
LOGI("QUICK LOAD"); LOGI("QUICK LOAD");
PortableKeyEvent(state, SDL_SCANCODE_F9, 0); PortableKeyEvent(state, SDL_SCANCODE_F9, 0);
} break;
else
default:
PortableAction(state, code); PortableAction(state, code);
break;
}
} }
void automapButton(int state,int code) void automapButton(int state,int code)
@ -266,7 +270,6 @@ void inventoryButton(int state,int code)
tcGameWeapons->setEnabled(true); tcGameWeapons->setEnabled(true);
tcInventory->setEnabled(false); tcInventory->setEnabled(false);
} }
} }
void menuButton(int state,int code) void menuButton(int state,int code)
@ -275,41 +278,45 @@ void menuButton(int state,int code)
} }
static int weaponWheelVisible = false; static int weaponWheelVisible = false;
void weaponWheelSelected(int enabled) void weaponWheelSelected(int enabled)
{ {
if (enabled) if (!enabled)
{ {
tcGameWeapons->fade(1, 5);
weaponWheelVisible = false;
return;
}
for (int n=0; n<10; n++) for (int n=0; n<10; n++)
{ {
weaponWheel->setSegmentEnabled(n,(PortableGetWeapons() >> n) & 0x1); weaponWheel->setSegmentEnabled(n, (PortableRead(READ_WEAPONS) >> n) & 0x1);
} }
tcGameWeapons->fade(0, 5); //fade in tcGameWeapons->fade(0, 5); //fade in
weaponWheelVisible = true; weaponWheelVisible = true;
} }
else
{
tcGameWeapons->fade(1,5);
weaponWheelVisible = false;
}
}
void weaponWheelChosen(int segment) void weaponWheelChosen(int segment)
{ {
LOGI("weaponWheel %d",segment); LOGI("weaponWheel %d",segment);
if (segment != -1)
if (segment == -1) //Nothing was selected
{ {
int32_t lw = PortableRead(READ_LASTWEAPON);
if (lw != -1)
{
PortableAction(1, gamefunc_Weapon_1 + lw);
PortableAction(0, gamefunc_Weapon_1 + lw);
}
return;
}
PortableAction(1, gamefunc_Weapon_1 + segment); PortableAction(1, gamefunc_Weapon_1 + segment);
PortableAction(0, gamefunc_Weapon_1 + segment); PortableAction(0, gamefunc_Weapon_1 + segment);
} }
else //Nothing was selected
{
if (getLastWeapon() != -1)
{
PortableAction(1, gamefunc_Weapon_1 + getLastWeapon());
PortableAction(0, gamefunc_Weapon_1 + getLastWeapon());
}
}
}
int left_double_action; int left_double_action;
@ -345,14 +352,12 @@ void left_stick(float joy_x, float joy_y,float mouse_x, float mouse_y)
PortableMove(joy_y * 15 * forward_sens,-strafe * strafe_sens); PortableMove(joy_y * 15 * forward_sens,-strafe * strafe_sens);
} }
extern int crouchToggleState; //Set in anroid_in.c
void right_stick(float joy_x, float joy_y,float mouse_x, float mouse_y) void right_stick(float joy_x, float joy_y,float mouse_x, float mouse_y)
{ {
//LOGI(" mouse x = %f",mouse_x); //LOGI(" mouse x = %f",mouse_x);
int invert = invertLook?-1:1; int invert = invertLook?-1:1;
float scale = ((shooting && precisionShoot) || crouchToggleState)?0.3:1; float scale = (shooting && precisionShoot) ? 0.3f : 1.f;
PortableLookPitch(LOOK_MODE_MOUSE,-mouse_y * pitch_sens * invert * scale); PortableLookPitch(LOOK_MODE_MOUSE,-mouse_y * pitch_sens * invert * scale);
@ -368,20 +373,9 @@ void mouseMove(int action,float x, float y,float dx, float dy)
if (weaponWheelVisible) if (weaponWheelVisible)
return; return;
/*
if (abs(dx) < 0.001)
{
dx * 0.1;
}
*/
int invert = invertLook? -1 : 1; int invert = invertLook? -1 : 1;
float scale; float scale = (shooting && precisionShoot) ? 0.2f : 1.f;
if (sniperMode)
scale = 0.2;
else
scale = ((shooting && precisionShoot) || crouchToggleState)?0.2:1;
PortableLookPitch(LOOK_MODE_MOUSE, -dy * pitch_sens * invert * scale); PortableLookPitch(LOOK_MODE_MOUSE, -dy * pitch_sens * invert * scale);
@ -396,13 +390,10 @@ void setHideSticks(bool v)
void touchSettingsButton(int state) void touchSettingsButton(int state)
{ {
//We wanna pause the game when doign settings int32_t paused = PortableRead(READ_PAUSED);
if (state && !isPaused())
{ //We wanna pause the game when doing settings
PortableKeyEvent(1,SDL_SCANCODE_PAUSE,0); if (state && !paused || !state && paused)
PortableKeyEvent(0,SDL_SCANCODE_PAUSE,0);
}
else if (!state && isPaused())
{ {
PortableKeyEvent(1,SDL_SCANCODE_PAUSE,0); PortableKeyEvent(1,SDL_SCANCODE_PAUSE,0);
PortableKeyEvent(0,SDL_SCANCODE_PAUSE,0); PortableKeyEvent(0,SDL_SCANCODE_PAUSE,0);
@ -555,12 +546,12 @@ void initControls(int width, int height,const char * graphics_path,const char *s
//controlsContainer.initGL(); //controlsContainer.initGL();
} }
int loadedGLImages=0;
int inMenuLast = 1;
int inAutomapLast = 0;
void frameControls() void frameControls()
{ {
static int loadedGLImages = 0;
static int inMenuLast = 1;
static int inAutomapLast = 0;
//LOGI("frameControls"); //LOGI("frameControls");
//We need to do this here now because duke loads a new gl context //We need to do this here now because duke loads a new gl context
if (!loadedGLImages) if (!loadedGLImages)
@ -573,12 +564,12 @@ void frameControls()
} }
//LOGI("frameControls"); //LOGI("frameControls");
if (PortableIsSoftwareMode()) if (PortableRead(READ_RENDERER) == REND_CLASSIC)
curRenderer = REND_SOFT; curRenderer = REND_SOFT;
else else
curRenderer = REND_GL; curRenderer = REND_GL;
int inMenuNew = PortableInMenu(); int inMenuNew = PortableRead(READ_MENU);
if (inMenuLast != inMenuNew) if (inMenuLast != inMenuNew)
{ {
inMenuLast = inMenuNew; inMenuLast = inMenuNew;
@ -597,7 +588,7 @@ void frameControls()
} }
} }
int inAutomapNew = PortableInAutomap() && !inMenuLast; //Dont show if menu comes up int inAutomapNew = PortableRead(READ_AUTOMAP) && !inMenuLast; //Dont show if menu comes up
if (inAutomapLast != inAutomapNew) if (inAutomapLast != inAutomapNew)
{ {
inAutomapLast = inAutomapNew; inAutomapLast = inAutomapNew;
@ -615,7 +606,6 @@ void frameControls()
controlsContainer.draw(); controlsContainer.draw();
} }
void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,int other) void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,int other)
{ {

View file

@ -5,11 +5,13 @@
#include "common_game.h" #include "common_game.h"
#include "osd.h" #include "osd.h"
#include "player.h" #include "player.h"
#include "game.h"
#include "build.h"
#include "jmact/keyboard.h" #include "jmact/keyboard.h"
#include "jmact/control.h" #include "jmact/control.h"
#include "../src/video/android/SDL_androidkeyboard.h" #include "../src/video/android/SDL_androidkeyboard.h" // FIXME: include header locally if necessary
#include "in_android.h" #include "in_android.h"
@ -17,29 +19,22 @@
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__)) #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO,"DUKE", __VA_ARGS__))
extern int32_t main(int32_t argc, char *argv []);
#define BUTTONSET(x,value) (CONTROL_ButtonState |= ((uint64_t)value<<((uint64_t)(x))))
#define BUTTONCLEAR(x) (CONTROL_ButtonState &= ~((uint64_t)1<<((uint64_t)(x))))
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode); extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
extern int SDL_SendKeyboardText(const char *text); extern int SDL_SendKeyboardText(const char *text);
char sdl_text[2]; static float forwardmove, sidemove; //Joystick mode
int PortableKeyEvent(int state, int code,int unicode){ static char sdl_text[2];
int PortableKeyEvent(int state, int code,int unicode)
{
LOGI("PortableKeyEvent %d %d %d",state,code,unicode); LOGI("PortableKeyEvent %d %d %d",state,code,unicode);
/* SDL_SendKeyboardKey(state ? SDL_PRESSED : SDL_RELEASED, code);
if (state)
Android_OnKeyDown(code);
else
Android_OnKeyUp(code);
return;
*/
if (state)
SDL_SendKeyboardKey(SDL_PRESSED, code);
else
SDL_SendKeyboardKey(SDL_RELEASED, code);
SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE); SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
if (code == 42) if (code == 42)
@ -62,27 +57,20 @@ int PortableKeyEvent(int state, int code,int unicode){
} }
int crouchToggleState=0;
#define BUTTONSET(x,value) (CONTROL_ButtonState |= ((uint64_t)value<<((uint64_t)(x))))
#define BUTTONCLEAR(x) (CONTROL_ButtonState &= ~((uint64_t)1<<((uint64_t)(x))))
uint64_t functionSticky = 0; //To let at least one tick
uint64_t functionHeld = 0;
void changeActionState(int state, int action) void changeActionState(int state, int action)
{ {
if (state) if (state)
{ {
//BUTTONSET(action,1); //BUTTONSET(action,1);
functionSticky |= ((uint64_t)1<<((uint64_t)(action))); droidplayer.functionSticky |= ((uint64_t)1<<((uint64_t)(action)));
functionHeld |= ((uint64_t)1<<((uint64_t)(action))); droidplayer.functionHeld |= ((uint64_t)1<<((uint64_t)(action)));
return;
} }
else
{
//BUTTONCLEAR(action); //BUTTONCLEAR(action);
functionHeld &= ~((uint64_t)1<<((uint64_t)(action))); droidplayer.functionHeld &= ~((uint64_t) 1<<((uint64_t) (action)));
}
} }
void PortableAction(int state, int action) void PortableAction(int state, int action)
@ -92,28 +80,24 @@ void PortableAction(int state, int action)
//Special toggle for crouch, NOT when using jetpack or in water //Special toggle for crouch, NOT when using jetpack or in water
if (!g_player[myconnectindex].ps->jetpack_on && if (!g_player[myconnectindex].ps->jetpack_on &&
g_player[myconnectindex].ps->on_ground && g_player[myconnectindex].ps->on_ground &&
(sector[g_player[myconnectindex].ps->cursectnum].lotag != 2))// This means underwater! (sector[g_player[myconnectindex].ps->cursectnum].lotag != ST_2_UNDERWATER))
{ {
if (action == gamefunc_Crouch) if (action == gamefunc_Crouch)
{ {
if (state) if (state)
{ droidplayer.crouchToggleState = !droidplayer.crouchToggleState;
crouchToggleState =!crouchToggleState;
} state = droidplayer.crouchToggleState;
state = crouchToggleState;
} }
} }
//Check if jumping while crouched //Check if jumping while crouched
if (action == gamefunc_Jump) if (action == gamefunc_Jump)
{ {
if (crouchToggleState) droidplayer.crouchToggleState = 0;
{
crouchToggleState = 0;
changeActionState(0, gamefunc_Crouch); changeActionState(0, gamefunc_Crouch);
} }
}
changeActionState(state,action); changeActionState(state,action);
LOGI("PortableAction state = 0x%016llX",CONTROL_ButtonState); LOGI("PortableAction state = 0x%016llX",CONTROL_ButtonState);
@ -121,26 +105,14 @@ void PortableAction(int state, int action)
// =================== FORWARD and SIDE MOVMENT ============== // =================== FORWARD and SIDE MOVMENT ==============
float forwardmove, sidemove; //Joystick mode
void PortableMoveFwd(float fwd) void PortableMoveFwd(float fwd)
{ {
if (fwd > 1) forwardmove = fclamp2(fwd, -1.f, 1.f);
fwd = 1;
else if (fwd < -1)
fwd = -1;
forwardmove = fwd;
} }
void PortableMoveSide(float strafe) void PortableMoveSide(float strafe)
{ {
if (strafe > 1) sidemove = fclamp2(strafe, -1.f, 1.f);
strafe = 1;
else if (strafe < -1)
strafe = -1;
sidemove = strafe;
} }
void PortableMove(float fwd, float strafe) void PortableMove(float fwd, float strafe)
@ -191,72 +163,57 @@ void PortableLookYaw(int mode, float yaw)
void PortableCommand(const char * cmd){} void PortableCommand(const char * cmd)
{
extern int32_t main(int32_t argc, char *argv[]); OSD_Dispatch(cmd);
void PortableInit(int argc,const char ** argv){ }
void PortableInit(int argc,const char ** argv)
{
main(argc, argv); main(argc, argv);
} }
void PortableFrame(){ void PortableFrame()
{
//NOT USED for DUKE //NOT USED for DUKE
} }
int PortableInMenu(){ int32_t PortableRead(portableread_t r)
return ( (g_player[myconnectindex].ps->gm & MODE_MENU) || !(g_player[myconnectindex].ps->gm & MODE_GAME))?1:0;
}
unsigned int PortableGetWeapons()
{ {
switch (r)
{
case READ_MENU:
return (g_player[myconnectindex].ps->gm & MODE_MENU) == MODE_MENU || (g_player[myconnectindex].ps->gm & MODE_GAME) != MODE_GAME;
case READ_WEAPONS:
return g_player[myconnectindex].ps->gotweapon; return g_player[myconnectindex].ps->gotweapon;
} case READ_AUTOMAP:
int PortableInAutomap() return ud.overhead_on != 0;
{ case READ_KEYBOARD:
return 0;
case READ_RENDERER:
return getrendermode();
case READ_LASTWEAPON:
return droidplayer.lastWeapon;
case READ_PAUSED:
return ud.pause_on != 0;
default:
return 0; return 0;
} }
int PortableShowKeyboard(){
return 0;
}
int PortableIsSoftwareMode()
{
if (getrendermode() >= REND_POLYMOST)
return 0;
else
return 1;
}
static int lastWeapon = -1;
int getLastWeapon(){
return lastWeapon;
}
extern user_defs ud;
int isPaused()
{
return ud.pause_on;
} }
///This stuff is called from the game/engine ///This stuff is called from the game/engine
void setLastWeapon(int w) void CONTROL_Android_SetLastWeapon(int w)
{ {
LOGI("setLastWeapon %d",w); LOGI("setLastWeapon %d",w);
lastWeapon = w; droidplayer.lastWeapon = w;
} }
void CONTROL_Android_ClearButton(int32_t whichbutton) void CONTROL_Android_ClearButton(int32_t whichbutton)
{ {
BUTTONCLEAR(whichbutton); BUTTONCLEAR(whichbutton);
functionHeld &= ~((uint64_t)1<<((uint64_t)(whichbutton))); droidplayer.functionHeld &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
} }
void CONTROL_Android_PollDevices(ControlInfo *info) void CONTROL_Android_PollDevices(ControlInfo *info)
@ -280,7 +237,6 @@ void CONTROL_Android_PollDevices(ControlInfo *info)
break; break;
} }
switch(look_yaw_mode) switch(look_yaw_mode)
{ {
case LOOK_MODE_MOUSE: case LOOK_MODE_MOUSE:
@ -292,10 +248,10 @@ void CONTROL_Android_PollDevices(ControlInfo *info)
break; break;
} }
CONTROL_ButtonState = 0; CONTROL_ButtonState = 0;
CONTROL_ButtonState |= functionSticky; CONTROL_ButtonState |= droidplayer.functionSticky;
CONTROL_ButtonState |= functionHeld; CONTROL_ButtonState |= droidplayer.functionHeld;
functionSticky = 0; droidplayer.functionSticky = 0;
//LOGI("poll state = 0x%016llX",CONTROL_ButtonState); //LOGI("poll state = 0x%016llX",CONTROL_ButtonState);
} }

View file

@ -1,18 +1,39 @@
#include "function.h" #include "function.h"
#include "compat.h"
enum {
LOOK_MODE_MOUSE = 0,
LOOK_MODE_ABSOLUTE,
#define LOOK_MODE_MOUSE 0 LOOK_MODE_JOYSTICK
#define LOOK_MODE_ABSOLUTE 1 };
#define LOOK_MODE_JOYSTICK 2
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
typedef enum {
READ_MENU,
READ_WEAPONS,
READ_AUTOMAP,
READ_KEYBOARD,
READ_RENDERER,
READ_LASTWEAPON,
READ_PAUSED
} portableread_t;
int32_t PortableRead(portableread_t r);
typedef struct
{
int32_t crouchToggleState;
int32_t lastWeapon;
uint64_t functionSticky; //To let at least one tick
uint64_t functionHeld;
} androidplayer_t;
extern androidplayer_t droidplayer;
int PortableKeyEvent(int state, int code, int unicode); int PortableKeyEvent(int state, int code, int unicode);
void PortableAction(int state, int action); void PortableAction(int state, int action);
@ -26,21 +47,6 @@ void PortableCommand(const char * cmd);
void PortableInit(int argc, const char ** argv); void PortableInit(int argc, const char ** argv);
void PortableFrame(); void PortableFrame();
int PortableInMenu();
int PortableShowKeyboard();
int PortableInAutomap();
unsigned int PortableGetWeapons();
int getLastWeapon();
int isPaused();
//check mode, so touch graphcics can adapt
int PortableIsSoftwareMode();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -2688,6 +2688,8 @@ void G_PrintGameQuotes(int32_t snum)
{ {
#ifdef GEKKO #ifdef GEKKO
k = 16; k = 16;
#elif defined(__ANDROID__)
k = 24;
#else #else
k = 0; k = 0;
#endif #endif

View file

@ -29,7 +29,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "premap.h" #include "premap.h"
int32_t osdhightile = 0; int32_t osdhightile = 0;
#ifdef __ANDROID__
double osdscale = 2.0f;
#else
double osdscale = 1.0f; double osdscale = 1.0f;
#endif
#define OSD_SCALE(x) (int32_t)(osdscale != 1.f ? nearbyintf(osdscale*(double)(x)) : x) #define OSD_SCALE(x) (int32_t)(osdscale != 1.f ? nearbyintf(osdscale*(double)(x)) : x)

View file

@ -3238,7 +3238,7 @@ static void P_ChangeWeapon(DukePlayer_t *p, int32_t weapon)
if (p->holster_weapon) if (p->holster_weapon)
{ {
#ifdef __ANDROID__ #ifdef __ANDROID__
setLastWeapon(p->last_weapon); CONTROL_Android_SetLastWeapon(p->last_weapon);
#endif #endif
p->weapon_pos = WEAPON_POS_RAISE; p->weapon_pos = WEAPON_POS_RAISE;