switch to using stream base game loading

This commit is contained in:
Emmanuel Hansen 2023-08-05 13:07:14 +00:00
parent 3f8d269719
commit 8f8f9e996a
4 changed files with 34 additions and 7 deletions

View File

@ -12,6 +12,7 @@ import java.io.File
import kotlin.concurrent.thread
class GameHost(context: Context?, val mainViewModel: MainViewModel) : SurfaceView(context), SurfaceHolder.Callback {
private var game: GameModel? = null
private var _isClosed: Boolean = false
private var _renderingThreadWatcher: Thread? = null
private var _height: Int = 0
@ -71,6 +72,8 @@ class GameHost(context: Context?, val mainViewModel: MainViewModel) : SurfaceVie
if(_isStarted)
return;
game = mainViewModel.gameModel
_nativeRyujinx.inputInitialize(width, height)
val settings = QuickSettings(mainViewModel.activity)
@ -130,5 +133,7 @@ class GameHost(context: Context?, val mainViewModel: MainViewModel) : SurfaceVie
}
}
_nativeRyujinx.graphicsRendererRunLoop()
game?.close()
}
}
}

View File

@ -2,6 +2,7 @@ package org.ryujinx.android.viewmodels
import android.content.Context
import android.net.Uri
import android.os.ParcelFileDescriptor
import androidx.documentfile.provider.DocumentFile
import com.anggrayudi.storage.file.extension
import org.ryujinx.android.Helpers
@ -9,6 +10,7 @@ import org.ryujinx.android.RyujinxNative
class GameModel(var file: DocumentFile, val context: Context) {
private var descriptor: ParcelFileDescriptor? = null
var fileName: String?
var fileSize = 0.0
var titleName: String? = null
@ -37,7 +39,18 @@ class GameModel(var file: DocumentFile, val context: Context) {
return uri.path
}
fun getIsXci() : Boolean {
fun open() : Int {
descriptor = context.contentResolver.openFileDescriptor(file.uri, "rw")
return descriptor?.fd ?: 0
}
fun close() {
descriptor?.close()
descriptor = null
}
fun isXci() : Boolean {
return file.extension == "xci"
}
}
@ -49,4 +62,4 @@ class GameInfo {
var Developer: String? = null
var Version: String? = null
var IconCache: String? = null
}
}

View File

@ -20,6 +20,7 @@ import java.io.File
@SuppressLint("WrongConstant")
class MainViewModel(val activity: MainActivity) {
var gameModel: GameModel? = null
var gameHost: GameHost? = null
var controller: GameController? = null
var performanceManager: PerformanceManager? = null
@ -54,7 +55,12 @@ class MainViewModel(val activity: MainActivity) {
fun loadGame(game:GameModel) : Boolean {
var nativeRyujinx = RyujinxNative()
val path = game.getPath() ?: return false
val descriptor = game.open()
if(descriptor == 0)
return false
gameModel = game;
val settings = QuickSettings(activity)
@ -131,7 +137,7 @@ class MainViewModel(val activity: MainActivity) {
if(!success)
return false
success = nativeRyujinx.deviceLoad(path)
success = nativeRyujinx.deviceLoadDescriptor(descriptor, game.isXci())
if(!success)
return false
@ -171,4 +177,4 @@ class MainViewModel(val activity: MainActivity) {
fun backCalled() {
}
}
}

View File

@ -358,6 +358,9 @@ class HomeViews {
viewModel.mainViewModel?.navController?.navigate("game")
}
}
else {
gameModel.close()
}
showLoading.value = false
}
}
@ -421,4 +424,4 @@ class HomeViews {
fun HomePreview() {
Home()
}
}
}