Skip to content

Commit

Permalink
Move from Java to Kotlin
Browse files Browse the repository at this point in the history
This commit converts all Java code to Kotlin and improves the structure and performance of most rewritten parts.
  • Loading branch information
PixelyIon committed Dec 11, 2019
1 parent 3871698 commit 9db0c20
Show file tree
Hide file tree
Showing 22 changed files with 781 additions and 1,140 deletions.
1 change: 0 additions & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
Expand All @@ -13,6 +15,9 @@ android {
abiFilters "arm64-v8a"
}
}
kotlinOptions {
jvmTarget = "1.8"
}
buildTypes {
release {
debuggable true
Expand Down Expand Up @@ -51,4 +56,9 @@ dependencies {
implementation 'androidx.preference:preference:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'me.xdrop:fuzzywuzzy:1.2.0'
implementation "androidx.core:core-ktx:1.1.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
88 changes: 88 additions & 0 deletions app/src/main/java/emu/skyline/GameActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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
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
private var inputQueue: Long? = null
private lateinit var gameThread: Thread
private var halt: Boolean = false

private external fun executeRom(romString: String, romType: Int, romFd: Int, preferenceFd: Int, logFd: Int)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.game_activity)
rom = intent.getParcelableExtra("romUri")!!
val romType = intent.getIntExtra("romType", 0)
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")
logFd = ParcelFileDescriptor.open(log, ParcelFileDescriptor.MODE_READ_WRITE)
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()
halt = true
gameThread.join()
romFd.close()
preferenceFd.close()
logFd.close()
}

override fun surfaceCreated(holder: SurfaceHolder?) {
Log.d("surfaceCreated", "Holder: ${holder.toString()}")
surface = holder!!.surface
}

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
}

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
}

override fun onInputQueueDestroyed(queue: InputQueue?) {
Log.d("onInputQueueDestroyed", "InputQueue: ${queue.toString()}")
inputQueue = null
}
}
150 changes: 0 additions & 150 deletions app/src/main/java/emu/skyline/GameAdapter.java

This file was deleted.

Loading

0 comments on commit 9db0c20

Please sign in to comment.