More cleanup

This commit is contained in:
Clownacy 2020-04-13 13:56:29 +01:00
parent aa9e486086
commit 58fc9a392a
2 changed files with 30 additions and 16 deletions

View file

@ -6,8 +6,8 @@
#include "SDL.h"
#include "../../WindowsWrapper.h"
#include "../Misc.h"
#include "../../WindowsWrapper.h"
#define DEADZONE 10000
@ -142,6 +142,7 @@ BOOL ControllerBackend_ResetJoystickStatus(void)
void ControllerBackend_JoystickConnect(Sint32 joystick_id)
{
const char *joystick_name = SDL_JoystickNameForIndex(joystick_id);
if (joystick_name != NULL)
{
Backend_PrintInfo("Joystick #%d connected - %s", joystick_id, joystick_name);
@ -172,17 +173,22 @@ void ControllerBackend_JoystickConnect(Sint32 joystick_id)
// Set up neutral axes
axis_neutrals = (Sint16*)malloc(sizeof(Sint16) * total_axes);
if (axis_neutrals != NULL)
{
for (int i = 0; i < total_axes; ++i)
axis_neutrals[i] = SDL_JoystickGetAxis(joystick, i);
return;
}
else
{
Backend_PrintError("Couldn't allocate memory for neutral axes");
}
}
else
{
SDL_JoystickClose(joystick);
joystick = NULL;
}
SDL_JoystickClose(joystick);
joystick = NULL;
}
else
{

View file

@ -45,22 +45,29 @@ BOOL Backend_Init(void)
const char *driver = SDL_GetCurrentVideoDriver();
if (driver != NULL)
{
Backend_PrintInfo("Selected SDL video driver: %s", driver);
else
Backend_PrintError("No SDL video driver initialized !");
return TRUE;
return TRUE;
}
else
{
Backend_PrintError("No SDL video driver initialized!");
}
}
else
{
std::string error_message = std::string("Could not initialise SDL video subsystem: ") + SDL_GetError();
Backend_ShowMessageBox("Fatal error", error_message.c_str());
}
std::string error_message = std::string("Could not initialise SDL video subsystem: ") + SDL_GetError();
Backend_ShowMessageBox("Fatal error", error_message.c_str());
SDL_Quit();
return FALSE;
}
std::string error_message = std::string("Could not initialise SDL: ") + SDL_GetError();
Backend_ShowMessageBox("Fatal error", error_message.c_str());
else
{
std::string error_message = std::string("Could not initialise SDL: ") + SDL_GetError();
Backend_ShowMessageBox("Fatal error", error_message.c_str());
}
return FALSE;
}
@ -301,6 +308,7 @@ void Backend_GetKeyboardState(BOOL *out_keyboard_state)
void Backend_ShowMessageBox(const char *title, const char *message)
{
fprintf(stderr, "ShowMessageBox - '%s' - '%s'\n", title, message);
if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window) != 0)
Backend_PrintError("Was also unable to display a message box containing the error: %s", SDL_GetError());
}