mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-16 12:05:38 +00:00
Added joystick hat support. Began work on axis support (config should accept axes now, but my controller seems to be breaking).
This commit is contained in:
parent
b3fb58ebdb
commit
646cda75a6
|
@ -9,6 +9,8 @@ SDL_Event* InputManager::lastEvent = NULL;
|
|||
|
||||
std::map<int, InputManager::InputButton> InputManager::joystickButtonMap, InputManager::joystickAxisMap;
|
||||
|
||||
int InputManager::deadzone = 32000;
|
||||
|
||||
void InputManager::registerComponent(GuiComponent* comp)
|
||||
{
|
||||
inputVector.push_back(comp);
|
||||
|
@ -78,8 +80,22 @@ void InputManager::processEvent(SDL_Event* event)
|
|||
if(event->type == SDL_JOYBUTTONDOWN) //defaults to false, so no else
|
||||
keyDown = true;
|
||||
|
||||
//hurr no config yet durr
|
||||
button = joystickButtonMap[event->jbutton.button];
|
||||
}else{
|
||||
if(event->type == SDL_JOYHATMOTION)
|
||||
{
|
||||
//no keyUp for hat movement yet, but this should be easily accomplished by
|
||||
//keeping the previous hat movement and checking if it moved from centered to anything else (keyDown) or back to centered (keyUp)
|
||||
keyDown = true;
|
||||
if(event->jhat.value & SDL_HAT_UP)
|
||||
button = UP;
|
||||
if(event->jhat.value & SDL_HAT_DOWN)
|
||||
button = DOWN;
|
||||
if(event->jhat.value & SDL_HAT_LEFT)
|
||||
button = LEFT;
|
||||
if(event->jhat.value & SDL_HAT_RIGHT)
|
||||
button = RIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,12 +131,12 @@ void InputManager::loadConfig(std::string path)
|
|||
|
||||
while(std::getline(stream, token[tokNum], ' '))
|
||||
{
|
||||
tokNum++;
|
||||
if(tokNum > 3)
|
||||
if(tokNum >= 3)
|
||||
{
|
||||
std::cerr << "Error - input config line \"" << line << "\" has more than three tokens!\n";
|
||||
break;
|
||||
return;
|
||||
}
|
||||
tokNum++;
|
||||
}
|
||||
|
||||
|
||||
|
@ -129,7 +145,7 @@ void InputManager::loadConfig(std::string path)
|
|||
joystickButtonMap[atoi(token[1].c_str())] = (InputButton)atoi(token[2].c_str());
|
||||
}else if(token[0] == "AXIS")
|
||||
{
|
||||
|
||||
joystickAxisMap[atoi(token[1].c_str())] = (InputButton)atoi(token[2].c_str());
|
||||
}else{
|
||||
std::cerr << "Invalid input type - " << token[0] << "\n";
|
||||
return;
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace InputManager {
|
|||
|
||||
extern std::vector<GuiComponent*> inputVector;
|
||||
extern SDL_Event* lastEvent; //mostly for GuiInputConfig
|
||||
extern int deadzone;
|
||||
|
||||
extern std::map<int, InputButton> joystickButtonMap;
|
||||
extern std::map<int, InputButton> joystickAxisMap;
|
||||
|
|
|
@ -69,6 +69,21 @@ void GuiInputConfig::onInput(InputManager::InputButton button, bool keyDown)
|
|||
mInputNum++;
|
||||
}
|
||||
|
||||
if(event->type == SDL_JOYAXISMOTION)
|
||||
{
|
||||
std::cout << "motion on axis " << event->jaxis.axis << " to value " << event->jaxis.value << "\n";
|
||||
|
||||
if(event->jaxis.value > InputManager::deadzone)
|
||||
{
|
||||
mAxisMap[event->jaxis.axis] = (InputManager::InputButton)mInputNum;
|
||||
mInputNum++;
|
||||
}else if(event->jaxis.value < -InputManager::deadzone)
|
||||
{
|
||||
mAxisMap[-event->jaxis.axis] = (InputManager::InputButton)mInputNum;
|
||||
mInputNum++;
|
||||
}
|
||||
}
|
||||
|
||||
if(mInputNum >= sInputCount)
|
||||
{
|
||||
mDone = true;
|
||||
|
|
Loading…
Reference in a new issue