mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-28 23:05:29 +03:00
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:
parent
3a657c44cc
commit
c966220bab
@ -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
|
* 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
|
* 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
|
val axis = axisItem.value
|
||||||
var value = event.getAxisValue(axis)
|
var value = event.getAxisValue(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) {
|
||||||
var polarity = value > 0 || (value == 0f && axesHistory[axisItem.index]?.let { it >= 0 } == true)
|
var polarity = value > 0 || (value == 0f && axesHistory[axisItem.index] >= 0)
|
||||||
|
|
||||||
val guestEvent = MotionHostEvent(event.device.descriptor, axis, polarity).let { hostEvent ->
|
val guestEvent = MotionHostEvent(event.device.descriptor, axis, polarity).let { hostEvent ->
|
||||||
inputManager.eventMap[hostEvent] ?: if (value == 0f) {
|
inputManager.eventMap[hostEvent] ?: if (value == 0f) {
|
||||||
|
@ -152,7 +152,7 @@ class ButtonDialog @JvmOverloads constructor(private val item : ControllerButton
|
|||||||
}
|
}
|
||||||
|
|
||||||
val axes = MotionHostEvent.axes
|
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 ->
|
view.setOnGenericMotionListener { _, event ->
|
||||||
// We want all input events from Joysticks and Buttons that are [MotionEvent.ACTION_MOVE] and not from the D-pad
|
// 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)
|
val value = event.getAxisValue(axis)
|
||||||
|
|
||||||
// This checks the history of the axis so we can ignore any stagnant 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
|
axesHistory[axisItem.index] = value
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user