Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: [patch proposal] Multiple Mice Support seems to work  (Read 538 times)

michal.ania

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
[patch proposal] Multiple Mice Support seems to work
« on: March 15, 2011, 06:33:12 AM »

Hello!
I don't like play with paddles and joysticks in shooter games (it is so hard to target heads with those gizmos) but I like to play them with other players. So I thought it would be funny to play with other players on one computer.
So here is a patch for OIS to support multiple mice. It seems to work (checked under Linux and Windows). You can download it from here: multiple_mouse_OIS.diff

I'm not good in legal stuff so if I did something wrong with the license notice just write me and I'll rewrite it (I did add "Altered OIS source information ... " in files that were changed).

So what I did and how it works:
Linux:
Since XInput2 is part of X11 now i just used it. (resources: http://who-t.blogspot.com/ http://alec.mooo.com/mpx.html )
To set the XInput2 to work you must pass parameters to InputMenager::createInputSystem( ParamList & params ):
Code: [Select]
"x11_XInput2" => "true"If it will not be set old InputManager will be used
Code: [Select]
"x11_XInput2_fallback" => "false"If it will be set then if some error will issue during initialization of XInput2 an exception will be thrown.
By default no exception will be thrown but the old InputMenager will be used.

To see multiple mice pointers see: http://alec.mooo.com/mpx.html
In shortcut:
Code: [Select]
sudo urpmi xinput #it's simple program to manage devices
xinput create-master "Secondary Pointer Name" #create secondary pointer
#plug other mouse (any time just before next statement)
xinput list #to see ids (id=number)
xinput reattach <id of mouse> <id of master> #as id I mean number
#happily play with multiple mice pointers
#cleanup:
xinput remove-master <id of secondary pointer>
xinput reattach <other mice> <master id>
If you dont create additional pointers you will not be able to use multiple mice.

Win32:
I used RawInput and hooks ( http://www.jstookey.com/arcade/rawmouse/ http://msdn.microsoft.com/en-us/library/ms645536 )
I cross-compiled it with mingw so I dont know if it works under M$VC. It was tested on Windows 7 and it seems to work fine.
Parameters for InputMenager::createInputSystem( ParamList & ):
Code: [Select]
"RawInput" => "true"If not set the old InputManager will be used
Code: [Select]
"allowFallback" => "false"If it will be set then if some error will issue during initialization of RawInput an exception will be thrown.
By default no exception will be thrown but the old InputMenager will be used.
Code: [Select]
"w32_mouse" => "DISCL_BACKGROUND"
"w32_mouse" => "DISCL_EXCLUSIVE"
"w32_mouse" => "DISCL_FOREGROUND"
"w32_mouse" => "DISCL_NONEXCLUSIVE"
I tried to ensure similar behaviour it used to had in old InputManager
Code: [Select]
"w32_mouse" => "RIDEV_CAPTUREMOUSE"
"w32_mouse" => "RIDEV_EXINPUTSINK"
"w32_mouse" => "RIDEV_INPUTSINK"
"w32_mouse" => "RIDEV_NOLEGACY"
Meaning of these flags can be found here: http://msdn.microsoft.com/en-us/library/ms645565%28v=VS.85%29.aspx
Code: [Select]
"RawInput_THREAD" => "thread in which hook functions will work"Set if you want pass param to SetWindowsHookEx, if not set it works fine.
Code: [Select]
"RawInput_WINDOW" => windowHandleIf not set works fine, if you realy want to set this look here: http://msdn.microsoft.com/en-us/library/ms645565
Just like old "WINDOW" param - if you set that no need to worry.
Code: [Select]
"user32.dll" => "path to user32.dll if it should be dynamically loadedI couldn't dynamically load that library so it's meaningless.

Other:
I don't have any other OSes, sorry.

I didn't exactly knew what the return value in the listeners mean. As I read the code guess that if listener returns true it wants to get next messages and if false than it wants to stop. And so I implemented the new Mice.

I also changed the ConsoleApp demo to work with multiple mice.

To show how it work I set the new managers to work I turn them on by default in this patch, to change the behaviour to described,
you need to change in these files:
LinuxX11XInput2.cpp
Code: [Select]
//if( i != paramList.end() && i->second != "false" ) //ania: I used XInput2 by default for debug
  if( i == paramList.end() || i->second != "true" ) //we use old Manager by default
    return new LinuxInputManager();
Win32RawInput.cpp
Code: [Select]
 if( i != paramList.end() && i->second != "false" ) //ania: for debug I use RawInput
//if( i == paramList.end() || i->second != "true" ) // by default we use old manager
    return new Win32InputManager();

Both RawInput and XInput2 can support multiple keyboards too, but for other devices than mice I just copied old code.

Hope someone can use it.
Best regards and sorry for my English.
« Last Edit: March 15, 2011, 07:23:48 AM by michal.ania »
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Re: [patch proposal] Multiple Mice Support seems to work
« Reply #1 on: March 18, 2011, 06:40:18 PM »

Thanks for letting us know about this... I may incorporate this into OIS when i remove DirectInput based mouse/keyboard... even though it is rare to have more than one mouse plugged in, it would be a nifty feature to support multiple.
Logged