HermanssoN
Senior Newbie 
|
 |
«
Posted
2009-10-05 19:40:01 » |
|
Hello, I'm trying to implement Mouse input. I've brought up the topic in another thread when asking questions about the keyboard. The reason I made a whole new thread is caus Iv'e got the error: 1
| Failed to poll device: Device is released |
I'm trying to get the mouse movement using this loop: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| m_mouse.poll(); m_mouseQueue = m_mouse.getEventQueue(); Event event = new Event(); while( m_mouseQueue.getNextEvent(event)) { Component c = event.getComponent(); float data = c.getPollData(); if(data != 0.0f ) { m_mouseDown.put(c.getIdentifier(), true); m_deltaMouse.x = m_mouse.getX().getPollData(); m_deltaMouse.x = m_mouse.getY().getPollData(); } else { m_mouseDown.put(event.getComponent().getIdentifier(), false); m_deltaMouse.x = 0.0f; m_deltaMouse.x = 0.0f; } } |
in my main loop I print the values to the output console in Eclipse and get: 1 2 3 4 5 6 7 8 9 10 11 12
| Failed to poll device: Device is released Failed to poll device: Device is released delta mouse x : 0.0 delta mouse y : 0.0 Failed to poll device: Device is released Failed to poll device: Device is released delta mouse x : 0.0 delta mouse y : 0.0 Failed to poll device: Device is released Failed to poll device: Device is released delta mouse x : 0.0 and so on... |
It seems like JInput looses and regains contact wit my mouse?? I'm using windows xp, and the mouse is a Razer Krait
|
|
|
|
|
endolf
|
 |
«
Reply #1 - Posted
2009-10-05 20:06:48 » |
|
You're mixing event queues and the old way, get the value of the axis from the event and update your map from that. You're also update m_deltaMouse.x twice instead of x and then y.
Do you have other applications running at the same time?, JInput doesn't like it if other apps steal the devices.
Endolf
|
|
|
|
HermanssoN
Senior Newbie 
|
 |
«
Reply #2 - Posted
2009-10-05 20:10:12 » |
|
Ok I made some more tests: the pooling now looks like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| m_mouse.poll(); m_mouseQueue = m_mouse.getEventQueue(); Event event = new Event(); while( m_mouseQueue.getNextEvent(event)) { Component c = event.getComponent(); float data = c.getPollData(); if(data != 0.0f ) { m_mouseDown.put(c.getIdentifier(), true); } else { m_mouseDown.put(event.getComponent().getIdentifier(), false); } } m_deltaMouse.x = m_mouse.getX().getPollData(); m_deltaMouse.y = m_mouse.getY().getPollData(); |
No bigg change: the test app now looks like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| JFrame f = new JFrame("This is a test"); int sizeX = 400; int sizeY = 400; f.setSize(sizeX, sizeY); Container content = f.getContentPane(); content.setBackground(Color.white); f.addWindowListener(new ExitListener()); f.setVisible(true); while( true ) { SharkInput.getInstance().capture(); if( SharkInput.getInstance().getKeyboard().isKeyDown(Identifier.Key.Q)) { System.exit(0); break; } float dx = SharkInput.getInstance().getMouse().getDelta().x; float dy = SharkInput.getInstance().getMouse().getDelta().y; if(dx != 0.0f || dy != 0.0f) { sizeX += dx; sizeY += dy; f.setSize(sizeX,sizeY); } } } |
The window should resize after my mouse movement and it does. But I still get the : Failed to poll device: Device is released. Is it normal to get that? cause it seems to work. And I guess using eclipse ouput don't give me the correct readning, most likley to many update per second. The out put will be filled instantly.
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
HermanssoN
Senior Newbie 
|
 |
«
Reply #3 - Posted
2009-10-05 20:13:19 » |
|
Oh we posted at the same time  I fixed the double m_deltaMouse.y = x. Very clumsy of me  but the eror message still is spammed? well eclipse is running of course, Windows media player and Google Chrome. polling like this makes no differance: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| m_mouse.poll(); m_mouseQueue = m_mouse.getEventQueue(); Event event = new Event(); while( m_mouseQueue.getNextEvent(event)) { Component c = event.getComponent(); float data = c.getPollData(); if(data != 0.0f ) { m_mouseDown.put(c.getIdentifier(), true); m_deltaMouse.x = m_mouse.getX().getPollData(); m_deltaMouse.y = m_mouse.getY().getPollData(); } else { m_mouseDown.put(event.getComponent().getIdentifier(), false); } } |
|
|
|
|
|
endolf
|
 |
«
Reply #4 - Posted
2009-10-05 20:21:59 » |
|
Hi
I've only ever seen that message when something has gone wrong, I have no idea off the top of my head why it's doing that. I was thinking of other apps that might want the mouse through directx, but that doesn't seem to be the case. Hmm.
Can you run the controller text test and post what falls out of it?
Thanks
Endolf
|
|
|
|
HermanssoN
Senior Newbie 
|
 |
«
Reply #5 - Posted
2009-10-05 20:28:07 » |
|
I'm faitly new to Java and JINput, how do I run it. I got the jinput-test folder.
|
|
|
|
|
HermanssoN
Senior Newbie 
|
 |
«
Reply #6 - Posted
2009-10-05 20:57:27 » |
|
I didn't realize that it was a class in the JInput API, I tought it was an executable. anyways, I don't understand how to use it, I tryed this: 1 2 3 4 5
| public static void main( String[]args) { System.setProperty("jinput.plugins", "net.java.games.util.plugins.test.PluginTest"); PluginTest.main(args); } |
I got this message: 1 2 3 4 5 6
| java.io.FileNotFoundException: Plugin directory test_plugins not found. at net.java.games.util.plugins.Plugins.scanPlugins(Plugins.java:82) at net.java.games.util.plugins.Plugins.<init>(Plugins.java:76) at net.java.games.util.plugins.test.PluginTest.<init>(PluginTest.java:92) at net.java.games.util.plugins.test.PluginTest.main(PluginTest.java:119) at Application.main(Application.java:56) |
|
|
|
|
|
endolf
|
 |
«
Reply #7 - Posted
2009-10-06 07:58:07 » |
|
Hi
The first post in the getting started thread will show you how to run the tests. You can always look at that thread to see how to use the event queue correctly too. Or you can look at the tests that are in the sources.
HTH
Endolf
|
|
|
|
HermanssoN
Senior Newbie 
|
 |
«
Reply #8 - Posted
2009-10-06 16:31:41 » |
|
I found the error. I used following before creatingmy controlls 1
| System.setProperty("jinput.plugins", "net.java.games.input.DirectInputEnvironmentPlugin"); |
If I remove that no erros occure.
|
|
|
|
|
HermanssoN
Senior Newbie 
|
 |
«
Reply #9 - Posted
2009-10-06 16:43:54 » |
|
Also worth mentioning is that if I use this loop when polling the mouse evry thing works perfectly: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| m_mouse.poll(); m_mouseQueue = m_mouse.getEventQueue(); Event event = new Event(); while( m_mouseQueue.getNextEvent(event)) { Component c = event.getComponent(); float data = c.getPollData(); if(data != 0.0f ) { m_mouseDown.put(c.getIdentifier(), true); } else { m_mouseDown.put(event.getComponent().getIdentifier(), false); } } m_deltaMouse.x = m_mouse.getX().getPollData(); m_deltaMouse.y = m_mouse.getY().getPollData(); |
If I use this version delta mouse won't be set to 0.0f when mouse is still: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| m_mouse.poll(); m_mouseQueue = m_mouse.getEventQueue(); Event event = new Event(); while( m_mouseQueue.getNextEvent(event)) { Component c = event.getComponent(); float data = c.getPollData(); if(data != 0.0f ) { m_mouseDown.put(c.getIdentifier(), true); m_deltaMouse.x = m_mouse.getX().getPollData(); m_deltaMouse.y = m_mouse.getY().getPollData(); } else { m_mouseDown.put(event.getComponent().getIdentifier(), false); m_deltaMouse.x = 0.0f; m_deltaMouse.y = 0.0f; } } |
I allso tryed to get all data from the event as you mentioned above, when pointing out that I was mixing the old polling with the newer queue system, but the result is the same as the atempt above,: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| m_mouse.poll(); m_mouseQueue = m_mouse.getEventQueue(); Event event = new Event(); while( m_mouseQueue.getNextEvent(event)) { Component c = event.getComponent(); float data = c.getPollData(); if(data != 0.0f ) { m_mouseDown.put(c.getIdentifier(), true); if( c.getIdentifier() == Identifier.Axis.X) m_deltaMouse.x = c.getPollData(); if( c.getIdentifier() == Identifier.Axis.Y) m_deltaMouse.y = c.getPollData(); } else { m_mouseDown.put(event.getComponent().getIdentifier(), false); if( c.getIdentifier() == Identifier.Axis.X) m_deltaMouse.x = 0.0f; if( c.getIdentifier() == Identifier.Axis.Y) m_deltaMouse.y = 0.0f; } } |
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
endolf
|
 |
«
Reply #10 - Posted
2009-10-06 18:16:54 » |
|
Instead of calling c.getPollData(), try event.getValue()
HTH
Endolf
|
|
|
|
HermanssoN
Senior Newbie 
|
 |
«
Reply #11 - Posted
2009-10-06 20:52:59 » |
|
Same story  It seems like I don't recive any event for mouse stop. I tried to switch to another mouse but no change there either. I got a steady -1 in x and y. :/
|
|
|
|
|
endolf
|
 |
«
Reply #12 - Posted
2009-10-07 08:04:57 » |
|
Hi
Nope, the mouse doesn't stop. It's a relative device not an absolute one. If you get no event from it in a poll cycle the it didn't move. It's a discussion that has come up before, we *could* fake a 'it didn't move' event, but then you'd see that every poll, unless we did more fiddling. We decided that JInput should probably expose what the device says, and let users of the JInput API decide what they wish to do.
On the other hand, it's something that I don't like either, but I'm not sure I like faking it either.
Endolf
|
|
|
|
|