Skip to content

Instantly share code, notes, and snippets.

@grrussel
Created July 26, 2016 19:27
Show Gist options
  • Save grrussel/6bf44e5b058af61865ecc4a70a2c0753 to your computer and use it in GitHub Desktop.
Save grrussel/6bf44e5b058af61865ecc4a70a2c0753 to your computer and use it in GitHub Desktop.
Multiple joystick / controllers for SImple2D
From ddcb39e799fa19a904f3ed96b196d94957ba28ce Mon Sep 17 00:00:00 2001
From: George Russell <grrussel@gmail.com>
Date: Mon, 25 Jul 2016 19:03:36 +0200
Subject: [PATCH] Remove helper message (+1 squashed commit) Squashed commits:
[374c548] Fix the fix! (+1 squashed commit) Squashed commits: [edc590a] Fix
for multiple controllers
---
include/simple2d.h | 2 +-
src/simple2d.c | 7 ++-----
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/include/simple2d.h b/include/simple2d.h
index 654190b..38b35c2 100644
--- a/include/simple2d.h
+++ b/include/simple2d.h
@@ -55,7 +55,7 @@ typedef void (*S2D_Render)(void);
typedef void (*S2D_On_Key)(const char *key);
typedef void (*S2D_On_Key_Down)(const char *key);
typedef void (*S2D_On_Mouse)(int x, int y);
-typedef void (*S2D_On_Controller)(bool is_axis, int axis, int val, bool is_btn, int btn);
+typedef void (*S2D_On_Controller)(int which, bool is_axis, int axis, int val, bool is_btn, int btn);
// S2D_Color
typedef struct {
diff --git a/src/simple2d.c b/src/simple2d.c
index 9aa66a5..94bdfcd 100644
--- a/src/simple2d.c
+++ b/src/simple2d.c
@@ -653,7 +653,6 @@ S2D_Window *S2D_CreateWindow(const char *title, int width, int height,
sprintf(S2D_msg, "Found a valid controller, named: %s\n",
SDL_GameControllerName(controller));
S2D_Log(S2D_msg, S2D_INFO);
- break; // Break after first available controller
} else {
sprintf(S2D_msg, "Could not open game controller %i: %s\n", i, SDL_GetError());
S2D_Log(S2D_msg, S2D_ERROR);
@@ -683,8 +682,6 @@ S2D_Window *S2D_CreateWindow(const char *title, int width, int height,
sprintf(S2D_msg, "Could not open Joystick %i", i);
S2D_Log(S2D_msg, S2D_ERROR);
}
-
- break; // Break after first available joystick
}
}
@@ -797,12 +794,12 @@ int S2D_Show(S2D_Window *window) {
case SDL_JOYAXISMOTION:
if (window->on_controller)
- window->on_controller(true, e.jaxis.axis, e.jaxis.value, false, 0);
+ window->on_controller(e.jaxis.which, true, e.jaxis.axis, e.jaxis.value, false, 0);
break;
case SDL_JOYBUTTONDOWN:
if (window->on_controller)
- window->on_controller(false, 0, 0, true, e.jbutton.button);
+ window->on_controller(e.jaxis.which, false, 0, 0, true, e.jbutton.button);
break;
case SDL_WINDOWEVENT:
--
2.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment