Skip to content

Commit 77207eb

Browse files
committed
Adjustable gamepad sensitivity
1 parent efdd681 commit 77207eb

File tree

7 files changed

+113
-17
lines changed

7 files changed

+113
-17
lines changed

foreign.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define STR_LGC "Load Game called\n\""
3333
#define STR_EMPTY "empty"
3434
#define STR_CALIB "Calibrate"
35-
#define STR_JOYST "Joystick"
35+
#define STR_JOYST "Gamepad"
3636
#define STR_MOVEJOY "Move joystick to\nupper left and\npress button 0\n"
3737
#define STR_MOVEJOY2 "Move joystick to\nlower right and\npress button 1\n"
3838
#define STR_ESCEXIT "ESC to exit"
@@ -44,18 +44,20 @@
4444
#define STR_SB "Sound Blaster"
4545

4646
#define STR_MOUSEEN "Mouse Enabled"
47-
#define STR_JOYEN "Joystick Enabled"
47+
#define STR_JOYEN "Gamepad Enabled"
4848
#define STR_PORT2 "Use joystick port 2"
49-
#define STR_GAMEPAD "Gravis GamePad Enabled"
50-
#define STR_SENS "Mouse Sensitivity"
49+
#define STR_GAMEPAD "Gamepad Enabled"
50+
#define STR_SENS "Mouse Sensitivity"
51+
#define STR_JOYSENS "Gamepad Sensitivity"
5152
#define STR_CUSTOM "Customize controls"
5253

5354
#define STR_DADDY "Can I play, Daddy?"
5455
#define STR_HURTME "Don't hurt me."
5556
#define STR_BRINGEM "Bring 'em on!"
5657
#define STR_DEATH "I am Death incarnate!"
5758

58-
#define STR_MOUSEADJ "Adjust Mouse Sensitivity"
59+
#define STR_MOUSEADJ "Adjust Mouse Sensitivity"
60+
#define STR_JOYADJ "Adjust Gamepad Sensitivity"
5961
#define STR_SLOW "Slow"
6062
#define STR_FAST "Fast"
6163

wl_agent.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,12 @@ void ControlMovement (objtype *ob)
173173
oldy = player->y;
174174

175175
int joyx, joyy;
176-
IN_GetJoyDelta (&joyx, &joyy, SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_RIGHTY);
176+
float joyfactor = 1;
177+
if (joystickenabled) {
178+
IN_GetJoyDelta (&joyx, &joyy, SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_RIGHTY);
179+
joyfactor = abs(joyx) / 127.0;
180+
}
177181

178-
float joyfactor = abs(joyx) / 127.0;
179182
if(buttonstate[bt_strafeleft] || joyx < -JOYDEADZONE)
180183
{
181184
angle = ob->angle + ANGLES/4;

wl_def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ extern fixed scale;
911911

912912
extern int dirangle[9];
913913

914+
extern int joyadjustment;
914915
extern int mouseadjustment;
915916
extern int shootdelta;
916917
extern unsigned screenofs;

wl_main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void Quit (const char *error,...);
7272
boolean startgame;
7373
boolean loadedgame;
7474
int mouseadjustment;
75+
int joyadjustment;
7576

7677
char configdir[256] = "";
7778
char configname[13] = "config.";
@@ -172,6 +173,7 @@ void ReadConfig(void)
172173

173174
read(file,&viewsize,sizeof(viewsize));
174175
read(file,&mouseadjustment,sizeof(mouseadjustment));
176+
read(file,&joyadjustment,sizeof(joyadjustment));
175177

176178
close(file);
177179

@@ -198,6 +200,9 @@ void ReadConfig(void)
198200
if(mouseadjustment<0) mouseadjustment=0;
199201
else if(mouseadjustment>9) mouseadjustment=9;
200202

203+
if(joyadjustment<0) joyadjustment=0;
204+
else if(joyadjustment>9) joyadjustment=9;
205+
201206
if(viewsize<4) viewsize=4;
202207
else if(viewsize>21) viewsize=21;
203208

@@ -234,6 +239,7 @@ void ReadConfig(void)
234239

235240
viewsize = 19; // start with a good size
236241
mouseadjustment=5;
242+
joyadjustment=5;
237243
}
238244

239245
SD_SetMusicMode (sm);
@@ -289,6 +295,7 @@ void WriteConfig(void)
289295

290296
write(file,&viewsize,sizeof(viewsize));
291297
write(file,&mouseadjustment,sizeof(mouseadjustment));
298+
write(file,&joyadjustment,sizeof(joyadjustment));
292299

293300
close(file);
294301
}

wl_menu.cpp

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ CP_itemtype SndMenu[] = {
120120
};
121121

122122
#ifdef JAPAN
123-
enum { CTL_MOUSEENABLE, CTL_JOYENABLE, CTL_JOY2BUTTONUNKNOWN, CTL_GAMEPADUNKONWN, CTL_MOUSESENS, CTL_CUSTOMIZE };
123+
enum { CTL_MOUSEENABLE, CTL_JOYENABLE, CTL_JOY2BUTTONUNKNOWN, CTL_GAMEPADUNKONWN, CTL_MOUSESENS, CTL_JOYSENS, CTL_CUSTOMIZE };
124124
#else
125-
enum { CTL_MOUSEENABLE, CTL_MOUSESENS, CTL_JOYENABLE, CTL_CUSTOMIZE };
125+
enum { CTL_MOUSEENABLE, CTL_MOUSESENS, CTL_JOYENABLE, CTL_JOYSENS, CTL_CUSTOMIZE };
126126
#endif
127127

128128
CP_itemtype CtlMenu[] = {
@@ -132,11 +132,13 @@ CP_itemtype CtlMenu[] = {
132132
{0, "", 0},
133133
{0, "", 0},
134134
{0, "", MouseSensitivity},
135+
{0, "", JoySensitivity},
135136
{1, "", CustomControls}
136137
#else
137138
{0, STR_MOUSEEN, 0},
138139
{0, STR_SENS, MouseSensitivity},
139140
{0, STR_JOYEN, 0},
141+
{0, STR_JOYSENS, JoySensitivity},
140142
{1, STR_CUSTOM, CustomControls}
141143
#endif
142144
};
@@ -1985,6 +1987,7 @@ CP_Control (int)
19851987
break;
19861988

19871989
case CTL_MOUSESENS:
1990+
case CTL_JOYSENS:
19881991
case CTL_CUSTOMIZE:
19891992
DrawCtlScreen ();
19901993
MenuFadeIn ();
@@ -2009,7 +2012,7 @@ CP_Control (int)
20092012
// DRAW MOUSE SENSITIVITY SCREEN
20102013
//
20112014
void
2012-
DrawMouseSens (void)
2015+
DrawSlider (int value, const char *sorg)
20132016
{
20142017
#ifdef JAPAN
20152018
CA_CacheScreen (S_MOUSESENSPIC);
@@ -2026,7 +2029,7 @@ DrawMouseSens (void)
20262029
WindowW = 320;
20272030
PrintY = 82;
20282031
SETFONTCOLOR (READCOLOR, BKGDCOLOR);
2029-
US_CPrint (STR_MOUSEADJ);
2032+
US_CPrint (sorg);
20302033

20312034
SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
20322035
#ifdef SPANISH
@@ -2046,13 +2049,86 @@ DrawMouseSens (void)
20462049

20472050
VWB_Bar (60, 97, 200, 10, TEXTCOLOR);
20482051
DrawOutline (60, 97, 200, 10, 0, HIGHLIGHT);
2049-
DrawOutline (60 + 20 * mouseadjustment, 97, 20, 10, 0, READCOLOR);
2050-
VWB_Bar (61 + 20 * mouseadjustment, 98, 19, 9, READHCOLOR);
2052+
DrawOutline (60 + 20 * value, 97, 20, 10, 0, READCOLOR);
2053+
VWB_Bar (61 + 20 * value, 98, 19, 9, READHCOLOR);
20512054

20522055
VW_UpdateScreen ();
20532056
MenuFadeIn ();
20542057
}
20552058

2059+
///////////////////////////
2060+
//
2061+
// ADJUST MOUSE SENSITIVITY
2062+
//
2063+
int
2064+
JoySensitivity (int)
2065+
{
2066+
ControlInfo ci;
2067+
int exit = 0, oldJA;
2068+
2069+
2070+
oldJA = joyadjustment;
2071+
DrawSlider (joyadjustment, STR_JOYADJ);
2072+
do
2073+
{
2074+
SDL_Delay(5);
2075+
ReadAnyControl (&ci);
2076+
switch (ci.dir)
2077+
{
2078+
case dir_North:
2079+
case dir_West:
2080+
if (joyadjustment)
2081+
{
2082+
joyadjustment--;
2083+
VWB_Bar (60, 97, 200, 10, TEXTCOLOR);
2084+
DrawOutline (60, 97, 200, 10, 0, HIGHLIGHT);
2085+
DrawOutline (60 + 20 * joyadjustment, 97, 20, 10, 0, READCOLOR);
2086+
VWB_Bar (61 + 20 * joyadjustment, 98, 19, 9, READHCOLOR);
2087+
VW_UpdateScreen ();
2088+
SD_PlaySound (MOVEGUN1SND);
2089+
TicDelay(20);
2090+
}
2091+
break;
2092+
2093+
case dir_South:
2094+
case dir_East:
2095+
if (joyadjustment < 9)
2096+
{
2097+
joyadjustment++;
2098+
VWB_Bar (60, 97, 200, 10, TEXTCOLOR);
2099+
DrawOutline (60, 97, 200, 10, 0, HIGHLIGHT);
2100+
DrawOutline (60 + 20 * joyadjustment, 97, 20, 10, 0, READCOLOR);
2101+
VWB_Bar (61 + 20 * joyadjustment, 98, 19, 9, READHCOLOR);
2102+
VW_UpdateScreen ();
2103+
SD_PlaySound (MOVEGUN1SND);
2104+
TicDelay(20);
2105+
}
2106+
break;
2107+
default:
2108+
break;
2109+
}
2110+
2111+
if (ci.button0 || Keyboard[sc_Space] || Keyboard[sc_Enter])
2112+
exit = 1;
2113+
else if (ci.button1 || Keyboard[sc_Escape])
2114+
exit = 2;
2115+
2116+
}
2117+
while (!exit);
2118+
2119+
if (exit == 2)
2120+
{
2121+
joyadjustment = oldJA;
2122+
SD_PlaySound (ESCPRESSEDSND);
2123+
}
2124+
else
2125+
SD_PlaySound (SHOOTSND);
2126+
2127+
WaitKeyUp ();
2128+
MenuFadeOut ();
2129+
2130+
return 0;
2131+
}
20562132

20572133
///////////////////////////
20582134
//
@@ -2066,7 +2142,7 @@ MouseSensitivity (int)
20662142

20672143

20682144
oldMA = mouseadjustment;
2069-
DrawMouseSens ();
2145+
DrawSlider (mouseadjustment, STR_MOUSEADJ);
20702146
do
20712147
{
20722148
SDL_Delay(5);
@@ -2145,14 +2221,17 @@ DrawCtlScreen (void)
21452221
DrawStripes (10);
21462222
VWB_DrawPic (80, 0, C_CONTROLPIC);
21472223
VWB_DrawPic (112, 184, C_MOUSELBACKPIC);
2148-
DrawWindow (CTL_X - 8, CTL_Y - 5, CTL_W, CTL_H, BKGDCOLOR);
2224+
DrawWindow (CTL_X - 8, CTL_Y - 5, CTL_W, lengthof(CtlMenu) * 15, BKGDCOLOR);
21492225
#endif
21502226
WindowX = 0;
21512227
WindowW = 320;
21522228
SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
21532229

21542230
if (IN_JoyPresent())
2231+
{
21552232
CtlMenu[CTL_JOYENABLE].active = 1;
2233+
CtlMenu[CTL_JOYSENS].active = 1;
2234+
}
21562235

21572236
if (MousePresent)
21582237
{
@@ -2712,7 +2791,7 @@ DrawCustomScreen (void)
27122791

27132792
#ifndef SPEAR
27142793
PrintY = CST_Y;
2715-
US_CPrint ("Game Controller\n");
2794+
US_CPrint ("Gamepad\n");
27162795
#else
27172796
PrintY = CST_Y + 13;
27182797
VWB_DrawPic (128, 48, C_MOUSEPIC);

wl_menu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void DrawLoadSaveScreen(int loadsave);
167167
void DrawNewEpisode(void);
168168
void DrawNewGame(void);
169169
void DrawChangeView(int view);
170-
void DrawMouseSens(void);
170+
void DrawSlider(int value);
171171
void DrawCtlScreen(void);
172172
void DrawCustomScreen(void);
173173
void DrawLSAction(int which);
@@ -198,6 +198,7 @@ int CP_EndGame(int);
198198
int CP_CheckQuick(ScanCode scancode);
199199
int CustomControls(int);
200200
int MouseSensitivity(int);
201+
int JoySensitivity(int);
201202

202203
void CheckForEpisodes(void);
203204

wl_play.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ void PollJoystickMove (void)
378378
newcontroly = (int) ((abs(joyy) / 127.0) * delta);
379379
}
380380

381+
// Multiply out joy adjustment
382+
newcontrolx = (int) (newcontrolx * (((joyadjustment + 1) + 5) / 10.0));
383+
381384
if (joyx > JOYDEADZONE || buttonstate[bt_turnright])
382385
controlx += newcontrolx;
383386
else if (joyx < -JOYDEADZONE || buttonstate[bt_turnleft])

0 commit comments

Comments
 (0)