Start to work on support for various controllers
This commit is contained in:
@@ -40,7 +40,7 @@ Director::Director(std::string path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
mInput = new Input(mFileList[52]);
|
mInput = new Input(mFileList[53]);
|
||||||
//mInput2 = new Input(mOptions->input[1]);
|
//mInput2 = new Input(mOptions->input[1]);
|
||||||
//mInput[0] = new Input(INPUT_USE_KEYBOARD);
|
//mInput[0] = new Input(INPUT_USE_KEYBOARD);
|
||||||
//mInput[1] = new Input(INPUT_USE_GAMECONTROLLER);
|
//mInput[1] = new Input(INPUT_USE_GAMECONTROLLER);
|
||||||
@@ -272,7 +272,7 @@ void Director::setFileList()
|
|||||||
mFileList[51] = mExecutablePath + "/" + "../media/lang/ba_BA.txt";
|
mFileList[51] = mExecutablePath + "/" + "../media/lang/ba_BA.txt";
|
||||||
|
|
||||||
// DATA
|
// DATA
|
||||||
mFileList[52] = mExecutablePath + "/" + "../data/gamecontrollerdb.txt";
|
mFileList[53] = mExecutablePath + "/" + "../data/gamecontrollerdb.txt";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada
|
// Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ Input::~Input()
|
|||||||
{
|
{
|
||||||
//SDL_GameControllerClose(mGameController);
|
//SDL_GameControllerClose(mGameController);
|
||||||
//if (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
|
// 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
|
// 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 successKeyboard = false;
|
||||||
bool successGameController = false;
|
bool successGameController = false;
|
||||||
@@ -92,7 +94,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device)
|
|||||||
{
|
{
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0)
|
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
|
||||||
successGameController = true;
|
successGameController = true;
|
||||||
else
|
else
|
||||||
successGameController = false;
|
successGameController = false;
|
||||||
@@ -101,7 +103,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device)
|
|||||||
{
|
{
|
||||||
if (!mGameControllerBindings[input].active)
|
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;
|
mGameControllerBindings[input].active = true;
|
||||||
successGameController = true;
|
successGameController = true;
|
||||||
@@ -113,7 +115,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) == 0)
|
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) == 0)
|
||||||
{
|
{
|
||||||
mGameControllerBindings[input].active = false;
|
mGameControllerBindings[input].active = false;
|
||||||
successGameController = false;
|
successGameController = false;
|
||||||
@@ -137,8 +139,8 @@ bool Input::discoverGameController()
|
|||||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||||
|
|
||||||
if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str())<0)
|
if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str()) < 0)
|
||||||
printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError());
|
printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError());
|
||||||
|
|
||||||
int nJoysticks = SDL_NumJoysticks();
|
int nJoysticks = SDL_NumJoysticks();
|
||||||
mNumGamepads = 0;
|
mNumGamepads = 0;
|
||||||
@@ -162,16 +164,18 @@ bool Input::discoverGameController()
|
|||||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||||
{
|
{
|
||||||
mConnectedControllers.push_back(pad);
|
mConnectedControllers.push_back(pad);
|
||||||
|
std::string separator(" #");
|
||||||
std::string name = SDL_GameControllerNameForIndex(i);
|
std::string name = SDL_GameControllerNameForIndex(i);
|
||||||
std::cout << SDL_GameControllerNameForIndex(i) << std::endl;
|
|
||||||
name.resize(25);
|
name.resize(25);
|
||||||
|
name = name + separator + std::to_string(i);
|
||||||
|
std::cout << name << std::endl;
|
||||||
mControllerNames.push_back(name);
|
mControllerNames.push_back(name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
mGameController = mConnectedControllers[0];
|
//mGameController = mConnectedControllers[0];
|
||||||
SDL_GameControllerEventState(SDL_ENABLE);
|
SDL_GameControllerEventState(SDL_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ private:
|
|||||||
};
|
};
|
||||||
GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
|
|
||||||
SDL_GameController *mGameController; // Manejador para el mando
|
//SDL_GameController *mGameController; // Manejador para el mando
|
||||||
std::vector<SDL_GameController*> mConnectedControllers;
|
std::vector<SDL_GameController*> mConnectedControllers;
|
||||||
std::vector<std::string> mControllerNames;
|
std::vector<std::string> mControllerNames;
|
||||||
int mNumGamepads;
|
int mNumGamepads;
|
||||||
@@ -72,7 +72,7 @@ public:
|
|||||||
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
|
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
bool checkInput(Uint8 input, bool repeat, int device=INPUT_USE_ANY);
|
bool checkInput(Uint8 input, bool repeat, int device=INPUT_USE_ANY, int index=0);
|
||||||
|
|
||||||
// Comprueba si hay algun mando conectado
|
// Comprueba si hay algun mando conectado
|
||||||
bool gameControllerFound();
|
bool gameControllerFound();
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ void Text::initOffsetFromFile()
|
|||||||
if (rfile.is_open() && rfile.good())
|
if (rfile.is_open() && rfile.good())
|
||||||
{
|
{
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
|
printf("Reading %s file\n", mFile.c_str());
|
||||||
|
|
||||||
// Lee los dos primeros valores del fichero
|
// Lee los dos primeros valores del fichero
|
||||||
std::getline(rfile, buffer);
|
std::getline(rfile, buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user