debuging memory leaks
This commit is contained in:
163
source/input.cpp
Normal file
163
source/input.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
#include "input.h"
|
||||
|
||||
// Constructor
|
||||
Input::Input()
|
||||
{
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
mInput[i].scancode = 0;
|
||||
mInput[i].active = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Input::~Input()
|
||||
{
|
||||
}
|
||||
|
||||
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
||||
{
|
||||
mInput[input].scancode = code;
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool Input::checkInput(Uint8 input, bool repeat)
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
if (mKeystates[mInput[input].scancode] != 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mInput[input].active)
|
||||
{
|
||||
if (mKeystates[mInput[input].scancode] != 0)
|
||||
{
|
||||
mInput[input].active = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mKeystates[mInput[input].scancode] == 0)
|
||||
{
|
||||
mInput[input].active = false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 algun mando conectado
|
||||
/*if (SDL_NumJoysticks() < 1)
|
||||
{
|
||||
printf("Warning: No joysticks connected!\n");
|
||||
mGameControllerFound = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Carga el mando
|
||||
mGameController = SDL_JoystickOpen(0);
|
||||
mGameControllerFound = true;
|
||||
|
||||
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 << SDL_JoystickNumButtons(mGameController) << " buttons\n";
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
Reference in New Issue
Block a user