FAQ  •  Register  •  Login

(Mod) PS3 Joypad Support

Forum rules
This forum is for technical discussion only. If you are interested in gameplay or client-side issues, please post in Bitfighter Features.
<<

CrazyLinuxNerd

User avatar

Posts: 40

Joined: Mon Feb 07, 2011 4:43 pm

Location: England

Post Thu Feb 10, 2011 11:02 pm

(Mod) PS3 Joypad Support

Hi, as you may know, I'm not a developer :-D.

However. I somehow dug into the source code, changed a few things, and attempted to add PS3 Joypad support. I was partially successful.

Only problem with my Implementation, is that it:

1) Doesn't Support X, Square, Triangle, O or R3 & L3 (You could use dpad instead)
2) Can be very sensitive
3) sometimes buttons randomly switch on. However pressing the button will switch it off.

Reason I did this was because with the old config, buttons would come on and stick on, and would require and entire game reboot to switch off (so a bit of a pain in the.. for me)

I had to use Logitech dual for the controllers axis to work also. So buttons where wrong in config or looked wrong rather.

This attempts to solve this. buttons that do work, will detect properly as they should in F7 page. and other places. (except the above)

I've only tested this on Fedora 14, with the controller running bluetooth.

I am not a C++ coder, or programmer at that, I've only ever edited the code never actually completely started a C++ project from scratch :-) I'm used to writing PHP however, thus i was able to work my way around it all. (It's quite similar)

This is far from perfect. And you may want to remap the controls on it. (Like using DPAD as an alternative to X, T, S, and O. Like I did).

Hopefully, someone with a bit more experience in C++ will be able to pick this up and make it much better :-).

You can find the patch file here (It was built against Google Codes 015 code, no higher):

http://pastebin.com/UjV5VS94

Enjoy! :D

PS: you may need to change directories etc in patch file. If you want the pre-edited files, I will send them to you in a zip file :-) Just PM me if that's the case. (They will be raw cpp files, not compiled)

- Jake
Last edited by CrazyLinuxNerd on Wed Feb 16, 2011 4:47 am, edited 1 time in total.
<<

CrazyLinuxNerd

User avatar

Posts: 40

Joined: Mon Feb 07, 2011 4:43 pm

Location: England

Post Wed Feb 16, 2011 4:45 am

Re: PS3 Joypad Support

Just an update on that. I updated this to latest google code revision, should work on rev fdb12b22ef or higher, as long as input.h and input.cpp are not changed.

If it stops working let me know :-).

Buttons Circle and Triangle are now usable also. And the controller is now automatically detected (under linux)

X and Square are now only broken buttons :-). (also R3 and L3, though you could assign those to X and square if you like)

Again, only tested on linux, your more than welcome to test on windows, in theory it should work, but I can't say whether or not it will. :-)

Again, if you want original two modified files, let me know :-).

Below is the new patchfile :-).
  Code:
diff -crB ./zap/input.cpp ../modbitfighter/zap/input.cpp
*** ./zap/input.cpp 2011-02-16 11:32:21.456369737 +0000
--- ../modbitfighter/zap/input.cpp  2011-02-16 11:10:20.761830768 +0000
***************
*** 114,127 ****
  }
 
  // Unfortunately, Linux and Windows map joystick axes differently
! // From ControllerTypeType enum ---> LogitechWingman, LogitechDualAction, SaitekDualAnalogP880, SaitekDualAnalogRumblePad, PS2DualShock, PS2DualShockConversionCable, XBoxController, XBoxControllerOnXBox
! //                                                                Wingmn    DualAct   P880     RumbPad     PS2  PS2 w/Cnvrtr  XBox    XBoxOnXBox
! static U32 controllerButtonCounts[ControllerTypeCount] =          { 9,       10,       9,        10,       10,       10,      10,       14 };     // How many buttons?
  #ifdef TNL_OS_LINUX
! //                                      ? = need to change?         ?       works       ?          ?        ?         ?        ?         ?
! static U32 shootAxisRemaps[ControllerTypeCount][AXIS_COUNT] = { { 5, 6 }, { 2, 3 }, { 5, 2 }, { 5, 2 }, { 2, 3 }, { 5, 2}, { 3, 4 }, { 3, 4 } };  // What axes to use for firing?  Should we let users set this somehow?
  #else
! static U32 shootAxisRemaps[ControllerTypeCount][AXIS_COUNT] = { { 5, 6 }, { 2, 5 }, { 5, 2 }, { 5, 2 }, { 2, 5 }, { 5, 2}, { 3, 4 }, { 3, 4 } };
  #endif
   
  // PS3 Joystick: http://ps3media.ign.com/ps3/image/article/705/705934/e3-2006-in-depth-with-the-ps3-controller-20060515010609802.jpg
--- 114,127 ----
  }
 
  // Unfortunately, Linux and Windows map joystick axes differently
! // From ControllerTypeType enum ---> LogitechWingman, LogitechDualAction, SaitekDualAnalogP880, SaitekDualAnalogRumblePad, PS2DualShock, PS2DualShockConversionCable, PS3DualShock, XBoxController, XBoxControllerOnXBox                                                                                                                                              \/ FIXME: Someone check PS3 Joypad on windows!
! //                                                                Wingmn    DualAct   P880     RumbPad     PS2  PS2 w/Cnvrtr  PS3   XBox    XBoxOnXBox
! static U32 controllerButtonCounts[ControllerTypeCount] =          { 9,       10,       9,        10,       10,       10,      10,     10,     14 };     // How many buttons?
  #ifdef TNL_OS_LINUX
! //                                      ? = need to change?         ?       works       ?          ?        ?         ?        ?         ?         ?
! static U32 shootAxisRemaps[ControllerTypeCount][AXIS_COUNT] = { { 5, 6 }, { 2, 3 }, { 5, 2 }, { 5, 2 }, { 2, 5 }, { 5, 2}, { 2, 3 }, { 3, 4 }, { 3, 4 } };  // What axes to use for firing?  Should we let users set this somehow?
  #else
! static U32 shootAxisRemaps[ControllerTypeCount][AXIS_COUNT] = { { 5, 6 }, { 2, 5 }, { 5, 2 }, { 5, 2 }, { 2, 5 }, { 5, 2}, { 2, 5 }, { 3, 4 }, { 3, 4 } };
  #endif
   
  // PS3 Joystick: http://ps3media.ign.com/ps3/image/article/705/705934/e3-2006-in-depth-with-the-ps3-controller-20060515010609802.jpg
***************
*** 224,229 ****
--- 224,249 ----
        0,
        0,
     },
+   { // PS3DualShock    13
+       ControllerButtonStart, // Start
+       0, // L3 - Unused
+       0, // R3 - Unused
+       ControllerButtonBack, // Select
+       ControllerButtonDPadUp, // DPAD Up
+       ControllerButtonDPadRight, // DPAD Right
+       ControllerButtonDPadDown, // DPAD Down
+       ControllerButtonDPadLeft, // DPAD Left
+       ControllerButton5, // L2
+       ControllerButton6, // R2    
+       ControllerButton7, // L1
+       ControllerButton8, // R1
+       ControllerButton4, // Triangle
+       ControllerButton2, // Circle
+       // FIXME: If you can get X and Square Working. Add them as these buttons:
+       // ControllerButton1 // X
+       // ControllerButton3 // Square
+       // Above order should be correct. X is Button 14 Square is Button 15.
+    },
     { // XBoxController     10
        ControllerButton1,      // A
        ControllerButton2,      // B
***************
*** 492,497 ****
--- 512,525 ----
        else
           return rectButtonWidth;
     }
+   // http://ps3media.ign.com/ps3/image/article/705/705934/e3-2006-in-depth-with-the-ps3-controller-20060515010609802.jpg
+   else if(joy == PS3DualShock)
+    {
+       if(buttonIndex < 4)
+          return 18;
+       else
+          return rectButtonWidth;
+    }
     else if(joy == XBoxController || joy == XBoxControllerOnXBox)
     {
        if(buttonIndex < 4)
***************
*** 661,666 ****
--- 689,763 ----
           }
        }
     }
+   // http://ps3media.ign.com/ps3/image/article/705/705934/e3-2006-in-depth-with-the-ps3-controller-20060515010609802.jpg
+   // Based on PS2DualShock
+    else if(joy == PS3DualShock)
+    {
+       if(buttonIndex >= controllerButtonCounts[joy])
+          return;
+
+       static F32 color[6][3] = {
+          { 0.5, 0.5, 1 },
+          { 1, 0.5, 0.5 },
+          { 1, 0.5, 1 },
+          { 0.5, 1, 0.5 },
+          { 0.7, 0.7, 0.7 },
+          { 0.7, 0.7, 0.7 }
+       };
+       Color c(color[buttonIndex][0], color[buttonIndex][1], color[buttonIndex][2]);
+       Point center(x, y + 8);
+       if(buttonIndex < 4)
+       {
+          setButtonColor(activated);
+          drawCircle(center, 9);
+          glColor(c);
+          switch(buttonIndex)
+          {
+          case 0:     // X
+             glBegin(GL_LINES);
+             glVertex(center + Point(-5, -5));
+             glVertex(center + Point(5, 5));
+             glVertex(center + Point(-5, 5));
+             glVertex(center + Point(5, -5));
+             glEnd();
+             break;
+          case 1:     // Circle
+             drawCircle(center, 6);
+             break;
+          case 2:     // Square
+             glBegin(GL_LINE_LOOP);
+             glVertex(center + Point(-5, -5));
+             glVertex(center + Point(-5, 5));
+             glVertex(center + Point(5, 5));
+             glVertex(center + Point(5, -5));
+             glEnd();
+             break;
+          case 3:     // Triangle
+             glBegin(GL_LINE_LOOP);
+             glVertex(center + Point(0, -7));
+             glVertex(center + Point(6, 5));
+             glVertex(center + Point(-6, 5));
+             glEnd();
+             break;
+          }
+       }
+       else
+       {
+          string labels[] = { "L2", "R2", "L1", "R1", "Sel", "Strt" };
+          if (buttonIndex < 9)    // Shoulder buttons
+             renderRectButton(Point(x, y), labels[buttonIndex - 4].c_str(), ALIGN_CENTER, activated);
+          else
+          {  // Triangle button
+             setButtonColor(activated);
+             glBegin(GL_LINE_LOOP);
+                glVertex(center + Point(-15, -9));
+                glVertex(center + Point(-15, 10));
+                glVertex(center + Point(12, 0));
+             glEnd();
+            UserInterface::drawString(x - 13, y + 3, 8, labels[buttonIndex - 4].c_str());
+          }
+       }
+    }
     else if(joy == XBoxController || joy == XBoxControllerOnXBox)
     {
        if(buttonIndex >= controllerButtonCounts[joy])
***************
*** 756,761 ****
--- 853,863 ----
        else if(gJoystickNames[gUseStickNumber - 1] == "PC Conversion Cable")
           ret = PS2DualShockConversionCable;                          // http://ecx.images-amazon.com/images/I/4 ... SS500_.jpg
 
+       // Note that on Linux, when I plug in the controller, DMSG outputs Sony PLAYSTATION(R)3 Controller.
+       // Was connected.. Thus i have used it here. This may be different on Windows...
+       else if(gJoystickNames[gUseStickNumber - 1].find("PLAYSTATION(R)3") != string::npos)
+           ret = PS3DualShock;                                                     // http://ps3media.ign.com/ps3/image/article/705/705934/e3-2006-in-depth-with-the-ps3-controller-20060515010609802.jpg
+
        else if(gJoystickNames[gUseStickNumber - 1] == "P880")
           ret = SaitekDualAnalogP880;
 
***************
*** 796,801 ****
--- 898,905 ----
        return PS2DualShock;
     else if (strJoystick == "PS2DualShockConversionCable")
        return PS2DualShockConversionCable;
+       else if (strJoystick == "PS3DualShock")
+       return PS3DualShock;
     else if (strJoystick == "XBoxController")
        return XBoxController;
     else if (strJoystick == "XBoxControllerOnXBox")
***************
*** 824,829 ****
--- 928,935 ----
           return "PS2DualShock";
        case PS2DualShockConversionCable:
           return "PS2DualShockConversionCable";
+       case PS3DualShock:
+           return "PS3DualShock";
        case XBoxController:
           return "XBoxController";
        case XBoxControllerOnXBox:
***************
*** 853,858 ****
--- 959,966 ----
           return "PS2 Dualshock USB";
        case PS2DualShockConversionCable:
           return "PS2 Dualshock USB with Conversion Cable";
+       case PS3DualShock:
+          return "PS3 Sixaxis";
        case XBoxController:
           return "XBox Controller USB";
        case XBoxControllerOnXBox:
***************
*** 1186,1191 ****
--- 1294,1306 ----
     if(buttonDown & ControllerButton6) simulateKeyDown(BUTTON_6);
     if(buttonDown & ControllerButton7) simulateKeyDown(BUTTON_7);
     if(buttonDown & ControllerButton8) simulateKeyDown(BUTTON_8);
+  /*   if(buttonDown & ControllerButton9) simulateKeyDown(BUTTON_9);
+   if(buttonDown & ControllerButton10) simulateKeyDown(BUTTON_10);
+   if(buttonDown & ControllerButton11) simulateKeyDown(BUTTON_11);
+   if(buttonDown & ControllerButton12) simulateKeyDown(BUTTON_12);
+   if(buttonDown & ControllerButton13) simulateKeyDown(BUTTON_13);
+   if(buttonDown & ControllerButton14) simulateKeyDown(BUTTON_14);
+    if(buttonDown & ControllerButton15) simulateKeyDown(BUTTON_15); */
     if(buttonDown & ControllerButtonStart) simulateKeyDown(BUTTON_START);
     if(buttonDown & ControllerButtonBack) simulateKeyDown(BUTTON_BACK);
     if(buttonDown & ControllerButtonDPadUp) simulateKeyDown(BUTTON_DPAD_UP);
***************
*** 1201,1206 ****
--- 1316,1328 ----
     if(buttonUp & ControllerButton6) simulateKeyUp(BUTTON_6);
     if(buttonUp & ControllerButton7) simulateKeyUp(BUTTON_7);
     if(buttonUp & ControllerButton8) simulateKeyUp(BUTTON_8);
+  /*  if(buttonUp & ControllerButton9) simulateKeyUp(BUTTON_9);
+    if(buttonUp & ControllerButton10) simulateKeyUp(BUTTON_10);
+    if(buttonUp & ControllerButton11) simulateKeyUp(BUTTON_11);
+    if(buttonUp & ControllerButton12) simulateKeyUp(BUTTON_12);
+    if(buttonUp & ControllerButton13) simulateKeyUp(BUTTON_13);
+    if(buttonUp & ControllerButton14) simulateKeyUp(BUTTON_14);
+    if(buttonUp & ControllerButton15) simulateKeyUp(BUTTON_15); */
     if(buttonUp & ControllerButtonStart) simulateKeyUp(BUTTON_START);
     if(buttonUp & ControllerButtonBack) simulateKeyUp(BUTTON_BACK);
     if(buttonUp & ControllerButtonDPadUp) simulateKeyUp(BUTTON_DPAD_UP);
diff -crB ./zap/input.h ../modbitfighter/zap/input.h
*** ./zap/input.h   2011-02-16 11:32:21.462370806 +0000
--- ../modbitfighter/zap/input.h    2011-02-14 00:11:26.185542948 +0000
***************
*** 45,50 ****
--- 45,51 ----
     SaitekDualAnalogRumblePad, // 4 buttons on top, 4 in front
     PS2DualShock,
     PS2DualShockConversionCable,
+   PS3DualShock,
     XBoxController,
     XBoxControllerOnXBox,
     ControllerTypeCount,
<<

raptor

Posts: 1046

Joined: Mon Oct 11, 2010 9:03 pm

Post Wed Feb 16, 2011 12:11 pm

Re: (Mod) PS3 Joypad Support

Hi CLN,

Your patch made it into trunk:
http://code.google.com/p/bitfighter/sou ... 77fcd4b0de
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Wed Feb 16, 2011 12:16 pm

Re: (Mod) PS3 Joypad Support

CLN -- do you have access to a windows machine that you could use to see if your joystick patch works there as well (I would send you a build to test with)?
<<

CrazyLinuxNerd

User avatar

Posts: 40

Joined: Mon Feb 07, 2011 4:43 pm

Location: England

Post Wed Feb 16, 2011 12:40 pm

Re: (Mod) PS3 Joypad Support

Hi.

I wasn't expecting patch to make it into trunk :-). I personally do not have any windows machines that I control though I probably can get on one. How hard is it to build bitfighter for windows? I assume it should be like Linux, open a terminal and type make? If it is difficult, I might grab the exe off watusimoto to test it :-)

But non-the-less if I can get-a-hold of a windows machine (I will need to seek owners permission of course, shouldn't be too hard), I would gladly test it :-).

:-).
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Wed Feb 16, 2011 2:05 pm

Re: (Mod) PS3 Joypad Support

It's very easy to build for windows once you have your dev environment set up. But getting that working takes some effort. We'll be doing a 015a release sometime in the near future, which will include your code. If you get access to a machine before then, I'll send you an installer, otherwise, the standard 015a installer will do the trick.
<<

CrazyLinuxNerd

User avatar

Posts: 40

Joined: Mon Feb 07, 2011 4:43 pm

Location: England

Post Wed Feb 16, 2011 5:10 pm

Re: (Mod) PS3 Joypad Support

watusimoto wrote:It's very easy to build for windows once you have your dev environment set up. But getting that working takes some effort. We'll be doing a 015a release sometime in the near future, which will include your code. If you get access to a machine before then, I'll send you an installer, otherwise, the standard 015a installer will do the trick.
Hi, I managed to dig out one of my old virtual machines, which had windows XP

(I know it's not windows 7, but it's still a copy of windows :-) plus it's the last one I ever used :-) so don't really know how to use the newer ones. Lol. Bet you don't hear that very often "I don't know how to use windows, but I know Linux off by heart" xD.)

From a quick test run with 015 it appears it *should* work buttons seem to be the same, and name is detected almost the same :-). Of course. I have no way of telling if my mods will work with it, without of course the mods :-)

So, can someone send me a latest build for windows? Thanks! :-D. Save me some time trying to configure windows :-).

Also, for PS3 joypad drivers I used these on windows: http://dl.qj.net/playstation-3/tools-an ... or-pc.html

Screen-shot below of detection:
http://img46.imageshack.us/img46/598/screenshotnqf.png

Using that screen is how I will be testing the joypad on windows (correct button detection etc). Far to laggy for a flat out game, but a quick spin on a map or two would be feasible. :-).

- Jake
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Wed Feb 16, 2011 9:44 pm

Re: (Mod) PS3 Joypad Support

<<

CrazyLinuxNerd

User avatar

Posts: 40

Joined: Mon Feb 07, 2011 4:43 pm

Location: England

Post Thu Feb 17, 2011 2:41 am

Re: (Mod) PS3 Joypad Support

Ok. Got some good news! :-D.

Quick test spin on Windows XP, Virtual machine.

  • Controller got automatically detected
  • Buttons are still mapped correctly
  • Axis still works (This is the bit that could of been broken mainly
  • Works Ingame

Thanks to the help of sam686 I was also able to delete the ini file, and test with fresh settings :-).

But non-the-less all appears well :-). Played a couple of games with sam686 (well sort of, but with very low FPS due to VM).

- Jake.
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Thu Feb 17, 2011 3:14 am

Re: (Mod) PS3 Joypad Support

Excellent!

Return to Technical Discussion

Who is online

Users browsing this forum: No registered users and 6 guests