Getting available USB ports on system to achieve game console behavior
Hi everyone I'm not sure if this question should be posted on .NET or Multiplayer forum, but here it goes. I have been developing a game with DirectX, which is intended to use several USB devices (over 20 and one for each player). I know how to load each connected USB device and use it, but the problem is that using that amount of devices creates the need to handle where a device is connected. For example, a game console like Xbox if you have connected controls on ports 1 and 4 (2 players) and you are on a select character screen, the game shows you the cursor of each player with a tag like 1p,4p or something like that. The thing is that the game loads input devices based on port number rather than device number, but if I try to do this behavior on windows, players 1 and 4 will be known as 1 and 2 and the player on port 4 (when thinking himself as 4, will be tagged with a 2 number). The problem is that when using several USB devices (sometimes 20, sometimes 10) connected to any port in any order, I need a fast method to tell the user who he is. Without this feature, I need to map each device to a player number at runtime (human work) which may take a long time (unacceptable to users). That’s why I need a game console like behavior on Windows. I'm using C# and I have tried a lot of APIs and DLLs. I'm not sure if I don't know how to use them to achieve my goal or if those tools just cannot do what I need, but some of the tools I have looked up are the following: USBSharp http://www.lvr.com/hidpage.htm#csharp - Uses Windows API functions like SetupDiGetClassDevs and SetupDiEnumDeviceInterfaces from setupapi.dll but it reads devices based on device rather than port. LibUsb-Win32 http://libusb-win32.sourceforge.net/ - If I'm right, this reads based on device rather than port. PortTalk http://www.beyondlogic.org/porttalk/porttalk.htm - Seems to be useful but i didn't see a way to use .NET with it. WinIO http://www.internals.com/ - This one seems to be even more powerful than i need, but i'm not sure if it can enumerate USB ports. I also read about getrawinput* set of functions from user32.dll but i didn't find port information. Any help or suggestions to solve this problem will be greatly appreciated. Best regards.
You could perhaps just iterate over the USB devices and enumerate the player controllers as you come to them and throw them in a lookup map. So first come across is 1p, 2nd is 2p, etc.
That's more or less how the wireless controllers on the XBOX 360 work: 1st controller to attach is 1p, 2nd is 2p, etc. If you turn off a controller, the other ones maintain the same player designation presumably b/c the xbox maintins a map of USB id -> player number.
-me
That's more or less how the wireless controllers on the XBOX 360 work: 1st controller to attach is 1p, 2nd is 2p, etc. If you turn off a controller, the other ones maintain the same player designation presumably b/c the xbox maintins a map of USB id -> player number.
-me
Quote:
Original post by Palidine
You could perhaps just iterate over the USB devices and enumerate the player controllers as you come to them and throw them in a lookup map. So first come across is 1p, 2nd is 2p, etc.
That's more or less how the wireless controllers on the XBOX 360 work: 1st controller to attach is 1p, 2nd is 2p, etc. If you turn off a controller, the other ones maintain the same player designation presumably b/c the xbox maintins a map of USB id -> player number.
-me
Thanks, that's what i'm doing right now. I iterate over my devices and assign them a number, the problem is that if i connect 20 devices, the players don't know who they are in the screen. For example, when you have a controll on your game console and see the character selection screen, usually you can do two things to recognize yourself on that screen.
- Move your pad until you realize which cursor/image you are
- See what port you are connected on (lets say 3) and then look for the tagged cursor/image with number 3.
The problem with the first approach is that there are over 20 images moving at the time and its confusing to recognize yourself. The second one seems more straight to me, but i don't know how to implement it.
I can use the first approach if lets say a moderator maps each device to a tag before users use the game and that moderator tells everyone who they are, but that's slow, so i wanted to do something easier and faster.
Thanks for your suggestions.
The way the 360 solves this problem is to have visual feedback on the devices themselves. The wireless controllers have 4 possible LEDs surrounding the bigass X button. If you're p1, the upper left is illuminated, if you're p2 the upper right is illuminated, etc. So when the console assigns a specific controller to a player slot, it sends that info back to the controller and the controller displays that information to the player.
As far as in-game representation goes, that's typically solved again by a reliable HUD location per player. Again, p1 is upper left, p2 is upper right, etc. Bomerman solves this (because it's not split screen) by putting a HUD element in the same reliable place that is color-coded to match the color of the in-game character. p1's health bar and such is upper left -> hud there is white -> p1's controlled character is white.
Other solutions again use color or other player chosen graphics/archetypes. In a fighting game you know which character you selected, in other games (halo) you know what color skin you chose, etc. Give the players a creation screen where they select a color or shape or archetype so that when the game starts they just look for the chosen thing and now they're oriented.
-me
As far as in-game representation goes, that's typically solved again by a reliable HUD location per player. Again, p1 is upper left, p2 is upper right, etc. Bomerman solves this (because it's not split screen) by putting a HUD element in the same reliable place that is color-coded to match the color of the in-game character. p1's health bar and such is upper left -> hud there is white -> p1's controlled character is white.
Other solutions again use color or other player chosen graphics/archetypes. In a fighting game you know which character you selected, in other games (halo) you know what color skin you chose, etc. Give the players a creation screen where they select a color or shape or archetype so that when the game starts they just look for the chosen thing and now they're oriented.
-me
Quote:
Original post by Palidine
The way the 360 solves this problem is to have visual feedback on the devices themselves. The wireless controllers have 4 possible LEDs surrounding the bigass X button. If you're p1, the upper left is illuminated, if you're p2 the upper right is illuminated, etc. So when the console assigns a specific controller to a player slot, it sends that info back to the controller and the controller displays that information to the player.
As far as in-game representation goes, that's typically solved again by a reliable HUD location per player. Again, p1 is upper left, p2 is upper right, etc. Bomerman solves this (because it's not split screen) by putting a HUD element in the same reliable place that is color-coded to match the color of the in-game character. p1's health bar and such is upper left -> hud there is white -> p1's controlled character is white.
Other solutions again use color or other player chosen graphics/archetypes. In a fighting game you know which character you selected, in other games (halo) you know what color skin you chose, etc. Give the players a creation screen where they select a color or shape or archetype so that when the game starts they just look for the chosen thing and now they're oriented.
-me
Hi
The LED implementation sounds interesting, I thought something similar before by using rumble feature, but my USB devices don't have any kind of lights or rumble feature to do this.
To automate this process without knowing the port the device is connected in, the best I can do is ask the user to connect a device on all USB ports available, even when there is no need to use them all, that way if a user uses control 7, I can iterate through non-used but connected devices 1-6 and tag the device as 7.
Right now I’m assigning each player a number and a color based on device number. I thought on doing some kind of wizard to assign a personalized shape and color on a per device basis, so each player will know who he is on the game. It's possible, but this task requires time and that's what I want to avoid as much as possible because if I have 20 players this time can become a problem.
I'm thinking that as a requirement to run the application correctly, the USB devices should be connected in order, so if I have a USB hub with 20 ports, a requirement should be to connect all devices together (for example ports 1-7) and the non-used ports should be leaved all together (8-20). That way I think I should label the devices with a number which makes sense with the port number.
Well it's just an idea.
Thanks for your suggestions.
Quote:
Original post by Palidine
The way the 360 solves this problem is to have visual feedback on the devices themselves. The wireless controllers have 4 possible LEDs surrounding the bigass X button. If you're p1, the upper left is illuminated, if you're p2 the upper right is illuminated, etc. So when the console assigns a specific controller to a player slot, it sends that info back to the controller and the controller displays that information to the player.
As far as in-game representation goes, that's typically solved again by a reliable HUD location per player. Again, p1 is upper left, p2 is upper right, etc. Bomerman solves this (because it's not split screen) by putting a HUD element in the same reliable place that is color-coded to match the color of the in-game character. p1's health bar and such is upper left -> hud there is white -> p1's controlled character is white.
Other solutions again use color or other player chosen graphics/archetypes. In a fighting game you know which character you selected, in other games (halo) you know what color skin you chose, etc. Give the players a creation screen where they select a color or shape or archetype so that when the game starts they just look for the chosen thing and now they're oriented.
-me
Hi
The LED implementation sounds interesting, I thought something similar before by using rumble feature, but my USB devices don't have any kind of lights or rumble feature to do this.
To automate this process without knowing the port the device is connected in, the best I can do is ask the user to connect a device on all USB ports available, even when there is no need to use them all, that way if a user uses control 7, I can iterate through non-used but connected devices 1-6 and tag the device as 7.
Right now I’m assigning each player a number and a color based on device number. I thought on doing some kind of wizard to assign a personalized shape and color on a per device basis, so each player will know who he is on the game. It's possible, but this task requires time and that's what I want to avoid as much as possible because if I have 20 players this time can become a problem.
I'm thinking that as a requirement to run the application correctly, the USB devices should be connected in order, so if I have a USB hub with 20 ports, a requirement should be to connect all devices together (for example ports 1-7) and the non-used ports should be leaved all together (8-20). That way I think I should label the devices with a number which makes sense with the port number.
Well it's just an idea.
Thanks for your suggestions.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement