Remove duplicate game.controllerSensitivity proxy

It wasn't a direct duplicate of key.sensitivity, but it was still
basically the same thing. Although to be fair, at least the case-switch
conversion didn't get duplicated everywhere unlike game.slowdown.

So now key.sensitivity functions the same as game.controllerSensitivity,
and it only gets converted to its actual value whenever a joystick input
happens in key.Poll(), unlike previously where it got converted every
single frame on the title screen (there was even a comment that said
"TODO bit wasteful doing this every poll").
This commit is contained in:
Misa
2020-11-12 17:16:18 -08:00
committed by Ethan Lee
parent bc9dff8c2a
commit fb19787489
6 changed files with 32 additions and 37 deletions

View File

@@ -9,34 +9,32 @@
#include "Graphics.h"
#include "Music.h"
void KeyPoll::setSensitivity(int _value)
int inline KeyPoll::getThreshold()
{
switch (_value)
switch (sensitivity)
{
case 0:
sensitivity = 28000;
break;
case 1:
sensitivity = 16000;
break;
case 2:
sensitivity = 8000;
break;
case 3:
sensitivity = 4000;
break;
case 4:
sensitivity = 2000;
break;
case 0:
return 28000;
case 1:
return 16000;
case 2:
return 8000;
case 3:
return 4000;
case 4:
return 2000;
}
return 8000;
}
KeyPoll::KeyPoll()
{
xVel = 0;
yVel = 0;
setSensitivity(2);
// 0..5
sensitivity = 2;
quitProgram = 0;
keybuffer="";
@@ -199,11 +197,13 @@ void KeyPoll::Poll()
buttonmap[(SDL_GameControllerButton) evt.cbutton.button] = false;
break;
case SDL_CONTROLLERAXISMOTION:
{
const int threshold = getThreshold();
switch (evt.caxis.axis)
{
case SDL_CONTROLLER_AXIS_LEFTX:
if ( evt.caxis.value > -sensitivity &&
evt.caxis.value < sensitivity )
if ( evt.caxis.value > -threshold &&
evt.caxis.value < threshold )
{
xVel = 0;
}
@@ -213,8 +213,8 @@ void KeyPoll::Poll()
}
break;
case SDL_CONTROLLER_AXIS_LEFTY:
if ( evt.caxis.value > -sensitivity &&
evt.caxis.value < sensitivity )
if ( evt.caxis.value > -threshold &&
evt.caxis.value < threshold )
{
yVel = 0;
}
@@ -225,6 +225,7 @@ void KeyPoll::Poll()
break;
}
break;
}
case SDL_CONTROLLERDEVICEADDED:
{
SDL_GameController *toOpen = SDL_GameControllerOpen(evt.cdevice.which);