mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
controller getaxisraw, calibration on startup
This commit is contained in:
@@ -183,12 +183,6 @@ public class AppLoader implements ApplicationListener {
|
||||
public static TerrarumController gamepad = null;
|
||||
public static float gamepadDeadzone = 0.2f;
|
||||
|
||||
public static boolean inDeadzone(TerrarumController controller, int axis) {
|
||||
float ax = controller.getAxis(axis);
|
||||
float zero = (axis < 4) ? getConfigFloatArray("gamepadaxiszeropoints")[axis] : 0f;
|
||||
|
||||
return Math.abs(ax - zero) < gamepadDeadzone;
|
||||
}
|
||||
|
||||
/**
|
||||
* For the events depends on rendering frame (e.g. flicker on post-hit invincibility)
|
||||
@@ -360,13 +354,17 @@ public class AppLoader implements ApplicationListener {
|
||||
environment = RunningEnvironment.CONSOLE;
|
||||
|
||||
// calibrate the sticks
|
||||
/*float[] axesZeroPoints = new float[]{
|
||||
gamepad.getAxis(0),
|
||||
gamepad.getAxis(1),
|
||||
gamepad.getAxis(2),
|
||||
gamepad.getAxis(3)
|
||||
printdbg(this, "Calibrating the gamepad...");
|
||||
float[] axesZeroPoints = new float[]{
|
||||
gamepad.getAxisRaw(0),
|
||||
gamepad.getAxisRaw(1),
|
||||
gamepad.getAxisRaw(2),
|
||||
gamepad.getAxisRaw(3)
|
||||
};
|
||||
setConfig("gamepadaxiszeropoints", axesZeroPoints);*/
|
||||
setConfig("gamepadaxiszeropoints", axesZeroPoints);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printdbg(this, "Axis " + i + ": " + axesZeroPoints[i]);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -12,7 +12,7 @@ class GdxControllerAdapter(val c: Controller): TerrarumController {
|
||||
return c.getButton(index)
|
||||
}
|
||||
|
||||
override fun getAxis(index: Int): Float {
|
||||
override fun getAxisRaw(index: Int): Float {
|
||||
return c.getAxis(index)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package net.torvald.terrarum.controller
|
||||
|
||||
import net.torvald.terrarum.AppLoader.gamepadDeadzone
|
||||
import net.torvald.terrarum.AppLoader.getConfigFloatArray
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2019-02-09.
|
||||
*/
|
||||
@@ -40,7 +43,24 @@ interface TerrarumController {
|
||||
*
|
||||
* @return 0f..1f for the axis
|
||||
*/
|
||||
fun getAxis(index: Int): Float
|
||||
fun getAxisRaw(index: Int): Float
|
||||
/**
|
||||
* Returns deadzone-applied axis value. Deadzone must be stored in the app's config database as the IntArray gamepadaxiszeropoints
|
||||
*/
|
||||
fun getAxis(index:Int): Float {
|
||||
val raw = getAxisRaw(index)
|
||||
val zero = if (index < 4) getConfigFloatArray("gamepadaxiszeropoints")[index] else 0f
|
||||
val inDeadzone = Math.abs(raw - zero) < gamepadDeadzone
|
||||
|
||||
return if (inDeadzone) 0f else raw
|
||||
}
|
||||
|
||||
fun inDeadzone(axis: Int): Boolean {
|
||||
val ax = getAxisRaw(axis)
|
||||
val zero = if (axis < 4) getConfigFloatArray("gamepadaxiszeropoints")[axis] else 0f
|
||||
|
||||
return Math.abs(ax - zero) < gamepadDeadzone
|
||||
}
|
||||
|
||||
/**
|
||||
* ```
|
||||
|
||||
@@ -36,7 +36,7 @@ class XinputControllerAdapter(val c: XInputDevice): TerrarumController {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getAxis(index: Int): Float {
|
||||
override fun getAxisRaw(index: Int): Float {
|
||||
if (c.poll()) {
|
||||
val axes = c.components.axes
|
||||
|
||||
|
||||
@@ -233,12 +233,6 @@ open class ActorHumanoid(
|
||||
axisRX = gamepad.getAxis(AppLoader.getConfigInt("gamepadaxisrx"))
|
||||
axisRY = gamepad.getAxis(AppLoader.getConfigInt("gamepadaxisry"))
|
||||
|
||||
// deadzonning
|
||||
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxislx"))) axisX = 0f
|
||||
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxisly"))) axisY = 0f
|
||||
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxisrx"))) axisRX = 0f
|
||||
if (AppLoader.inDeadzone(gamepad, AppLoader.getConfigInt("gamepadaxisry"))) axisRY = 0f
|
||||
|
||||
isJumpDown = Gdx.input.isKeyPressed(AppLoader.getConfigInt("keyjump")) ||
|
||||
gamepad.getButton(AppLoader.getConfigInt("gamepadltrigger"))
|
||||
}
|
||||
|
||||
BIN
work_files/graphics/fonts/hebrew_rtl_variable.psd
LFS
Normal file
BIN
work_files/graphics/fonts/hebrew_rtl_variable.psd
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user