diff options
3 files changed, 24 insertions, 13 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index 82f8e3b50..d17e087fe 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt | |||
| @@ -38,7 +38,6 @@ import androidx.window.layout.WindowLayoutInfo | |||
| 38 | import com.google.android.material.dialog.MaterialAlertDialogBuilder | 38 | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| 39 | import com.google.android.material.slider.Slider | 39 | import com.google.android.material.slider.Slider |
| 40 | import kotlinx.coroutines.Dispatchers | 40 | import kotlinx.coroutines.Dispatchers |
| 41 | import kotlinx.coroutines.flow.collect | ||
| 42 | import kotlinx.coroutines.flow.collectLatest | 41 | import kotlinx.coroutines.flow.collectLatest |
| 43 | import kotlinx.coroutines.launch | 42 | import kotlinx.coroutines.launch |
| 44 | import org.yuzu.yuzu_emu.HomeNavigationDirections | 43 | import org.yuzu.yuzu_emu.HomeNavigationDirections |
| @@ -141,7 +140,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 141 | 140 | ||
| 142 | // So this fragment doesn't restart on configuration changes; i.e. rotation. | 141 | // So this fragment doesn't restart on configuration changes; i.e. rotation. |
| 143 | retainInstance = true | 142 | retainInstance = true |
| 144 | emulationState = EmulationState(game.path) | 143 | emulationState = EmulationState(game.path) { |
| 144 | return@EmulationState driverViewModel.isInteractionAllowed.value | ||
| 145 | } | ||
| 145 | } | 146 | } |
| 146 | 147 | ||
| 147 | /** | 148 | /** |
| @@ -371,6 +372,15 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 371 | } | 372 | } |
| 372 | } | 373 | } |
| 373 | launch { | 374 | launch { |
| 375 | repeatOnLifecycle(Lifecycle.State.RESUMED) { | ||
| 376 | driverViewModel.isInteractionAllowed.collect { | ||
| 377 | if (it) { | ||
| 378 | startEmulation() | ||
| 379 | } | ||
| 380 | } | ||
| 381 | } | ||
| 382 | } | ||
| 383 | launch { | ||
| 374 | repeatOnLifecycle(Lifecycle.State.CREATED) { | 384 | repeatOnLifecycle(Lifecycle.State.CREATED) { |
| 375 | emulationViewModel.emulationStarted.collectLatest { | 385 | emulationViewModel.emulationStarted.collectLatest { |
| 376 | if (it) { | 386 | if (it) { |
| @@ -398,19 +408,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 398 | } | 408 | } |
| 399 | } | 409 | } |
| 400 | } | 410 | } |
| 401 | launch { | ||
| 402 | repeatOnLifecycle(Lifecycle.State.RESUMED) { | ||
| 403 | driverViewModel.isInteractionAllowed.collect { | ||
| 404 | if (it) { | ||
| 405 | onEmulationStart() | ||
| 406 | } | ||
| 407 | } | ||
| 408 | } | ||
| 409 | } | ||
| 410 | } | 411 | } |
| 411 | } | 412 | } |
| 412 | 413 | ||
| 413 | private fun onEmulationStart() { | 414 | private fun startEmulation() { |
| 414 | if (!NativeLibrary.isRunning() && !NativeLibrary.isPaused()) { | 415 | if (!NativeLibrary.isRunning() && !NativeLibrary.isPaused()) { |
| 415 | if (!DirectoryInitialization.areDirectoriesReady) { | 416 | if (!DirectoryInitialization.areDirectoriesReady) { |
| 416 | DirectoryInitialization.start() | 417 | DirectoryInitialization.start() |
| @@ -810,7 +811,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 810 | } | 811 | } |
| 811 | } | 812 | } |
| 812 | 813 | ||
| 813 | private class EmulationState(private val gamePath: String) { | 814 | private class EmulationState( |
| 815 | private val gamePath: String, | ||
| 816 | private val emulationCanStart: () -> Boolean | ||
| 817 | ) { | ||
| 814 | private var state: State | 818 | private var state: State |
| 815 | private var surface: Surface? = null | 819 | private var surface: Surface? = null |
| 816 | 820 | ||
| @@ -904,6 +908,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 904 | State.PAUSED -> Log.warning( | 908 | State.PAUSED -> Log.warning( |
| 905 | "[EmulationFragment] Surface cleared while emulation paused." | 909 | "[EmulationFragment] Surface cleared while emulation paused." |
| 906 | ) | 910 | ) |
| 911 | |||
| 907 | else -> Log.warning( | 912 | else -> Log.warning( |
| 908 | "[EmulationFragment] Surface cleared while emulation stopped." | 913 | "[EmulationFragment] Surface cleared while emulation stopped." |
| 909 | ) | 914 | ) |
| @@ -913,6 +918,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 913 | 918 | ||
| 914 | private fun runWithValidSurface() { | 919 | private fun runWithValidSurface() { |
| 915 | NativeLibrary.surfaceChanged(surface) | 920 | NativeLibrary.surfaceChanged(surface) |
| 921 | if (!emulationCanStart.invoke()) { | ||
| 922 | return | ||
| 923 | } | ||
| 924 | |||
| 916 | when (state) { | 925 | when (state) { |
| 917 | State.STOPPED -> { | 926 | State.STOPPED -> { |
| 918 | val emulationThread = Thread({ | 927 | val emulationThread = Thread({ |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt index 15ae3a42b..5ed754c96 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt | |||
| @@ -144,6 +144,7 @@ class DriverViewModel : ViewModel() { | |||
| 144 | val selectedDriverFile = File(StringSetting.DRIVER_PATH.getString()) | 144 | val selectedDriverFile = File(StringSetting.DRIVER_PATH.getString()) |
| 145 | val selectedDriverMetadata = GpuDriverHelper.customDriverSettingData | 145 | val selectedDriverMetadata = GpuDriverHelper.customDriverSettingData |
| 146 | if (GpuDriverHelper.installedCustomDriverData == selectedDriverMetadata) { | 146 | if (GpuDriverHelper.installedCustomDriverData == selectedDriverMetadata) { |
| 147 | setDriverReady() | ||
| 147 | return | 148 | return |
| 148 | } | 149 | } |
| 149 | 150 | ||
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index c6c55b20c..c20c2d2b8 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp | |||
| @@ -247,6 +247,7 @@ Core::SystemResultStatus EmulationSession::InitializeEmulation(const std::string | |||
| 247 | m_system.GetCpuManager().OnGpuReady(); | 247 | m_system.GetCpuManager().OnGpuReady(); |
| 248 | m_system.RegisterExitCallback([&] { HaltEmulation(); }); | 248 | m_system.RegisterExitCallback([&] { HaltEmulation(); }); |
| 249 | 249 | ||
| 250 | OnEmulationStarted(); | ||
| 250 | return Core::SystemResultStatus::Success; | 251 | return Core::SystemResultStatus::Success; |
| 251 | } | 252 | } |
| 252 | 253 | ||