Always use the first available joystick with SDL 1.2
This commit is contained in:
parent
d5f12b2f2b
commit
72a5f36654
8 changed files with 21 additions and 11 deletions
|
@ -395,12 +395,13 @@ if(BACKEND_PLATFORM MATCHES "SDL2")
|
||||||
target_sources(CSE2 PRIVATE
|
target_sources(CSE2 PRIVATE
|
||||||
"src/Backends/Controller/SDL.cpp"
|
"src/Backends/Controller/SDL.cpp"
|
||||||
"src/Backends/Platform/SDL2.cpp"
|
"src/Backends/Platform/SDL2.cpp"
|
||||||
"src/Backends/Shared/SDL2.h"
|
"src/Backends/Shared/SDL.h"
|
||||||
)
|
)
|
||||||
elseif(BACKEND_PLATFORM MATCHES "SDL1")
|
elseif(BACKEND_PLATFORM MATCHES "SDL1")
|
||||||
target_sources(CSE2 PRIVATE
|
target_sources(CSE2 PRIVATE
|
||||||
"src/Backends/Controller/SDL.cpp"
|
"src/Backends/Controller/SDL.cpp"
|
||||||
"src/Backends/Platform/SDL1.cpp"
|
"src/Backends/Platform/SDL1.cpp"
|
||||||
|
"src/Backends/Shared/SDL.h"
|
||||||
)
|
)
|
||||||
elseif(BACKEND_PLATFORM MATCHES "GLFW3")
|
elseif(BACKEND_PLATFORM MATCHES "GLFW3")
|
||||||
target_sources(CSE2 PRIVATE
|
target_sources(CSE2 PRIVATE
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#include "../Misc.h"
|
#include "../Misc.h"
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#include "../Shared/SDL.h"
|
||||||
#include "../Shared/SDL2.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define DEADZONE 10000
|
#define DEADZONE 10000
|
||||||
|
|
||||||
|
@ -24,6 +22,11 @@ bool ControllerBackend_Init(void)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
|
if (SDL_NumJoysticks() > 0)
|
||||||
|
ControllerBackend_JoystickConnect(0);
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,10 +131,13 @@ bool ControllerBackend_GetJoystickStatus(bool **buttons, unsigned int *button_co
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
||||||
void ControllerBackend_JoystickConnect(Sint32 joystick_id)
|
void ControllerBackend_JoystickConnect(Sint32 joystick_id)
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
const char *joystick_name = SDL_JoystickNameForIndex(joystick_id);
|
const char *joystick_name = SDL_JoystickNameForIndex(joystick_id);
|
||||||
|
#else
|
||||||
|
const char *joystick_name = SDL_JoystickName(joystick_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (joystick_name != NULL)
|
if (joystick_name != NULL)
|
||||||
{
|
{
|
||||||
|
@ -189,6 +195,7 @@ void ControllerBackend_JoystickConnect(Sint32 joystick_id)
|
||||||
|
|
||||||
void ControllerBackend_JoystickDisconnect(Sint32 joystick_id)
|
void ControllerBackend_JoystickDisconnect(Sint32 joystick_id)
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
SDL_JoystickID current_joystick_id = SDL_JoystickInstanceID(joystick);
|
SDL_JoystickID current_joystick_id = SDL_JoystickInstanceID(joystick);
|
||||||
if (current_joystick_id < 0)
|
if (current_joystick_id < 0)
|
||||||
Backend_PrintError("Couldn't get instance ID for current joystick: %s", SDL_GetError());
|
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);
|
free(axis_neutrals);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#include "../Rendering.h"
|
#include "../Rendering.h"
|
||||||
#include "../Shared/SDL2.h"
|
#include "../Shared/SDL.h"
|
||||||
#include "../../Attributes.h"
|
#include "../../Attributes.h"
|
||||||
|
|
||||||
#define DO_KEY(SDL_KEY, BACKEND_KEY) \
|
#define DO_KEY(SDL_KEY, BACKEND_KEY) \
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#include "../Misc.h"
|
#include "../Misc.h"
|
||||||
#include "../Shared/SDL2.h"
|
#include "../Shared/SDL.h"
|
||||||
|
|
||||||
typedef struct RenderBackend_Surface
|
typedef struct RenderBackend_Surface
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
#include "../Misc.h"
|
#include "../Misc.h"
|
||||||
#include "../Shared/SDL2.h"
|
#include "../Shared/SDL.h"
|
||||||
|
|
||||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#include "../../../Misc.h"
|
#include "../../../Misc.h"
|
||||||
#include "../../../Shared/SDL2.h"
|
#include "../../../Shared/SDL.h"
|
||||||
|
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#include "../../../Misc.h"
|
#include "../../../Misc.h"
|
||||||
#include "../../../Shared/SDL2.h"
|
#include "../../../Shared/SDL.h"
|
||||||
|
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
extern SDL_Window *window;
|
extern SDL_Window *window;
|
||||||
|
#endif
|
||||||
|
|
||||||
void ControllerBackend_JoystickConnect(Sint32 joystick_id);
|
void ControllerBackend_JoystickConnect(Sint32 joystick_id);
|
||||||
void ControllerBackend_JoystickDisconnect(Sint32 joystick_id);
|
void ControllerBackend_JoystickDisconnect(Sint32 joystick_id);
|
Loading…
Add table
Reference in a new issue