Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Controllers - should these work in the sandbox?  (Read 1994 times)
0 Members and 1 Guest are viewing this topic.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Posted 2005-08-21 13:12:39 »

If they should, then some extra bits are required in org.lwjgl.input.Controllers Smiley

Checked on PC only so far.  Got to do something else so will check on Mac later

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  
import java.security.AccessController;
import java.security.PrivilegedAction;

...

   public static void create() throws LWJGLException {
      if (created)
         return;
     
      try {
         net.java.games.input.Controller[] found = (net.java.games.input.Controller[])
                            AccessController.doPrivileged(new PrivilegedAction() {
                                public Object run() {
                                    String plugins = System.getProperty("jinput.plugins");        
                                    if (plugins == null) {
                                        if (System.getProperty("os.name").startsWith("Win"))
                                                System.setProperty("jinput.plugins",WINDOWS_PLUGIN);
                                        if (System.getProperty("os.name").startsWith("Lin"))
                                                System.setProperty("jinput.plugins",LINUX_PLUGIN);
                                        if (System.getProperty("os.name").startsWith("Mac"))
                                                System.setProperty("jinput.plugins",MACOS_PLUGIN);
                                    }
                                    return ControllerEnvironment.getDefaultEnvironment().getControllers();
                                }
                            });           

         ArrayList lollers = new ArrayList();
         for (int i=0;i<found.length;i++) {
            net.java.games.input.Controller c = found[i];
   
            if ((!c.getType().equals(net.java.games.input.Controller.Type.KEYBOARD)) &&
               (!c.getType().equals(net.java.games.input.Controller.Type.MOUSE))) {
               lollers.add(c);
            }
         }
           
         int length = lollers.size();
         
         for (int i=0;i<length;i++) {
            final net.java.games.input.Controller c = (net.java.games.input.Controller) lollers.get(i);
   
                                AccessController.doPrivileged(new PrivilegedAction() {
                                    public Object run() {
                                        createController(c);
                                        return null;
                                    }
                                });

         }
         
         created = true;
      } catch (Throwable e) {
         throw new LWJGLException("Failed to initialise controllers",e);
      }
   }

Time flies like a bird. Fruit flies like a banana.
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2005-08-21 13:53:51 »

Nice one Alan, you're dead right.

Kev

Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #2 - Posted 2005-08-22 00:01:24 »

Another issue.

The PC returns values between -1 and +1 for each axis.

The Mac initially returns +1 for all axes, until you stir the sticks.  Then for each axis an auto-calibration appears to take place.  If the sticks are fully stired around the four quadrants, then the final range is 0 to 1 for each axis.

My current workaround is to check for a Mac and the double the value received from each axis, then subtract 1.

If you forget to stir the sticks, you will get maximum rate movement in all axes, until the sticks are stired.  Then everything is alright.

Other notes:
- There appears to be a memory leak.  After lots of debug cycles Netbeans runs out of memory.
- POV doesn't work correctly on the Mac, so you can't use it x-platform
- The same controller is detected twice on the Mac

Time flies like a bird. Fruit flies like a banana.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2005-08-22 08:52:13 »

Re: memory link - are you calling clearEvents() on Controllers each loop?

Kev

Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #4 - Posted 2005-08-22 09:15:17 »

Well no, but the prog does read all pending events every frame (so hopefully shouldn't need to).   However if I run the game a dozen times within session with the Netbeans IDE there are out of memory errors.  While this has happened before the controllers stuff was in, it occurs more frequently now (or it could be my imagination).  Maybe JInput does not clean up its plugins when classes are disposed & some native resource allocations are left hanging about.   Your destroy method in Controllers is commented out, so you are probably aware of this.  Smiley

Alan

Time flies like a bird. Fruit flies like a banana.
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2005-08-22 12:48:13 »

Hold on, are you talking about between process invocations? As in restarting the game all together?

Kev

Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #6 - Posted 2005-08-22 21:06:27 »

I know it sounds odd.  Netbeans 3.6 (I know - old) tends to fall over if apps repeatedly terminate abnormally.   I also noticed this behaviour more frequently after adding controllers.  I wondered if there was a memory leak somewhere.

I found this

Quote
If you run out of memory, it could be that there are too many processes running simultaneously. This can happen if you run a program and it crashes but the process has not been terminated or if you omit the line System.exit(0);.
Periodically you can select View / Execution for a list of processes and right-click on each unnecessary process to terminate it(or exit NetBeans completely and then re-start).

So I could be wrong Wink  Maybe something just keeled over.  I'll do some more scientific testing.

Edit - Think I'm wrong Smiley - I ran the app a good dozen times within Netbeans without hitting any problems.  I think my earlier problems must have been purely down to app crashes during development destabilising Netbeans.

Time flies like a bird. Fruit flies like a banana.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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 (22 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (52 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!