Game Development Community

Detecting Which Controller Initiated the Input

by Michael Malandra · in Torque X 2D · 04/07/2009 (12:41 pm) · 6 replies

I've gone through the InputMap and InputManager classes, and there doesn't seem to be any way to return which controller initiated the input. This functionality would be good for the main menu, where whichever controller pressed the button to start the game would be considered the 'active' controller. Is there an inherent way to do this, or would I have to extend the InputMap class and modify the ProcessInput function and the coinciding delegates that are called? Thanks!

#1
04/07/2009 (1:24 pm)
I'm not sure there is a way to do with with TX but XNA can certainly do it. Check the XNA best practices. You'll be interested in the section "Gamers Use One Xbox 360 Controller".
#2
04/07/2009 (2:37 pm)
Yea, I've read that article after my game was kicked because it only used controller one (some guy then marked that as a crash). Seems simple enough to do it through XNA, but I'd rather have the ability to detect the functionality through the Torque InputManager and InputMap classes.
#3
04/07/2009 (6:33 pm)
Ok, I got it working, althought I'm not sure if I'm allowed to do this since I modified the TorqueX InputMap class because I got sick of trying to figure out how I could efficiently override the ProcessInput method. Anyways, it was fairly simple:

//MY CHANGES
            if (data.DeviceNumber < 5 && data.DeviceNumber >= 0)
            {
                _deviceNumber = data.DeviceNumber;
            }

These three lines of code are called first in ProcessInput of InputMap. I created a public property called DeviceNumber that returns the int _deviceNumber field so that I can access it from my Action/Make/Break delegates.
#4
04/10/2009 (1:22 pm)
Could you spell that out more extensively? I really don't understand the whole process? You ask for input, the first controller input gets assigned to DeviceNumber ? how is this.

I am certain this is something everyone planning on doing XBLCG would want to do.
#5
04/10/2009 (3:34 pm)
When input is received from a controller, it is sent through the ProcessInput method in an InputEventData type named data. data contains all sorts of information about the input, ranging from the type of device that sent the input, the button pressed, and the device number, which is what I was concerned with in this scenario. I added a private variable '_deviceNumber' to the InputMap class to store this value. By default, if no input is received the device number is set to 5 (for 360, haven't tested with pc). Since the _deviceNumber is now stored from the last input, when the corresponding delegate is called, we can get this number through a property that we call DeviceNumber (or whatever u want to call it). So, for example, for a method that defines an action delegate, we can say

void actionMethod(float val)
{
if(val == 1)
Console.WriteLine(InputMap.DeviceNumber);
}

This delegate would be called if the InputMap has a BindAction that uses this action delegate. The output would be the controller number that initiated the input. This is as best as I can describe it from work right now.
#6
04/13/2009 (6:42 am)
Thanks Michael! Now I just need to work on making a user interface!