Gamepad on Mac

Monkey Targets Forums/Desktop/Gamepad on Mac

skape(Posted 2014) [#1]
Hi all,

I am currently testing implementation of gamepad controls on Mac. I am using an Xbox 360 controller with a third party driver for Mac. The driver seems to be working great, I have tried it successfully in a couple of games--everything seems to map correctly and I have access to both analog sticks and all of the buttons (I have not tried the analog triggers yet.)

My problem is that in Monkey, all of the button and most of the axis mappings are quite wonky. The left analog stick works fine, but the right is strange. The y-axis is mapping to the x-axis, and the left analog trigger is mapping to the x-axis. Additionally, the buttons are mapping strangely: the d-pad maps to the "lettered buttons" (in a strange way), and the lettered buttons map somewhat randomly. This is somewhat expected, as I've heard that the exact mapping can change between operating systems. The buttons issue I should be able to work around using custom mapping, but the axis issue is potentially a problem.

Anyone have any experience with this?

Thanks!


Sensei(Posted 2014) [#2]
Hi Unlikely.
I am in the process of having to test my xbox360 controller on the mac and linux too so will see if i get the same issues as you do.
Which 3rd party driver did you use?


skape(Posted 2014) [#3]
Hi Sensei,
Will be interesting to hear your results! I'm curious if this is consistent across systems, or not. If it is, it can probably be worked around easily enough.

I'm using Colin Munro's Mac OSX Gamepad controller driver.

It seems to work great everywhere I've tried it on Mavericks. Monkey reports the axis and buttons strangely though. The 360 controller doesn't have a "Z" axis for the analog sticks, so it seems that Monkey goes ahead and puts the next stick's first axis for the first stick's z-axis... etc. So everything gets strangely shifted. Also the buttons are not how Monkey has them mapped. However, you can get access to all of the buttons and the analog controls.


Sensei(Posted 2014) [#4]
Hi again,
So I tried this driver: http://www.imore.com/how-hook-xbox-360-controller-your-mac and found the same issue where pretty much all the functions work, but most are mapped totally wrong. Found it amusing, but nonetheless, not correct.
I'm in the process of seeing if I can get my ps3 controller connected to the mac to see if it does the same thing.

For worst case, I was thinking you could do a bit of jiggery pokery of remapping your in-game keys for mac specifically, using the HostOS state for GLFW

#if TARGET="glfw"
Select HostOS
		Case "winnt"
			' Normal joystick stuff
		Case "macos"
			' Remapped for mac
		Case "linux"
			' Remapped for linux?
		End
#End


I still need to test my 360 controller on my linux mint install to see if it works on there :) again, will let you know soon.

EDIT: I just noticed you and I tried the same driver from Colin Munro's site :)


Sensei(Posted 2014) [#5]
PS. Load up the joytest.monkey in the bananas folder. You'll find everything works, just mostly wrong :)
You can make a note of those changes and then use similar logic I explained above to accommodate your monkey game on the mac with the xbox 360 controller.
I'm going to have to do it myself for my game.


skape(Posted 2014) [#6]
Aye, I originally discovered the peculiarities using the joytest banana. ;)

I am wondering if it is consistently wonky (in which case I can do what you have suggested with the platform specific input code, or if it's just my system. Glad to know (sorry, sounds strange), that you are having similar issues. ;) Does yours map similarly to how I described above?


Sensei(Posted 2014) [#7]
Ok the good news is this. My idea worked.
In my game, I have a method called GetControls() that does the following:
Method getControls:Void()
    #If OUYA = "1"
      updateOuyaControls()
    #ElseIf TARGET = "android"
      updateAndroidControls()
    #ElseIf TARGET = "html5"
      updateKeyboardControls()
    #ElseIf TARGET = "psm"
      updateVitaControls()
    #ElseIf TARGET = "glfw"
      updateKeyboardControls()
      Local operatingSystem:String = String(HostOS())
      Select operatingSystem
				Case "winnt"
					updateJoystickControls()
				Case "macos"
					updateJoystickControlsMac()
			End
    #ElseIf TARGET = "xna"
			updateJoystickControls()
    #End
  End


Then in my updateJoystickControlsMac() method, I just remapped the buttons, based on the results I got with the joytest.monkey bananas:

Method updateJoystickControlsMac:Void()
' Game state
    If gameState = STATE_GAME
      If JoyDown(JOY_X) Or JoyX() < -0.5
        joyHorizontal = LEFT
      End
      If JoyDown(JOY_Y) Or JoyX() > 0.5
        joyHorizontal = RIGHT
      End
      If JoyDown(JOY_LEFT)
        joyButton = BUTTON_A
      End
      If JoyDown(JOY_UP)
				joyButton = BUTTON_B
			End
      If JoyDown(JOY_RSB)
        joyButton2 = TRIGGER
      End
      ' Quit to menu
      If GAMEPAUSED
        If JoyDown(JOY_RB)
          joyButton = BACK
        End
      End
      ' Pause
      If JoyDown(JOY_DOWN)
        joyButton = BUTTON_D
      End
    End
End


This may not be the best way to do things like this, but it's how I did it and it works a treat.
Hope that helps?

Ps. I tried the 360 controller in Fez via Steam on my mac, and it works perfectly out of the box, so it's definately a Monkey issue, therefore I feel my method does the job fine from my initial tests.


skape(Posted 2014) [#8]
Hey, thanks for the code bit Jaco. I have something very similar in my game at the moment. :)

Ps. I tried the 360 controller in Fez via Steam on my mac, and it works perfectly out of the box, so it's definately a Monkey issue, therefore I feel my method does the job fine from my initial tests.

Yep, I am seeing the same thing here. All of the games I have tried the 360 controller with work great without any remapping, so there's something strange going on in the Monkey internals. I may have a look and see if I can figure it out... But yeah, seems to be a viable workaround!

Cheers! :)