Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  Rescan controllers  (Read 4420 times)
0 Members and 1 Guest are viewing this topic.
Offline Perfect Slayer

Junior Newbie





« Posted 2011-09-16 19:27:48 »

According this topic (http://www.java-gaming.org/index.php?topic=21694.0) and my own tests, the controller environnement could not rescan controllers.
I'm just getting the source and I wonder how many time it take to add this feature and if it is only java fix or I need to fix native part.

I need controller rescan so why not add it myself if you help me in explaining the main architecture  Wink
Offline Perfect Slayer

Junior Newbie





« Reply #1 - Posted 2011-09-17 10:43:31 »

I made some patches to net.java.games.input.DirectInputEnvironmentPlugin and net.java.games.input.DefaultControllerEnvironment classes and it seems to work. (I am on Windows for now).
I need to improve cleaning device first and test again.

I will keep this post up to date if you are interested in  Wink
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #2 - Posted 2011-09-17 12:08:44 »

Hi

Definitely interested, it's not something I've implemented myself as it's not important to me, so to finally have someone who is bothered enough to actually implement it is great news.

Keep us updated on progress.

Endolf

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Perfect Slayer

Junior Newbie





« Reply #3 - Posted 2011-09-20 11:46:52 »

I wonder why java API is frozen to 1.4 ?  Huh
Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2011-09-20 15:10:38 »

I wonder why java API is frozen to 1.4 ?  Huh
O____o ?
What are you talking about?

Offline Perfect Slayer

Junior Newbie





« Reply #5 - Posted 2011-09-20 18:03:35 »

The ant build script wants 1.4 java source :
1  
<javacsource="1.4" target="1.4">


And yes, Sun Oracle has release Java 7  Wink
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #6 - Posted 2011-09-20 18:48:15 »

Hi

This was originally done as there were embedded VMs that were running 1.4 that were being targeted by the sun game group, who did the original API work for JInput, Jogl and Joal. It's not changed since then because nobody has been bothered enough by the restriction to go through the code base, plus the plugins and update anything that needed changing Smiley. Until someone does, then the target version might as well stay at 1.4 Smiley

Endolf

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #7 - Posted 2012-02-25 14:12:24 »

I'm interresting in rescan controllers too. I just have bumped into this problem  Wink
I'm doing a frontend for a acarde cabinet. So it start without keyboard or mouse, and time to time, they need to be connected/disconnected.
Offline Perfect Slayer

Junior Newbie





« Reply #8 - Posted 2012-02-25 18:29:06 »

Yes, I succed in rescanning controller.

If I remember well, I only do it for Windows (my target platform) and in Java 6.
If you are interested in, may be I could make you a patch  Wink
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #9 - Posted 2012-02-25 19:36:51 »

Please do Smiley, even if it's only for 1 os, it would be good to have this submission.

Thanks

Endolf

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #10 - Posted 2012-02-27 08:55:26 »

It should nice  Grin Thanks.
Offline Perfect Slayer

Junior Newbie





« Reply #11 - Posted 2012-02-27 20:36:51 »

I paste you my patch here :

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  
Index: coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java
===================================================================
--- coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java   (revision 247)
+++ coreAPI/src/java/net/java/games/input/DefaultControllerEnvironment.java   (working copy)
-169,6 +169,21 @@
                e.printStackTrace();
             }
          }
+        } else {
+           controllers = new ArrayList();
+           for (Object ceName : loadedPlugins) {
+            try {
+               Class ceClass = Class.forName((String) ceName);
+               ControllerEnvironment ce = (ControllerEnvironment) ceClass.newInstance();
+               if (ce.isSupported()) {
+                  addControllers(ce.getControllers());
+               } else {
+                  logln(ceClass.getName() + " is not supported");
+               }
+            } catch (Exception e) {
+               e.printStackTrace();
+            }
+           }
         }
         Controller[] ret = new Controller[controllers.size()];
         Iterator it = controllers.iterator();
Index: plugins/windows/src/java/net/java/games/input/DirectInputEnvironmentPlugin.java
===================================================================
--- plugins/windows/src/java/net/java/games/input/DirectInputEnvironmentPlugin.java   (revision 247)
+++ plugins/windows/src/java/net/java/games/input/DirectInputEnvironmentPlugin.java   (working copy)
-111,28 +111,20 @@
       }
    }
 
-   private final Controller[] controllers;
+   private Controller[] controllers = new Controller[0];
    private final List active_devices = new ArrayList();
    private final DummyWindow window;
 
    /** Creates new DirectInputEnvironment */
    public DirectInputEnvironmentPlugin() {      
       DummyWindow window = null;
-      Controller[] controllers = new Controller[]{};
       if(isSupported()) {
          try {
             window = new DummyWindow();
-            try {
-               controllers = enumControllers(window);
-            } catch (IOException e) {
-               window.destroy();
-               throw e;
-            }
          } catch (IOException e) {
             logln("Failed to enumerate devices: " + e.getMessage());
          }
          this.window = window;
-         this.controllers = controllers;
          AccessController.doPrivileged(
                new PrivilegedAction() {
                   public final Object run() {
-144,12 +136,23 @@
          // These are final fields, so can't set them, then over ride
         // them if we are supported.
         this.window = null;
-         this.controllers = controllers;
       }
    }
 
    public final Controller[] getControllers() {
-      return controllers;
+      if (this.window != null) {
+         try {
+            try {
+               this.controllers = this.enumControllers(this.window);
+            } catch (IOException e) {
+               this.window.destroy();
+               throw e;
+            }
+         } catch (IOException e) {
+            logln("Failed to enumerate devices: " + e.getMessage());
+         }
+      }
+      return this.controllers;
    }
 
    private final Component[] createComponents(IDirectInputDevice device, boolean map_mouse_buttons) {


As you could see, I only upgrade DirectInputEnvironnementPlugin (and DefaultControllerEnvironnement  Roll Eyes)
May be you will need to change the implicit for-each for Java 1.4.

The patch works well for me. I suppose it could be applied to other platforms.

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.

CogWheelz (15 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (15 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

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
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!