working on text notifications
This commit is contained in:
206
source/input.cpp
206
source/input.cpp
@@ -17,41 +17,19 @@ Input::Input(int source)
|
||||
|
||||
mSource = source;
|
||||
|
||||
if (mSource == USE_GAMECONTROLLER)
|
||||
{
|
||||
/*
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
int nJoysticks = SDL_NumJoysticks();
|
||||
int numGamepads = 0;
|
||||
|
||||
// Count how many controllers there are
|
||||
for (int i = 0; i < nJoysticks; i++)
|
||||
if (SDL_IsGameController(i))
|
||||
numGamepads++;
|
||||
|
||||
printf("%i joysticks found, %i are gamepads\n", nJoysticks, numGamepads);
|
||||
//SDL_JoystickEventState(SDL_ENABLE);
|
||||
*/
|
||||
if (!discoverGameController())
|
||||
mSource = USE_KEYBOARD;
|
||||
}
|
||||
|
||||
// Comprueba si hay algún mando conectado
|
||||
//discoverGameController();
|
||||
|
||||
// En caso de haber un mando, el objeto se puede utilizar con entradas de mando
|
||||
//if (mGameControllerFound)
|
||||
// mSource = source;
|
||||
// Si no hay un mando, el objeto se configura como teclado
|
||||
//else
|
||||
// mSource = USE_KEYBOARD;
|
||||
|
||||
if (mSource == USE_KEYBOARD)
|
||||
printf("Input using KEYBOARD\n");
|
||||
if (mSource == INPUT_USE_KEYBOARD)
|
||||
printf("\nInput requested KEYBOARD\n");
|
||||
else
|
||||
printf("Input using GAMECONTROLLER\n");
|
||||
printf("\nInput requested GAMECONTROLLER");
|
||||
|
||||
if (mSource == INPUT_USE_GAMECONTROLLER)
|
||||
if (!discoverGameController())
|
||||
mSource = INPUT_USE_KEYBOARD;
|
||||
|
||||
if (mSource == INPUT_USE_KEYBOARD)
|
||||
printf("Input asigned was KEYBOARD\n");
|
||||
else
|
||||
printf("Input asigned was GAMECONTROLLER (%s)\n", SDL_GameControllerNameForIndex(0));
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -74,7 +52,7 @@ void Input::bindGameController(Uint8 input, SDL_GameControllerButton button)
|
||||
// Comprueba si un input esta activo
|
||||
bool Input::checkInput(Uint8 input, bool repeat)
|
||||
{
|
||||
if (mSource == USE_KEYBOARD)
|
||||
if (mSource == INPUT_USE_KEYBOARD)
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
||||
|
||||
@@ -152,173 +130,41 @@ bool Input::checkInput(Uint8 input, bool repeat)
|
||||
}
|
||||
}
|
||||
|
||||
// Gestiona las entradas desde el mando de juego
|
||||
/*bool Input::checkGameController(Uint8 state)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
// No hay mando. Siempre devuelve falso salvo NO_INPUT que siempre es cierto
|
||||
if (!mGameControllerFound)
|
||||
{
|
||||
if (state == NO_INPUT)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case INPUT_NULL:
|
||||
success = !checkGameController(INPUT_UP) && !checkGameController(INPUT_DOWN) && !checkGameController(INPUT_LEFT) && !checkGameController(INPUT_RIGHT) &&
|
||||
!checkGameController(INPUT_ACCEPT) && !checkGameController(INPUT_CANCEL) && !checkGameController(INPUT_PAUSE) &&
|
||||
!checkGameController(INPUT_FIRE_UP) && !checkGameController(INPUT_FIRE_LEFT) && !checkGameController(INPUT_FIRE_RIGHT);
|
||||
break;
|
||||
case INPUT_UP:
|
||||
success = (SDL_JoystickGetAxis(mGameController, 1) < -JOYSTICK_DEAD_ZONE) || (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_DPAD_UP));
|
||||
break;
|
||||
case INPUT_DOWN:
|
||||
success = (SDL_JoystickGetAxis(mGameController, 1) > JOYSTICK_DEAD_ZONE) || (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_DPAD_DOWN));
|
||||
break;
|
||||
case INPUT_LEFT:
|
||||
success = (SDL_JoystickGetAxis(mGameController, 0) < -JOYSTICK_DEAD_ZONE) || (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_DPAD_LEFT));
|
||||
break;
|
||||
case INPUT_RIGHT:
|
||||
success = (SDL_JoystickGetAxis(mGameController, 0) > JOYSTICK_DEAD_ZONE) || (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_DPAD_RIGHT));
|
||||
break;
|
||||
case INPUT_ACCEPT:
|
||||
success = (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_B));
|
||||
break;
|
||||
case INPUT_CANCEL:
|
||||
success = (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_A));
|
||||
break;
|
||||
case INPUT_PAUSE:
|
||||
success = (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_START));
|
||||
break;
|
||||
case INPUT_FIRE_UP:
|
||||
success = (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_Y));
|
||||
break;
|
||||
case INPUT_FIRE_LEFT:
|
||||
success = (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_X));
|
||||
break;
|
||||
case INPUT_FIRE_RIGHT:
|
||||
success = (SDL_JoystickGetButton(mGameController, SDL_CONTROLLER_BUTTON_B));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return success;
|
||||
}*/
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
bool Input::discoverGameController()
|
||||
{
|
||||
bool found = false;
|
||||
/*
|
||||
printf("%i joystics found\n", SDL_NumJoysticks());
|
||||
for (int i = 0; i < SDL_NumJoysticks(); ++i)
|
||||
{
|
||||
if (SDL_IsGameController(i))
|
||||
{
|
||||
char *mapping;
|
||||
printf("Index %i is a compatible controller, named %s\n", i, SDL_GameControllerNameForIndex(i));
|
||||
mGameController = SDL_GameControllerOpen(i);
|
||||
mapping = SDL_GameControllerMapping(mGameController);
|
||||
printf("Controller %i is mapped as %s\n", i, mapping);
|
||||
SDL_free(mapping);
|
||||
found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Index %i is not a compatible controller.\n", i);
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
int nJoysticks = SDL_NumJoysticks();
|
||||
int numGamepads = 0;
|
||||
mNumGamepads = 0;
|
||||
|
||||
// Count how many controllers there are
|
||||
for (int i = 0; i < nJoysticks; i++)
|
||||
if (SDL_IsGameController(i))
|
||||
numGamepads++;
|
||||
mNumGamepads++;
|
||||
|
||||
printf("%i joysticks found, %i are gamepads\n", nJoysticks, numGamepads);
|
||||
printf(" (%i joysticks found, %i are gamepads)\n", nJoysticks, mNumGamepads);
|
||||
|
||||
//if (numGamepads > 0)
|
||||
// found = true;
|
||||
//SDL_JoystickEventState(SDL_ENABLE);
|
||||
|
||||
if (numGamepads > 0)
|
||||
if (mNumGamepads > 0)
|
||||
{
|
||||
for (int i = 0; i < numGamepads; i++)
|
||||
found = true;
|
||||
|
||||
for (int i = 0; i < mNumGamepads; i++)
|
||||
{
|
||||
// Open the controller and add it to our list
|
||||
mGameController = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(mGameController) == 1)
|
||||
//connectedControllers.push_back(pad);
|
||||
{
|
||||
found = true;
|
||||
printf("%s\n", SDL_GameControllerNameForIndex(i));
|
||||
}
|
||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
mConnectedControllers.push_back(pad);
|
||||
else
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
|
||||
mGameController = mConnectedControllers[0];
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
}
|
||||
|
||||
//SDL_GameControllerGetButton(mGameController, SDL_CONTROLLER_BUTTON_A);
|
||||
//printf("hola");
|
||||
return found;
|
||||
}
|
||||
/*if (SDL_NumJoysticks() < 1)
|
||||
{
|
||||
printf("Warning: No joysticks connected!\n");
|
||||
mGameControllerFound = false;
|
||||
std::cout << "Warning: No joysticks connected!\n";
|
||||
}
|
||||
else
|
||||
{*/
|
||||
// Carga el mando
|
||||
|
||||
/*mGameController = SDL_GameControllerOpen(0);
|
||||
|
||||
if (mGameController == NULL)
|
||||
{
|
||||
printf("Warning: Unable to open game controller!\nSDL Error: %s\n", SDL_GetError());
|
||||
mGameControllerFound = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%i joysticks were found.\n", SDL_NumJoysticks());
|
||||
std::cout << "joysticks were found!\n";
|
||||
mGameControllerFound = true;
|
||||
|
||||
//printf("%i buttons\n", SDL_JoystickNumButtons(mGameController));
|
||||
|
||||
// Obtiene el dispositivo de control háptico
|
||||
mControllerHaptic = SDL_HapticOpenFromJoystick(mGameController);
|
||||
if (mControllerHaptic == NULL)
|
||||
{
|
||||
printf("Warning: Controller does not support haptics!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Haptics detected\n");
|
||||
|
||||
// Inicializa la vibración
|
||||
if (SDL_HapticRumbleInit(mControllerHaptic) < 0)
|
||||
{
|
||||
printf("Warning: Unable to initialize rumble!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mGameControllerFound;
|
||||
}*/
|
||||
}
|
||||
Reference in New Issue
Block a user