Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JInput / Re: Cant get data to poll on: 2011-03-25 22:23:42
yes, axis and buttons in jtest seem to update fine
2  Java Game APIs & Engines / JInput / Re: Cant get data to poll on: 2011-03-25 14:49:08
It works with both tests, heres the console output from text test.

Quote
Twin USB Joystick
Type: Stick
Component Count: 17
Component 0: Trigger
    Identifier: Trigger
    ComponentType: Absolute Digital
Component 1: Thumb
    Identifier: Thumb
    ComponentType: Absolute Digital
Component 2: Thumb 2
    Identifier: Thumb 2
    ComponentType: Absolute Digital
Component 3: Top
    Identifier: Top
    ComponentType: Absolute Digital
Component 4: Top 2
    Identifier: Top 2
    ComponentType: Absolute Digital
Component 5: Pinkie
    Identifier: Pinkie
    ComponentType: Absolute Digital
Component 6: Base
    Identifier: Base
    ComponentType: Absolute Digital
Component 7: Base 2
    Identifier: Base 2
    ComponentType: Absolute Digital
Component 8: Base 3
    Identifier: Base 3
    ComponentType: Absolute Digital
Component 9: Base 4
    Identifier: Base 4
    ComponentType: Absolute Digital
Component 10: Base 5
    Identifier: Base 5
    ComponentType: Absolute Digital
Component 11: Base 6
    Identifier: Base 6
    ComponentType: Absolute Digital
Component 12: x
    Identifier: x
    ComponentType: Absolute Analog
Component 13: y
    Identifier: y
    ComponentType: Absolute Analog
Component 14: z
    Identifier: z
    ComponentType: Absolute Analog
Component 15: rz
    Identifier: rz
    ComponentType: Absolute Analog
Component 16: pov
    Identifier: pov
    ComponentType: Absolute Digital

3  Java Game APIs & Engines / JInput / Re: Cant get data to poll on: 2011-03-24 22:02:20
Seems my problem wasnt cleared up completely by the code change, only I am now more confused than before. I have two joysticks, which I am not plugging in at the same time. Both joysticks, when run with jtest respond correctly and fully. However with my code above, only one joystick responds correctly.

The first one a standard USB gravis gamepad, works fine in my code and jtest.

The second one, an adapter hub for ps2 controllers, works fully with jtest.
However under my code, its detected, and only one component axis change is detected, only right after the program starts.
I add a few lines to dump a list of all the detected controllers, and I tried plugging the ps2 controller into player 2's slot to see
if I had the wrong controller. Again jtest works fine with it attached to player 1's port on the adapter hub.

Quote
Linux plugin claims to have found 2 controllers
Available Controller List
Twin USB Joystick
Twin USB Joystick
Active Joystick set to: Twin USB Joystick
x:-1.0
y:-1.0
z:-1.0
rz:-1.0

The axis change that is detected doesnt seem to be related to the controller, because I get the same output with not controller plugged into the hub after starting the program. I am confused as to why jtest would find the output and not this code,
4  Java Game APIs & Engines / JInput / Re: Cant get data to poll on: 2011-03-24 21:17:20
I changed several things in the code, and now it works well. I'm not really sure why, but I think I was either calling pollData() to many times instead of storing it to a variable, or because the function calling the poll of this module had a Synchronized keyword on it. But I rewrote it this way and it works now.

 Also: I never did get controller connection/disconnection listener to work. That may be because im on a linux build

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  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;

public class Joystick
{
    private Controller    Joystick_Controller = null;

    private float[]       Joystick_oldpoll  = new float[20];

    public Joystick()
    {
        // find a joystick
       processfindJoystick();
       
    }

    public void processfindJoystick()
    {
        this.Joystick_Controller = null;

        // poll a list of present controllers.
       Controller[] tempList = ControllerEnvironment.getDefaultEnvironment()
                .getControllers();

        for(Controller currentController: tempList)
            if(checkisJoystick(currentController))
            {
                setJoystick(currentController);
                return;
            }

        System.out.println("No joystick found.");
    }

    public void setJoystick(Controller newJoy)
    {
                this.Joystick_Controller = newJoy;

                System.out.println("Active Joystick set to: "
                        + this.Joystick_Controller.getName());              
    }

    public boolean checkisJoystick(Controller thisController)
    {
        if(thisController.getType() == Controller.Type.GAMEPAD ||
           thisController.getType() == Controller.Type.STICK)
            if(thisController.poll())
             return true;

        return false;
    }

    public void poll()
    {
        if(this.Joystick_Controller != null)
            if(!this.Joystick_Controller.poll())
                this.processfindJoystick();


        if(this.Joystick_Controller == null)
        {
            System.out.println("No Joystick");
            return;
        }

        float tempPollData = 0.0f;
           
        for(int currentComp = 0;
        currentComp < this.Joystick_Controller.getComponents().length;
        currentComp++)
        {
            tempPollData = this.Joystick_Controller
                    .getComponents()[currentComp].getPollData();

            if(tempPollData != this.Joystick_oldpoll[currentComp])
            {
                System.out.println(this.Joystick_Controller.getComponents()
                        [currentComp].getName());

                this.Joystick_oldpoll[currentComp] = tempPollData;

            }
        }                          
    }
}


5  Java Game APIs & Engines / JInput / Re: Cant get data to poll on: 2011-03-24 20:11:27
Ive swapped controllers, checked my security permissions, and tried a few other things. I noticed the module gives some errors when loading but so does the test module. And the test module still works correctly.

My console output from the code is:

Quote
Loading: net.java.games.input.LinuxEnvironmentPlugin
Failed to open device (/dev/input/event11): Failed to open device /dev/input/event11 (13)

Failed to open device (/dev/input/event10): Failed to open device /dev/input/event10 (13)

Failed to open device (/dev/input/event7): Failed to open device /dev/input/event7 (13)

Failed to open device (/dev/input/event6): Failed to open device /dev/input/event6 (13)

Failed to open device (/dev/input/event5): Failed to open device /dev/input/event5 (13)

Failed to open device (/dev/input/event4): Failed to open device /dev/input/event4 (13)

Failed to open device (/dev/input/event3): Failed to open device /dev/input/event3 (13)

Failed to open device (/dev/input/event2): Failed to open device /dev/input/event2 (13)

Failed to open device (/dev/input/event1): Failed to open device /dev/input/event1 (13)

Failed to open device (/dev/input/event0): Failed to open device /dev/input/event0 (13)

Linux plugin claims to have found 1 controllers
Active Joystick set to: Gravis GamePad Pro USB



6  Java Game APIs & Engines / JInput / Re: Cant get data to poll on: 2011-03-24 13:47:08
Yes. Ive run the test module and it works fine. Button presses are displayed normally. When I run the code provided, the only output I get is the notice that my joystick has been found. However button/axis presses do not generate output.
7  Java Game APIs & Engines / JInput / Cant get data to poll on: 2011-03-24 04:24:34
I wrote a small class to implement jinput for joysticks into my code, its picking up the joysticks but the poll data never updates. I have run jtest and it works just fine. Can someone point out whats going wrong before this lib makes me what to hurl an input device? Huh

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  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
import net.java.games.input.Controller;
import net.java.games.input.ControllerListener;
import net.java.games.input.ControllerEvent;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Component;

public class Joystick implements ControllerListener
{
    private Controller    Joystick_Controller = null;

    private Component[]   Joystick_Parts;
    private float[]       Joystick_oldState;

    public Joystick()
    {
        // add this module to controller listeners
       ControllerEnvironment.getDefaultEnvironment()
                .addControllerListener(this);

        // find a joystick
       processfindJoystick();
       
    }

    public void processfindJoystick()
    {
        this.Joystick_Controller = null;

        // poll a list of present controllers.
       Controller[] tempList = ControllerEnvironment.getDefaultEnvironment()
                .getControllers();

        for(Controller currentController: tempList)
            if(checkisJoystick(currentController))
            {
                setJoystick(currentController);
                return;
            }

        System.out.println("No joystick found.");
    }

    public void setJoystick(Controller newJoy)
    {
                this.Joystick_Controller = newJoy;
                this.Joystick_Parts      = newJoy.getComponents();
                this.Joystick_oldState   = new float[Joystick_Parts.length];


                System.out.println("Active Joystick set to: "
                        + this.Joystick_Controller.getName());
               
                this.Joystick_Controller.poll();

                for(int currentState = 0; currentState <
                        this.Joystick_oldState.length; currentState++)
                    this.Joystick_oldState[currentState] =
                            this.Joystick_Parts[currentState].getPollData();
    }

    public boolean checkisJoystick(Controller thisController)
    {
        if(thisController.getType() == Controller.Type.GAMEPAD ||
           thisController.getType() == Controller.Type.STICK)
            return true;

        return false;
    }

    public void controllerAdded(ControllerEvent ev)
    {
       //  attach to new joystick if theres not one already
       if(Joystick_Controller == null)
          if(checkisJoystick(ev.getController()))
              this.setJoystick(ev.getController());
    }

    public void controllerRemoved(ControllerEvent ev)
    {
       // if we loose the joystick, try to find another one.
       if(ev.getController() == Joystick_Controller)
            this.processfindJoystick();
    }

    public void Poll()
    {
        if(this.Joystick_Controller != null)
            if(!this.Joystick_Controller.poll())
                this.processfindJoystick();
        else
            return;

        for(int currentState = 0; currentState <
            this.Joystick_oldState.length; currentState++)
            if(this.Joystick_oldState[currentState] !=
                 this.Joystick_Controller.getComponents()[currentState].getPollData())
                   System.out.println(this.Joystick_Parts[currentState]
                           .getName() + " " +
                        this.Joystick_Controller.getComponents()[currentState]
                           .getPollData());
                           
    }
}


Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!