a working jinput game

This is just jinput thrown into my tetris game. its not finished, and im not sure i will finish it, i just wanted to try out jinput in a game.

it even makes the keyboard control feel nicer than how i’d done it using AWT key refresh but i think i need to play with the speed to get it just right, it’s a little touchy.

i tested it with keyboard input, and analog joystick input.

differentiating between x or y axis + or - was one thing that caught me… you’ll find with the way i’ve done it that you can’t set right to left and vice versa on an analog controller. digital axes may not work at all, but that’s my fault. and buttons do work.

to fix this i need to do some more work, but i never have much time.

http://www.adam.com.au/kellyjones/java/InputAlpha.zip

Just unzip it somewhere, and run JMTetris.jar in the usual way. i included the jinput binaries. (i havent tested it without them in the same directory though). can someone who has jinput1.1 properly installed try running it on its own and let me know if that works too?

cough Web Start cough
:wink:

(now that the WebStart/JInput plugin issues are resolved)

ran into this problem:

Use of native libraries requires unrestricted access to system

i have set

Very cool!

I’m glad you’re seeing positive results.

if you find issues with either the APi or the plug-in(s) while working on this be sure to post them here :slight_smile:

NOO!!!, don’t post issues here, i’m trying to get back into coding my own stuff, don’t post them anywhere, wait a few months :stuck_out_tongue:

Seriously, post them here, and/or raise an issue over on the jinput.dev.java.net page.

Cheers

Endolf.

[quote]ran into this problem:

Use of native libraries requires unrestricted access to system

i have set
[/quote]
You need to decalre the native libs properly in the jnlp file. Folks here have done it maybe one can give you an example…

this is my first Webstart experience ever

ok, i messed up with some signing. fixed that, so it all loads and runs but the plugin isn’t found, i’ll look into it more later.

i noticed that my high scores file was being saved to the location i run the JNLP file from, and i dont know what happens when it’s run from the net as my ISP hasnt got it set up for JNLP. what’s the best solution in the case you want to save hi scores etc for the user?

Strangely enough it works if the controller folder is in the same location the jnlp file is launched from, but that’s of no real use when it comes to web deployment.

Do you want individual user’s high scores or competitive high scores across all users? If the former I believ you should just be able to open a file on the local system as long as the user has given you permissions. If you want it to be a competitive high scroe board across users, you’ll need to connect back to soem kind of server. Typically this is done with a servlet.

As for your jnlp, I’m going to post a seperate thread asking for people to contribute their working examples.

thanks.

meanwhile i fixed it so that the game knows which way the axis was pressed when the controls are being set so that left and right digital axes work correctly.

so now you can make it more challenging by setting right to left and left to right.

single jar if you have jinput installed into JRE:
http://www.adam.com.au/kellyjones/java/proto/jinput.jar

webstart that wont work due to ISP:
http://www.adam.com.au/kellyjones/java/proto/JMTetris.jnlp
(open it from addy line in webstart, works if jinput is installed to JRE)

ZIP with everything combined:
http://www.adam.com.au/kellyjones/java/InputAlpha.zip

i dont want a hi score server as i dont have a permanent connection or an isp willing to host a hi-score servlet.

There is a major problem with how you are bundling JInput.

Loading Tiles
Loading Graphics
Graphics Loading Done
Scanning jar: dxinput.jar
Examining file : META-INF/
Examining file : META-INF/MANIFEST.MF
Examining file : net/
Examining file : net/java/
Examining file : net/java/games/
Examining file : net/java/games/input/
Examining file : net/java/games/input/DirectInputAxis.class
Examining file : net/java/games/input/DirectInputDevice.class
Examining file : net/java/games/input/DirectInputEnvironmentPlugin.class
Found candidate class: net/java/games/input/DirectInputEnvironmentPlugin.class
Adding class to plugins:net.java.games.input.DirectInputEnvironmentPlugin
Examining file : net/java/games/input/DirectInputKeyboard.class
Examining file : net/java/games/input/DirectInputMouse$BallAxis.class
Examining file : net/java/games/input/DirectInputMouse$BallImpl.class
Examining file : net/java/games/input/DirectInputMouse$ButtonImpl.class
Examining file : net/java/games/input/DirectInputMouse$ButtonsImpl.class
Examining file : net/java/games/input/DirectInputMouse.class
Exception in thread “main” java.lang.UnsatisfiedLinkError: Can’t load /Users/scottpalmer/Desktop/InputAlpha Test/controller/libdxinput.jnilib
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1384)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
at net.java.games.input.DirectInputEnvironmentPlugin.(DirectInputEnvironmentPlugin.java:62)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:306)
at java.lang.Class.newInstance(Class.java:259)
at net.java.games.input.DefaultControllerEnvironment.scanControllersAt(DefaultControllerEnvironment.java:183)
at net.java.games.input.DefaultControllerEnvironment.scanControllers(DefaultControllerEnvironment.java:164)
at net.java.games.input.DefaultControllerEnvironment.access$000(DefaultControllerEnvironment.java:57)
at net.java.games.input.DefaultControllerEnvironment$1.run(DefaultControllerEnvironment.java:108)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:106)
at InputManager.(InputManager.java:20)
at JMTetris.(JMTetris.java:78)
at JMTetris.main(JMTetris.java:637)

You see, I’m trying this on a Mac - and because of the way the windows JInput is bundled it simply doesn’t work.

i dont have a mac, so didnt know how to bundle it. the jmtetris jar on it’s own will work as long as jinput is installed in the JRE… at least it does on windows.

is it possible to make a jinput bundled app that has jinput working on any OS like this? or does there need to be 3 separate downloads? it looks like the JARs from the other OS’s would conflict.

i have never tested if the first situation is possible, but the best case scenario is to get webstart working so that it’s all downloaded as needed, so im just waiting for now. i cant take any active part in the project, time’s short recently.

It should be possible with the JNLP to specify different configurations for different operating systems.

At worst you could make seperate JNLP files, but I don’t think thats necessary…

JK

I was testing the ZIP version when I posted the problem above.

Testing the JNLP I get:

Unable to load resource: http://www.adam.com.au/kellyjones/java/proto/HIDWrapper.jar

The structure of the JNLP looks ok at first glance.

If you are zipping then you might need seperate zips.

We could theoretically make the plug-ins OS aware and have them default to empty controller sets if they are on the wrong platform.

Arguments for or against?

JK

For: It makes some sence, you can bundle all built plugins in one app and not worry about what platform it’s on that way, larger download, less customisation.

Against: The linux plugin was broken again last time I played (joystick hat axes reversed and no hat working on my logiteck gamepad), it’s broken enough, are you really wanting me to break it more? :slight_smile:

Endolf

P.S. the linux plugin is in my list of things to fix, but unless someone other than me reports it, it can stay fairly low on said list. This is a vote for yes :slight_smile:

trying to make my code more adaptable by using an interface that specifies booleans for the 6 keys or buttons that i want to use, and generic methods (setKey (int keyNumber 1-6) and such), it’s becoming quite complicated. though i never imagined i’d be replacing the input, let alone have the user able to choose which method to use at startup (awt or jinput).

about half way done but not working on it a heck of a lot. the game i posted here was a big hack. it didnt even make use of the original set keys dialog, just painted that over the top.

i used serialization with the awt input method, and it will be interesting to see what happens when i try to load or serialize stuff from jinput.
as long i make sure there’s a catch for when the device is no longer plugged in etc. i’m assuming it should work OK. but we’ll find out soon enough.

here’s my interface, any suggestions welcome:



abstract class InputInterface
{
      boolean
            up = false,                  //1
            down = false,            //2
            left = false,            //3
            right = false,            //4
            a = false,                  //5
            b = false;                  //6
      JMTetris owner;
      
      public InputInterface()
      {
            
      }
      
      public void setOwner(JMTetris in)
      //use this after loading from serialized.
      {
            owner = in;
      }
      
      
      abstract String setKey(int keyNum);
            //return ("key that was pressed");
            //only returns after the key is set.
            //used to display the key or button name in the game dialog.
}

So this confuses me some…

What necessitated you put in AWT input as a backup? If theres something we need to fix about JInput I’d like to get clear on what it is.

Thanks

JK

the game originally had AWT for the input, and it’s a ‘just in case’

also i really dont think i’d like to see any kind of AWTKeyboard becoming a part of jinput, this basically shows that they can both be used when needed.

for example im still going to use awt input for the keys such as the F1 - F8 that do certain things and escape for the menu in case diferent keyboard layouts result in jinput reporting diferent button numbers or names.

Hi
ESC and the F keys should be ok, it’s things like @ # and " that all go funny, some of the letters are in different places if I recall on french/german keyboards too, but it’s been a while since I saw one, all I remeber is that they were a pain to use :). But the point is ESC and F1-F8 are safe.

I believe under windows that the keyboard layout is handled under directx so it’s not a worry on windows, under linux it is a problem, I’m not sure about OSx.

Cheers

Endolf