ref: 72a5f366547e12cab97eca00df1a09d4e178033e
parent: d5f12b2f2b2efd126c4b9b0ae8bc0b1b0acadd72
author: Cameron Cawley <ccawley2011@gmail.com>
date: Thu Jun 25 12:28:08 EDT 2020
Always use the first available joystick with SDL 1.2
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -395,12 +395,13 @@
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
--- 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 @@
return false;
}
+#if !SDL_VERSION_ATLEAST(2, 0, 0)
+ if (SDL_NumJoysticks() > 0)
+ ControllerBackend_JoystickConnect(0);
+#endif
+
return true;
}
@@ -128,10 +131,13 @@
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_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 @@
free(axis_neutrals);
}
-}
#endif
+}
--- 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) \
--- 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
{
--- 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))
--- 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;
--- 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;
--- /dev/null
+++ b/src/Backends/Shared/SDL.h
@@ -1,0 +1,10 @@
+#pragma once
+
+#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);
--- a/src/Backends/Shared/SDL2.h
+++ /dev/null
@@ -1,8 +1,0 @@
-#pragma once
-
-#include "SDL.h"
-
-extern SDL_Window *window;
-
-void ControllerBackend_JoystickConnect(Sint32 joystick_id);
-void ControllerBackend_JoystickDisconnect(Sint32 joystick_id);