Zero-initialize axes history instead of using null values

Use zero initialization for axes history instead of using null values. Fixes the first axis event after launching a game being completely ignored.
This commit is contained in:
lynxnb 2022-11-03 01:48:11 +01:00 committed by Niccolò Betto
parent 3a657c44cc
commit c966220bab
2 changed files with 5 additions and 5 deletions

View File

@ -117,7 +117,7 @@ class InputHandler(private val inputManager : InputManager, private val preferen
/**
* The last value of the axes so the stagnant axes can be eliminated to not wastefully look them up
*/
private val axesHistory = arrayOfNulls<Float>(MotionHostEvent.axes.size)
private val axesHistory = FloatArray(MotionHostEvent.axes.size)
/**
* Handles translating any [MotionHostEvent]s to a [GuestEvent] that is passed into libskyline
@ -128,8 +128,8 @@ class InputHandler(private val inputManager : InputManager, private val preferen
val axis = axisItem.value
var value = event.getAxisValue(axis)
if ((event.historySize != 0 && value != event.getHistoricalAxisValue(axis, 0)) || (axesHistory[axisItem.index]?.let { it == value } == false)) {
var polarity = value > 0 || (value == 0f && axesHistory[axisItem.index]?.let { it >= 0 } == true)
if ((event.historySize != 0 && value != event.getHistoricalAxisValue(axis, 0)) || axesHistory[axisItem.index] != value) {
var polarity = value > 0 || (value == 0f && axesHistory[axisItem.index] >= 0)
val guestEvent = MotionHostEvent(event.device.descriptor, axis, polarity).let { hostEvent ->
inputManager.eventMap[hostEvent] ?: if (value == 0f) {

View File

@ -152,7 +152,7 @@ class ButtonDialog @JvmOverloads constructor(private val item : ControllerButton
}
val axes = MotionHostEvent.axes
val axesHistory = arrayOfNulls<Float>(axes.size) // The last recorded value of an axis, this is used to eliminate any stagnant axes
val axesHistory = FloatArray(axes.size) // The last recorded value of an axis, this is used to eliminate any stagnant axes
view.setOnGenericMotionListener { _, event ->
// We want all input events from Joysticks and Buttons that are [MotionEvent.ACTION_MOVE] and not from the D-pad
@ -163,7 +163,7 @@ class ButtonDialog @JvmOverloads constructor(private val item : ControllerButton
val value = event.getAxisValue(axis)
// This checks the history of the axis so we can ignore any stagnant axis
if ((event.historySize == 0 || value == event.getHistoricalAxisValue(axis, 0)) && (axesHistory[axisItem.index]?.let { it == value } != false)) {
if ((event.historySize == 0 || value == event.getHistoricalAxisValue(axis, 0)) && axesHistory[axisItem.index] == value) {
axesHistory[axisItem.index] = value
continue
}