diff options
| author | Tom Pratt <tom.pratt@outlook.com> | 2026-04-22 18:46:12 +0200 |
|---|---|---|
| committer | Tom Pratt <tompratt@squareup.com> | 2026-05-19 12:02:56 +0200 |
| commit | 38b5c7370c47a6760bfce4cb8f9c45ab5d403dbb (patch) | |
| tree | 7134ed6dea86f946d184f39633ba1fcc0174af5c /Source/Android/app/src/main/java | |
| parent | 86956b21bea7f6450f180fddf2ffcb2e1077a3b6 (diff) | |
Implement StopGame callback and use it to finish the emulation activity
Diffstat (limited to 'Source/Android/app/src/main/java')
| -rw-r--r-- | Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/netplay/Netplay.kt | 13 | ||||
| -rw-r--r-- | Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt | 7 |
2 files changed, 19 insertions, 1 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/netplay/Netplay.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/netplay/Netplay.kt index 94de9bd98c..a90d1b00d8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/netplay/Netplay.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/netplay/Netplay.kt @@ -44,6 +44,9 @@ object Netplay { private val _launchGame = Channel<String>(Channel.CONFLATED) val launchGame = _launchGame.receiveAsFlow() + private val _stopGame = Channel<Unit>(Channel.CONFLATED) + val stopGame = _stopGame.receiveAsFlow() + private val _connectionErrors = Channel<String>(Channel.BUFFERED) val connectionErrors = _connectionErrors.receiveAsFlow() @@ -123,6 +126,7 @@ object Netplay { } _launchGame.flush() + _stopGame.flush() _connectionErrors.flush() _players.resetReplayCache() _messages.resetReplayCache() @@ -166,9 +170,16 @@ object Netplay { @JvmStatic fun onBootGame(gameFilePath: String, bootSessionDataPointer: Long) { this.bootSessionDataPointer = bootSessionDataPointer + _stopGame.flush() _launchGame.trySend(gameFilePath) } + @Keep + @JvmStatic + fun onStopGame() { + _stopGame.trySend(Unit) + } + @JvmStatic fun onConnectionError(message: String) { _connectionErrors.trySend(message) @@ -244,6 +255,6 @@ object Netplay { } } -private fun Channel<String>.flush() { +private fun <T> Channel<T>.flush() { while (this.tryReceive().isSuccess) Unit } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt index 4ee4aee8aa..61a5493950 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.kt @@ -10,6 +10,9 @@ import android.view.SurfaceHolder import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import androidx.lifecycle.lifecycleScope +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.launch import org.dolphinemu.dolphinemu.NativeLibrary import org.dolphinemu.dolphinemu.activities.EmulationActivity import org.dolphinemu.dolphinemu.databinding.FragmentEmulationBinding @@ -220,6 +223,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { val paths = requireNotNull(gamePaths) { "Cannot start emulation without any game paths" } + lifecycleScope.launch { + Netplay.stopGame.first() + stopEmulation() + } NativeLibrary.RunNetPlay(paths, riivolution) } else { Log.debug("[EmulationFragment] Starting emulation thread.") |
