use of com.b3dgs.lionengine.InputDevice in project lionengine by b3dgs.
the class StateHandler method update.
/*
* Updatable
*/
@Override
public void update(double extrp) {
if (current != null) {
for (final InputDevice input : inputs) {
updateInput(StateInputDirectionalUpdater.class, InputDeviceDirectional.class, input);
updateInput(StateInputPointerUpdater.class, InputDevicePointer.class, input);
}
current.update(extrp);
final State old = current;
for (final InputDevice input : inputs) {
current = checkNext(InputDeviceDirectional.class, input);
if (!old.equals(current)) {
break;
}
current = checkNext(InputDevicePointer.class, input);
if (!old.equals(current)) {
break;
}
}
if (!old.equals(current)) {
old.exit();
}
}
}
use of com.b3dgs.lionengine.InputDevice in project lionengine by b3dgs.
the class Loader method handle.
/**
* Handle the sequence with its screen until no more sequence to run.
*
* @param config The configuration used.
* @param sequenceClass The the next sequence to start.
* @param arguments The sequence arguments list if needed by its constructor.
* @throws LionEngineException If an exception occurred.
*/
private static void handle(Config config, Class<? extends Sequencable> sequenceClass, Object... arguments) {
final Screen screen = Graphics.createScreen(config);
try {
screen.start();
screen.awaitReady();
final Context context = new ContextWrapper(screen);
Sequencable nextSequence = UtilSequence.create(sequenceClass, context, arguments);
while (nextSequence != null) {
final Sequencable sequence = nextSequence;
final String sequenceName = sequence.getClass().getName();
Verbose.info(SEQUENCE_START, sequenceName);
sequence.start(screen);
Verbose.info(SEQUENCE_END, sequenceName);
nextSequence = sequence.getNextSequence();
sequence.onTerminated(nextSequence != null);
}
} finally {
screen.dispose();
config.getDevices().forEach(InputDevice::close);
}
}
use of com.b3dgs.lionengine.InputDevice in project lionengine by b3dgs.
the class DeviceControllerConfig method create.
/**
* Create device controller from configuration.
*
* @param services The services reference (must not be <code>null</code>).
* @param media The media configuration (must not be <code>null</code>).
* @return The created controller.
* @throws LionEngineException If unable to read node.
*/
public static DeviceController create(Services services, Media media) {
final Context context = services.get(Context.class);
final DeviceController controller = new DeviceControllerModel();
final Collection<DeviceControllerConfig> configs = DeviceControllerConfig.imports(services, media);
for (final DeviceControllerConfig config : configs) {
final InputDevice device = context.getInputDevice(config.getDevice());
if (device instanceof DevicePush) {
final DevicePush push = (DevicePush) device;
config.getHorizontal().forEach(h -> controller.addHorizontal(push, new DeviceActionModel(h, push)));
config.getVertical().forEach(v -> controller.addVertical(push, new DeviceActionModel(v, push)));
config.getFire().entrySet().forEach(e -> e.getValue().forEach(c -> controller.addFire(device, e.getKey(), new DeviceActionModel(c, push))));
}
if (device instanceof DevicePointer) {
final DevicePointer pointer = (DevicePointer) device;
controller.addHorizontal(pointer, () -> pointer.getMoveX());
controller.addVertical(pointer, () -> -pointer.getMoveY());
}
if (config.isDisabled()) {
controller.setDisabled(device.getName(), true, true);
}
}
return controller;
}
use of com.b3dgs.lionengine.InputDevice in project lionengine by b3dgs.
the class DeviceControllerModel method update.
@Override
public void update(double extrp) {
for (final InputDevice device : devices) {
device.update(extrp);
}
axisHorizontal = 0.0;
for (int i = 0; i < horizontalCount; i++) {
final DeviceAction action = horizontal.get(i);
if (!Boolean.TRUE.equals(disabledHorizontal.get(actionToDevice.get(action)))) {
axisHorizontal += action.getAction();
}
}
axisVertical = 0.0;
for (int i = 0; i < verticalCount; i++) {
final DeviceAction action = vertical.get(i);
if (!Boolean.TRUE.equals(disabledVertical.get(actionToDevice.get(action)))) {
axisVertical += vertical.get(i).getAction();
}
}
for (final List<DeviceAction> actions : fire.values()) {
final int n = actions.size();
for (int i = 0; i < n; i++) {
final DeviceAction action = actions.get(i);
if (Double.compare(action.getAction(), 0) <= 0) {
fired.put(action, Boolean.FALSE);
}
}
}
}
Aggregations