Always use the first available joystick with SDL 1.2

This commit is contained in:
Cameron Cawley 2020-06-25 16:28:08 +01:00
parent d5f12b2f2b
commit 72a5f36654
8 changed files with 21 additions and 11 deletions

View file

@ -395,12 +395,13 @@ if(BACKEND_PLATFORM MATCHES "SDL2")
target_sources(CSE2 PRIVATE
"src/Backends/Controller/SDL.cpp"
"src/Backends/Platform/SDL2.cpp"
"src/Backends/Shared/SDL2.h"
"src/Backends/Shared/SDL.h"
)
elseif(BACKEND_PLATFORM MATCHES "SDL1")
target_sources(CSE2 PRIVATE
"src/Backends/Controller/SDL.cpp"
"src/Backends/Platform/SDL1.cpp"
"src/Backends/Shared/SDL.h"
)
elseif(BACKEND_PLATFORM MATCHES "GLFW3")
target_sources(CSE2 PRIVATE

View file

@ -6,9 +6,7 @@
#include "SDL.h"
#include "../Misc.h"
#if SDL_VERSION_ATLEAST(2, 0, 0)
#include "../Shared/SDL2.h"
#endif
#include "../Shared/SDL.h"
#define DEADZONE 10000
@ -24,6 +22,11 @@ bool ControllerBackend_Init(void)
return false;
}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (SDL_NumJoysticks() > 0)
ControllerBackend_JoystickConnect(0);
#endif
return true;
}
@ -128,10 +131,13 @@ bool ControllerBackend_GetJoystickStatus(bool **buttons, unsigned int *button_co
return true;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
void ControllerBackend_JoystickConnect(Sint32 joystick_id)
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
const char *joystick_name = SDL_JoystickNameForIndex(joystick_id);
#else
const char *joystick_name = SDL_JoystickName(joystick_id);
#endif
if (joystick_name != NULL)
{
@ -189,6 +195,7 @@ void ControllerBackend_JoystickConnect(Sint32 joystick_id)
void ControllerBackend_JoystickDisconnect(Sint32 joystick_id)
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_JoystickID current_joystick_id = SDL_JoystickInstanceID(joystick);
if (current_joystick_id < 0)
Backend_PrintError("Couldn't get instance ID for current joystick: %s", SDL_GetError());
@ -201,5 +208,5 @@ void ControllerBackend_JoystickDisconnect(Sint32 joystick_id)
free(axis_neutrals);
}
}
#endif
}

View file

@ -10,7 +10,7 @@
#include "SDL.h"
#include "../Rendering.h"
#include "../Shared/SDL2.h"
#include "../Shared/SDL.h"
#include "../../Attributes.h"
#define DO_KEY(SDL_KEY, BACKEND_KEY) \

View file

@ -8,7 +8,7 @@
#include "SDL.h"
#include "../Misc.h"
#include "../Shared/SDL2.h"
#include "../Shared/SDL.h"
typedef struct RenderBackend_Surface
{

View file

@ -10,7 +10,7 @@
#include "../../WindowsWrapper.h"
#include "../Misc.h"
#include "../Shared/SDL2.h"
#include "../Shared/SDL.h"
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))

View file

@ -9,7 +9,7 @@
#include "SDL.h"
#include "../../../Misc.h"
#include "../../../Shared/SDL2.h"
#include "../../../Shared/SDL.h"
SDL_Window *window;

View file

@ -6,7 +6,7 @@
#include "SDL.h"
#include "../../../Misc.h"
#include "../../../Shared/SDL2.h"
#include "../../../Shared/SDL.h"
SDL_Window *window;

View file

@ -2,7 +2,9 @@
#include "SDL.h"
#if SDL_VERSION_ATLEAST(2, 0, 0)
extern SDL_Window *window;
#endif
void ControllerBackend_JoystickConnect(Sint32 joystick_id);
void ControllerBackend_JoystickDisconnect(Sint32 joystick_id);