mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-05-09 12:24:04 -05:00
Use existing settings API instead of custom jni calls
This commit is contained in:
parent
3572afcbbf
commit
371fa1a250
|
|
@ -25,7 +25,6 @@ import kotlinx.coroutines.flow.receiveAsFlow
|
|||
import kotlinx.coroutines.flow.runningFold
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.dolphinemu.dolphinemu.features.netplay.model.ConnectionType
|
||||
import org.dolphinemu.dolphinemu.features.netplay.model.NetplayMessage
|
||||
import org.dolphinemu.dolphinemu.features.netplay.model.Player
|
||||
import org.dolphinemu.dolphinemu.features.netplay.model.SaveTransferProgress
|
||||
|
|
@ -279,47 +278,6 @@ object Netplay {
|
|||
_saveTransferProgress.value = null
|
||||
}
|
||||
|
||||
// Settings
|
||||
object Settings {
|
||||
@JvmStatic
|
||||
external fun getNickname(): String
|
||||
|
||||
@JvmStatic
|
||||
external fun setNickname(nickname: String)
|
||||
|
||||
fun getConnectionType(): ConnectionType = ConnectionType.all
|
||||
.find { it.configValue == getTraversalChoice() } ?: throw IllegalStateException()
|
||||
|
||||
@JvmStatic
|
||||
external fun getTraversalChoice(): String
|
||||
|
||||
@JvmStatic
|
||||
external fun setTraversalChoice(traversalChoice: String)
|
||||
|
||||
@JvmStatic
|
||||
external fun getAddress(): String
|
||||
|
||||
@JvmStatic
|
||||
external fun setAddress(address: String)
|
||||
|
||||
@JvmStatic
|
||||
external fun getHostCode(): String
|
||||
|
||||
@JvmStatic
|
||||
external fun setHostCode(hostCode: String)
|
||||
|
||||
@JvmStatic
|
||||
external fun getConnectPort(): Int
|
||||
|
||||
@JvmStatic
|
||||
external fun setConnectPort(port: Int)
|
||||
|
||||
@JvmStatic
|
||||
external fun getClientBufferSize(): Int
|
||||
|
||||
@JvmStatic
|
||||
external fun setClientBufferSize(buffer: Int)
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> Channel<T>.flush() {
|
||||
|
|
|
|||
|
|
@ -20,5 +20,8 @@ sealed class ConnectionType(
|
|||
companion object {
|
||||
val all: List<ConnectionType>
|
||||
get() = listOf(DirectConnection, TraversalServer)
|
||||
|
||||
fun fromString(value: String): ConnectionType =
|
||||
all.find { it.configValue == value } ?: throw IllegalArgumentException("Invalid connection type: $value")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,25 +13,30 @@ import kotlinx.coroutines.flow.first
|
|||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import org.dolphinemu.dolphinemu.features.netplay.Netplay
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.NativeConfig
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheManager
|
||||
|
||||
class NetplaySetupViewModel : ViewModel() {
|
||||
private val _connectionRole = MutableStateFlow<ConnectionRole>(ConnectionRole.Connect)
|
||||
val connectionRole = _connectionRole.asStateFlow()
|
||||
|
||||
private val _nickname = MutableStateFlow(Netplay.Settings.getNickname())
|
||||
private val _nickname = MutableStateFlow(StringSetting.NETPLAY_NICKNAME.string)
|
||||
val nickname = _nickname.asStateFlow()
|
||||
|
||||
private val _connectionType = MutableStateFlow(Netplay.Settings.getConnectionType())
|
||||
private val _connectionType = MutableStateFlow(
|
||||
ConnectionType.fromString(StringSetting.NETPLAY_TRAVERSAL_CHOICE.string)
|
||||
)
|
||||
val connectionType = _connectionType.asStateFlow()
|
||||
|
||||
private val _ipAddress = MutableStateFlow(Netplay.Settings.getAddress())
|
||||
private val _ipAddress = MutableStateFlow(StringSetting.NETPLAY_ADDRESS.string)
|
||||
val ipAddress = _ipAddress.asStateFlow()
|
||||
|
||||
private val _hostCode = MutableStateFlow(Netplay.Settings.getHostCode())
|
||||
private val _hostCode = MutableStateFlow(StringSetting.NETPLAY_HOST_CODE.string)
|
||||
val hostCode = _hostCode.asStateFlow()
|
||||
|
||||
private val _connectPort = MutableStateFlow(Netplay.Settings.getConnectPort().toString())
|
||||
private val _connectPort = MutableStateFlow(IntSetting.NETPLAY_CONNECT_PORT.int.toString())
|
||||
val connectPort = _connectPort.asStateFlow()
|
||||
|
||||
private val _showNetplayScreen = Channel<Unit>(CONFLATED)
|
||||
|
|
@ -52,30 +57,34 @@ class NetplaySetupViewModel : ViewModel() {
|
|||
|
||||
fun setNickname(nickname: String) {
|
||||
_nickname.value = nickname
|
||||
Netplay.Settings.setNickname(nickname)
|
||||
StringSetting.NETPLAY_NICKNAME.setString(NativeConfig.LAYER_BASE, nickname)
|
||||
}
|
||||
|
||||
fun setConnectionType(connectionType: ConnectionType) {
|
||||
_connectionType.value = connectionType
|
||||
Netplay.Settings.setTraversalChoice(connectionType.configValue)
|
||||
StringSetting.NETPLAY_TRAVERSAL_CHOICE.setString(
|
||||
NativeConfig.LAYER_BASE, connectionType.configValue
|
||||
)
|
||||
}
|
||||
|
||||
fun setIpAddress(ipAddress: String) {
|
||||
if (ipAddress.all { it.isDigit() || it == '.' }) {
|
||||
_ipAddress.value = ipAddress
|
||||
Netplay.Settings.setAddress(ipAddress)
|
||||
StringSetting.NETPLAY_ADDRESS.setString(NativeConfig.LAYER_BASE, ipAddress)
|
||||
}
|
||||
}
|
||||
|
||||
fun setHostCode(hostCode: String) {
|
||||
_hostCode.value = hostCode
|
||||
Netplay.Settings.setHostCode(hostCode)
|
||||
StringSetting.NETPLAY_HOST_CODE.setString(NativeConfig.LAYER_BASE, hostCode)
|
||||
}
|
||||
|
||||
fun setConnectPort(port: String) {
|
||||
if (port.all { it.isDigit() }) {
|
||||
_connectPort.value = port
|
||||
port.toIntOrNull()?.let { Netplay.Settings.setConnectPort(it) }
|
||||
port.toIntOrNull()?.let {
|
||||
IntSetting.NETPLAY_CONNECT_PORT.setInt(NativeConfig.LAYER_BASE, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ import kotlinx.coroutines.flow.receiveAsFlow
|
|||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import org.dolphinemu.dolphinemu.features.netplay.Netplay
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.NativeConfig
|
||||
|
||||
//TODO save settings
|
||||
class NetplayViewModel : ViewModel() {
|
||||
val launchGame = Netplay.launchGame
|
||||
|
||||
|
|
@ -37,7 +38,7 @@ class NetplayViewModel : ViewModel() {
|
|||
val hostInputAuthority = Netplay.hostInputAuthorityEnabled
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false)
|
||||
|
||||
private val _maxBuffer = MutableStateFlow(Netplay.Settings.getClientBufferSize())
|
||||
private val _maxBuffer = MutableStateFlow(IntSetting.NETPLAY_CLIENT_BUFFER_SIZE.int)
|
||||
val maxBuffer = _maxBuffer.asStateFlow()
|
||||
|
||||
val saveTransferProgress = Netplay.saveTransferProgress
|
||||
|
|
@ -59,7 +60,7 @@ class NetplayViewModel : ViewModel() {
|
|||
|
||||
fun setMaxBuffer(buffer: Int) {
|
||||
_maxBuffer.value = buffer
|
||||
Netplay.Settings.setClientBufferSize(buffer)
|
||||
IntSetting.NETPLAY_CLIENT_BUFFER_SIZE.setInt(NativeConfig.LAYER_BASE, buffer)
|
||||
Netplay.adjustPadBufferSize(buffer)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,14 @@ enum class IntSetting(
|
|||
WIIMOTE_2_SOURCE(Settings.FILE_WIIMOTE, "Wiimote2", "Source", 0),
|
||||
WIIMOTE_3_SOURCE(Settings.FILE_WIIMOTE, "Wiimote3", "Source", 0),
|
||||
WIIMOTE_4_SOURCE(Settings.FILE_WIIMOTE, "Wiimote4", "Source", 0),
|
||||
WIIMOTE_BB_SOURCE(Settings.FILE_WIIMOTE, "BalanceBoard", "Source", 0);
|
||||
WIIMOTE_BB_SOURCE(Settings.FILE_WIIMOTE, "BalanceBoard", "Source", 0),
|
||||
NETPLAY_CONNECT_PORT(Settings.FILE_DOLPHIN, Settings.SECTION_INI_NETPLAY, "ConnectPort", 2626),
|
||||
NETPLAY_CLIENT_BUFFER_SIZE(
|
||||
Settings.FILE_DOLPHIN,
|
||||
Settings.SECTION_INI_NETPLAY,
|
||||
"BufferSizeClient",
|
||||
1
|
||||
);
|
||||
|
||||
override val isOverridden: Boolean
|
||||
get() = NativeConfig.isOverridden(file, section, key)
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ class Settings : Closeable {
|
|||
const val SECTION_INI_INTERFACE = "Interface"
|
||||
const val SECTION_INI_DSP = "DSP"
|
||||
const val SECTION_INI_GBA = "GBA"
|
||||
const val SECTION_INI_NETPLAY = "NetPlay"
|
||||
const val SECTION_LOGGER_LOGS = "Logs"
|
||||
const val SECTION_LOGGER_OPTIONS = "Options"
|
||||
const val SECTION_GFX_HARDWARE = "Hardware"
|
||||
|
|
|
|||
|
|
@ -101,7 +101,21 @@ enum class StringSetting(
|
|||
Settings.SECTION_ACHIEVEMENTS,
|
||||
"ApiToken",
|
||||
""
|
||||
);
|
||||
),
|
||||
NETPLAY_TRAVERSAL_CHOICE(
|
||||
Settings.FILE_DOLPHIN,
|
||||
Settings.SECTION_INI_NETPLAY,
|
||||
"TraversalChoice",
|
||||
"direct"
|
||||
),
|
||||
NETPLAY_HOST_CODE(
|
||||
Settings.FILE_DOLPHIN,
|
||||
Settings.SECTION_INI_NETPLAY,
|
||||
"HostCode",
|
||||
""
|
||||
),
|
||||
NETPLAY_ADDRESS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_NETPLAY, "Address", "127.0.0.1"),
|
||||
NETPLAY_NICKNAME(Settings.FILE_DOLPHIN, Settings.SECTION_INI_NETPLAY, "Nickname", "Player");
|
||||
|
||||
override val isOverridden: Boolean
|
||||
get() = NativeConfig.isOverridden(file, section, key)
|
||||
|
|
|
|||
|
|
@ -26,94 +26,6 @@ static NetPlay::NetPlayClient* GetPointer(JNIEnv* env)
|
|||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_getNickname(JNIEnv* env,
|
||||
jclass)
|
||||
{
|
||||
return ToJString(env, Config::Get(Config::NETPLAY_NICKNAME));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_setNickname(JNIEnv* env,
|
||||
jclass,
|
||||
jstring jnickname)
|
||||
{
|
||||
Config::SetBase(Config::NETPLAY_NICKNAME, GetJString(env, jnickname));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_getTraversalChoice(
|
||||
JNIEnv* env, jclass)
|
||||
{
|
||||
return ToJString(env, Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_setTraversalChoice(
|
||||
JNIEnv* env, jclass, jstring jtraversalChoice)
|
||||
{
|
||||
Config::SetBase(Config::NETPLAY_TRAVERSAL_CHOICE, GetJString(env, jtraversalChoice));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_getAddress(JNIEnv* env,
|
||||
jclass)
|
||||
{
|
||||
return ToJString(env, Config::Get(Config::NETPLAY_ADDRESS));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_setAddress(JNIEnv* env,
|
||||
jclass,
|
||||
jstring jaddress)
|
||||
{
|
||||
Config::SetBase(Config::NETPLAY_ADDRESS, GetJString(env, jaddress));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_getHostCode(JNIEnv* env,
|
||||
jclass)
|
||||
{
|
||||
return ToJString(env, Config::Get(Config::NETPLAY_HOST_CODE));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_setHostCode(JNIEnv* env,
|
||||
jclass,
|
||||
jstring jhostCode)
|
||||
{
|
||||
Config::SetBase(Config::NETPLAY_HOST_CODE, GetJString(env, jhostCode));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_getConnectPort(JNIEnv*,
|
||||
jclass)
|
||||
{
|
||||
return static_cast<jint>(Config::Get(Config::NETPLAY_CONNECT_PORT));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_setConnectPort(JNIEnv*,
|
||||
jclass,
|
||||
jint port)
|
||||
{
|
||||
Config::SetBase(Config::NETPLAY_CONNECT_PORT, static_cast<u16>(port));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_getClientBufferSize(JNIEnv*,
|
||||
jclass)
|
||||
{
|
||||
return static_cast<jint>(Config::Get(Config::NETPLAY_CLIENT_BUFFER_SIZE));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_00024Settings_setClientBufferSize(
|
||||
JNIEnv*, jclass, jint buffer)
|
||||
{
|
||||
Config::SetBase(Config::NETPLAY_CLIENT_BUFFER_SIZE, static_cast<u32>(buffer));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_netplay_Netplay_isClientConnected(JNIEnv* env, jclass)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user