diff --git a/assets/gamecontrollerdb.txt b/assets/gamecontrollerdb.txt new file mode 100644 index 0000000..6928554 --- /dev/null +++ b/assets/gamecontrollerdb.txt @@ -0,0 +1,96 @@ +# Windows - DINPUT +8f0e1200000000000000504944564944,Acme,platform:Windows,x:b2,a:b0,b:b1,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2, +341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows, +ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Windows, +6d0416c2000000000000504944564944,Generic DirectInput Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows, +6d0419c2000000000000504944564944,Logitech F710 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows, +88880803000000000000504944564944,PS3 Controller,a:b2,b:b1,back:b8,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b9,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:b7,rightx:a3,righty:a4,start:b11,x:b0,y:b3,platform:Windows, +4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,platform:Windows, +25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,back:b9,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b0,y:b3,platform:Windows, +4c05c405000000000000504944564944,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Windows, +6d0418c2000000000000504944564944,Logitech RumblePad 2 USB,platform:Windows,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3, +36280100000000000000504944564944,OUYA Controller,platform:Windows,a:b0,b:b3,y:b2,x:b1,start:b14,guide:b15,leftstick:b6,rightstick:b7,leftshoulder:b4,rightshoulder:b5,dpup:b8,dpleft:b10,dpdown:b9,dpright:b11,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b12,righttrigger:b13, +4f0400b3000000000000504944564944,Thrustmaster Firestorm Dual Power,a:b0,b:b2,y:b3,x:b1,start:b10,guide:b8,back:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Windows, +00f00300000000000000504944564944,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Windows, +00f0f100000000000000504944564944,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Windows, +28040140000000000000504944564944,GamePad Pro USB,platform:Windows,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,lefttrigger:b6,righttrigger:b7, +ff113133000000000000504944564944,SVEN X-PAD,platform:Windows,a:b2,b:b3,y:b1,x:b0,start:b5,back:b4,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b8,righttrigger:b9, +8f0e0300000000000000504944564944,Piranha xtreme,platform:Windows,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2, +8f0e0d31000000000000504944564944,Multilaser JS071 USB,platform:Windows,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7, +10080300000000000000504944564944,PS2 USB,platform:Windows,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a4,righty:a2,lefttrigger:b4,righttrigger:b5, +79000600000000000000504944564944,G-Shark GS-GP702,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b6,righttrigger:b7,platform:Windows, +4b12014d000000000000504944564944,NYKO AIRFLO,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b10,start:b9,leftstick:a0,rightstick:a2,leftshoulder:a3,rightshoulder:b5,dpup:h0.1,dpdown:h0.0,dpleft:h0.8,dpright:h0.2,leftx:h0.6,lefty:h0.12,rightx:h0.9,righty:h0.4,lefttrigger:b6,righttrigger:b7,platform:Windows, +d6206dca000000000000504944564944,PowerA Pro Ex,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.0,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows, +a3060cff000000000000504944564944,Saitek P2500,a:b2,b:b3,y:b1,x:b0,start:b4,guide:b10,back:b5,leftstick:b8,rightstick:b9,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,platform:Windows, +8f0e0300000000000000504944564944,Trust GTX 28,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows, +4f0415b3000000000000504944564944,Thrustmaster Dual Analog 3.2,platform:Windows,x:b1,a:b0,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3, +6f0e1e01000000000000504944564944,Rock Candy Gamepad for PS3,platform:Windows,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,guide:b12,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2, + +# OS X +0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X, +6d0400000000000016c2000000000000,Logitech F310 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X, +6d0400000000000018c2000000000000,Logitech F510 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X, +6d040000000000001fc2000000000000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,platform:Mac OS X, +6d0400000000000019c2000000000000,Logitech Wireless Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Mac OS X, +4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,platform:Mac OS X, +4c05000000000000c405000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,Platform:Mac OS X, +5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,platform:Mac OS X, +891600000000000000fd000000000000,Razer Onza Tournament,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,leftstick:b6,rightstick:b7,leftshoulder:b4,rightshoulder:b5,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Mac OS X, +4f0400000000000000b3000000000000,Thrustmaster Firestorm Dual Power,a:b0,b:b2,y:b3,x:b1,start:b10,guide:b8,back:b9,leftstick:b11,rightstick:,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Mac OS X, +8f0e0000000000000300000000000000,Piranha xtreme,platform:Mac OS X,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2, +0d0f0000000000004d00000000000000,HORI Gem Pad 3,platform:Mac OS X,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7, +79000000000000000600000000000000,G-Shark GP-702,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,platform:Mac OS X, +4f0400000000000015b3000000000000,Thrustmaster Dual Analog 3.2,platform:Mac OS X,x:b1,a:b0,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3, +AD1B00000000000001F9000000000000,Gamestop BB-070 X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,platform:Mac OS X, +050000005769696d6f74652028303000,Wiimote,a:b4,b:b5,y:b9,x:b10,start:b6,guide:b8,back:b7,dpup:b2,dpleft:b0,dpdown:b3,dpright:b1,leftx:a0,lefty:a1,lefttrigger:b11,righttrigger:,leftshoulder:b12,platform:Mac OS X, + +# Linux +0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Linux, +03000000ba2200002010000001010000,Jess Technology USB Game Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b3,y:b0,platform:Linux, +030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, +030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, +030000006d0400001ec2000020200000,Logitech F510 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, +030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux, +030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, +030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,platform:Linux, +030000004c050000c405000011010000,Sony DualShock 4,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:b6,righttrigger:b7,platform:Linux, +030000006f0e00003001000001010000,EA Sports PS3 Controller,platform:Linux,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7, +03000000de280000ff11000001000000,Valve Streaming Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, +030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, +030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, +030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, +03000000100800000100000010010000,Twin USB PS2 Adapter,a:b2,b:b1,y:b0,x:b3,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b4,righttrigger:b5,platform:Linux, +03000000a306000023f6000011010000,Saitek Cyborg V.1 Game Pad,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b6,righttrigger:b7,platform:Linux, +030000004f04000020b3000010010000,Thrustmaster 2 in 1 DT,a:b0,b:b2,y:b3,x:b1,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Linux, +030000004f04000023b3000000010000,Thrustmaster Dual Trigger 3-in-1,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a5, +030000008f0e00000300000010010000,GreenAsia Inc. USB Joystick ,platform:Linux,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2, +030000008f0e00001200000010010000,GreenAsia Inc. USB Joystick ,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2, +030000005e0400009102000007010000,X360 Wireless Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Linux, +030000006d04000016c2000010010000,Logitech Logitech Dual Action,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3, +03000000260900008888000000010000,GameCube {WiseGroup USB box},a:b0,b:b2,y:b3,x:b1,start:b7,leftshoulder:,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,rightstick:,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,platform:Linux, +030000006d04000011c2000010010000,Logitech WingMan Cordless RumblePad,a:b0,b:b1,y:b4,x:b3,start:b8,guide:b5,back:b2,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b9,righttrigger:b10,platform:Linux, +030000006d04000018c2000010010000,Logitech Logitech RumblePad 2 USB,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3, +05000000d6200000ad0d000001000000,Moga Pro,platform:Linux,a:b0,b:b1,y:b3,x:b2,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a5,righttrigger:a4, +030000004f04000009d0000000010000,Thrustmaster Run N Drive Wireless PS3,platform:Linux,a:b1,b:b2,x:b0,y:b3,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7, +030000004f04000008d0000000010000,Thrustmaster Run N Drive Wireless,platform:Linux,a:b1,b:b2,x:b0,y:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:b6,righttrigger:b7, +0300000000f000000300000000010000,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Linux, +0300000000f00000f100000000010000,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Linux, +030000006f0e00001f01000000010000,Generic X-Box pad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4, +03000000280400000140000000010000,Gravis GamePad Pro USB ,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftx:a0,lefty:a1, +030000005e0400008902000021010000,Microsoft X-Box pad v2 (US),platform:Linux,x:b3,a:b0,b:b1,y:b4,back:b6,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b5,lefttrigger:a2,rightshoulder:b2,righttrigger:a5,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a3,righty:a4, +030000006f0e00001e01000011010000,Rock Candy Gamepad for PS3,platform:Linux,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,guide:b12,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2, +03000000250900000500000000010000,Sony PS2 pad with SmartJoy adapter,platform:Linux,a:b2,b:b1,y:b0,x:b3,start:b8,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5, +030000008916000000fd000024010000,Razer Onza Tournament,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Linux, +030000004f04000000b3000010010000,Thrustmaster Firestorm Dual Power,a:b0,b:b2,y:b3,x:b1,start:b10,guide:b8,back:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Linux, +03000000ad1b000001f5000033050000,Hori Pad EX Turbo 2,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,platform:Linux, +050000004c050000c405000000010000,PS4 Controller (Bluetooth),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux, +060000004c0500006802000000010000,PS3 Controller (Bluetooth),a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,platform:Linux, +03000000790000000600000010010000,DragonRise Inc. Generic USB Joystick ,platform:Linux,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a4, +03000000666600000488000000010000,Super Joy Box 5 Pro,platform:Linux,a:b2,b:b1,x:b3,y:b0,back:b9,start:b8,leftshoulder:b6,rightshoulder:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5,dpup:b12,dpleft:b15,dpdown:b14,dpright:b13, +05000000362800000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,platform:Linux,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2, +05000000362800000100000003010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,platform:Linux,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2, +030000008916000001fd000024010000,Razer Onza Classic Edition,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:b11,dpdown:b14,dpright:b12,dpup:b13,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4, +030000005e040000d102000001010000,Microsoft X-Box One pad,platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4, +03000000790000001100000010010000,RetroLink Saturn Classic Controller,platform:Linux,x:b3,a:b0,b:b1,y:b4,back:b5,guide:b2,start:b8,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1, +050000007e0500003003000001000000,Nintendo Wii U Pro Controller,platform:Linux,a:b0,b:b1,x:b3,y:b2,back:b8,start:b9,guide:b10,leftshoulder:b4,rightshoulder:b5,leftstick:b11,rightstick:b12,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:b13,dpleft:b15,dpdown:b14,dpright:b16, +030000005e0400008e02000004010000,Microsoft X-Box 360 pad,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,guide:b8,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2, diff --git a/mkxp.pro b/mkxp.pro index b715d5f..e4e38c4 100644 --- a/mkxp.pro +++ b/mkxp.pro @@ -246,7 +246,8 @@ EMBED = \ shader/simpleMatrix.vert \ shader/tilemapvx.vert \ assets/liberation.ttf \ - assets/icon.png + assets/icon.png \ + assets/gamecontrollerdb.txt SHARED_FLUID { DEFINES += SHARED_FLUID diff --git a/src/eventthread.cpp b/src/eventthread.cpp index e3bf194..ddf3a54 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,8 @@ #include +#include + typedef void (ALC_APIENTRY *LPALCDEVICEPAUSESOFT) (ALCdevice *device); typedef void (ALC_APIENTRY *LPALCDEVICERESUMESOFT) (ALCdevice *device); @@ -70,6 +73,7 @@ initALCFunctions(ALCdevice *alcDev) #define HAVE_ALC_DEVICE_PAUSE alc.DevicePause uint8_t EventThread::keyStates[]; +EventThread::ControllerState EventThread::gcState; EventThread::JoyState EventThread::joyState; EventThread::MouseState EventThread::mouseState; EventThread::TouchState EventThread::touchState; @@ -131,9 +135,21 @@ void EventThread::process(RGSSThreadData &rtData) bool terminate = false; - SDL_Joystick *js = 0; - if (SDL_NumJoysticks() > 0) - js = SDL_JoystickOpen(0); + std::map controllers; + std::map joysticks; + + for (int i = 0; i < SDL_NumJoysticks(); ++i) { + if (SDL_IsGameController(i)) { + //Load as game controller + SDL_GameController *gc = SDL_GameControllerOpen(i); + int id = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(gc)); + controllers[id] = gc; + } else { + //Fall back to joystick + SDL_Joystick *js = SDL_JoystickOpen(i); + joysticks[SDL_JoystickInstanceID(js)] = js; + } + } char buffer[128]; @@ -145,6 +161,12 @@ void EventThread::process(RGSSThreadData &rtData) int winW, winH; int i; + SDL_Joystick *js; + SDL_GameController *gc; + int id; + std::map::iterator jsit; + std::map::iterator gcit; + SDL_GetWindowSize(win, &winW, &winH); SettingsMenu *sMenu = 0; @@ -157,7 +179,7 @@ void EventThread::process(RGSSThreadData &rtData) break; } - if (sMenu && sMenu->onEvent(event)) + if (sMenu && sMenu->onEvent(event, joysticks)) { if (sMenu->destroyReq()) { @@ -330,31 +352,64 @@ void EventThread::process(RGSSThreadData &rtData) keyStates[event.key.keysym.scancode] = false; break; + case SDL_CONTROLLERBUTTONDOWN: + gcState.buttons[event.cbutton.button] = true; + break; + + case SDL_CONTROLLERBUTTONUP: + gcState.buttons[event.cbutton.button] = false; + break; + + case SDL_CONTROLLERAXISMOTION: + gcState.axes[event.caxis.axis] = event.caxis.value; + break; + + case SDL_CONTROLLERDEVICEADDED: + gc = SDL_GameControllerOpen(event.jdevice.which); + id = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(gc)); + controllers[id] = gc; + break; + + case SDL_CONTROLLERDEVICEREMOVED: + gcit = controllers.find(event.jdevice.which); + SDL_GameControllerClose(gcit->second); + controllers.erase(gcit); + break; + case SDL_JOYBUTTONDOWN : - joyState.buttons[event.jbutton.button] = true; + if (joysticks.find(event.jbutton.which) != joysticks.end()) + joyState.buttons[event.jbutton.button] = true; break; case SDL_JOYBUTTONUP : - joyState.buttons[event.jbutton.button] = false; + if (joysticks.find(event.jbutton.which) != joysticks.end()) + joyState.buttons[event.jbutton.button] = false; break; case SDL_JOYHATMOTION : - joyState.hats[event.jhat.hat] = event.jhat.value; + if (joysticks.find(event.jbutton.which) != joysticks.end()) + joyState.hats[event.jhat.hat] = event.jhat.value; break; case SDL_JOYAXISMOTION : - joyState.axes[event.jaxis.axis] = event.jaxis.value; + if (joysticks.find(event.jbutton.which) != joysticks.end()) + joyState.axes[event.jaxis.axis] = event.jaxis.value; break; case SDL_JOYDEVICEADDED : - if (event.jdevice.which > 0) + if (SDL_IsGameController(event.jdevice.which)) break; - - js = SDL_JoystickOpen(0); + js = SDL_JoystickOpen(event.jdevice.which); + joysticks[SDL_JoystickInstanceID(js)] = js; break; case SDL_JOYDEVICEREMOVED : - resetInputStates(); + jsit = joysticks.find(event.jdevice.which); + if (jsit != joysticks.end()) { + SDL_JoystickClose(jsit->second); + joysticks.erase(jsit); + resetInputStates(); + } break; case SDL_MOUSEBUTTONDOWN : @@ -442,8 +497,10 @@ void EventThread::process(RGSSThreadData &rtData) /* Just in case */ rtData.syncPoint.resumeThreads(); - if (SDL_JoystickGetAttached(js)) - SDL_JoystickClose(js); + for (gcit = controllers.begin(); gcit != controllers.end(); ++gcit) + SDL_GameControllerClose(gcit->second); + for (jsit = joysticks.begin(); jsit != joysticks.end(); ++jsit) + SDL_JoystickClose(jsit->second); delete sMenu; } @@ -514,6 +571,7 @@ void EventThread::cleanup() void EventThread::resetInputStates() { memset(&keyStates, 0, sizeof(keyStates)); + memset(&gcState, 0, sizeof(gcState)); memset(&joyState, 0, sizeof(joyState)); memset(&mouseState.buttons, 0, sizeof(mouseState.buttons)); memset(&touchState, 0, sizeof(touchState)); diff --git a/src/eventthread.h b/src/eventthread.h index 46051f1..3501f1d 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -46,6 +47,12 @@ union SDL_Event; class EventThread { public: + struct ControllerState + { + int axes[SDL_CONTROLLER_AXIS_MAX]; + bool buttons[SDL_CONTROLLER_BUTTON_MAX]; + }; + struct JoyState { int axes[256]; @@ -72,6 +79,7 @@ public: }; static uint8_t keyStates[SDL_NUM_SCANCODES]; + static ControllerState gcState; static JoyState joyState; static MouseState mouseState; static TouchState touchState; diff --git a/src/input.cpp b/src/input.cpp index f73cb72..12730e5 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -100,6 +100,56 @@ struct KbBinding : public Binding SDL_Scancode source; }; +/* Controller button binding */ +struct GcButtonBinding : public Binding +{ + GcButtonBinding() {} + + bool sourceActive() const + { + return EventThread::gcState.buttons[source]; + } + + bool sourceRepeatable() const + { + return true; + } + + uint8_t source; +}; + +/* Controller axis binding */ +struct GcAxisBinding : public Binding +{ + GcAxisBinding() {} + + GcAxisBinding(uint8_t source, + AxisDir dir, + Input::ButtonCode target) + : Binding(target), + source(source), + dir(dir) + {} + + bool sourceActive() const + { + int val = EventThread::gcState.axes[source]; + + if (dir == Negative) + return val < -JAXIS_THRESHOLD; + else /* dir == Positive */ + return val > JAXIS_THRESHOLD; + } + + bool sourceRepeatable() const + { + return true; + } + + uint8_t source; + AxisDir dir; +}; + /* Joystick button binding */ struct JsButtonBinding : public Binding { @@ -262,6 +312,8 @@ struct InputPrivate { std::vector kbStatBindings; std::vector kbBindings; + std::vector gcABindings; + std::vector gcBBindings; std::vector jsABindings; std::vector jsHBindings; std::vector jsBBindings; @@ -370,6 +422,8 @@ struct InputPrivate void applyBindingDesc(const BDescVec &d) { kbBindings.clear(); + gcABindings.clear(); + gcBBindings.clear(); jsABindings.clear(); jsHBindings.clear(); jsBBindings.clear(); @@ -395,6 +449,25 @@ struct InputPrivate break; } + case CAxis : + { + GcAxisBinding bind; + bind.source = src.d.ja.axis; + bind.dir = src.d.ja.dir; + bind.target = desc.target; + gcABindings.push_back(bind); + + break; + } + case CButton : + { + GcButtonBinding bind; + bind.source = src.d.jb; + bind.target = desc.target; + gcBBindings.push_back(bind); + + break; + } case JAxis : { JsAxisBinding bind; @@ -435,6 +508,8 @@ struct InputPrivate appendBindings(msBindings); appendBindings(kbBindings); + appendBindings(gcABindings); + appendBindings(gcBBindings); appendBindings(jsABindings); appendBindings(jsHBindings); appendBindings(jsBBindings); diff --git a/src/keybindings.cpp b/src/keybindings.cpp index 2267a30..266bc50 100644 --- a/src/keybindings.cpp +++ b/src/keybindings.cpp @@ -64,24 +64,38 @@ struct JsBindingData } }; +struct GcBindingData +{ + int source; + Input::ButtonCode target; + + void add(BDescVec &d) const + { + SourceDesc src; + src.type = CButton; + src.d.jb = source; + + BindingDesc desc; + desc.src = src; + desc.target = target; + + d.push_back(desc); + } +}; + /* Common */ static const KbBindingData defaultKbBindings[] = { - { SDL_SCANCODE_LEFT, Input::Left }, + { SDL_SCANCODE_LEFT, Input::Left }, { SDL_SCANCODE_RIGHT, Input::Right }, { SDL_SCANCODE_UP, Input::Up }, { SDL_SCANCODE_DOWN, Input::Down }, - { SDL_SCANCODE_H, Input::Left }, - { SDL_SCANCODE_L, Input::Right }, - { SDL_SCANCODE_K, Input::Up }, - { SDL_SCANCODE_J, Input::Down }, { SDL_SCANCODE_Z, Input::Action }, - { SDL_SCANCODE_SPACE, Input::Action }, - { SDL_SCANCODE_RETURN, Input::Action }, + { SDL_SCANCODE_SPACE, Input::Action }, { SDL_SCANCODE_X, Input::Cancel }, + { SDL_SCANCODE_ESCAPE, Input::Cancel }, { SDL_SCANCODE_A, Input::Menu }, - { SDL_SCANCODE_ESCAPE, Input::Menu }, - { SDL_SCANCODE_KP_0, Input::Menu }, + { SDL_SCANCODE_RETURN, Input::Menu }, { SDL_SCANCODE_S, Input::Items }, { SDL_SCANCODE_LSHIFT, Input::Run }, { SDL_SCANCODE_LCTRL, Input::Deactivate }, @@ -91,17 +105,28 @@ static const KbBindingData defaultKbBindings[] = static elementsN(defaultKbBindings); -static const JsBindingData defaultJsBindings[] = +static const GcBindingData defaultGcBindings[] = { - { 0, Input::Action }, + { SDL_CONTROLLER_BUTTON_DPAD_LEFT, Input::Left }, + { SDL_CONTROLLER_BUTTON_DPAD_RIGHT, Input::Right }, + { SDL_CONTROLLER_BUTTON_DPAD_UP, Input::Up }, + { SDL_CONTROLLER_BUTTON_DPAD_DOWN, Input::Down }, + { SDL_CONTROLLER_BUTTON_A, Input::Action }, + { SDL_CONTROLLER_BUTTON_B, Input::Cancel }, + { SDL_CONTROLLER_BUTTON_X, Input::Run }, + { SDL_CONTROLLER_BUTTON_Y, Input::Items }, + { SDL_CONTROLLER_BUTTON_START, Input::Menu }, + { SDL_CONTROLLER_BUTTON_BACK, Input::Deactivate }, + { SDL_CONTROLLER_BUTTON_LEFTSHOULDER, Input::L }, + { SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, Input::R }, }; -static elementsN(defaultJsBindings); +static elementsN(defaultGcBindings); -static void addAxisBinding(BDescVec &d, uint8_t axis, AxisDir dir, Input::ButtonCode target) +static void addGcAxisBinding(BDescVec &d, uint8_t axis, AxisDir dir, Input::ButtonCode target) { SourceDesc src; - src.type = JAxis; + src.type = CAxis; src.d.ja.axis = axis; src.d.ja.dir = dir; @@ -112,20 +137,6 @@ static void addAxisBinding(BDescVec &d, uint8_t axis, AxisDir dir, Input::Button d.push_back(desc); } -static void addHatBinding(BDescVec &d, uint8_t hat, uint8_t pos, Input::ButtonCode target) -{ - SourceDesc src; - src.type = JHat; - src.d.jh.hat = hat; - src.d.jh.pos = pos; - - BindingDesc desc; - desc.src = src; - desc.target = target; - - d.push_back(desc); -} - BDescVec genDefaultBindings() { BDescVec d; @@ -133,23 +144,20 @@ BDescVec genDefaultBindings() for (size_t i = 0; i < defaultKbBindingsN; ++i) defaultKbBindings[i].add(d); - for (size_t i = 0; i < defaultJsBindingsN; ++i) - defaultJsBindings[i].add(d); + for (size_t i = 0; i < defaultGcBindingsN; ++i) + defaultGcBindings[i].add(d); - addAxisBinding(d, 0, Negative, Input::Left ); - addAxisBinding(d, 0, Positive, Input::Right); - addAxisBinding(d, 1, Negative, Input::Up ); - addAxisBinding(d, 1, Positive, Input::Down ); - - addHatBinding(d, 0, SDL_HAT_LEFT, Input::Left ); - addHatBinding(d, 0, SDL_HAT_RIGHT, Input::Right); - addHatBinding(d, 0, SDL_HAT_UP, Input::Up ); - addHatBinding(d, 0, SDL_HAT_DOWN, Input::Down ); + addGcAxisBinding(d, SDL_CONTROLLER_AXIS_LEFTX, Negative, Input::Left ); + addGcAxisBinding(d, SDL_CONTROLLER_AXIS_LEFTX, Positive, Input::Right ); + addGcAxisBinding(d, SDL_CONTROLLER_AXIS_LEFTY, Negative, Input::Up ); + addGcAxisBinding(d, SDL_CONTROLLER_AXIS_LEFTY, Positive, Input::Down ); + addGcAxisBinding(d, SDL_CONTROLLER_AXIS_TRIGGERLEFT, Positive, Input::Deactivate); + addGcAxisBinding(d, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, Positive, Input::Run ); return d; } -#define FORMAT_VER 3 +#define FORMAT_VER 0 struct Header { @@ -239,12 +247,14 @@ static bool verifyDesc(const BindingDesc &desc) return true; case Key: return src.d.scan < SDL_NUM_SCANCODES; + case CButton: case JButton: return true; case JHat: /* Only accept single directional binds */ return src.d.jh.pos == SDL_HAT_LEFT || src.d.jh.pos == SDL_HAT_RIGHT || src.d.jh.pos == SDL_HAT_UP || src.d.jh.pos == SDL_HAT_DOWN; + case CAxis: case JAxis: return src.d.ja.dir == Negative || src.d.ja.dir == Positive; default: diff --git a/src/keybindings.h b/src/keybindings.h index d0c2754..c843701 100644 --- a/src/keybindings.h +++ b/src/keybindings.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,8 @@ enum SourceType { Invalid, Key, + CButton, + CAxis, JButton, JAxis, JHat @@ -82,8 +85,10 @@ struct SourceDesc return true; case Key: return d.scan == o.d.scan; + case CButton: case JButton: return d.jb == o.d.jb; + case CAxis: case JAxis: return (d.ja.axis == o.d.ja.axis) && (d.ja.dir == o.d.ja.dir); case JHat: diff --git a/src/main.cpp b/src/main.cpp index 92fe615..c16a18d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,6 +41,7 @@ #include "binding.h" #include "icon.png.xxd" +#include "gamecontrollerdb.txt.xxd" static void rgssThreadError(RGSSThreadData *rtData, const std::string &msg) @@ -172,7 +173,7 @@ int main(int argc, char *argv[]) SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); /* initialize SDL first */ - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) { showInitError(std::string("Error initializing SDL: ") + SDL_GetError()); return 0; @@ -295,6 +296,11 @@ int main(int argc, char *argv[]) RGSSThreadData rtData(&eventThread, argv[0], win, alcDev, mode.refresh_rate, conf); + /* Add controller bindings from embedded controller DB */ + SDL_RWops *controllerDB = SDL_RWFromConstMem(assets_gamecontrollerdb_txt, + assets_gamecontrollerdb_txt_len); + SDL_GameControllerAddMappingsFromRW(controllerDB, 1); + int winW, winH; SDL_GetWindowSize(win, &winW, &winH); rtData.windowSizeMsg.post(Vec2i(winW, winH)); diff --git a/src/settingsmenu.cpp b/src/settingsmenu.cpp index 730e64c..cec9cf0 100644 --- a/src/settingsmenu.cpp +++ b/src/settingsmenu.cpp @@ -81,6 +81,24 @@ static elementsN(vButtons); /* Human readable string representation */ std::string sourceDescString(const SourceDesc &src) { + static const char *const gcButtonNames[SDL_CONTROLLER_BUTTON_MAX] = { + "A Button", + "B Button", + "X Button", + "Y Button", + "Back Button", + "Guide Button", + "Start Button", + "Left Stick", + "Right Stick", + "Left Shoulder", + "Right Shoulder", + "D-Pad (Up)", + "D-Pad (Down)", + "D-Pad (Left)", + "D-Pad (Right)", + }; + char buf[128]; char pos; @@ -100,10 +118,44 @@ std::string sourceDescString(const SourceDesc &src) if (*str == '\0') return "Unknown key"; else - return str; + return std::string(str) + " Key"; } + + case CButton: + snprintf(buf, sizeof(buf), "%s", gcButtonNames[src.d.jb]); + return buf; + + case CAxis: + switch (src.d.ja.axis) { + case SDL_CONTROLLER_AXIS_LEFTX: + if (src.d.ja.dir == Negative) + return "Left Stick (Left)"; + else + return "Left Stick (Right)"; + case SDL_CONTROLLER_AXIS_LEFTY: + if (src.d.ja.dir == Negative) + return "Left Stick (Up)"; + else + return "Left Stick (Down)"; + case SDL_CONTROLLER_AXIS_RIGHTX: + if (src.d.ja.dir == Negative) + return "Right Stick (Left)"; + else + return "Right Stick (Right)"; + case SDL_CONTROLLER_AXIS_RIGHTY: + if (src.d.ja.dir == Negative) + return "Right Stick (Up)"; + else + return "Right Stick (Down)"; + case SDL_CONTROLLER_AXIS_TRIGGERLEFT: + return "Left Trigger"; + case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: + return "Right Trigger"; + } + return ""; + case JButton: - snprintf(buf, sizeof(buf), "JS %d", src.d.jb); + snprintf(buf, sizeof(buf), "Joy Button %d", src.d.jb); return buf; case JHat: @@ -128,12 +180,12 @@ std::string sourceDescString(const SourceDesc &src) default: pos = '-'; } - snprintf(buf, sizeof(buf), "Hat %d:%c", + snprintf(buf, sizeof(buf), "Joy Hat %d:%c", src.d.jh.hat, pos); return buf; case JAxis: - snprintf(buf, sizeof(buf), "Axis %d%c", + snprintf(buf, sizeof(buf), "Joy Axis %d%c", src.d.ja.axis, src.d.ja.dir == Negative ? '-' : '+'); return buf; } @@ -638,9 +690,28 @@ struct SettingsMenuPrivate break; + case SDL_CONTROLLERBUTTONDOWN: + desc.type = CButton; + desc.d.jb = event.cbutton.button; + break; + + case SDL_CONTROLLERAXISMOTION: + { + int v = event.caxis.value; + + /* Only register if pushed halfway through */ + if (v > -JAXIS_THRESHOLD && v < JAXIS_THRESHOLD) + return true; + + desc.type = CAxis; + desc.d.ja.axis = event.caxis.axis; + desc.d.ja.dir = v < 0 ? Negative : Positive; + break; + } + case SDL_JOYBUTTONDOWN: desc.type = JButton; - desc.d.jb = event.jbutton.button; + desc.d.jb = event.cbutton.button; break; case SDL_JOYHATMOTION: @@ -1011,7 +1082,7 @@ SettingsMenu::SettingsMenu(RGSSThreadData &rtData) const char *info = "Use left click to bind a slot, right click to clear its binding"; p->infoLabel = Label(p, IntRect(16, 16, winSize.x, 16), info, cText, cText, cText); - const char *warn = "Warning: Same physical key bound to multiple slots"; + const char *warn = "Warning: Same physical action bound to multiple slots"; p->dupWarnLabel = Label(p, IntRect(16, 40, winSize.x, 16), warn, 255, 0, 0); p->widgets.push_back(&p->infoLabel); @@ -1034,7 +1105,8 @@ SettingsMenu::~SettingsMenu() delete p; } -bool SettingsMenu::onEvent(const SDL_Event &event) +bool SettingsMenu::onEvent(const SDL_Event &event, + const std::map &joysticks) { /* First, check whether this event is for us */ switch (event.type) @@ -1051,6 +1123,9 @@ bool SettingsMenu::onEvent(const SDL_Event &event) return false; break; + case SDL_CONTROLLERBUTTONDOWN: + case SDL_CONTROLLERBUTTONUP: + case SDL_CONTROLLERAXISMOTION: case SDL_JOYBUTTONDOWN : case SDL_JOYBUTTONUP : case SDL_JOYHATMOTION : @@ -1129,11 +1204,29 @@ bool SettingsMenu::onEvent(const SDL_Event &event) break; } + case SDL_CONTROLLERBUTTONDOWN: + case SDL_CONTROLLERAXISMOTION: + if (p->state != AwaitingInput) + return true; + break; + case SDL_JOYBUTTONDOWN: + if (p->state != AwaitingInput) + return true; + if (joysticks.find(event.jbutton.which) == joysticks.end()) + return true; + break; case SDL_JOYHATMOTION: + if (p->state != AwaitingInput) + return true; + if (joysticks.find(event.jhat.which) == joysticks.end()) + return true; + break; case SDL_JOYAXISMOTION: if (p->state != AwaitingInput) return true; + if (joysticks.find(event.jaxis.which) == joysticks.end()) + return true; break; case SDL_MOUSEBUTTONDOWN: diff --git a/src/settingsmenu.h b/src/settingsmenu.h index 1107860..836111c 100644 --- a/src/settingsmenu.h +++ b/src/settingsmenu.h @@ -24,6 +24,9 @@ #include +#include +#include + struct SettingsMenuPrivate; struct RGSSThreadData; union SDL_Event; @@ -35,7 +38,8 @@ public: ~SettingsMenu(); /* Returns true if the event was consumed */ - bool onEvent(const SDL_Event &event); + bool onEvent(const SDL_Event &event, + const std::map &joysticks); void raise(); bool destroyReq() const;