From c6e003ee9b35683cb4857e2a324f34be2d7a1e9e Mon Sep 17 00:00:00 2001 From: terminx Date: Wed, 17 May 2006 03:13:39 +0000 Subject: [PATCH] Input changes from JonoF git-svn-id: https://svn.eduke32.com/eduke32@171 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/config.c | 16 ++-- polymer/eduke32/source/config.h | 2 +- polymer/eduke32/source/game.c | 45 ++++----- polymer/eduke32/source/jmact/control.c | 115 ++++------------------ polymer/eduke32/source/menus.c | 13 ++- polymer/eduke32/source/osdcmds.c | 25 +++++ polymer/eduke32/source/player.c | 127 ++++++++++++------------- 7 files changed, 142 insertions(+), 201 deletions(-) diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index 6e64b6ae1..b9f74b9a0 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -59,7 +59,7 @@ int32 MixRate; //int32 MidiPort; int32 ReverseStereo; -int32 ControllerType; +int32 UseJoystick = 0, UseMouse = 1; int32 RunMode; int32 AutoAim; // JBF 20031125 int32 ShowOpponentWeapons; @@ -200,7 +200,6 @@ void CONFIG_SetDefaults( void ) AmbienceToggle = 1; AutoAim = 1; - ControllerType = 1; FXDevice = 0; FXVolume = 220; MixRate = 44100; @@ -241,6 +240,8 @@ void CONFIG_SetDefaults( void ) ud.statusbarmode = 0; ud.statusbarscale = 100; ud.weaponswitch = 3; // new+empty + UseJoystick = 0; + UseMouse = 1; VoiceToggle = 2; Bstrcpy(ud.rtsname, "DUKE.RTS"); @@ -670,13 +671,13 @@ void CONFIG_ReadSetup( void ) SCRIPT_GetNumber( scripthandle, "Sound Setup", "MixRate",&MixRate); SCRIPT_GetNumber( scripthandle, "Sound Setup", "ReverseStereo",&ReverseStereo); - SCRIPT_GetNumber( scripthandle, "Controls","ControllerType",&ControllerType); SCRIPT_GetNumber( scripthandle, "Controls","MouseAimingFlipped",&ud.mouseflip); // mouse aiming inverted SCRIPT_GetNumber( scripthandle, "Controls","MouseAiming",&ud.mouseaiming); // 1=momentary/0=toggle + ps[0].aim_mode = ud.mouseaiming; SCRIPT_GetNumber( scripthandle, "Controls","MouseFilter",&MouseFilter); SCRIPT_GetNumber( scripthandle, "Controls","SmoothInput",&SmoothInput); - //SCRIPT_GetNumber( scripthandle, "Controls","GameMouseAiming",(int32 *)&ps[0].aim_mode); // dupe of below (?) - ps[0].aim_mode = ud.mouseaiming; + SCRIPT_GetNumber( scripthandle, "Controls","UseJoystick",&UseJoystick); + SCRIPT_GetNumber( scripthandle, "Controls","UseMouse",&UseMouse); SCRIPT_GetNumber( scripthandle, "Controls","AimingFlag",(int32 *)&myaimmode); // (if toggle mode) gives state SCRIPT_GetNumber( scripthandle, "Controls","RunKeyBehaviour",&ud.runkey_mode); // JBF 20031125 SCRIPT_GetNumber( scripthandle, "Controls","AutoAim",&AutoAim); // JBF 20031125 @@ -713,12 +714,13 @@ void CONFIG_WriteSetup( void ) SCRIPT_PutNumber( scripthandle, "Controls","AimingFlag",(long) myaimmode,false,false); SCRIPT_PutNumber( scripthandle, "Controls","AutoAim",AutoAim,false,false); - // SCRIPT_PutNumber( scripthandle, "Controls","GameMouseAiming",(int32) ps[myconnectindex].aim_mode,false,false); - SCRIPT_PutNumber( scripthandle, "Controls", "MouseAimingFlipped",ud.mouseflip,false,false); + SCRIPT_PutNumber( scripthandle, "Controls","MouseAimingFlipped",ud.mouseflip,false,false); SCRIPT_PutNumber( scripthandle, "Controls","MouseAiming",ud.mouseaiming,false,false); SCRIPT_PutNumber( scripthandle, "Controls","MouseFilter",MouseFilter,false,false); SCRIPT_PutNumber( scripthandle, "Controls","SmoothInput",SmoothInput,false,false); SCRIPT_PutNumber( scripthandle, "Controls","RunKeyBehaviour",ud.runkey_mode,false,false); + SCRIPT_PutNumber( scripthandle, "Controls","UseJoystick",UseJoystick,false,false); + SCRIPT_PutNumber( scripthandle, "Controls","UseMouse",UseMouse,false,false); SCRIPT_PutNumber( scripthandle, "Controls","WeaponSwitchMode",ud.weaponswitch,false,false); SCRIPT_PutNumber( scripthandle, "Misc", "AutoMsg",ud.automsg,false,false); diff --git a/polymer/eduke32/source/config.h b/polymer/eduke32/source/config.h index a4430e887..a7ca2c962 100644 --- a/polymer/eduke32/source/config.h +++ b/polymer/eduke32/source/config.h @@ -42,7 +42,7 @@ extern int32 MixRate; //extern int32 MidiPort; extern int32 ReverseStereo; -extern int32 ControllerType; +extern int32 UseJoystick, UseMouse; extern int32 RunMode; extern int32 AutoAim; extern int32 MouseFilter; diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 840c32c21..c3bcc942e 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -7645,6 +7645,7 @@ static int parse_rancid_net(scriptfile *script) Bsprintf(tempbuf,"%s",strtok(NULL,":")); if(atoi(tempbuf) > 1024) Bsprintf(rancid_local_port_string,"-p %s",tempbuf); + Bfree(ip); } break; case T_MODE: @@ -7652,6 +7653,7 @@ static int parse_rancid_net(scriptfile *script) char *mode; if (scriptfile_getstring(script,&mode)) break; + Bfree(mode); } break; case T_ALLOW: @@ -7660,6 +7662,7 @@ static int parse_rancid_net(scriptfile *script) if (scriptfile_getstring(script,&ip)) break; Bstrcpy(rancid_ip_strings[rancid_players++],ip); + Bfree(ip); } break; case T_EOF: @@ -7751,7 +7754,7 @@ void checkcommandline(int argc,char **argv) { if(load_rancid_net(CommandNet) != -1) { - char tmp[16]; + char tmp[32]; CommandNet = 0; @@ -7827,10 +7830,10 @@ void checkcommandline(int argc,char **argv) { if(Bstrcmp(rancid_ip_strings[j],rancid_ip_strings[MAXPLAYERS]) == 0) Bsprintf(rancid_ip_strings[j],"/n1"); - netparam[j] = rancid_ip_strings[j]; + netparam[j] = (char *)&rancid_ip_strings[j]; } if(j != netparamcount) - netparam[j] = rancid_local_port_string; + netparam[j] = (char *)&rancid_local_port_string; } } i++; @@ -8533,21 +8536,22 @@ void Startup(void) exit(1); } - if (CONTROL_Startup( ControllerType, &GetTime, TICRATE )) { + if (CONTROL_Startup( 1, &GetTime, TICRATE )) { uninitengine(); exit(1); } SetupGameButtons(); - CONFIG_SetupMouse(); - CONFIG_SetupJoystick(); + CONFIG_SetupMouse(); + CONFIG_SetupJoystick(); + + CONTROL_JoystickEnabled = (UseJoystick && CONTROL_JoyPresent); + CONTROL_MouseEnabled = (UseMouse && CONTROL_MousePresent); - // JBF 20040215: evil and nasty place to do this, but joysticks are evil and nasty too - if (ControllerType == controltype_keyboardandjoystick) { - for (i=0;i0)); - CONTROL_JoyPresent = ((inputdevices & 3) == 3); - CONTROL_JoystickEnabled = CONTROL_JoyPresent; - break; - } - - if (CONTROL_MousePresent) + // case controltype_keyboardandmouse: + CONTROL_NumMouseAxes = MAXMOUSEAXES; + CONTROL_NumMouseButtons = MAXMOUSEBUTTONS; + CONTROL_MousePresent = MOUSE_Init(); + CONTROL_MouseEnabled = CONTROL_MousePresent; + // break; + + // case controltype_keyboardandjoystick: + CONTROL_NumJoyAxes = min(MAXJOYAXES,joynumaxes); + CONTROL_NumJoyButtons = min(MAXJOYBUTTONS,joynumbuttons + 4*(joynumhats>0)); + CONTROL_JoyPresent = ((inputdevices & 4) == 4); + CONTROL_JoystickEnabled = CONTROL_JoyPresent; + // break; + //} + + if (CONTROL_MousePresent) initprintf("CONTROL_Startup: Mouse Present\n"); if (CONTROL_JoyPresent) initprintf("CONTROL_Startup: Joystick Present\n"); diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 02e51f33f..ed35a01c6 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -113,14 +113,11 @@ static int probe_(int type,int x,int y,int i,int n) s = 1+(CONTROL_GetMouseSensitivity()>>4); - if( ControllerType == 1 && CONTROL_MousePresent ) { CONTROL_GetInput( &minfo ); mi += minfo.dz; } - else minfo.dz = minfo.dyaw = 0; - if( x == (320>>1) ) centre = 320>>2; else centre = 0; @@ -561,7 +558,6 @@ void menus(void) getpackets(); - if(ControllerType == 1 && CONTROL_MousePresent) { if(buttonstat != 0 && !onbar) { @@ -572,7 +568,6 @@ void menus(void) else buttonstat = MOUSE_GetButtons(); } - else buttonstat = 0; if( (ps[myconnectindex].gm&MODE_MENU) == 0 ) { @@ -2447,7 +2442,7 @@ cheat_for_port_credits: currentlist = 0; case 5: case 6: - if (x==6 && (!CONTROL_JoystickEnabled || !CONTROL_JoyPresent)) break; + if (x==6 && !CONTROL_JoyPresent) break; cmenu(204+x-4); break; } @@ -2458,7 +2453,7 @@ cheat_for_port_credits: menutext(160,c+18+18+18, MENUHIGHLIGHT(3),ud.recstat == 1,"PLAYER SETUP"); menutext(160,c+18+18+18+18, MENUHIGHLIGHT(4),0,"KEYBOARD SETUP"); menutext(160,c+18+18+18+18+18, MENUHIGHLIGHT(5),0,"MOUSE SETUP"); - menutext(160,c+18+18+18+18+18+18,MENUHIGHLIGHT(6),CONTROL_JoyPresent==0 || CONTROL_JoystickEnabled==0,"JOYSTICK SETUP"); + menutext(160,c+18+18+18+18+18+18,MENUHIGHLIGHT(6),CONTROL_JoyPresent==0,"JOYSTICK SETUP"); break; // JBF 20031206: Video settings menu @@ -3300,6 +3295,10 @@ cheat_for_port_credits: else l = analog_turning; JoystickAnalogueAxes[thispage*2+(x==7)] = l; CONTROL_MapAnalogAxis(thispage*2+(x==7),l,controldevice_joystick); + { + extern int32 mouseyaxismode; // player.c + mouseyaxismode = -1; + } break; default:break; } diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index 368aac43e..3c9e42122 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -599,6 +599,28 @@ void onvideomodechange(int newmode) restorepalette = 1; } +int osdcmd_usemousejoy(const osdfuncparm_t *parm) +{ + int showval = (parm->numparms < 1); + if (!Bstrcasecmp(parm->name, "usemouse")) { + if (showval) { OSD_Printf("usemouse is %d\n", UseMouse); } + else { + UseMouse = (atoi(parm->parms[0]) != 0); + CONTROL_MouseEnabled = (UseMouse && CONTROL_MousePresent); + } + return OSDCMD_OK; + } + else if (!Bstrcasecmp(parm->name, "usejoystick")) { + if (showval) { OSD_Printf("usejoystick is %d\n", UseJoystick); } + else { + UseJoystick = (atoi(parm->parms[0]) != 0); + CONTROL_JoystickEnabled = (UseJoystick && CONTROL_JoyPresent); + } + return OSDCMD_OK; + } + return OSDCMD_SHOWHELP; +} + int osdcmd_mpmap(const osdfuncparm_t *parm) { int i; @@ -686,6 +708,9 @@ int registerosdcommands(void) OSD_RegisterFunction("restartvid","restartvid: reinitialised the video mode",osdcmd_restartvid); OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode); + OSD_RegisterFunction("usemouse","usemouse: enables input from the mouse if it is present",osdcmd_usemousejoy); + OSD_RegisterFunction("usejoystick","usejoystick: enables input from the joystick if it is present",osdcmd_usemousejoy); + //baselayer_onvideomodechange = onvideomodechange; return 0; diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 2957d4bfe..d2c9d977a 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -2684,6 +2684,7 @@ void displayweapon(short snum) long myaimmode = 0, myaimstat = 0, omyaimstat = 0; +int32 mouseyaxismode = -1; static ControlInfo lastinfo = { 0,0,0,0,0,0 }; static int jump_input = 0; @@ -2691,7 +2692,6 @@ static int jump_input = 0; void getinput(short snum) { short j, daang; - // MED ControlInfo info; int32 tics; boolean running; @@ -2703,19 +2703,54 @@ void getinput(short snum) momx = momy = 0; p = &ps[snum]; + if( (p->gm&MODE_MENU) || (p->gm&MODE_TYPE) || (ud.pause_on && !KB_KeyPressed(sc_Pause)) ) + { + CONTROL_GetInput( &info ); + memset(&lastinfo, 0, sizeof(lastinfo)); + loc.fvel = vel = 0; + loc.svel = svel = 0; + loc.avel = angvel = 0; + loc.horz = horiz = 0; + loc.bits = (((long)gamequit)<<26); + return; + } + + if (ud.mouseaiming) + myaimmode = BUTTON(gamefunc_Mouse_Aiming); + else + { + omyaimstat = myaimstat; myaimstat = BUTTON(gamefunc_Mouse_Aiming); + if (myaimstat > omyaimstat) + { + myaimmode ^= 1; + FTA(44+myaimmode,p); + } + } + + { + int32 i; + if (myaimmode) i = analog_lookingupanddown; + else i = MouseAnalogueAxes[1]; + + if (i != mouseyaxismode) { + CONTROL_MapAnalogAxis(1, i, controldevice_mouse); + mouseyaxismode = i; + } + } + CONTROL_GetInput( &info ); if(MouseFilter) { - if(info.dz > 0) + if(info.dpitch > 0) { - info.dz -= MouseFilter; - if(info.dz < 0) info.dz = 0; + info.dpitch -= MouseFilter; + if(info.dpitch < 0) info.dpitch = 0; } - else if(info.dz < 0) + else if(info.dpitch < 0) { - info.dz += MouseFilter; - if(info.dz > 0) info.dz = 0; + info.dpitch += MouseFilter; + if(info.dpitch > 0) info.dpitch = 0; } if(info.dyaw > 0) { @@ -2729,32 +2764,9 @@ void getinput(short snum) } } - if( (p->gm&MODE_MENU) || (p->gm&MODE_TYPE) || (ud.pause_on && !KB_KeyPressed(sc_Pause)) ) - { - loc.fvel = vel = 0; - loc.svel = svel = 0; - loc.avel = angvel = 0; - loc.horz = horiz = 0; - loc.bits = (((long)gamequit)<<26); - info.dz = info.dyaw = 0; - return; - } - tics = totalclock-lastcontroltime; lastcontroltime = totalclock; - if (ud.mouseaiming) - myaimmode = BUTTON(gamefunc_Mouse_Aiming); - else - { - omyaimstat = myaimstat; myaimstat = BUTTON(gamefunc_Mouse_Aiming); - if (myaimstat > omyaimstat) - { - myaimmode ^= 1; - FTA(44+myaimmode,p); - } - } - if(multiflag == 1) { loc.bits = 1<<17; @@ -2840,9 +2852,6 @@ void getinput(short snum) svel = vel = angvel = horiz = 0; - if( CONTROL_JoystickEnabled ) - if ( running ) info.dz *= 2; - if(SmoothInput) { if( BUTTON(gamefunc_Strafe) ) { @@ -2853,17 +2862,11 @@ void getinput(short snum) lastinfo.dyaw = (lastinfo.dyaw+info.dyaw) % 64; } - if( myaimmode ) - { - if(ud.mouseflip) - horiz = -(info.dz+lastinfo.dz)/(314-128); - else horiz = (info.dz+lastinfo.dz)/(314-128); + if(ud.mouseflip) + horiz = -(info.dpitch+lastinfo.dpitch)/(314-128); + else horiz = (info.dpitch+lastinfo.dpitch)/(314-128); - lastinfo.dz = (lastinfo.dz+info.dz) % (314-128); - info.dz = 0; - } else { - lastinfo.dz = info.dz % (1<<6); - } + lastinfo.dpitch = (lastinfo.dpitch+info.dpitch) % (314-128); } else { @@ -2873,16 +2876,13 @@ void getinput(short snum) angvel = info.dyaw/64; } - if( myaimmode ) - { - if(ud.mouseflip) - horiz -= info.dz/(314-128); - else horiz += info.dz/(314-128); - info.dz = 0; - } + if(ud.mouseflip) + horiz -= info.dpitch/(314-128); + else horiz += info.dpitch/(314-128); } svel -= info.dx; + lastinfo.dz = info.dz % (1<<6); vel = -info.dz>>6; if (running) @@ -2899,13 +2899,9 @@ void getinput(short snum) if (BUTTON(gamefunc_Strafe)) { if ( BUTTON(gamefunc_Turn_Left) && (ps[snum].movement_lock[3] == 0)) - { svel -= -keymove; - } if ( BUTTON(gamefunc_Turn_Right) && (ps[snum].movement_lock[4] == 0)) - { svel -= keymove; - } } else { @@ -2913,30 +2909,20 @@ void getinput(short snum) { turnheldtime += tics; if (turnheldtime>=TURBOTURNTIME) - { angvel -= turnamount; - } else - { angvel -= PREAMBLETURN; - } } else if ( BUTTON(gamefunc_Turn_Right)) { turnheldtime += tics; if (turnheldtime>=TURBOTURNTIME) - { angvel += turnamount; - } else - { angvel += PREAMBLETURN; - } } else - { turnheldtime=0; - } } if ( BUTTON(gamefunc_Strafe_Left) && (ps[snum].movement_lock[3] == 0)) @@ -4405,6 +4391,7 @@ HORIZONLY: } // center_view + i = 0; if( sb_snum&(1<<18) || p->hard_landing) { SetGameVarID(g_iReturnVarID,0,pi,snum); @@ -4425,6 +4412,7 @@ HORIZONLY: p->return_to_center = 9; if( sb_snum&(1<<5) ) p->horiz += 12; // running p->horiz += 12; + i++; } } @@ -4438,6 +4426,7 @@ HORIZONLY: p->return_to_center = 9; if( sb_snum&(1<<5) ) p->horiz -= 12; p->horiz -= 12; + i++; } } @@ -4450,6 +4439,7 @@ HORIZONLY: // running if( sb_snum&(1<<5) ) p->horiz += 6; p->horiz += 6; + i++; } } @@ -4462,6 +4452,7 @@ HORIZONLY: // running if( sb_snum&(1<<5) ) p->horiz -= 6; p->horiz -= 6; + i++; } } if(p->return_to_center > 0) @@ -4469,6 +4460,7 @@ HORIZONLY: { p->return_to_center--; p->horiz += 33-(p->horiz/3); + i++; } if(p->hard_landing > 0) @@ -4477,13 +4469,12 @@ HORIZONLY: p->horiz -= (p->hard_landing<<4); } - if(p->aim_mode) - p->horiz += sync[snum].horz; - else + if(i) { if( p->horiz > 95 && p->horiz < 105) p->horiz = 100; if( p->horizoff > -5 && p->horizoff < 5) p->horizoff = 0; } + p->horiz += sync[snum].horz; if(p->horiz > 299) p->horiz = 299; else if(p->horiz < -99) p->horiz = -99; @@ -4915,7 +4906,7 @@ SHOOTINCODE: if(*kb == aplWeaponSpawnTime[p->curr_weapon][snum]) DoSpawn(p); - if ((*kb) >= aplWeaponTotalTime[p->curr_weapon][snum]) + if ((*kb) >= aplWeaponTotalTime[p->curr_weapon][snum]) { if(/*!(aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_CHECKATRELOAD) && */ p->reloading == 1 || (aplWeaponReload[p->curr_weapon][snum] > aplWeaponTotalTime[p->curr_weapon][snum] && p->ammo_amount[p->curr_weapon] > 0