2019-12-02 14:39:08 +01:00
|
|
|
package emu.skyline
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.ParcelFileDescriptor
|
|
|
|
import android.util.Log
|
|
|
|
import android.view.InputQueue
|
|
|
|
import android.view.Surface
|
|
|
|
import android.view.SurfaceHolder
|
|
|
|
import android.view.WindowManager
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2019-12-11 01:14:16 +01:00
|
|
|
import emu.skyline.loader.getTitleFormat
|
2019-12-02 14:39:08 +01:00
|
|
|
import kotlinx.android.synthetic.main.game_activity.*
|
|
|
|
import java.io.File
|
|
|
|
import java.lang.reflect.Method
|
|
|
|
|
|
|
|
class GameActivity : AppCompatActivity(), SurfaceHolder.Callback, InputQueue.Callback {
|
|
|
|
init {
|
|
|
|
System.loadLibrary("skyline") // libskyline.so
|
|
|
|
}
|
|
|
|
|
|
|
|
private lateinit var rom: Uri
|
|
|
|
private lateinit var romFd: ParcelFileDescriptor
|
|
|
|
private lateinit var preferenceFd: ParcelFileDescriptor
|
|
|
|
private lateinit var logFd: ParcelFileDescriptor
|
|
|
|
private var surface: Surface? = null
|
2019-12-26 19:10:29 +01:00
|
|
|
private var inputQueue: Long = 0L
|
2019-12-02 14:39:08 +01:00
|
|
|
private lateinit var gameThread: Thread
|
|
|
|
|
|
|
|
private external fun executeRom(romString: String, romType: Int, romFd: Int, preferenceFd: Int, logFd: Int)
|
2019-12-26 19:10:29 +01:00
|
|
|
private external fun setHalt(halt: Boolean)
|
|
|
|
private external fun setSurface(surface: Surface?)
|
2019-12-02 14:39:08 +01:00
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.game_activity)
|
2019-12-11 01:14:16 +01:00
|
|
|
rom = intent.data!!
|
|
|
|
val romType = getTitleFormat(rom, contentResolver).ordinal
|
2019-12-02 14:39:08 +01:00
|
|
|
romFd = contentResolver.openFileDescriptor(rom, "r")!!
|
|
|
|
val preference = File("${applicationInfo.dataDir}/shared_prefs/${applicationInfo.packageName}_preferences.xml")
|
|
|
|
preferenceFd = ParcelFileDescriptor.open(preference, ParcelFileDescriptor.MODE_READ_WRITE)
|
|
|
|
val log = File("${applicationInfo.dataDir}/skyline.log")
|
2019-12-02 18:40:53 +01:00
|
|
|
logFd = ParcelFileDescriptor.open(log, ParcelFileDescriptor.MODE_CREATE or ParcelFileDescriptor.MODE_READ_WRITE)
|
2019-12-02 14:39:08 +01:00
|
|
|
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
|
|
|
game_view.holder.addCallback(this)
|
|
|
|
//window.takeInputQueue(this)
|
|
|
|
gameThread = Thread {
|
|
|
|
while ((surface == null))
|
|
|
|
Thread.yield()
|
|
|
|
executeRom(Uri.decode(rom.toString()), romType, romFd.fd, preferenceFd.fd, logFd.fd)
|
|
|
|
runOnUiThread { finish() }
|
|
|
|
}
|
|
|
|
gameThread.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
super.onDestroy()
|
2019-12-26 19:10:29 +01:00
|
|
|
setHalt(true)
|
2019-12-02 14:39:08 +01:00
|
|
|
gameThread.join()
|
|
|
|
romFd.close()
|
|
|
|
preferenceFd.close()
|
|
|
|
logFd.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun surfaceCreated(holder: SurfaceHolder?) {
|
|
|
|
Log.d("surfaceCreated", "Holder: ${holder.toString()}")
|
|
|
|
surface = holder!!.surface
|
2019-12-26 19:10:29 +01:00
|
|
|
setSurface(surface)
|
2019-12-02 14:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun surfaceChanged(holder: SurfaceHolder?, format: Int, width: Int, height: Int) {
|
|
|
|
Log.d("surfaceChanged", "Holder: ${holder.toString()}, Format: $format, Width: $width, Height: $height")
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun surfaceDestroyed(holder: SurfaceHolder?) {
|
|
|
|
Log.d("surfaceDestroyed", "Holder: ${holder.toString()}")
|
|
|
|
surface = null
|
2019-12-26 19:10:29 +01:00
|
|
|
setSurface(surface)
|
2019-12-02 14:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onInputQueueCreated(queue: InputQueue?) {
|
|
|
|
Log.i("onInputQueueCreated", "InputQueue: ${queue.toString()}")
|
|
|
|
val clazz = Class.forName("android.view.InputQueue")
|
|
|
|
val method: Method = clazz.getMethod("getNativePtr")
|
|
|
|
inputQueue = method.invoke(queue)!! as Long
|
2019-12-26 19:10:29 +01:00
|
|
|
//setQueue(inputQueue)
|
2019-12-02 14:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onInputQueueDestroyed(queue: InputQueue?) {
|
|
|
|
Log.d("onInputQueueDestroyed", "InputQueue: ${queue.toString()}")
|
2019-12-26 19:10:29 +01:00
|
|
|
inputQueue = 0L
|
|
|
|
//setQueue(inputQueue)
|
2019-12-02 14:39:08 +01:00
|
|
|
}
|
|
|
|
}
|