Skip to content

Commit 22c498f

Browse files
authored
Controllers bindings for windows (#86)
* Xbox One and 360 controllers for windows * DS4 bindings * Code cleaning
1 parent 69aa27f commit 22c498f

2 files changed

Lines changed: 68 additions & 21 deletions

File tree

input/binds_windows.go

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,71 @@ package input
33
import "github.com/libretro/ludo/libretro"
44

55
var joyBinds = map[string]joybinds{
6-
"Microsoft X-Box 360 pad": xbox360JoyBinds,
6+
"Microsoft X-Box 360 pad": xbox360JoyBinds,
7+
"Xbox 360 Controller": xboxOneJoyBinds,
8+
"Wireless Controller": ds4JoyBinds,
9+
"PLAYSTATION(R)3 Controller": ds3JoyBinds,
710
}
811

9-
// FIXME Joypad bindings fox Xbox360 pad on Windows
1012
var xbox360JoyBinds = joybinds{
11-
bind{btn, 0, 0, 0}: libretro.DeviceIDJoypadB,
12-
bind{btn, 1, 0, 0}: libretro.DeviceIDJoypadA,
13-
bind{btn, 2, 0, 0}: libretro.DeviceIDJoypadY,
14-
bind{btn, 3, 0, 0}: libretro.DeviceIDJoypadX,
15-
bind{btn, 4, 0, 0}: libretro.DeviceIDJoypadL,
16-
bind{btn, 5, 0, 0}: libretro.DeviceIDJoypadR,
17-
bind{btn, 6, 0, 0}: libretro.DeviceIDJoypadSelect,
18-
bind{btn, 7, 0, 0}: libretro.DeviceIDJoypadStart,
19-
bind{btn, 8, 0, 0}: ActionMenuToggle,
20-
bind{btn, 9, 0, 0}: libretro.DeviceIDJoypadL3,
21-
bind{btn, 10, 0, 0}: libretro.DeviceIDJoypadR3,
22-
bind{axis, 6, -1, -0.5}: libretro.DeviceIDJoypadLeft,
23-
bind{axis, 6, 1, 0.5}: libretro.DeviceIDJoypadRight,
24-
bind{axis, 7, -1, -0.5}: libretro.DeviceIDJoypadUp,
25-
bind{axis, 7, 1, 0.5}: libretro.DeviceIDJoypadDown,
26-
bind{axis, 2, 1, 0.5}: libretro.DeviceIDJoypadL2,
27-
bind{axis, 5, 1, 0.5}: libretro.DeviceIDJoypadR2,
13+
bind{btn, 0, 0, 0}: libretro.DeviceIDJoypadB,
14+
bind{btn, 1, 0, 0}: libretro.DeviceIDJoypadA,
15+
bind{btn, 2, 0, 0}: libretro.DeviceIDJoypadY,
16+
bind{btn, 3, 0, 0}: libretro.DeviceIDJoypadX,
17+
bind{btn, 4, 0, 0}: libretro.DeviceIDJoypadL,
18+
bind{btn, 5, 0, 0}: libretro.DeviceIDJoypadR,
19+
bind{btn, 6, 0, 0}: libretro.DeviceIDJoypadSelect,
20+
bind{btn, 7, 0, 0}: libretro.DeviceIDJoypadStart,
21+
bind{btn, 8, 0, 0}: libretro.DeviceIDJoypadL3,
22+
bind{btn, 9, 0, 0}: libretro.DeviceIDJoypadR3,
23+
bind{btn, 10, 0, 0}: libretro.DeviceIDJoypadUp,
24+
bind{btn, 11, 0, 0}: libretro.DeviceIDJoypadRight,
25+
bind{btn, 12, 0, 0}: libretro.DeviceIDJoypadDown,
26+
bind{btn, 13, 0, 0}: libretro.DeviceIDJoypadLeft,
27+
bind{axis, 4, 1, 0}: libretro.DeviceIDJoypadL2,
28+
bind{axis, 5, 1, 0}: libretro.DeviceIDJoypadL3,
2829
}
30+
31+
var xboxOneJoyBinds = joybinds{
32+
bind{btn, 0, 0, 0}: libretro.DeviceIDJoypadB,
33+
bind{btn, 1, 0, 0}: libretro.DeviceIDJoypadA,
34+
bind{btn, 2, 0, 0}: libretro.DeviceIDJoypadY,
35+
bind{btn, 3, 0, 0}: libretro.DeviceIDJoypadX,
36+
bind{btn, 4, 0, 0}: libretro.DeviceIDJoypadL,
37+
bind{btn, 5, 0, 0}: libretro.DeviceIDJoypadR,
38+
bind{btn, 6, 0, 0}: libretro.DeviceIDJoypadSelect,
39+
bind{btn, 7, 0, 0}: libretro.DeviceIDJoypadStart,
40+
bind{btn, 8, 0, 0}: libretro.DeviceIDJoypadL3,
41+
bind{btn, 9, 0, 0}: libretro.DeviceIDJoypadR3,
42+
bind{btn, 10, 0, 0}: libretro.DeviceIDJoypadUp,
43+
bind{btn, 11, 0, 0}: libretro.DeviceIDJoypadRight,
44+
bind{btn, 12, 0, 0}: libretro.DeviceIDJoypadDown,
45+
bind{btn, 13, 0, 0}: libretro.DeviceIDJoypadLeft,
46+
bind{axis, 4, 1, 0}: libretro.DeviceIDJoypadL2,
47+
bind{axis, 5, 1, 0}: libretro.DeviceIDJoypadL3,
48+
}
49+
50+
var ds4JoyBinds = joybinds{
51+
bind{btn, 0, 0, 0}: libretro.DeviceIDJoypadX,
52+
bind{btn, 1, 0, 0}: libretro.DeviceIDJoypadB,
53+
bind{btn, 2, 0, 0}: libretro.DeviceIDJoypadA,
54+
bind{btn, 3, 0, 0}: libretro.DeviceIDJoypadY,
55+
bind{btn, 4, 0, 0}: libretro.DeviceIDJoypadL,
56+
bind{btn, 5, 0, 0}: libretro.DeviceIDJoypadR,
57+
bind{btn, 4, 0, 0}: libretro.DeviceIDJoypadL2,
58+
bind{btn, 5, 0, 0}: libretro.DeviceIDJoypadR2,
59+
bind{btn, 6, 0, 0}: libretro.DeviceIDJoypadSelect,
60+
bind{btn, 7, 0, 0}: libretro.DeviceIDJoypadStart,
61+
bind{btn, 8, 0, 0}: libretro.DeviceIDJoypadL3,
62+
bind{btn, 9, 0, 0}: libretro.DeviceIDJoypadR3,
63+
bind{btn, 10, 0, 0}: ActionMenuToggle,
64+
bind{btn, 14, 0, 0}: libretro.DeviceIDJoypadUp,
65+
bind{btn, 15, 0, 0}: libretro.DeviceIDJoypadRight,
66+
bind{btn, 16, 0, 0}: libretro.DeviceIDJoypadDown,
67+
bind{btn, 17, 0, 0}: libretro.DeviceIDJoypadLeft,
68+
bind{axis, 3, 1, 0}: libretro.DeviceIDJoypadL2,
69+
bind{axis, 4, 1, 0}: libretro.DeviceIDJoypadL3,
70+
}
71+
72+
// Detected but doesn't send inputs
73+
var ds3JoyBinds = joybinds{}

input/input.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ func pollJoypads(state inputstate) inputstate {
9999
for k, v := range jb {
100100
switch k.kind {
101101
case btn:
102-
if glfw.Action(buttonState[k.index]) == glfw.Press {
102+
if int(k.index) < len(buttonState) &&
103+
glfw.Action(buttonState[k.index]) == glfw.Press {
103104
state[p][v] = true
104105
}
105106
case axis:
106-
if k.direction*axisState[k.index] > k.threshold*k.direction {
107+
if int(k.index) < len(axisState) &&
108+
k.direction*axisState[k.index] > k.threshold*k.direction {
107109
state[p][v] = true
108110
}
109111
}

0 commit comments

Comments
 (0)