当前位置: 首页>>代码示例>>Java>>正文


Java ControllerEnvironment类代码示例

本文整理汇总了Java中net.java.games.input.ControllerEnvironment的典型用法代码示例。如果您正苦于以下问题:Java ControllerEnvironment类的具体用法?Java ControllerEnvironment怎么用?Java ControllerEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ControllerEnvironment类属于net.java.games.input包,在下文中一共展示了ControllerEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: nativesTest

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
@Test
public void nativesTest() {
  new NativeLibrary("jinput") //
      .register(Platform.Windows_x86, "jinput-dx8.dll") //
      .register(Platform.Windows_x86, "jinput-raw.dll") //
      .register(Platform.Windows_x64, "jinput-dx8_64.dll") //
      .register(Platform.Windows_x64, "jinput-raw_64.dll") //
      .register(Platform.Linux_x86, "libjinput-linux.so") //
      .register(Platform.Linux_x64, "libjinput-linux64.so") //
      .register(Platform.MacOS, "libjinput-osx.jnilib") //
      .require(true) //
      .deleteOnExit(true)//
      .extractTo(new File("target", "jinput-natives")) //
      .load(Loaders.JAVA_LIBRARY_PATH__LOADER);

  final Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
  assertTrue(controllers.length > 0);
  for (final Controller controller : controllers) {
    System.out.println(controller.getName());
  }
}
 
开发者ID:klaushauschild1984,项目名称:java-natives,代码行数:22,代码来源:JInputTest.java

示例2: GamepadHandler

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public GamepadHandler()
{
    ArrayList<Controller> controllers = new ArrayList<Controller>(Arrays.asList(ControllerEnvironment.getDefaultEnvironment().getControllers()));
    Controller current;
    
    for (int i=0;i<controllers.size();i++)
    {
        current = controllers.get(i);
        
        if (current.getType() == Controller.Type.GAMEPAD || current.getType() == Controller.Type.STICK)
            m_GamePads.add(new Gamepad(current));
        else
            controllers.remove(i--);
        
    }
    
    //m_JInputControllerHandles = controllers.toArray(new net.java.games.input.Controller[controllers.size()]);
    
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:20,代码来源:GamepadHandler.java

示例3: getButtonController

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
 * Description of the Method
 *
 * @param index Description of the Parameter
 * @return Description of the Return Value
 */
public static int getButtonController(int index) {
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cs = ce.getControllers();

    int controllerCount = 0;
    for (int d = 0; d < cs.length; d++) {
        Controller.Type type = cs[d].getType();
        if ((type == Controller.Type.GAMEPAD) || (type == Controller.Type.STICK) || cs[d].getName().toLowerCase().contains("wiimote") || cs[d].getName().toLowerCase().contains("shuttle")) {
            if (controllerCount == index) {
                return d;
            }
            controllerCount++;
        }
    }
    return -1;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:23,代码来源:YassInput.java

示例4: getButton

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
 * Gets the button attribute of the YassInput class
 *
 * @param d Description of the Parameter
 * @param i Description of the Parameter
 * @return The button value
 */
public static int getButton(int d, int i) {
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cs = ce.getControllers();

    int buttonCount = 0;
    Component[] comps = cs[d].getComponents();
    for (int c = 0; c < comps.length; c++) {
        if (!(comps[c].getIdentifier() instanceof Component.Identifier.Axis)) {
            if (buttonCount == i) {
                return c;
            }
            buttonCount++;
        }
    }
    return -1;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:24,代码来源:YassInput.java

示例5: pollAllButtons

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
 * Description of the Method
 */
public void pollAllButtons() {
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cs = ce.getControllers();
    for (Controller cc : cs) {
        Controller.Type type = cc.getType();
        //if (type == Controller.Type.MOUSE || type == Controller.Type.KEYBOARD) {
            // continue;
        //} else
        if (type == Controller.Type.GAMEPAD || type == Controller.Type.STICK) {
            cc.poll();
        } else if (type == Controller.Type.UNKNOWN) {
            cc.poll();
        } else if (cc.getName().toLowerCase().contains("wiimote")) {
            cc.poll();
        }
    }
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:21,代码来源:YassInput.java

示例6: rediscoverJoysticks

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public static Map<String, ControllerConfiguration> rediscoverJoysticks()
{
    Controller[] availableControllers = ControllerEnvironment.getDefaultEnvironment().getControllers();

    Map<String, ControllerConfiguration> controllerConfig = new LinkedHashMap<>();
    Map<String, Integer> deviceCounter = new LinkedHashMap<>();

    controllerConfig.clear();
    for (Controller controller : availableControllers)
    {
        if (sTYPES_TO_IGNORE.contains(controller.getType()))
        {
            continue;
        }

        Class<? extends IMockJoystick> specializationClass = getDefaultSpecialization(controller);

        int deviceCtr = deviceCounter.getOrDefault(controller.getName(), 0);
        deviceCounter.put(controller.getName(), ++deviceCtr);

        String deviceName = controller.getName() + " " + deviceCtr;

        ControllerConfiguration configuration = new ControllerConfiguration(controller, specializationClass);
        controllerConfig.put(deviceName, configuration);
    }

    return sort(controllerConfig);
}
 
开发者ID:ArcticWarriors,项目名称:snobot-2017,代码行数:29,代码来源:JoystickDiscoverer.java

示例7: findGamepad

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public static Controller findGamepad() throws InterruptedException {
    Controller instance;
    do {
        Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
        instance = Stream.of(controllers)
                .filter(controller -> controller.getType() == GAMEPAD)
                .findAny()
                .orElseGet(() -> {
                    LOG.error("No controllers of type GAMEPAD found! Will retry in 5 sec");
                    return null;
                });
        if (instance == null) {
            Thread.sleep(5000);
        }
    } while (instance == null);
    LOG.info("Found a controller of type GAMEPAD: {}", instance);
    return instance;
}
 
开发者ID:Sythog,项目名称:gamepad-control,代码行数:19,代码来源:ControllerUtils.java

示例8: initKeyboard

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
 * Init
 */
public static void initKeyboard() {
	controllerEnvironment = ControllerEnvironment.getDefaultEnvironment();
	controllers = controllerEnvironment.getControllers();

	for(int i = 0; i < controllers.length; i++) {
		Controller c = controllers[i];

		if((c.getType() == Controller.Type.KEYBOARD) && (c instanceof Keyboard)) {
			if(NullpoMinoSlick.useJInputKeyboard) {
				log.debug("initKeyboard: Keyboard found");
			}
			keyboard = (Keyboard)c;
		}
	}

	if((keyboard == null) && (NullpoMinoSlick.useJInputKeyboard)) {
		log.error("initKeyboard: Keyboard NOT FOUND");

		// Linux
		if(System.getProperty("os.name").startsWith("Linux")) {
			log.error("If you can use sudo, try the following command and start NullpoMino again:");
			log.error("sudo chmod go+r /dev/input/*");
		}
	}
}
 
开发者ID:PoochyEXE,项目名称:nullpomino,代码行数:29,代码来源:JInputManager.java

示例9: JoystickHandler

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public JoystickHandler()
{
	connectBuffer();
	
	Controller[] ca = ControllerEnvironment.getDefaultEnvironment()
			.getControllers();
	
	// find the joystick
	for (int i = 0; i < ca.length; i++)
	{
		
		if (ca[i].getType() ==Controller.Type.STICK )
		{
			joystick = ca[i];
			x_axis = joystick.getComponent(Component.Identifier.Axis.X);
			landButton = joystick.getComponent(Component.Identifier.Button.TRIGGER);
		}
	}		
}
 
开发者ID:Damacustas,项目名称:UAVBCI,代码行数:20,代码来源:JoystickHandler.java

示例10: updateControllers

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
public void updateControllers() {
	mousecontrollers.clear();
	keyboardcontrollers.clear();
	gamepadcontrollers.clear();

	Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
	for (Controller c : ca) {
		Type t = c.getType();
		if (t == Type.MOUSE)
			mousecontrollers.add((Mouse) c);
		if (t == Type.KEYBOARD)
			keyboardcontrollers.add((Keyboard) c);
		if (t == Type.GAMEPAD)
			gamepadcontrollers.add(c);
	}
}
 
开发者ID:tdc22,项目名称:JAwesomeEngine,代码行数:17,代码来源:JInputReader.java

示例11: updateGamepads

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
private void updateGamepads() {
  this.handleHotPluggedControllers = true;
  try {
    this.hackTheShitOutOfJInputBecauseItSucksHard();
    // update plugged in gamepads
    for (int i = 0; i < ControllerEnvironment.getDefaultEnvironment().getControllers().length; i++) {
      final Controller controller = ControllerEnvironment.getDefaultEnvironment().getControllers()[i];
      final Type type = controller.getType();
      if (!type.equals(Type.GAMEPAD)) {
        continue;
      }

      final IGamepad existing = Input.getGamepad(i);
      if (existing != null && existing.getName().equals(controller.getName())) {
        // already added
        continue;
      }

      // add new gamepads
      final IGamepad newGamepad = new Gamepad(i, controller);
      Input.gamepads().add(newGamepad);
      for (final Consumer<IGamepad> cons : this.gamepadAddedConsumer) {
        cons.accept(newGamepad);
      }
    }
  } catch (IllegalStateException e) {
    this.loop.terminate();
  } finally {
    this.handleHotPluggedControllers = false;
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:32,代码来源:GamepadManager.java

示例12: init

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
 * Description of the Method
 */
public static void init() {
    try {
        // JInput bug: list is never refreshed
        ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
        ce.getControllers();
    } catch (java.lang.UnsatisfiedLinkError e) {
        System.out.println("No jinput-raw in java.library.path");
    }
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:13,代码来源:YassInput.java

示例13: getControllerIndex

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
 * Gets the controllerIndex attribute of the YassInput object
 *
 * @param s Description of the Parameter
 * @return The controllerIndex value
 */
public int getControllerIndex(String s) {
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cs = ce.getControllers();
    for (int d = 0; d < cs.length; d++) {
        if (cs[d].getName().equals(s)) {
            return d;
        }
    }
    return -1;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:17,代码来源:YassInput.java

示例14: getController

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
 * Gets the controller attribute of the YassInput object
 *
 * @param s Description of the Parameter
 * @return The controller value
 */
public Controller getController(String s) {
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cs = ce.getControllers();
    for (Controller c : cs) {
        if (c.getName().equals(s)) {
            return c;
        }
    }
    return null;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:17,代码来源:YassInput.java

示例15: getComponentIndex

import net.java.games.input.ControllerEnvironment; //导入依赖的package包/类
/**
 * Gets the componentIndex attribute of the YassInput object
 *
 * @param d Description of the Parameter
 * @param s Description of the Parameter
 * @return The componentIndex value
 */
public int getComponentIndex(int d, String s) {
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cs = ce.getControllers();
    Component[] comps = cs[d].getComponents();
    for (int c = 0; c < comps.length; c++) {
        if (comps[c].getName().equals(s)) {
            return c;
        }
    }
    return -1;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:19,代码来源:YassInput.java


注:本文中的net.java.games.input.ControllerEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。