summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorTom Pratt <tom.pratt@outlook.com>2026-04-09 23:26:58 +0200
committerTom Pratt <tompratt@squareup.com>2026-05-19 12:02:55 +0200
commitaf2fda564954b975115b212221aa13f0308fe406 (patch)
tree71ea4b5b8004c1ec5f91d8af01a508a402bd0922 /Source/Android/app/src/main/java
parentb72f3c1afc6a4d4ba3dfffa19de33a425c55d679 (diff)
Reorder netplay class
Put all the boring settings at the bottom to reduce scrolling!
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/netplay/Netplay.kt98
1 files 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,10 +27,61 @@ object Netplay {
private val _connectionErrors = Channel<String>(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
fun getConnectionType(): ConnectionType = ConnectionType.all
@@ -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<String>.flush() {