diff --git a/CMakeLists.txt b/CMakeLists.txt index f2498895..b062ccd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/Backends/Controller/SDL.cpp b/src/Backends/Controller/SDL.cpp index 0d55c239..8d281ff4 100644 --- a/src/Backends/Controller/SDL.cpp +++ b/src/Backends/Controller/SDL.cpp @@ -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 +} diff --git a/src/Backends/Platform/SDL2.cpp b/src/Backends/Platform/SDL2.cpp index 1ab1dcbb..5e25cf45 100644 --- a/src/Backends/Platform/SDL2.cpp +++ b/src/Backends/Platform/SDL2.cpp @@ -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) \ diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 41c4c0ef..2fba59dd 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -8,7 +8,7 @@ #include "SDL.h" #include "../Misc.h" -#include "../Shared/SDL2.h" +#include "../Shared/SDL.h" typedef struct RenderBackend_Surface { diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 4995e50d..7a155775 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -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)) diff --git a/src/Backends/Rendering/Window/OpenGL3/SDL2.cpp b/src/Backends/Rendering/Window/OpenGL3/SDL2.cpp index 8046a463..d96cecdb 100644 --- a/src/Backends/Rendering/Window/OpenGL3/SDL2.cpp +++ b/src/Backends/Rendering/Window/OpenGL3/SDL2.cpp @@ -9,7 +9,7 @@ #include "SDL.h" #include "../../../Misc.h" -#include "../../../Shared/SDL2.h" +#include "../../../Shared/SDL.h" SDL_Window *window; diff --git a/src/Backends/Rendering/Window/Software/SDL2.cpp b/src/Backends/Rendering/Window/Software/SDL2.cpp index bc630a75..1c267641 100644 --- a/src/Backends/Rendering/Window/Software/SDL2.cpp +++ b/src/Backends/Rendering/Window/Software/SDL2.cpp @@ -6,7 +6,7 @@ #include "SDL.h" #include "../../../Misc.h" -#include "../../../Shared/SDL2.h" +#include "../../../Shared/SDL.h" SDL_Window *window; diff --git a/src/Backends/Shared/SDL2.h b/src/Backends/Shared/SDL.h similarity index 82% rename from src/Backends/Shared/SDL2.h rename to src/Backends/Shared/SDL.h index 264c847c..c540be14 100644 --- a/src/Backends/Shared/SDL2.h +++ b/src/Backends/Shared/SDL.h @@ -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);