forked from MeloNX/MeloNX
android - add option to disable motion
This commit is contained in:
parent
b5d48e8324
commit
a64eb877a2
@ -206,7 +206,8 @@ class MainActivity : BaseActivity() {
|
||||
setFullScreen(true)
|
||||
NativeHelpers.instance.setTurboMode(true)
|
||||
force60HzRefreshRate(true)
|
||||
motionSensorManager.register()
|
||||
if (QuickSettings(this).enableMotion)
|
||||
motionSensorManager.register()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,27 +79,37 @@ class MotionSensorManager(val activity: MainActivity) : SensorEventListener2 {
|
||||
fun unregister(){
|
||||
sensorManager.unregisterListener(this)
|
||||
isRegistered = false
|
||||
|
||||
if (controllerId != -1){
|
||||
RyujinxNative.instance.inputSetAccelerometerData(0.0F, 0.0F, 0.0F, controllerId)
|
||||
RyujinxNative.instance.inputSetGyroData(0.0F, 0.0F, 0.0F, controllerId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSensorChanged(event: SensorEvent?) {
|
||||
if (controllerId != -1)
|
||||
event?.apply {
|
||||
when (sensor.type) {
|
||||
Sensor.TYPE_ACCELEROMETER -> {
|
||||
val x = motionAcelOrientation[0] * event.values[1]
|
||||
val y = motionAcelOrientation[1] * event.values[0]
|
||||
val z = motionAcelOrientation[2] * event.values[2]
|
||||
if (isRegistered)
|
||||
event?.apply {
|
||||
when (sensor.type) {
|
||||
Sensor.TYPE_ACCELEROMETER -> {
|
||||
val x = motionAcelOrientation[0] * event.values[1]
|
||||
val y = motionAcelOrientation[1] * event.values[0]
|
||||
val z = motionAcelOrientation[2] * event.values[2]
|
||||
|
||||
RyujinxNative.instance.inputSetAccelerometerData(x, y, z, controllerId)
|
||||
}
|
||||
RyujinxNative.instance.inputSetAccelerometerData(x, y, z, controllerId)
|
||||
}
|
||||
|
||||
Sensor.TYPE_GYROSCOPE -> {
|
||||
val x = motionGyroOrientation[0] * event.values[1]
|
||||
val y = motionGyroOrientation[1] * event.values[0]
|
||||
val z = motionGyroOrientation[2] * event.values[2]
|
||||
RyujinxNative.instance.inputSetGyroData(x, y, z, controllerId)
|
||||
Sensor.TYPE_GYROSCOPE -> {
|
||||
val x = motionGyroOrientation[0] * event.values[1]
|
||||
val y = motionGyroOrientation[1] * event.values[0]
|
||||
val z = motionGyroOrientation[2] * event.values[2]
|
||||
RyujinxNative.instance.inputSetGyroData(x, y, z, controllerId)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
RyujinxNative.instance.inputSetAccelerometerData(0.0F, 0.0F, 0.0F, controllerId)
|
||||
RyujinxNative.instance.inputSetGyroData(0.0F, 0.0F, 0.0F, controllerId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,8 @@ class MainViewModel(val activity: MainActivity) {
|
||||
activity.setFullScreen(true)
|
||||
navController?.navigate("game")
|
||||
activity.isGameRunning = true
|
||||
motionSensorManager?.register()
|
||||
if (QuickSettings(activity).enableMotion)
|
||||
motionSensorManager?.register()
|
||||
}
|
||||
|
||||
fun setProgressStates(
|
||||
|
@ -17,6 +17,7 @@ class QuickSettings(val activity: Activity) {
|
||||
var resScale : Float
|
||||
var isGrid : Boolean
|
||||
var useSwitchLayout : Boolean
|
||||
var enableMotion : Boolean
|
||||
|
||||
// Logs
|
||||
var enableDebugLogs: Boolean
|
||||
@ -43,6 +44,7 @@ class QuickSettings(val activity: Activity) {
|
||||
useVirtualController = sharedPref.getBoolean("useVirtualController", true)
|
||||
isGrid = sharedPref.getBoolean("isGrid", true)
|
||||
useSwitchLayout = sharedPref.getBoolean("useSwitchLayout", true)
|
||||
enableMotion = sharedPref.getBoolean("enableMotion", true)
|
||||
|
||||
enableDebugLogs = sharedPref.getBoolean("enableDebugLogs", false)
|
||||
enableStubLogs = sharedPref.getBoolean("enableStubLogs", false)
|
||||
@ -69,6 +71,7 @@ class QuickSettings(val activity: Activity) {
|
||||
editor.putBoolean("useVirtualController", useVirtualController)
|
||||
editor.putBoolean("isGrid", isGrid)
|
||||
editor.putBoolean("useSwitchLayout", useSwitchLayout)
|
||||
editor.putBoolean("enableMotion", enableMotion)
|
||||
|
||||
editor.putBoolean("enableDebugLogs", enableDebugLogs)
|
||||
editor.putBoolean("enableStubLogs", enableStubLogs)
|
||||
|
@ -55,6 +55,7 @@ class SettingsViewModel(var navController: NavHostController, val activity: Main
|
||||
useVirtualController: MutableState<Boolean>,
|
||||
isGrid: MutableState<Boolean>,
|
||||
useSwitchLayout: MutableState<Boolean>,
|
||||
enableMotion: MutableState<Boolean>,
|
||||
enableDebugLogs: MutableState<Boolean>,
|
||||
enableStubLogs: MutableState<Boolean>,
|
||||
enableInfoLogs: MutableState<Boolean>,
|
||||
@ -78,6 +79,7 @@ class SettingsViewModel(var navController: NavHostController, val activity: Main
|
||||
useVirtualController.value = sharedPref.getBoolean("useVirtualController", true)
|
||||
isGrid.value = sharedPref.getBoolean("isGrid", true)
|
||||
useSwitchLayout.value = sharedPref.getBoolean("useSwitchLayout", true)
|
||||
enableMotion.value = sharedPref.getBoolean("enableMotion", true)
|
||||
|
||||
enableDebugLogs.value = sharedPref.getBoolean("enableDebugLogs", false)
|
||||
enableStubLogs.value = sharedPref.getBoolean("enableStubLogs", false)
|
||||
@ -102,6 +104,7 @@ class SettingsViewModel(var navController: NavHostController, val activity: Main
|
||||
useVirtualController: MutableState<Boolean>,
|
||||
isGrid: MutableState<Boolean>,
|
||||
useSwitchLayout: MutableState<Boolean>,
|
||||
enableMotion: MutableState<Boolean>,
|
||||
enableDebugLogs: MutableState<Boolean>,
|
||||
enableStubLogs: MutableState<Boolean>,
|
||||
enableInfoLogs: MutableState<Boolean>,
|
||||
@ -125,6 +128,7 @@ class SettingsViewModel(var navController: NavHostController, val activity: Main
|
||||
editor.putBoolean("useVirtualController", useVirtualController.value)
|
||||
editor.putBoolean("isGrid", isGrid.value)
|
||||
editor.putBoolean("useSwitchLayout", useSwitchLayout.value)
|
||||
editor.putBoolean("enableMotion", enableMotion.value)
|
||||
|
||||
editor.putBoolean("enableDebugLogs", enableDebugLogs.value)
|
||||
editor.putBoolean("enableStubLogs", enableStubLogs.value)
|
||||
|
@ -20,6 +20,7 @@ import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -82,6 +83,9 @@ class GameViews {
|
||||
val enableVsync = remember {
|
||||
mutableStateOf(QuickSettings(mainViewModel.activity).enableVsync)
|
||||
}
|
||||
val enableMotion = remember {
|
||||
mutableStateOf(QuickSettings(mainViewModel.activity).enableMotion)
|
||||
}
|
||||
val showMore = remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
@ -169,28 +173,56 @@ class GameViews {
|
||||
modifier = Modifier.padding(16.dp),
|
||||
shape = MaterialTheme.shapes.medium
|
||||
) {
|
||||
Row(modifier = Modifier.padding(8.dp)) {
|
||||
IconButton(modifier = Modifier.padding(4.dp), onClick = {
|
||||
showMore.value = false
|
||||
showController.value = !showController.value
|
||||
ryujinxNative.inputReleaseTouchPoint()
|
||||
mainViewModel.controller?.setVisible(showController.value)
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.videoGame(),
|
||||
contentDescription = "Toggle Virtual Pad"
|
||||
Column {
|
||||
Row(
|
||||
modifier = Modifier,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = "Enable Motion",
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterVertically)
|
||||
.padding(end = 16.dp)
|
||||
)
|
||||
Switch(checked = enableMotion.value, onCheckedChange = {
|
||||
showMore.value = false
|
||||
enableMotion.value = !enableMotion.value
|
||||
val settings = QuickSettings(mainViewModel.activity)
|
||||
settings.enableMotion = enableMotion.value
|
||||
settings.save()
|
||||
if (enableMotion.value)
|
||||
mainViewModel.motionSensorManager?.register()
|
||||
else
|
||||
mainViewModel.motionSensorManager?.unregister()
|
||||
})
|
||||
}
|
||||
IconButton(modifier = Modifier.padding(4.dp), onClick = {
|
||||
showMore.value = false
|
||||
enableVsync.value = !enableVsync.value
|
||||
RyujinxNative.instance.graphicsRendererSetVsync(enableVsync.value)
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.vSync(),
|
||||
tint = if (enableVsync.value) Color.Green else Color.Red,
|
||||
contentDescription = "Toggle VSync"
|
||||
)
|
||||
Row(modifier = Modifier.padding(8.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
IconButton(modifier = Modifier.padding(4.dp), onClick = {
|
||||
showMore.value = false
|
||||
showController.value = !showController.value
|
||||
ryujinxNative.inputReleaseTouchPoint()
|
||||
mainViewModel.controller?.setVisible(showController.value)
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.videoGame(),
|
||||
contentDescription = "Toggle Virtual Pad"
|
||||
)
|
||||
}
|
||||
IconButton(modifier = Modifier.padding(4.dp), onClick = {
|
||||
showMore.value = false
|
||||
enableVsync.value = !enableVsync.value
|
||||
RyujinxNative.instance.graphicsRendererSetVsync(
|
||||
enableVsync.value
|
||||
)
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.vSync(),
|
||||
tint = if (enableVsync.value) Color.Green else Color.Red,
|
||||
contentDescription = "Toggle VSync"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +121,7 @@ class SettingViews {
|
||||
}
|
||||
val isGrid = remember { mutableStateOf(true) }
|
||||
val useSwitchLayout = remember { mutableStateOf(true) }
|
||||
val enableMotion = remember { mutableStateOf(true) }
|
||||
|
||||
val enableDebugLogs = remember { mutableStateOf(true) }
|
||||
val enableStubLogs = remember { mutableStateOf(true) }
|
||||
@ -142,6 +143,7 @@ class SettingViews {
|
||||
useVirtualController,
|
||||
isGrid,
|
||||
useSwitchLayout,
|
||||
enableMotion,
|
||||
enableDebugLogs,
|
||||
enableStubLogs,
|
||||
enableInfoLogs,
|
||||
@ -174,6 +176,7 @@ class SettingViews {
|
||||
useVirtualController,
|
||||
isGrid,
|
||||
useSwitchLayout,
|
||||
enableMotion,
|
||||
enableDebugLogs,
|
||||
enableStubLogs,
|
||||
enableInfoLogs,
|
||||
@ -857,6 +860,21 @@ class SettingViews {
|
||||
useVirtualController.value = !useVirtualController.value
|
||||
})
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(8.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = "Enable Motion",
|
||||
modifier = Modifier.align(Alignment.CenterVertically)
|
||||
)
|
||||
Switch(checked = enableMotion.value, onCheckedChange = {
|
||||
enableMotion.value = !enableMotion.value
|
||||
})
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -1023,6 +1041,7 @@ class SettingViews {
|
||||
useVirtualController,
|
||||
isGrid,
|
||||
useSwitchLayout,
|
||||
enableMotion,
|
||||
enableDebugLogs,
|
||||
enableStubLogs,
|
||||
enableInfoLogs,
|
||||
|
Loading…
x
Reference in New Issue
Block a user