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_PollDevices(ControlInfo *info);
extern void setLastWeapon(int w);
extern void CONTROL_Android_SetLastWeapon(int w);
#endif
#endif

View file

@ -20,6 +20,7 @@ extern "C"
extern void SDL_SetSwapBufferCallBack(void (*pt2Func)(void));
#include "in_android.h"
#include "../function.h"
#include "../GL/gl.h"
#include "../GL/nano_gl.h"
@ -44,7 +45,6 @@ int android_screen_height;
#define KEY_SHOW_INVEN 0x1009
#define KEY_QUICK_SAVE 0x100A
#define KEY_QUICK_LOAD 0x100B
#define KEY_SNIPER 0x100C
#define KEY_QUICK_KEY1 0x1011
#define KEY_QUICK_KEY2 0x1012
@ -61,7 +61,6 @@ bool showSticks = true;
bool hideTouchControls = true;
bool shooting = false;
bool sniperMode = false;
static int controlsCreated = 0;
touchcontrols::TouchControlsContainer controlsContainer;
@ -202,55 +201,60 @@ void swapBuffers()
}
void gameButton(int state,int code)
void gameButton(int state, int code)
{
if (code == gamefunc_Fire)
{
shooting = state;
PortableAction(state, code);
}
if (code == KEY_SNIPER)
{
sniperMode = state;
}
else if (code == KEY_SHOW_KBRD)
{
if (state)
toggleKeyboard();
switch (code)
{
case gamefunc_Fire:
shooting = state;
PortableAction(state, code);
break;
PortableKeyEvent(state, SDL_SCANCODE_GRAVE,0);
}
else if (code == KEY_QUICK_CMD){
if (state == 1)
showCustomCommands();
}
else if (code == KEY_SHOW_INVEN){
if (state == 1)
{
if (!tcInventory->isEnabled())
{
tcInventory->setEnabled(true);
tcInventory->fade(0,5);
//disable weapon wheel so it does not show, enabled again after inventory cleared
tcGameWeapons->setEnabled(false);
}
else
{
tcInventory->setEnabled(false);
tcGameWeapons->setEnabled(true);
}
}
}
else if (code == KEY_QUICK_SAVE){
LOGI("QUICK SAVE");
PortableKeyEvent(state, SDL_SCANCODE_F6,0);
}
else if (code == KEY_QUICK_LOAD){
LOGI("QUICK LOAD");
PortableKeyEvent(state, SDL_SCANCODE_F9,0);
}
else
PortableAction(state, code);
case KEY_SHOW_KBRD:
if (state)
toggleKeyboard();
PortableKeyEvent(state, SDL_SCANCODE_GRAVE, 0);
break;
case KEY_QUICK_CMD:
if (state == 1)
showCustomCommands();
break;
case KEY_SHOW_INVEN:
if (state != 1)
break;
if (!tcInventory->isEnabled())
{
tcInventory->setEnabled(true);
tcInventory->fade(0, 5);
//disable weapon wheel so it does not show, enabled again after inventory cleared
tcGameWeapons->setEnabled(false);
}
else
{
tcInventory->setEnabled(false);
tcGameWeapons->setEnabled(true);
}
break;
case KEY_QUICK_SAVE:
LOGI("QUICK SAVE");
PortableKeyEvent(state, SDL_SCANCODE_F6, 0);
break;
case KEY_QUICK_LOAD:
LOGI("QUICK LOAD");
PortableKeyEvent(state, SDL_SCANCODE_F9, 0);
break;
default:
PortableAction(state, code);
break;
}
}
void automapButton(int state,int code)
@ -266,7 +270,6 @@ void inventoryButton(int state,int code)
tcGameWeapons->setEnabled(true);
tcInventory->setEnabled(false);
}
}
void menuButton(int state,int code)
@ -275,40 +278,44 @@ void menuButton(int state,int code)
}
static int weaponWheelVisible = false;
void weaponWheelSelected(int enabled)
{
if (enabled)
{
for (int n=0;n<10;n++)
{
weaponWheel->setSegmentEnabled(n,(PortableGetWeapons() >> n) & 0x1);
}
if (!enabled)
{
tcGameWeapons->fade(1, 5);
weaponWheelVisible = false;
return;
}
tcGameWeapons->fade(0,5); //fade in
weaponWheelVisible = true;
}
else
{
tcGameWeapons->fade(1,5);
weaponWheelVisible = false;
}
for (int n=0; n<10; n++)
{
weaponWheel->setSegmentEnabled(n, (PortableRead(READ_WEAPONS) >> n) & 0x1);
}
tcGameWeapons->fade(0, 5); //fade in
weaponWheelVisible = true;
}
void weaponWheelChosen(int segment)
{
LOGI("weaponWheel %d",segment);
if (segment != -1)
{
PortableAction(1, 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());
}
}
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(0, gamefunc_Weapon_1 + segment);
}
@ -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);
}
extern int crouchToggleState; //Set in anroid_in.c
void right_stick(float joy_x, float joy_y,float mouse_x, float mouse_y)
{
//LOGI(" mouse x = %f",mouse_x);
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);
@ -368,24 +373,13 @@ void mouseMove(int action,float x, float y,float dx, float dy)
if (weaponWheelVisible)
return;
/*
if (abs(dx) < 0.001)
{
dx * 0.1;
}
*/
int invert = invertLook?-1:1;
float scale;
if (sniperMode)
scale = 0.2;
else
scale = ((shooting && precisionShoot) || crouchToggleState)?0.2:1;
int invert = invertLook? -1 : 1;
float scale = (shooting && precisionShoot) ? 0.2f : 1.f;
PortableLookPitch(LOOK_MODE_MOUSE, -dy * pitch_sens * invert * scale);
PortableLookPitch(LOOK_MODE_MOUSE,-dy * pitch_sens * invert * scale);
PortableLookYaw(LOOK_MODE_MOUSE,dx*2*yaw_sens * scale);
PortableLookYaw(LOOK_MODE_MOUSE, dx * 2 * yaw_sens * scale);
}
void setHideSticks(bool v)
@ -396,13 +390,10 @@ void setHideSticks(bool v)
void touchSettingsButton(int state)
{
//We wanna pause the game when doign settings
if (state && !isPaused())
{
PortableKeyEvent(1,SDL_SCANCODE_PAUSE,0);
PortableKeyEvent(0,SDL_SCANCODE_PAUSE,0);
}
else if (!state && isPaused())
int32_t paused = PortableRead(READ_PAUSED);
//We wanna pause the game when doing settings
if (state && !paused || !state && paused)
{
PortableKeyEvent(1,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();
}
int loadedGLImages=0;
int inMenuLast = 1;
int inAutomapLast = 0;
void frameControls()
{
static int loadedGLImages = 0;
static int inMenuLast = 1;
static int inAutomapLast = 0;
//LOGI("frameControls");
//We need to do this here now because duke loads a new gl context
if (!loadedGLImages)
@ -573,12 +564,12 @@ void frameControls()
}
//LOGI("frameControls");
if (PortableIsSoftwareMode())
if (PortableRead(READ_RENDERER) == REND_CLASSIC)
curRenderer = REND_SOFT;
else
curRenderer = REND_GL;
int inMenuNew = PortableInMenu();
int inMenuNew = PortableRead(READ_MENU);
if (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)
{
inAutomapLast = inAutomapNew;
@ -615,7 +606,6 @@ void frameControls()
controlsContainer.draw();
}
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 "osd.h"
#include "player.h"
#include "game.h"
#include "build.h"
#include "jmact/keyboard.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"
@ -17,30 +19,23 @@
#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_SendKeyboardText(const char *text);
char sdl_text[2];
int PortableKeyEvent(int state, int code,int unicode){
static float forwardmove, sidemove; //Joystick mode
static char sdl_text[2];
int PortableKeyEvent(int state, int code,int unicode)
{
LOGI("PortableKeyEvent %d %d %d",state,code,unicode);
/*
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_SendKeyboardKey(state ? SDL_PRESSED : SDL_RELEASED, code);
SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
if (code == 42)
unicode = 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)
{
if (state)
{
//BUTTONSET(action,1);
functionSticky |= ((uint64_t)1<<((uint64_t)(action)));
functionHeld |= ((uint64_t)1<<((uint64_t)(action)));
}
else
{
//BUTTONCLEAR(action);
functionHeld &= ~((uint64_t)1<<((uint64_t)(action)));
}
droidplayer.functionSticky |= ((uint64_t)1<<((uint64_t)(action)));
droidplayer.functionHeld |= ((uint64_t)1<<((uint64_t)(action)));
return;
}
//BUTTONCLEAR(action);
droidplayer.functionHeld &= ~((uint64_t) 1<<((uint64_t) (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
if (!g_player[myconnectindex].ps->jetpack_on &&
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 (state)
{
crouchToggleState =!crouchToggleState;
}
state = crouchToggleState;
droidplayer.crouchToggleState = !droidplayer.crouchToggleState;
state = droidplayer.crouchToggleState;
}
}
//Check if jumping while crouched
if (action == gamefunc_Jump)
{
if (crouchToggleState)
{
crouchToggleState = 0;
changeActionState(0,gamefunc_Crouch);
}
}
//Check if jumping while crouched
if (action == gamefunc_Jump)
{
droidplayer.crouchToggleState = 0;
changeActionState(0, gamefunc_Crouch);
}
changeActionState(state,action);
LOGI("PortableAction state = 0x%016llX",CONTROL_ButtonState);
@ -121,26 +105,14 @@ void PortableAction(int state, int action)
// =================== FORWARD and SIDE MOVMENT ==============
float forwardmove, sidemove; //Joystick mode
void PortableMoveFwd(float fwd)
{
if (fwd > 1)
fwd = 1;
else if (fwd < -1)
fwd = -1;
forwardmove = fwd;
forwardmove = fclamp2(fwd, -1.f, 1.f);
}
void PortableMoveSide(float strafe)
{
if (strafe > 1)
strafe = 1;
else if (strafe < -1)
strafe = -1;
sidemove = strafe;
sidemove = fclamp2(strafe, -1.f, 1.f);
}
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)
{
OSD_Dispatch(cmd);
}
extern int32_t main(int32_t argc, char *argv[]);
void PortableInit(int argc,const char ** argv){
main(argc,argv);
void PortableInit(int argc,const char ** argv)
{
main(argc, argv);
}
void PortableFrame(){
void PortableFrame()
{
//NOT USED for DUKE
}
int PortableInMenu(){
return ( (g_player[myconnectindex].ps->gm & MODE_MENU) || !(g_player[myconnectindex].ps->gm & MODE_GAME))?1:0;
}
unsigned int PortableGetWeapons()
int32_t PortableRead(portableread_t r)
{
return g_player[myconnectindex].ps->gotweapon;
}
int PortableInAutomap()
{
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;
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;
case READ_AUTOMAP:
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;
}
}
///This stuff is called from the game/engine
void setLastWeapon(int w)
void CONTROL_Android_SetLastWeapon(int w)
{
LOGI("setLastWeapon %d",w);
lastWeapon = w;
droidplayer.lastWeapon = w;
}
void CONTROL_Android_ClearButton(int32_t whichbutton)
{
BUTTONCLEAR(whichbutton);
functionHeld &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
droidplayer.functionHeld &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
}
void CONTROL_Android_PollDevices(ControlInfo *info)
@ -280,7 +237,6 @@ void CONTROL_Android_PollDevices(ControlInfo *info)
break;
}
switch(look_yaw_mode)
{
case LOOK_MODE_MOUSE:
@ -292,10 +248,10 @@ void CONTROL_Android_PollDevices(ControlInfo *info)
break;
}
CONTROL_ButtonState = 0;
CONTROL_ButtonState |= functionSticky;
CONTROL_ButtonState |= functionHeld;
CONTROL_ButtonState |= droidplayer.functionSticky;
CONTROL_ButtonState |= droidplayer.functionHeld;
functionSticky = 0;
droidplayer.functionSticky = 0;
//LOGI("poll state = 0x%016llX",CONTROL_ButtonState);
}

View file

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

View file

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

View file

@ -29,7 +29,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "premap.h"
int32_t osdhightile = 0;
#ifdef __ANDROID__
double osdscale = 2.0f;
#else
double osdscale = 1.0f;
#endif
#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)
{
#ifdef __ANDROID__
setLastWeapon(p->last_weapon);
CONTROL_Android_SetLastWeapon(p->last_weapon);
#endif
p->weapon_pos = WEAPON_POS_RAISE;