JInput 2 beta

Hi,

We’ve been working for the last few week on an updated JInput implementation with plugin fixes and some new features like controller event queues. Since there was so much to do, the project got a little out of hand and took a little longer than expected. Now the code is feature complete (including all the original features), we’re making our changes available to the unsuspecting masses :slight_smile: You can access the code with subversion at:

http://download.oddlabs.com/oss_svnroot/sun

it includes the jutils and the jinput projects, since a few tweaks had to be done to jutil (changed where the jutils.jar file is copied). It is our intention that the changes be merged with the official JInput version, but since I haven’t got a developer role on jinput.dev.java.net (yet), we’ve had to make the changes in private. Here’s the changes:

Major:

  • Flattened Mouse so it isn’t separated into child controllers (ball, buttons).
  • Removed useless component members from Mouse and Keyboard. For example, Mouse.getX() is now simply getComponent(Component.Identifier.Axis.X).
  • Removed StandardKeyboard.
  • Removed Mouse.Button and Keyboard.Key since they only complicated plugins
  • Added Keyboard.isKeyDown(Component.Identifier.Key) (with default false for non-existent keys).
  • Removed Component.isPolling() and Component.setPolling().
  • Removed Component.isNormalized() since all plugins return normalized data for absolute axes anyway.
  • Windows XP: Added RawInputEnvironmentPlugin to enable multiple mice and keyboards. DirectInput will only report one system mouse and one system keyboard where all mice and keyboard input are combined (in fact, Windows was the OS with the most complicated and confusing APIs, apart from the fact that I had to code two separate plugins for it). The RawInputEnvironment is not enabled per default, since it seems to exclude mouse and keybaord input to DirectInput which will probably confuse unsuspecting applications. But at least there is now a method to access multiple keyboards and mice on windows xp.
  • DirectInput: Got rid of the nasty DataFormat special case handling. The DirectInput data format is now one large (java int) array which is a better match for the jinput abstraction than the builtin DirectInput data formats for mice, keyboards and joysticks.
  • Added event queue support. An Event contains a Component, a value and a relative timestamp in nanoseconds.
  • Basically rewrote all plugins from scratch, with focus on minimizing the amount of native code in general, and in particular for moving decisions from native to java, making the native code more general purpose and less likely to need changes. Additionally, all plugins support the new event queue interface. All plugins now have much better error handling (exceptions) and much tighter native code (no more global variables, helper functions declared static etc.). Additionally, all plugin internal java classes are package protected and final for added security.
  • Mac OS X: Added missing features and fixed broken Mouse.
  • Cleaned up build system and added option for a combined jinput.jar with all plugins as opposed to just the OS specific packages
  • JInput should now be thread safe.
  • Mac OS X intel mac support. The jinput-osx.jnilib library is for 10.4 or better (both ppc and i386), while libjinput-osx-legacy.jnilib is for 10.3 or earlier.

Minor:

  • Removed keyId from Component.Identifier.Key
  • Made components, children and rumblers final in AbstractController
  • Added Identifier->Component Map to AbstractController to avoid Keyboard special code and to speed up the Component.getComponent() method in general.
  • Added exceptions to native code for accurate error messages (instead of the standard printf). I use the checked IOException exclusively, but since exceptions are not exposed to user code, that can easily be changed.
  • Added printfJava(env, format, …) to native code to avoid printfs altogether

Issues not fixed:

  • Linux plugin report buttons ids with semantic value (trigger button, thumb button etc.) while all other plugins use simple button indices (0, 1, 2, 3 etc.). This is a property of the underlying linux input API and will probably confuse some jinput programs.
  • The Plugin architecture seems somewhat complex and IMHO unnecessary. It involves custom Classloaders to separate the each Plugin’s namespaces, but since you can’t use custom Classloaders in restricted environments (web start, applets) the plugins have to have manually separate namespaces anyway. I’m inclined to remove it, but since it was there originally, there is probably some use case it covers I don’t know about.

TODO:

  • A utility for collecting events from multiple controller at once. An application then just needs to register all its devices to the utility and only call poll() and getEventQueue() in one place. Event will probably need to be extended with a getController() method.

For those interested in the binaries only, here’s a zip package with all native binaries and the jinput.jar combined jar:

http://odense.kollegienet.dk/~naur/jinput-2-15032006.zip

  • elias

Cool! :smiley:

Excellent. Thanks Elias!

Terrific! COngrats guys! Its great to see you running with this 8)

Okay Guys,

Im trying to use JInput2 to geta roudn a nasty JINput bug.

My old axis finding code isnt working however. oi used to compare an identifier string (eg “w” with the identifier.getName()) but it
doesnt seem to work anymore.

Suggestions?

JK

I found and fixed the poblem.

Bug in my code that JInput happen to hide but JInput2 made pretty visible.

JK

MAjor problem in my demo…

I seem to be getting the Raw plug in on WIn32 and as a result I am rading the wrong keyboard device,

How do I force it to dx8 ?

OR how do I recognize and reject the raw keyboard device?

Thanks

jk

I’ve commented out line 126 and line 132 in DefaultControllerEnvironment.java to disable the raw plugin. I can’t commit here from the firewalled GDC wireless so you’ll have to do it manually for now :slight_smile:

  • elias

Hi

I’ve merged elias changes in to the CVS repository at cvs.dev.java.net under the branch version2.

It’s version 2 from the svn repository.

Endolf

Thanks guys!

I actually figrued out how to force it to use the DX plugin only from the -D flags, but by default you probably want it that way and to have to use falags to enable the raw input device…

Ah… “revision” 2… here I was poking around trying to find a “version2” tag or something :). 2 seemed like such a low number for the head revision of a subversion repository :slight_smile:

Hi

Yeah, on svn it’s revision 2, in CVS it’s on a branch called ‘version2’.

HTH

Endolf

I can build the oddlabs version fine, but when I test it with my own code (which worked earlier with this version of jinput: http://www.newdawnsoftware.com/resources/jinput/?C=M;O=D)
it is not finding a force feedback steering wheel I have connected. I have the latest version of the sources with the raw plugin commented out. I tried various combinations with dxinput.jar and the other dlls in the same folder or a “controller” folder. I tried various values for -Djinput.plugins.
It recognizes the directx plugin, but only lists the mouse and keyboard. It says “Failed to create rumblers: Failed to create effect (Ox80070057)”.

I was just wondering where are the right places to put all the jar files and dll files, if that is the problem. Thanks for any help.

Nevermind, I see the rumble stuff doesn’t work like it did before.

Is the source code for this version of jinput:
http://www.newdawnsoftware.com/resources/jinput/?C=M;O=D
available anywhere?
All the files there appear to only have the binaries.

Hi

It’s all in CVS, details over at jinput.dev.java.net.

It’s not tagged, so you’ll have to extract it by date if you want a particular date.

HTH

Endolf.

I’ve added support for wheels (and defaulted unknown devices as STICKs) and attempted to fix the FF issue for wheels (can’t test since I don’t have a wheel). Check out the latest source from subversion if you’d like to test it.

  • elias