Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411528 Posts in 69377 Topics- by 58433 Members - Latest Member: Bohdan_Zoshchenko

April 29, 2024, 01:32:05 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Local Multiplayer. Four gamepads. How?
Pages: [1]
Print
Author Topic: Local Multiplayer. Four gamepads. How?  (Read 2332 times)
Jimmy_Scythe
Level 0
**


View Profile
« on: August 30, 2008, 05:06:59 PM »

So I'm kicking around this idea for a multiplayer OFFLINE project and I've hit a brick wall right off the bat with the control scheme. I want to allow support for multiple controllers (up to four), as well as three players on the keyboard with one using the mouse and any combination thereof, but the DirectInput documentation isn't exactly friendly to gamepads and downright hostile to the idea that you'd want to use more than one.

I've also been unable to find a tutorial on this kind of thing anywhere as well. This seems kind of odd to me since there are a couple of tutorials floating around that deal with setting up a split screen in OpenGL. This leaves me with the sense that I'm completely thick and the answer must be obvious to everyone but me. Is this the case,  or has no one wanted to do two or more gamepads on one PC before?

If anyone can through me a bone on this one, I'd be mucho grateful.  Beer!

Logged
Jesseyay
Level 0
***



View Profile
« Reply #1 on: August 30, 2008, 05:20:49 PM »

Its probably easy to get working in C# with XNA.
I haven't tried it (don't have controllers) and it only works with 360 controllers. (I think, someone correct me if I'm wrong).

Code:
GamePad.GetState(PlayerIndex.One);
GamePad.GetState(PlayerIndex.Two);
GamePad.GetState(PlayerIndex.Three);
GamePad.GetState(PlayerIndex.Four);

Hope it helps.
Logged
muku
Level 10
*****


View Profile
« Reply #2 on: August 30, 2008, 05:28:41 PM »

The joystick functions in SDL should do exactly what you need. Look at http://www.libsdl.org/cgi/docwiki.cgi/SDL_API, scroll down to the Joystick bit.
Logged
Jimmy_Scythe
Level 0
**


View Profile
« Reply #3 on: September 03, 2008, 03:36:28 PM »

Okay, I wasn't able to even try the XNA thing since I'm not working with C# or any Microsoft programming tools. sorry...

I was able to enumerate four joysticks on my machine and get some stuff on the screen to move around with one controller using SDL in FreeBASIC. I'm pretty sure I could do the same thing in Dev C++. The problem is distinguishing what controller is sending an SDL_JoystickEvent. The SDL Wiki isn't exactly helpful there either. As a result, I haven't been able to control two separate objects, circles in this case, with two different controllers.

I'm kinda burned out at the moment, but I'm gonna dive right back in there and get this working... eventually...  Tired

Thanks for the help  Gentleman
Logged
muku
Level 10
*****


View Profile
« Reply #4 on: September 03, 2008, 03:44:22 PM »

Well, that sounds easy. Going off http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdljoybuttonevent.html, the joystick event struct has a field called "which" that gives you the index of the joystick in question.

Also, I think for basic movement it's better not to use axis events, but simply to poll the joystick every frame with SDL_JoystickGetAxis. You just pass that a Joystick object which was obtained by calling SDL_JoystickOpen with the appropriate joystick index.
Logged
Jimmy_Scythe
Level 0
**


View Profile
« Reply #5 on: September 03, 2008, 06:32:34 PM »

Well, that sounds easy. Going off http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdljoybuttonevent.html, the joystick event struct has a field called "which" that gives you the index of the joystick in question.

Also, I think for basic movement it's better not to use axis events, but simply to poll the joystick every frame with SDL_JoystickGetAxis. You just pass that a Joystick object which was obtained by calling SDL_JoystickOpen with the appropriate joystick index.

So in the interest of simplification I tried this and... now nothing is working.

I also wrote over the original program like a complete dumbass...

Here's the code for the joystick test thingy as it currently stands:

#include "fbgfx.bi"
#Include "SDL\SDL.bi"

 Type ObjectType
            x as Single
            y as Single
            speed as Single
    End Type
   
Dim Shared Xmove  as Short
Dim Shared Ymove  as Short

Dim Shared jptr As SDL_Joystick ptr
Dim Shared CircleM As ObjectType

Dim Shared event as SDL_Event

 Screen 13,8,2,0

    CircleM.x = 150   
    CircleM.y = 90
    CircleM.speed = 1

       
If (SDL_Init(SDL_INIT_JOYSTICK) <0) Then
   
        print "Couldn't initialize SDL"
        end
       
    End If


For I = 0 To SDL_NumJoysticks()-1
   
    jptr = SDL_JoystickOpen(I)
   
Next I

 Do
         
    Cls
    Circle (CircleM.x, CircleM.y), 10, 15
   
    Xmove = SDL_JoystickGetAxis(jptr,1)
    Ymove = SDL_JoystickGetAxis(jptr,0)
   
   
   
    if Xmove > 1 then CircleM.x = CircleM.x + CircleM.speed
   
    if Xmove < -1 then CircleM.x = CircleM.x - CircleM.speed
   
    if Ymove < 1 then CircleM.y = CircleM.y + CircleM.speed
   
    if Ymove > -1 then CircleM.y = CircleM.y - CircleM.speed
   
   

    Sleep 10, 1
   

 Loop
 
For Y = 0 To SDL_NumJoysticks()-1
   
    SDL_JoystickClose(jptr)
    Next Y


I've isolated parts of the code and it opens the joystick just fine. It closes the joysticks just fine too. For some reason it doesn't read anything from the joysticks. This particular little program was running with just one controller hooked up. I tried it with both the 360 controller and the logitech dual pro.

BTW, I noticed earlier that while enumerating joysticks the for loop always opened a joystick labeled 0. hence the SDL_NumJoysticks()-1

I'm gonna dig through the rest of the work I've done on this and see if I can't piece together how I got this working in the first place.  Cry

Note: I've gotten rid of the event handler thing and called SDL_JoystickUpdate() at the top of the do loop now and that does have some effect, but the results are really funky. Gonna have to mess with it some more.  Beer!
« Last Edit: September 03, 2008, 06:54:02 PM by Jimmy_Scythe » Logged
mjau
Level 3
***



View Profile
« Reply #6 on: September 03, 2008, 11:48:29 PM »

've isolated parts of the code and it opens the joystick just fine. It closes the joysticks just fine too. For some reason it doesn't read anything from the joysticks. This particular little program was running with just one controller hooked up. I tried it with both the 360 controller and the logitech dual pro.
The event system in SDL is tied to the video system, so you might have to init that as well.  Also, if that SDL_Init isn't the first one in your program, you should use SDL_InitSubSystem in stead.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic