Start to work on support for various controllers
This commit is contained in:
@@ -26,7 +26,9 @@ Input::~Input()
|
||||
{
|
||||
//SDL_GameControllerClose(mGameController);
|
||||
//if (mGameController)
|
||||
mGameController = nullptr;
|
||||
//mGameController = nullptr;
|
||||
for (int i = 0; i < mNumGamepads; i++)
|
||||
mConnectedControllers[i] = nullptr;
|
||||
}
|
||||
|
||||
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||
@@ -42,7 +44,7 @@ void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton butto
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool Input::checkInput(Uint8 input, bool repeat, int device)
|
||||
bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
{
|
||||
bool successKeyboard = false;
|
||||
bool successGameController = false;
|
||||
@@ -92,7 +94,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device)
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0)
|
||||
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
|
||||
successGameController = true;
|
||||
else
|
||||
successGameController = false;
|
||||
@@ -101,7 +103,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device)
|
||||
{
|
||||
if (!mGameControllerBindings[input].active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0)
|
||||
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
|
||||
{
|
||||
mGameControllerBindings[input].active = true;
|
||||
successGameController = true;
|
||||
@@ -113,7 +115,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) == 0)
|
||||
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) == 0)
|
||||
{
|
||||
mGameControllerBindings[input].active = false;
|
||||
successGameController = false;
|
||||
@@ -137,8 +139,8 @@ bool Input::discoverGameController()
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str())<0)
|
||||
printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError());
|
||||
if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str()) < 0)
|
||||
printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError());
|
||||
|
||||
int nJoysticks = SDL_NumJoysticks();
|
||||
mNumGamepads = 0;
|
||||
@@ -162,16 +164,18 @@ bool Input::discoverGameController()
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
{
|
||||
mConnectedControllers.push_back(pad);
|
||||
std::string separator(" #");
|
||||
std::string name = SDL_GameControllerNameForIndex(i);
|
||||
std::cout << SDL_GameControllerNameForIndex(i) << std::endl;
|
||||
name.resize(25);
|
||||
name = name + separator + std::to_string(i);
|
||||
std::cout << name << std::endl;
|
||||
mControllerNames.push_back(name);
|
||||
}
|
||||
else
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
|
||||
mGameController = mConnectedControllers[0];
|
||||
//mGameController = mConnectedControllers[0];
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user