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