Store netplay BootSessionData and use it to run the netplay game

This commit is contained in:
Tom Pratt
2026-04-08 15:20:19 +01:00
committed by Tom Pratt
parent 766374434c
commit 3ed9174208
8 changed files with 82 additions and 4 deletions

View File

@@ -342,6 +342,12 @@ object NativeLibrary {
@JvmStatic
external fun RunSystemMenu()
/**
* Begins emulation for a netplay session, using the BootSessionData provided by the host.
*/
@JvmStatic
external fun RunNetPlay(paths: Array<String>, riivolution: Boolean)
@JvmStatic
external fun ChangeDisc(path: String)

View File

@@ -4,12 +4,23 @@
package org.dolphinemu.dolphinemu.features.netplay
import androidx.annotation.Keep
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import org.dolphinemu.dolphinemu.features.netplay.model.ConnectionType
object Netplay {
@Keep
private var netPlayClientPointer: Long = 0
@Keep
private var bootSessionDataPointer: Long = 0
val isLaunching: Boolean
get() = bootSessionDataPointer != 0L
private val _launchGame = Channel<String>(Channel.CONFLATED)
val launchGame = _launchGame.receiveAsFlow()
@JvmStatic
external fun getNickname(): String
@@ -103,4 +114,10 @@ object Netplay {
@JvmStatic
private external fun Join(): Long
@JvmStatic
fun onBootGame(gameFilePath: String, bootSessionDataPointer: Long) {
this.bootSessionDataPointer = bootSessionDataPointer
_launchGame.trySend(gameFilePath)
}
}

View File

@@ -46,7 +46,12 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.dolphinemu.dolphinemu.R
import org.dolphinemu.dolphinemu.activities.EmulationActivity
import org.dolphinemu.dolphinemu.features.netplay.Netplay
import org.dolphinemu.dolphinemu.features.netplay.model.ConnectionRole
import org.dolphinemu.dolphinemu.features.netplay.model.ConnectionType
import org.dolphinemu.dolphinemu.features.netplay.model.NetplaySetupViewModel
@@ -64,6 +69,10 @@ class NetplaySetupActivity : AppCompatActivity(), ThemeProvider {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
Netplay.launchGame
.onEach { EmulationActivity.launch(this, it, false) }
.launchIn(lifecycleScope)
viewModel = ViewModelProvider(this)[NetplaySetupViewModel::class.java]
setContent {

View File

@@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment
import org.dolphinemu.dolphinemu.NativeLibrary
import org.dolphinemu.dolphinemu.activities.EmulationActivity
import org.dolphinemu.dolphinemu.databinding.FragmentEmulationBinding
import org.dolphinemu.dolphinemu.features.netplay.Netplay
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting
import org.dolphinemu.dolphinemu.features.settings.model.Settings
import org.dolphinemu.dolphinemu.overlay.InputOverlay
@@ -214,6 +215,12 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
if (launchSystemMenu) {
Log.debug("[EmulationFragment] Starting emulation thread for the Wii Menu.")
NativeLibrary.RunSystemMenu()
} else if (Netplay.isLaunching) {
Log.debug("[EmulationFragment] Starting emulation thread for Netplay.")
val paths = requireNotNull(gamePaths) {
"Cannot start emulation without any game paths"
}
NativeLibrary.RunNetPlay(paths, riivolution)
} else {
Log.debug("[EmulationFragment] Starting emulation thread.")
val paths = requireNotNull(gamePaths) {