Allow for manual refreshing of controller data

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent ff0c7bf1af
commit bcd48205cc
  1. BIN
      lib/bin/net/java/games/input/AWTEnvironmentPlugin.class
  2. BIN
      lib/bin/net/java/games/input/ControllerEnvironment.class
  3. BIN
      lib/bin/net/java/games/input/DefaultControllerEnvironment.class
  4. BIN
      lib/bin/net/java/games/input/DirectAndRawInputEnvironmentPlugin.class
  5. BIN
      lib/bin/net/java/games/input/DirectInputEnvironmentPlugin$ShutdownHook.class
  6. BIN
      lib/bin/net/java/games/input/DirectInputEnvironmentPlugin.class
  7. BIN
      lib/bin/net/java/games/input/LinuxEnvironmentPlugin$1.class
  8. BIN
      lib/bin/net/java/games/input/LinuxEnvironmentPlugin$ShutdownHook.class
  9. BIN
      lib/bin/net/java/games/input/LinuxEnvironmentPlugin.class
  10. BIN
      lib/bin/net/java/games/input/OSXEnvironmentPlugin.class
  11. BIN
      lib/bin/net/java/games/input/RawInputEnvironmentPlugin.class
  12. BIN
      lib/jinput.jar
  13. 33
      src/sig/RabiClone.java
  14. 26
      src/sig/objects/ConfigureControls.java

Binary file not shown.

@ -7,6 +7,7 @@ import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment; import net.java.games.input.ControllerEnvironment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import sig.engine.Panel; import sig.engine.Panel;
@ -24,6 +25,7 @@ import sig.engine.PaletteColor;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.lang.reflect.Constructor;
public class RabiClone{ public class RabiClone{
public static final String PROGRAM_NAME="RabiClone"; public static final String PROGRAM_NAME="RabiClone";
@ -48,6 +50,20 @@ public class RabiClone{
public static Controller[] CONTROLLERS = new Controller[]{}; public static Controller[] CONTROLLERS = new Controller[]{};
public static long lastControllerScan = System.currentTimeMillis(); public static long lastControllerScan = System.currentTimeMillis();
private static ControllerEnvironment createDefaultEnvironment() throws ReflectiveOperationException {
// Find constructor (class is package private, so we can't access it directly)
Constructor<ControllerEnvironment> constructor = (Constructor<ControllerEnvironment>)
Class.forName("net.java.games.input.DefaultControllerEnvironment").getDeclaredConstructors()[0];
// Constructor is package private, so we have to deactivate access control checks
constructor.setAccessible(true);
// Create object with default constructor
return constructor.newInstance();
}
public static void main(String[] args) { public static void main(String[] args) {
Key.InitializeKeyConversionMap(); Key.InitializeKeyConversionMap();
@ -79,7 +95,11 @@ public class RabiClone{
long lastGameTime = System.nanoTime(); long lastGameTime = System.nanoTime();
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers(); try {
CONTROLLERS = createDefaultEnvironment().getControllers();
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
while (true) { while (true) {
long timePassed = System.nanoTime()-lastGameTime; long timePassed = System.nanoTime()-lastGameTime;
lastGameTime=System.nanoTime(); lastGameTime=System.nanoTime();
@ -87,10 +107,6 @@ public class RabiClone{
//System.out.println(CONTROLLERS.length); //System.out.println(CONTROLLERS.length);
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
if (System.currentTimeMillis()-lastControllerScan>=5000) {
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().rescanControllers();
}
for (int i=0;i<CONTROLLERS.length;i++) { for (int i=0;i<CONTROLLERS.length;i++) {
if (CONTROLLERS[i].getType()==Controller.Type.KEYBOARD||CONTROLLERS[i].getType()==Controller.Type.MOUSE) { if (CONTROLLERS[i].getType()==Controller.Type.KEYBOARD||CONTROLLERS[i].getType()==Controller.Type.MOUSE) {
continue; continue;
@ -133,6 +149,13 @@ public class RabiClone{
ResetGame(); ResetGame();
OBJ.add(new ConfigureControls(p)); OBJ.add(new ConfigureControls(p));
} }
if (Key.isKeyHeld(KeyEvent.VK_F5)&&System.currentTimeMillis()-lastControllerScan>5000) {
try {
CONTROLLERS=createDefaultEnvironment().getControllers();
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
}
for (int i=0;i<OBJ.size();i++) { for (int i=0;i<OBJ.size();i++) {
OBJ.get(i).update(updateMult); OBJ.get(i).update(updateMult);

@ -3,6 +3,8 @@ package sig.objects;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.List; import java.util.List;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.Event; import net.java.games.input.Event;
import net.java.games.input.Component.Identifier; import net.java.games.input.Component.Identifier;
import net.java.games.input.Component.POV; import net.java.games.input.Component.POV;
@ -29,6 +31,12 @@ public class ConfigureControls extends Object{
public void update(double updateMult) { public void update(double updateMult) {
Event e = new Event(); Event e = new Event();
for (int i=0;i<RabiClone.CONTROLLERS.length;i++) { for (int i=0;i<RabiClone.CONTROLLERS.length;i++) {
Component[] components = RabiClone.CONTROLLERS[i].getComponents();
for (int j=0;j<components.length;j++) {
//Component c = components[j];
//System.out.println(c.getName()+","+c.getIdentifier()+": "+c.getPollData());
}
//System.out.println("--------");
while (RabiClone.CONTROLLERS[i].getEventQueue().getNextEvent(e)) { while (RabiClone.CONTROLLERS[i].getEventQueue().getNextEvent(e)) {
if (assigningKey) { if (assigningKey) {
List<KeyBind> clist = KeyBind.KEYBINDS.get(selectedAction); List<KeyBind> clist = KeyBind.KEYBINDS.get(selectedAction);
@ -67,15 +75,6 @@ public class ConfigureControls extends Object{
} }
} }
public void rawKeyPressed(int keyCode) {
if (assigningKey) {
List<KeyBind> clist = KeyBind.KEYBINDS.get(selectedAction);
clist.add(new KeyBind(keyCode));
KeyBind.KEYBINDS.put(selectedAction,clist);
assigningKey=false;
}
}
@Override @Override
protected void MousePressed(MouseEvent e) { protected void MousePressed(MouseEvent e) {
if (e.getButton()==MouseEvent.BUTTON1) { if (e.getButton()==MouseEvent.BUTTON1) {
@ -92,4 +91,13 @@ public class ConfigureControls extends Object{
return sb; return sb;
} }
public void rawKeyPressed(int keyCode) {
if (assigningKey) {
List<KeyBind> clist = KeyBind.KEYBINDS.get(selectedAction);
clist.add(new KeyBind(keyCode));
KeyBind.KEYBINDS.put(selectedAction,clist);
assigningKey=false;
}
}
} }

Loading…
Cancel
Save