From bfa68bf935aa9c034affc2d3fb16fb6531e48072 Mon Sep 17 00:00:00 2001 From: Tom Pratt Date: Thu, 9 Apr 2026 23:26:58 +0200 Subject: [PATCH] Reorder netplay class Put all the boring settings at the bottom to reduce scrolling! --- .../dolphinemu/features/netplay/Netplay.kt | 98 ++++++++++--------- 1 file changed, 51 insertions(+), 47 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 41b2bb6f8a..9b19c9c2fd 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 @@ -27,9 +27,60 @@ object Netplay { private val _connectionErrors = Channel(Channel.BUFFERED) val connectionErrors = _connectionErrors.receiveAsFlow() + suspend fun join(): Boolean = withContext(Dispatchers.IO) { + netPlayClientPointer = Join() + val isConnected = netPlayClientPointer != 0L && isClientConnected() + + if (!isActive) { + releaseNetplayClient() + return@withContext false + } + + if (isConnected) { + return@withContext true + } + + releaseNetplayClient() + false + } + + suspend fun quit() = withContext(Dispatchers.IO) { + releaseNetplayClient() + } + + private fun releaseNetplayClient() { + if (netPlayClientPointer != 0L) { + ReleaseNetplayClient() + netPlayClientPointer = 0 + } + _launchGame.flush() + _connectionErrors.flush() + } + + @JvmStatic + private external fun Join(): Long + @JvmStatic external fun isClientConnected(): Boolean + @JvmStatic + private external fun ReleaseNetplayClient() + + // NetPlayUI callbacks + + @JvmStatic + fun onBootGame(gameFilePath: String, bootSessionDataPointer: Long) { + this.bootSessionDataPointer = bootSessionDataPointer + _launchGame.trySend(gameFilePath) + } + + @JvmStatic + fun onConnectionError(message: String) { + _connectionErrors.trySend(message) + } + + // Settings + @JvmStatic external fun getNickname(): String @@ -116,53 +167,6 @@ object Netplay { indexName: String, indexPassword: String, ) - - suspend fun join(): Boolean = withContext(Dispatchers.IO) { - netPlayClientPointer = Join() - val isConnected = netPlayClientPointer != 0L && isClientConnected() - - if (!isActive) { - releaseNetplayClient() - return@withContext false - } - - if (isConnected) { - return@withContext true - } - - releaseNetplayClient() - false - } - - suspend fun quit() = withContext(Dispatchers.IO) { - releaseNetplayClient() - } - - private fun releaseNetplayClient() { - if (netPlayClientPointer != 0L) { - ReleaseNetplayClient() - netPlayClientPointer = 0 - } - _launchGame.flush() - _connectionErrors.flush() - } - - @JvmStatic - private external fun Join(): Long - - @JvmStatic - private external fun ReleaseNetplayClient() - - @JvmStatic - fun onBootGame(gameFilePath: String, bootSessionDataPointer: Long) { - this.bootSessionDataPointer = bootSessionDataPointer - _launchGame.trySend(gameFilePath) - } - - @JvmStatic - fun onConnectionError(message: String) { - _connectionErrors.trySend(message) - } } private fun Channel.flush() {