Android code updates, pay no attention. DONT_BUILD.

git-svn-id: https://svn.eduke32.com/eduke32@4434 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2014-04-12 22:10:36 +00:00
parent 5645858a64
commit 2293aa5f59
3 changed files with 561 additions and 629 deletions

View file

@ -11,11 +11,15 @@
#include <android/log.h>
#include "SDL_scancode.h"
#include "SDL_main.h"
#include "TouchControlsContainer.h"
#include "JNITouchControlsUtils.h"
extern "C"
{
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
//This is a new function I put into SDL2, file SDL_androidgl.c
extern void SDL_SetSwapBufferCallBack(void (*pt2Func)(void));
@ -38,7 +42,8 @@ static int curRenderer;
int android_screen_width;
int android_screen_height;
int android_sample_rate;
int android_audio_buffer_size;
#define KEY_QUICK_CMD 0x1005
#define KEY_SHOW_KBRD 0x1008
@ -51,14 +56,13 @@ int android_screen_height;
#define KEY_QUICK_KEY3 0x1013
#define KEY_QUICK_KEY4 0x1014
float gameControlsAlpha = 0.5;
bool showWeaponCycle = false;
bool turnMouseMode = true;
bool invertLook = false;
bool precisionShoot = false;
bool showSticks = true;
bool hideTouchControls = true;
bool toggleCrouch = true;
bool shooting = false;
@ -78,10 +82,10 @@ touchcontrols::TouchJoy *touchJoyRight;
touchcontrols::WheelSelect *weaponWheel;
extern JNIEnv* env_;
JavaVM* jvm_;
void openGLStart()
{
if (curRenderer == REND_GL)
{
glPushMatrix();
@ -117,7 +121,6 @@ void openGLStart()
}
else //software mode
{
glDisable(GL_ALPHA_TEST);
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
@ -128,14 +131,12 @@ void openGLStart()
glEnable(GL_TEXTURE_2D);
glDisable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
}
}
void openGLEnd()
{
if (curRenderer == REND_GL)
{
//glPopMatrix();
@ -146,50 +147,22 @@ void openGLEnd()
{
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glMatrixMode(GL_MODELVIEW);
}
}
void gameSettingsButton(int state)
{
//LOGTOUCH("gameSettingsButton %d",state);
if (state == 1)
{
jclass helloWorldClass;
jmethodID mainMethod;
helloWorldClass = env_->FindClass("com/beloko/duke/QuakeTouchControlsSettings");
mainMethod = env_->GetStaticMethodID(helloWorldClass, "showSettings", "()V");
env_->CallStaticVoidMethod(helloWorldClass, mainMethod);
showTouchSettings();
}
}
void showCustomCommands()
{
jclass helloWorldClass;
jmethodID mainMethod;
helloWorldClass = env_->FindClass("com/beloko/duke/QuakeCustomCommands");
mainMethod = env_->GetStaticMethodID(helloWorldClass, "showCommands", "()V");
env_->CallStaticVoidMethod(helloWorldClass, mainMethod);
}
void toggleKeyboard()
{
LOGI("toggleKeyboard");
jclass helloWorldClass;
jmethodID mainMethod;
helloWorldClass = env_->FindClass("com/beloko/duke/ShowKeyboard");
mainMethod = env_->GetStaticMethodID(helloWorldClass, "toggleKeyboard", "()V");
env_->CallStaticVoidMethod(helloWorldClass, mainMethod);
}
//Because there is no Frame(), we need to check back to java each frame to see if the app hase paused
static jclass NativeLibClass = 0;
static jmethodID checkPauseMethod = 0;
void swapBuffers()
{
if (NativeLibClass == 0)
@ -200,7 +173,6 @@ void swapBuffers()
env_->CallStaticVoidMethod(NativeLibClass, checkPauseMethod);
}
void gameButton(int state, int code)
{
switch (code)
@ -306,16 +278,12 @@ void weaponWheelChosen(int segment)
int32_t lw = PortableRead(READ_LASTWEAPON);
if (lw != -1)
{
PortableAction(1, gamefunc_Weapon_1 + lw);
PortableAction(0, gamefunc_Weapon_1 + lw);
}
PortableAction(2, gamefunc_Weapon_1 + lw);
return;
}
PortableAction(1, gamefunc_Weapon_1 + segment);
PortableAction(0, gamefunc_Weapon_1 + segment);
PortableAction(2, gamefunc_Weapon_1 + segment);
}
@ -341,6 +309,19 @@ void right_double_tap(int state)
float strafe_sens,forward_sens;
float pitch_sens,yaw_sens;
void mouseMove(int action, float x, float y, float dx, float dy)
{
//LOGI(" mouse dx = %f",dx);
if (weaponWheelVisible)
return;
double scale = (shooting && precisionShoot) ? PRECISIONSHOOTFACTOR : 1.f;
PortableLook(dx * 2 * yaw_sens * scale,
-dy * pitch_sens * scale * invertLook ? -1 : 1);
}
void left_stick(float joy_x, float joy_y, float mouse_x, float mouse_y)
{
joy_x *=10;
@ -355,31 +336,8 @@ void left_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);
int invert = invertLook?-1:1;
float scale = (shooting && precisionShoot) ? 0.3f : 1.f;
PortableLookPitch(LOOK_MODE_MOUSE,-mouse_y * pitch_sens * invert * scale);
if (turnMouseMode)
PortableLookYaw(LOOK_MODE_MOUSE,mouse_x*2*yaw_sens * scale);
else
PortableLookYaw(LOOK_MODE_JOYSTICK,joy_x*6*yaw_sens * scale);
}
void mouseMove(int action,float x, float y,float dx, float dy)
{
LOGI(" mouse dx = %f",dx);
if (weaponWheelVisible)
return;
int invert = invertLook? -1 : 1;
float scale = (shooting && precisionShoot) ? 0.2f : 1.f;
PortableLookPitch(LOOK_MODE_MOUSE, -dy * pitch_sens * invert * scale);
PortableLookYaw(LOOK_MODE_MOUSE, dx * 2 * yaw_sens * scale);
mouseMove(0, joy_x, joy_y, mouse_x, mouse_y);
}
void setHideSticks(bool v)
@ -395,8 +353,7 @@ void touchSettingsButton(int state)
//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);
PortableKeyEvent(2,SDL_SCANCODE_PAUSE,0);
}
}
@ -424,7 +381,7 @@ void initControls(int width, int height,const char * graphics_path,const char *s
tcAutomap = new touchcontrols::TouchControls("automap",false,true,1,false);
tcInventory = new touchcontrols::TouchControls("inventory",false,true,1,false);
tcGameLook = new touchcontrols::TouchControls("mouse",true,false);
controlsContainer.dukeHack = 1;
//controlsContainer.dukeHack = 1;
tcGameMain->signal_settingsButton.connect( sigc::ptr_fun(&gameSettingsButton) );
@ -433,8 +390,8 @@ void initControls(int width, int height,const char * graphics_path,const char *s
tcMenuMain->addControl(new touchcontrols::Button("up_arrow",touchcontrols::RectF(20,10,23,13),"arrow_up",SDL_SCANCODE_UP,true));
tcMenuMain->addControl(new touchcontrols::Button("left_arrow",touchcontrols::RectF(17,13,20,16),"arrow_left",SDL_SCANCODE_LEFT,true));
tcMenuMain->addControl(new touchcontrols::Button("right_arrow",touchcontrols::RectF(23,13,26,16),"arrow_right",SDL_SCANCODE_RIGHT,true));
tcMenuMain->addControl(new touchcontrols::Button("enter",touchcontrols::RectF(0,12,4,16),"enter",SDL_SCANCODE_RETURN));
tcMenuMain->addControl(new touchcontrols::Button("esc",touchcontrols::RectF(0,9,4,12),"esc",SDL_SCANCODE_ESCAPE));
tcMenuMain->addControl(new touchcontrols::Button("enter",touchcontrols::RectF(0,12,3,15),"enter",SDL_SCANCODE_RETURN));
tcMenuMain->addControl(new touchcontrols::Button("esc",touchcontrols::RectF(0,8,3,11),"esc",SDL_SCANCODE_ESCAPE));
tcMenuMain->signal_button.connect( sigc::ptr_fun(&menuButton) );
@ -470,26 +427,26 @@ void initControls(int width, int height,const char * graphics_path,const char *s
tcGameMain->addControl(new touchcontrols::Button("use",touchcontrols::RectF(23,4,26,7),"use",gamefunc_Open));
tcGameMain->addControl(new touchcontrols::Button("attack",touchcontrols::RectF(20,7,23,10),"fire2",gamefunc_Fire));
tcGameMain->addControl(new touchcontrols::Button("jump",touchcontrols::RectF(23,7,26,10),"jump",gamefunc_Jump));
tcGameMain->addControl(new touchcontrols::Button("crouch",touchcontrols::RectF(24,14,26,16),"crouch",gamefunc_Crouch));
tcGameMain->addControl(new touchcontrols::Button("kick",touchcontrols::RectF(20,4,23,7),"boot",gamefunc_Quick_Kick));
tcGameMain->addControl(new touchcontrols::Button("crouch",touchcontrols::RectF(24,12,26,14),"crouch",gamefunc_Crouch));
tcGameMain->addControl(new touchcontrols::Button("kick",touchcontrols::RectF(20,4,23,7),"boot",gamefunc_Quick_Kick,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_save",touchcontrols::RectF(24,0,26,2),"save",KEY_QUICK_SAVE));
tcGameMain->addControl(new touchcontrols::Button("quick_load",touchcontrols::RectF(20,0,22,2),"load",KEY_QUICK_LOAD));
tcGameMain->addControl(new touchcontrols::Button("map",touchcontrols::RectF(4,0,6,2),"map",gamefunc_Map));
tcGameMain->addControl(new touchcontrols::Button("keyboard",touchcontrols::RectF(8,0,10,2),"keyboard",KEY_SHOW_KBRD));
tcGameMain->addControl(new touchcontrols::Button("map",touchcontrols::RectF(4,0,6,2),"map",gamefunc_Map,false,true));
tcGameMain->addControl(new touchcontrols::Button("keyboard",touchcontrols::RectF(8,0,10,2),"keyboard",KEY_SHOW_KBRD,false,true));
tcGameMain->addControl(new touchcontrols::Button("show_inventory",touchcontrols::RectF(0,0,2,3),"inv",KEY_SHOW_INVEN));
tcGameMain->addControl(new touchcontrols::Button("show_inventory",touchcontrols::RectF(2,0,4,2),"inv",KEY_SHOW_INVEN));
tcGameMain->addControl(new touchcontrols::Button("next_weapon",touchcontrols::RectF(0,3,3,5),"next_weap",gamefunc_Next_Weapon));
tcGameMain->addControl(new touchcontrols::Button("prev_weapon",touchcontrols::RectF(0,7,3,9),"prev_weap",gamefunc_Previous_Weapon));
//tcGameMain->addControl(new touchcontrols::Button("sniper",touchcontrols::RectF(0,5,3,7),"sniper",KEY_SNIPER));
/*
//quick actions binds
tcGameMain->addControl(new touchcontrols::Button("quick_key_1",touchcontrols::RectF(4,3,6,5),"quick_key_1",KEY_QUICK_KEY1,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_key_2",touchcontrols::RectF(6,3,8,5),"quick_key_2",KEY_QUICK_KEY2,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_key_3",touchcontrols::RectF(8,3,10,5),"quick_key_3",KEY_QUICK_KEY3,false,true));
tcGameMain->addControl(new touchcontrols::Button("quick_key_4",touchcontrols::RectF(10,3,12,5),"quick_key_4",KEY_QUICK_KEY4,false,true));
*/
//Left stick
touchJoyLeft = new touchcontrols::TouchJoy("stick",touchcontrols::RectF(0,7,8,16),"strafe_arrow");
tcGameMain->addControl(touchJoyLeft);
@ -512,12 +469,13 @@ void initControls(int width, int height,const char * graphics_path,const char *s
mouse->signal_double_tap.connect(sigc::ptr_fun(&right_double_tap) );
mouse->setHideGraphics(true);
tcGameLook->addControl(mouse);
tcGameMain->addControl(mouse);
//tcGameLook->addControl(mouse);
//Weapons
weaponWheel = new touchcontrols::WheelSelect("weapon_wheel",touchcontrols::RectF(7,2,19,14),"weapon_wheel",10);
weaponWheel = new touchcontrols::WheelSelect("weapon_wheel",touchcontrols::RectF(7,2,19,14),"weapon_wheel_orange_blank",10);
weaponWheel->signal_selected.connect(sigc::ptr_fun(&weaponWheelChosen) );
weaponWheel->signal_enabled.connect(sigc::ptr_fun(&weaponWheelSelected));
tcGameWeapons->addControl(weaponWheel);
@ -527,11 +485,12 @@ void initControls(int width, int height,const char * graphics_path,const char *s
controlsContainer.addControlGroup(tcMenuMain);
controlsContainer.addControlGroup(tcInventory);//Need to be above tcGameMain incase buttons over stick
controlsContainer.addControlGroup(tcGameMain);
controlsContainer.addControlGroup(tcInventory);//Need to be above tcGameMain incase buttons over stick
controlsContainer.addControlGroup(tcGameWeapons);
//controlsContainer.addControlGroup(tcAutomap);
controlsContainer.addControlGroup(tcGameLook);
//controlsContainer.addControlGroup(tcGameLook);
controlsCreated = 1;
tcGameMain->setXMLFile((std::string)graphics_path + "/game.xml");
@ -564,10 +523,7 @@ void frameControls()
}
//LOGI("frameControls");
if (PortableRead(READ_RENDERER) == REND_CLASSIC)
curRenderer = REND_SOFT;
else
curRenderer = REND_GL;
curRenderer = (PortableRead(READ_RENDERER) != REND_CLASSIC);
int inMenuNew = PortableRead(READ_MENU);
if (inMenuLast != inMenuNew)
@ -608,16 +564,17 @@ void frameControls()
void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,int other)
{
gameControlsAlpha = 0.25 + (alpha * 0.75);
gameControlsAlpha = alpha;
if (tcGameMain)
{
tcGameMain->setAlpha(gameControlsAlpha);
controlsContainer.editButtonAlpha = gameControlsAlpha;
tcGameWeapons->setAlpha(gameControlsAlpha);
tcInventory->setAlpha(gameControlsAlpha);
}
showWeaponCycle = other & 0x1?true:false;
turnMouseMode = other & 0x2?true:false;
toggleCrouch = other & 0x2?true:false;
invertLook = other & 0x4?true:false;
precisionShoot = other & 0x8?true:false;
showSticks = other & 0x1000?true:false;
@ -653,11 +610,8 @@ void setTouchSettings(float alpha,float strafe,float fwd,float pitch,float yaw,i
forward_sens = fwd;
pitch_sens = pitch;
yaw_sens = yaw;
}
int quit_now = 0;
#define EXPORT_ME __attribute__ ((visibility("default")))
JNIEnv* env_;
@ -665,20 +619,22 @@ JNIEnv* env_;
int argc=1;
const char * argv[32];
std::string graphicpath;
std::string doom_path;
const char * getDoomPath()
static const char * getGamePath()
{
return doom_path.c_str();
}
jint EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_init( JNIEnv* env,
jobject thiz,jstring graphics_dir,jint mem_mb,jobjectArray argsArray,jint renderer,jstring doom_path_ )
jobject thiz,jstring graphics_dir,jint audio_rate,jint audio_buffer_size,jobjectArray argsArray,jint renderer,jstring doom_path_ )
{
env_ = env;
android_sample_rate = audio_rate;
android_audio_buffer_size = audio_buffer_size;
curRenderer = renderer;
//curRenderer = REND_SOFT;
curRenderer = REND_GL;
@ -698,11 +654,15 @@ Java_com_beloko_duke_engine_NativeLib_init( JNIEnv* env,
doom_path = (char *)(env)->GetStringUTFChars( doom_path_, 0);
//Change working dir, save games etc
// FIXME: potentially conflicts with chdirs in -game_dir support
chdir(getGamePath());
char timidity_env[512];
chdir(getDoomPath());
putenv("TIMIDITY_CFG=../timidity.cfg");
sprintf(timidity_env,"TIMIDITY_CFG=%s/../timidity.cfg",getGamePath());
//putenv("TIMIDITY_CFG=../timidity.cfg");
putenv(timidity_env);
LOGI("doom_path = %s",getDoomPath());
LOGI("doom_path = %s",getGamePath());
//argv[0] = "vavoom";
//argv[1] = "-basedir";
//argv[2] = "/sdcard/Beloko/Quake/FULL";
@ -715,7 +675,6 @@ Java_com_beloko_duke_engine_NativeLib_init( JNIEnv* env,
initControls(android_screen_width,-android_screen_height,graphicpath.c_str(),(graphicpath + "/touch_controls.xml").c_str());
//initControls(2,-2,graphicpath.c_str(),(graphicpath + "/prdoom.xml").c_str());
/*
if (renderer != REND_SOFT)
@ -746,8 +705,6 @@ Java_com_beloko_duke_engine_NativeLib_frame( JNIEnv* env,
LOGI("Java_com_beloko_duke_engine_NativeLib_frame");
PortableFrame();
frameControls();
return 0;
@ -756,6 +713,8 @@ Java_com_beloko_duke_engine_NativeLib_frame( JNIEnv* env,
__attribute__((visibility("default"))) jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
LOGI("JNI_OnLoad");
setTCJNIEnv(vm);
jvm_ = vm;
return JNI_VERSION_1_4;
}
@ -770,11 +729,9 @@ Java_com_beloko_duke_engine_NativeLib_keypress(JNIEnv *env, jobject obj,
{
if (down && (keycode == SDL_SCANCODE_ESCAPE ))
controlsContainer.finishEditing();
}
else
PortableKeyEvent(down,keycode,unicode);
}
@ -790,36 +747,43 @@ Java_com_beloko_duke_engine_NativeLib_touchEvent(JNIEnv *env, jobject obj,
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_doAction(JNIEnv *env, jobject obj,
jint state, jint action)
{
LOGI("doAction %d %d",state,action);
//gamepadButtonPressed();
if (hideTouchControls)
if (hideTouchControls && tcGameMain)
{
if (tcGameMain->isEnabled())
tcGameMain->animateOut(30);
LOGI("doAction %d %d",state,action);
if (tcGameWeapons->isEnabled())
tcGameWeapons->animateOut(30);
}
PortableAction(state,action);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogFwd(JNIEnv *env, jobject obj,
jfloat v)
{
PortableMoveFwd(v);
PortableMove(v, 0.f);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogSide(JNIEnv *env, jobject obj,
jfloat v)
{
PortableMoveSide(v);
PortableMove(0.f, v);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogPitch(JNIEnv *env, jobject obj,
jint mode,jfloat v)
{
PortableLookPitch(mode, v);
PortableLook(0.f, v);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_analogYaw(JNIEnv *env, jobject obj,
jint mode,jfloat v)
{
PortableLookYaw(mode, v);
PortableLook(v, 0.f);
}
void EXPORT_ME Java_com_beloko_duke_engine_NativeLib_setTouchSettings(JNIEnv *env, jobject obj,
@ -844,9 +808,6 @@ Java_com_beloko_duke_engine_NativeLib_quickCommand(JNIEnv *env, jobject obj,
PortableCommand(quickCommandString.c_str());
}
void EXPORT_ME
Java_com_beloko_duke_engine_NativeLib_setScreenSize( JNIEnv* env,
jobject thiz, jint width, jint height)
@ -855,11 +816,7 @@ Java_com_beloko_duke_engine_NativeLib_setScreenSize( JNIEnv* env,
android_screen_height = height;
}
#include "SDL_main.h"
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls)
void EXPORT_ME Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls)
{
/* This interface could expand with ABI negotiation, calbacks, etc. */
SDL_Android_Init(env, cls);
@ -867,5 +824,4 @@ void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls)
// SDL_EventState(SDL_TEXTINPUT,SDL_ENABLE);
}
}

View file

@ -21,15 +21,13 @@
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);
static float forwardmove, sidemove; //Joystick mode
static char sdl_text[2];
static droidinput_t droidinput;
int PortableKeyEvent(int state, int code,int unicode)
{
LOGI("PortableKeyEvent %d %d %d",state,code,unicode);
@ -50,118 +48,117 @@ int PortableKeyEvent(int state, int code,int unicode)
int posted = SDL_SendKeyboardText((const char*)sdl_text);
LOGI("posted = %d",posted);
}
if (state == 2)
PortableKeyEvent(0, code, unicode);
}
return 0;
}
void changeActionState(int state, int action)
{
if (state)
{
//BUTTONSET(action,1);
droidplayer.functionSticky |= ((uint64_t)1<<((uint64_t)(action)));
droidplayer.functionHeld |= ((uint64_t)1<<((uint64_t)(action)));
droidinput.functionSticky |= ((uint64_t)1<<((uint64_t)(action)));
droidinput.functionHeld |= ((uint64_t)1<<((uint64_t)(action)));
return;
}
//BUTTONCLEAR(action);
droidplayer.functionHeld &= ~((uint64_t) 1<<((uint64_t) (action)));
droidinput.functionHeld &= ~((uint64_t) 1<<((uint64_t) (action)));
}
void PortableAction(int state, int action)
{
LOGI("PortableAction action = %d, state = %d", action, state);
//Action is for the menu
if (action >= MENU_UP)
{
if (PortableRead(READ_MENU))
{
int sdl_code = 0;
switch (action)
{
case MENU_UP:
sdl_code = SDL_SCANCODE_UP;
break;
case MENU_DOWN:
sdl_code = SDL_SCANCODE_DOWN;
break;
case MENU_LEFT:
sdl_code = SDL_SCANCODE_LEFT;
break;
case MENU_RIGHT:
sdl_code = SDL_SCANCODE_RIGHT;
break;
case MENU_SELECT:
sdl_code = SDL_SCANCODE_RETURN;
break;
case MENU_BACK:
sdl_code = SDL_SCANCODE_ESCAPE;
break;
}
PortableKeyEvent(state, sdl_code, 0);
return;
}
}
else
{
if (PortableRead(READ_MENU)) //If in the menu, dont do any game actions
return;
//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)
droidplayer.crouchToggleState = !droidplayer.crouchToggleState;
droidinput.crouchToggleState = !droidinput.crouchToggleState;
state = droidplayer.crouchToggleState;
state = droidinput.crouchToggleState;
}
}
}
//Check if jumping while crouched
if (action == gamefunc_Jump)
{
droidplayer.crouchToggleState = 0;
crouchToggleState = 0;
changeActionState(0, gamefunc_Crouch);
}
changeActionState(state, action);
LOGI("PortableAction state = 0x%016llX", CONTROL_ButtonState);
}
}
// =================== FORWARD and SIDE MOVMENT ==============
void PortableMoveFwd(float fwd)
{
forwardmove = fclamp2(fwd, -1.f, 1.f);
}
void PortableMoveSide(float strafe)
{
sidemove = fclamp2(strafe, -1.f, 1.f);
}
void PortableMove(float fwd, float strafe)
{
PortableMoveFwd(fwd);
PortableMoveSide(strafe);
droidinput.forwardmove = fclamp2(fwd + droidinput.forwardmove, -1.f, 1.f);
droidinput.sidemove = fclamp2(strafe + droidinput.sidemove, -1.f, 1.f);
}
//======================================================================
//Look up and down
int look_pitch_mode;
float look_pitch_mouse,look_pitch_abs,look_pitch_joy;
void PortableLookPitch(int mode, float pitch)
void PortableLook(double yaw, double pitch)
{
//LOGI("PortableLookPitch %d %f",mode, pitch);
look_pitch_mode = mode;
switch(mode)
{
case LOOK_MODE_MOUSE:
look_pitch_mouse += pitch;
break;
case LOOK_MODE_ABSOLUTE:
look_pitch_abs = pitch;
break;
case LOOK_MODE_JOYSTICK:
look_pitch_joy = pitch;
break;
droidinput.pitch += pitch;
droidinput.yaw += yaw;
}
}
//left right
int look_yaw_mode;
float look_yaw_mouse,look_yaw_joy;
void PortableLookYaw(int mode, float yaw)
{
look_yaw_mode = mode;
switch(mode)
{
case LOOK_MODE_MOUSE:
look_yaw_mouse += yaw;
break;
case LOOK_MODE_JOYSTICK:
look_yaw_joy = yaw;
break;
}
}
void PortableCommand(const char * cmd)
{
@ -173,12 +170,6 @@ void PortableInit(int argc,const char ** argv)
main(argc, argv);
}
void PortableFrame()
{
//NOT USED for DUKE
}
int32_t PortableRead(portableread_t r)
{
switch (r)
@ -194,7 +185,7 @@ int32_t PortableRead(portableread_t r)
case READ_RENDERER:
return getrendermode();
case READ_LASTWEAPON:
return droidplayer.lastWeapon;
return droidinput.lastWeapon;
case READ_PAUSED:
return ud.pause_on != 0;
default:
@ -207,51 +198,32 @@ int32_t PortableRead(portableread_t r)
void CONTROL_Android_SetLastWeapon(int w)
{
LOGI("setLastWeapon %d",w);
droidplayer.lastWeapon = w;
droidinput.lastWeapon = w;
}
void CONTROL_Android_ClearButton(int32_t whichbutton)
{
BUTTONCLEAR(whichbutton);
droidplayer.functionHeld &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
droidinput.functionHeld &= ~((uint64_t)1<<((uint64_t)(whichbutton)));
}
void CONTROL_Android_PollDevices(ControlInfo *info)
{
//LOGI("CONTROL_Android_PollDevices %f %f",forwardmove,sidemove);
info->dz = -forwardmove * 5000;
info->dx = sidemove * 200;
info->dz = -droidinput.forwardmove * 5000;
info->dx = droidinput.sidemove * 200;
info->dpitch = droidinput.pitch * 100000;
info->dyaw = -droidinput.yaw * 80000;
switch(look_pitch_mode)
{
case LOOK_MODE_MOUSE:
info->dpitch = look_pitch_mouse * 100000;
look_pitch_mouse = 0;
break;
case LOOK_MODE_ABSOLUTE:
//cl.viewangles[0] = look_pitch_abs * 80;
break;
case LOOK_MODE_JOYSTICK:
info->dpitch = look_pitch_joy * 2000;
break;
}
droidinput.forwardmove = droidinput.sidemove = 0.f;
droidinput.pitch = droidinput.yaw = 0.f;
switch(look_yaw_mode)
{
case LOOK_MODE_MOUSE:
info->dyaw = -look_yaw_mouse * 80000;
look_yaw_mouse = 0;
break;
case LOOK_MODE_JOYSTICK:
info->dyaw = -look_yaw_joy * 4000;
break;
}
CONTROL_ButtonState = 0;
CONTROL_ButtonState |= droidplayer.functionSticky;
CONTROL_ButtonState |= droidplayer.functionHeld;
CONTROL_ButtonState |= droidinput.functionSticky;
CONTROL_ButtonState |= droidinput.functionHeld;
droidplayer.functionSticky = 0;
droidinput.functionSticky = 0;
//LOGI("poll state = 0x%016llX",CONTROL_ButtonState);
}

View file

@ -1,17 +1,23 @@
#include "function.h"
#include "compat.h"
enum {
LOOK_MODE_MOUSE = 0,
LOOK_MODE_ABSOLUTE,
LOOK_MODE_JOYSTICK
};
#ifdef __cplusplus
extern "C"
{
#endif
#define MENU_UP 0x200
#define MENU_DOWN 0x201
#define MENU_LEFT 0x202
#define MENU_RIGHT 0x203
#define MENU_SELECT 0x204
#define MENU_BACK 0x205
#define BUTTONSET(x,value) (CONTROL_ButtonState |= ((uint64_t)value<<((uint64_t)(x))))
#define BUTTONCLEAR(x) (CONTROL_ButtonState &= ~((uint64_t)1<<((uint64_t)(x))))
#define PRECISIONSHOOTFACTOR 0.3f
typedef enum {
READ_MENU,
READ_WEAPONS,
@ -22,30 +28,28 @@ extern "C"
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;
double pitch, yaw;
float forwardmove, sidemove;
} droidinput_t;
int PortableKeyEvent(int state, int code, int unicode);
int PortableRead(portableread_t r);
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 PortableLook(double yaw, double pitch);
void PortableCommand(const char * cmd);
void PortableInit(int argc, const char ** argv);
void PortableFrame();
#ifdef __cplusplus
}