mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-21 03:52:48 +00:00
Replay motion event history during input processing
This commit is contained in:
parent
6a27780d56
commit
307e807c8f
@ -510,6 +510,20 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
// ACTION_MOVE is special because it always has actionIndex == 0
|
// ACTION_MOVE is special because it always has actionIndex == 0
|
||||||
// We'll call the move handlers for all indexes manually
|
// We'll call the move handlers for all indexes manually
|
||||||
|
|
||||||
|
// First process the historical events
|
||||||
|
for (int i = 0; i < event.getHistorySize(); i++) {
|
||||||
|
for (TouchContext aTouchContextMap : touchContextMap) {
|
||||||
|
if (aTouchContextMap.getActionIndex() < event.getPointerCount())
|
||||||
|
{
|
||||||
|
aTouchContextMap.touchMoveEvent(
|
||||||
|
(int)event.getHistoricalX(aTouchContextMap.getActionIndex(), i),
|
||||||
|
(int)event.getHistoricalY(aTouchContextMap.getActionIndex(), i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now process the current values
|
||||||
for (TouchContext aTouchContextMap : touchContextMap) {
|
for (TouchContext aTouchContextMap : touchContextMap) {
|
||||||
if (aTouchContextMap.getActionIndex() < event.getPointerCount())
|
if (aTouchContextMap.getActionIndex() < event.getPointerCount())
|
||||||
{
|
{
|
||||||
@ -561,6 +575,12 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// First process the history
|
||||||
|
for (int i = 0; i < event.getHistorySize(); i++) {
|
||||||
|
updateMousePosition((int)event.getHistoricalX(i), (int)event.getHistoricalY(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now process the current values
|
||||||
updateMousePosition((int)event.getX(), (int)event.getY());
|
updateMousePosition((int)event.getX(), (int)event.getY());
|
||||||
|
|
||||||
lastButtonState = event.getButtonState();
|
lastButtonState = event.getButtonState();
|
||||||
|
@ -340,64 +340,106 @@ public class ControllerHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean handleMotionEvent(MotionEvent event) {
|
private void handleAxisSet(ControllerMapping mapping, float lsX, float lsY, float rsX,
|
||||||
ControllerMapping mapping = getMappingForDevice(event.getDevice());
|
float rsY, float lt, float rt, float hatX, float hatY) {
|
||||||
|
|
||||||
// Handle left stick events outside of the deadzone
|
|
||||||
if (mapping.leftStickXAxis != -1 && mapping.leftStickYAxis != -1) {
|
if (mapping.leftStickXAxis != -1 && mapping.leftStickYAxis != -1) {
|
||||||
Vector2d leftStickVector = handleDeadZone(event.getAxisValue(mapping.leftStickXAxis),
|
Vector2d leftStickVector = handleDeadZone(lsX, lsY, mapping.leftStickDeadzoneRadius);
|
||||||
event.getAxisValue(mapping.leftStickYAxis), mapping.leftStickDeadzoneRadius);
|
|
||||||
|
|
||||||
leftStickX = (short)(leftStickVector.getX() * 0x7FFE);
|
leftStickX = (short) (leftStickVector.getX() * 0x7FFE);
|
||||||
leftStickY = (short)(-leftStickVector.getY() * 0x7FFE);
|
leftStickY = (short) (-leftStickVector.getY() * 0x7FFE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle right stick events outside of the deadzone
|
|
||||||
if (mapping.rightStickXAxis != -1 && mapping.rightStickYAxis != -1) {
|
if (mapping.rightStickXAxis != -1 && mapping.rightStickYAxis != -1) {
|
||||||
Vector2d rightStickVector = handleDeadZone(event.getAxisValue(mapping.rightStickXAxis),
|
Vector2d rightStickVector = handleDeadZone(rsX, rsY, mapping.rightStickDeadzoneRadius);
|
||||||
event.getAxisValue(mapping.rightStickYAxis), mapping.rightStickDeadzoneRadius);
|
|
||||||
|
|
||||||
rightStickX = (short)(rightStickVector.getX() * 0x7FFE);
|
rightStickX = (short) (rightStickVector.getX() * 0x7FFE);
|
||||||
rightStickY = (short)(-rightStickVector.getY() * 0x7FFE);
|
rightStickY = (short) (-rightStickVector.getY() * 0x7FFE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle controllers with analog triggers
|
|
||||||
if (mapping.leftTriggerAxis != -1 && mapping.rightTriggerAxis != -1) {
|
if (mapping.leftTriggerAxis != -1 && mapping.rightTriggerAxis != -1) {
|
||||||
float L2 = event.getAxisValue(mapping.leftTriggerAxis);
|
|
||||||
float R2 = event.getAxisValue(mapping.rightTriggerAxis);
|
|
||||||
|
|
||||||
if (mapping.triggersIdleNegative) {
|
if (mapping.triggersIdleNegative) {
|
||||||
L2 = (L2 + 1) / 2;
|
lt = (lt + 1) / 2;
|
||||||
R2 = (R2 + 1) / 2;
|
rt = (rt + 1) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
leftTrigger = (byte)(L2 * 0xFF);
|
leftTrigger = (byte)(lt * 0xFF);
|
||||||
rightTrigger = (byte)(R2 * 0xFF);
|
rightTrigger = (byte)(rt * 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hats emulate d-pad events
|
|
||||||
if (mapping.hatXAxis != -1 && mapping.hatYAxis != -1) {
|
if (mapping.hatXAxis != -1 && mapping.hatYAxis != -1) {
|
||||||
float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
|
|
||||||
float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
|
|
||||||
|
|
||||||
inputMap &= ~(ControllerPacket.LEFT_FLAG | ControllerPacket.RIGHT_FLAG);
|
inputMap &= ~(ControllerPacket.LEFT_FLAG | ControllerPacket.RIGHT_FLAG);
|
||||||
if (hatX < -(0.5 + mapping.hatXDeadzone)) {
|
if (hatX < -0.5) {
|
||||||
inputMap |= ControllerPacket.LEFT_FLAG;
|
inputMap |= ControllerPacket.LEFT_FLAG;
|
||||||
}
|
}
|
||||||
else if (hatX > (0.5 + mapping.hatXDeadzone)) {
|
else if (hatX > 0.5) {
|
||||||
inputMap |= ControllerPacket.RIGHT_FLAG;
|
inputMap |= ControllerPacket.RIGHT_FLAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputMap &= ~(ControllerPacket.UP_FLAG | ControllerPacket.DOWN_FLAG);
|
inputMap &= ~(ControllerPacket.UP_FLAG | ControllerPacket.DOWN_FLAG);
|
||||||
if (hatY < -(0.5 + mapping.hatYDeadzone)) {
|
if (hatY < -0.5) {
|
||||||
inputMap |= ControllerPacket.UP_FLAG;
|
inputMap |= ControllerPacket.UP_FLAG;
|
||||||
}
|
}
|
||||||
else if (hatY > (0.5 + mapping.hatYDeadzone)) {
|
else if (hatY > 0.5) {
|
||||||
inputMap |= ControllerPacket.DOWN_FLAG;
|
inputMap |= ControllerPacket.DOWN_FLAG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendControllerInputPacket();
|
sendControllerInputPacket();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean handleMotionEvent(MotionEvent event) {
|
||||||
|
ControllerMapping mapping = getMappingForDevice(event.getDevice());
|
||||||
|
float lsX = 0, lsY = 0, rsX = 0, rsY = 0, rt = 0, lt = 0, hatX = 0, hatY = 0;
|
||||||
|
|
||||||
|
// Replay the full history before getting the current values
|
||||||
|
for (int i = 0; i < event.getHistorySize(); i++) {
|
||||||
|
if (mapping.leftStickXAxis != -1 && mapping.leftStickYAxis != -1) {
|
||||||
|
lsX = event.getHistoricalAxisValue(mapping.leftStickXAxis, i);
|
||||||
|
lsY = event.getHistoricalAxisValue(mapping.leftStickYAxis, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapping.rightStickXAxis != -1 && mapping.rightStickYAxis != -1) {
|
||||||
|
rsX = event.getHistoricalAxisValue(mapping.rightStickXAxis, i);
|
||||||
|
rsY = event.getHistoricalAxisValue(mapping.rightStickYAxis, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapping.leftTriggerAxis != -1 && mapping.rightTriggerAxis != -1) {
|
||||||
|
lt = event.getHistoricalAxisValue(mapping.leftTriggerAxis, i);
|
||||||
|
rt = event.getHistoricalAxisValue(mapping.rightTriggerAxis, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapping.hatXAxis != -1 && mapping.hatYAxis != -1) {
|
||||||
|
hatX = event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_X, i);
|
||||||
|
hatY = event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_Y, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleAxisSet(mapping, lsX, lsY, rsX, rsY, lt, rt, hatX, hatY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now handle the current set of values
|
||||||
|
if (mapping.leftStickXAxis != -1 && mapping.leftStickYAxis != -1) {
|
||||||
|
lsX = event.getAxisValue(mapping.leftStickXAxis);
|
||||||
|
lsY = event.getAxisValue(mapping.leftStickYAxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapping.rightStickXAxis != -1 && mapping.rightStickYAxis != -1) {
|
||||||
|
rsX = event.getAxisValue(mapping.rightStickXAxis);
|
||||||
|
rsY = event.getAxisValue(mapping.rightStickYAxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapping.leftTriggerAxis != -1 && mapping.rightTriggerAxis != -1) {
|
||||||
|
lt = event.getAxisValue(mapping.leftTriggerAxis);
|
||||||
|
rt = event.getAxisValue(mapping.rightTriggerAxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapping.hatXAxis != -1 && mapping.hatYAxis != -1) {
|
||||||
|
hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
|
||||||
|
hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleAxisSet(mapping, lsX, lsY, rsX, rsY, lt, rt, hatX, hatY);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user