mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
deferred savegame collection for faster startup
This commit is contained in:
@@ -26,10 +26,10 @@ import kotlin.math.roundToInt
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2023-06-24.
|
* Created by minjaesong on 2023-06-24.
|
||||||
*/
|
*/
|
||||||
class SavegameCollection(files0: List<DiskSkimmer>) {
|
class SavegameCollection(files0: List<DiskSkimmer>, prefiltered: Boolean) {
|
||||||
|
|
||||||
/** Sorted in reverse by the last modified time of the files, index zero being the most recent */
|
/** Sorted in reverse by the last modified time of the files, index zero being the most recent */
|
||||||
val files = files0.sortedBy { it.diskFile.name }.sortedByDescending {
|
val files = if (prefiltered) files0 else files0.sortedBy { it.diskFile.name }.sortedByDescending {
|
||||||
it.getLastModifiedTime().shl(2) or
|
it.getLastModifiedTime().shl(2) or
|
||||||
it.diskFile.extension.matches(Regex("^[abc]${'$'}")).toLong(1) or
|
it.diskFile.extension.matches(Regex("^[abc]${'$'}")).toLong(1) or
|
||||||
it.diskFile.extension.isBlank().toLong(0)
|
it.diskFile.extension.isBlank().toLong(0)
|
||||||
@@ -40,19 +40,28 @@ class SavegameCollection(files0: List<DiskSkimmer>) {
|
|||||||
val manualSaves = files.filter { !it.diskFile.extension.matches(Regex("[a-z]")) }
|
val manualSaves = files.filter { !it.diskFile.extension.matches(Regex("[a-z]")) }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
printdbg(this, "Rebuilding skimmers (${files.size})")
|
||||||
|
// files.forEach { it.rebuild() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rebuildLoadable() {
|
||||||
|
loadable().rebuild()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rebuildAll() {
|
||||||
files.forEach { it.rebuild() }
|
files.forEach { it.rebuild() }
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun collectFromBaseFilename(skimmers: List<DiskSkimmer>, name: String): SavegameCollection {
|
fun collectFromBaseFilename(skimmers: List<DiskSkimmer>, name: String): SavegameCollection {
|
||||||
return SavegameCollection(skimmers)
|
return SavegameCollection(skimmers, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun collectFromBaseFilename(dir: File, name: String): SavegameCollection {
|
fun collectFromBaseFilename(dir: File, name: String): SavegameCollection {
|
||||||
val files = dir.listFiles().filter { it.name.startsWith(name) }
|
val files = dir.listFiles().filter { it.name.startsWith(name) }
|
||||||
.mapNotNull { try { DiskSkimmer(it, true) } catch (e: Throwable) { null } }
|
.mapNotNull { try { DiskSkimmer(it, true) } catch (e: Throwable) { null } }
|
||||||
return SavegameCollection(files)
|
return SavegameCollection(files, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -799,7 +799,7 @@ fun AppUpdateListOfSavegames() {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}.sortedByDescending { it.getLastModifiedTime() }
|
}.sortedByDescending { it.getLastModifiedTime() }
|
||||||
val filteringResults = arrayListOf<List<DiskSkimmer>>()
|
val filteringResults = arrayListOf<List<DiskSkimmer>>() // first element of the list is always file with no suffix
|
||||||
worldsDirLs.forEach {
|
worldsDirLs.forEach {
|
||||||
val li = arrayListOf(it)
|
val li = arrayListOf(it)
|
||||||
listOf(".1",".2",".3",".a",".b",".c").forEach { suffix ->
|
listOf(".1",".2",".3",".a",".b",".c").forEach { suffix ->
|
||||||
@@ -818,6 +818,8 @@ fun AppUpdateListOfSavegames() {
|
|||||||
|
|
||||||
printdbg("ListSavegames", " collecting...")
|
printdbg("ListSavegames", " collecting...")
|
||||||
val collection = SavegameCollection.collectFromBaseFilename(list, it.diskFile.name)
|
val collection = SavegameCollection.collectFromBaseFilename(list, it.diskFile.name)
|
||||||
|
printdbg("ListSavegames", " disk rebuilding...")
|
||||||
|
collection.rebuildLoadable()
|
||||||
printdbg("ListSavegames", " get UUID...")
|
printdbg("ListSavegames", " get UUID...")
|
||||||
val worldUUID = collection.getUUID()
|
val worldUUID = collection.getUUID()
|
||||||
|
|
||||||
@@ -862,6 +864,8 @@ fun AppUpdateListOfSavegames() {
|
|||||||
|
|
||||||
printdbg("ListSavegames", " collecting...")
|
printdbg("ListSavegames", " collecting...")
|
||||||
val collection = SavegameCollection.collectFromBaseFilename(list, it.diskFile.name)
|
val collection = SavegameCollection.collectFromBaseFilename(list, it.diskFile.name)
|
||||||
|
printdbg("ListSavegames", " disk rebuilding...")
|
||||||
|
collection.rebuildLoadable()
|
||||||
printdbg("ListSavegames", " get UUID...")
|
printdbg("ListSavegames", " get UUID...")
|
||||||
val playerUUID = collection.getUUID()
|
val playerUUID = collection.getUUID()
|
||||||
|
|
||||||
|
|||||||
@@ -523,6 +523,7 @@ class UIItemPlayerCells(
|
|||||||
val loadable = App.savegamePlayers[playerUUID]!!.loadable()
|
val loadable = App.savegamePlayers[playerUUID]!!.loadable()
|
||||||
printdbg(this, "UUID: ${playerUUID}")
|
printdbg(this, "UUID: ${playerUUID}")
|
||||||
printdbg(this, "File: ${loadable.diskFile.absolutePath}")
|
printdbg(this, "File: ${loadable.diskFile.absolutePath}")
|
||||||
|
loadable.rebuild()
|
||||||
loadable.getFile(SAVEGAMEINFO)?.bytes?.let {
|
loadable.getFile(SAVEGAMEINFO)?.bytes?.let {
|
||||||
var lastPlayTime0 = 0L
|
var lastPlayTime0 = 0L
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
|||||||
|
|
||||||
if (altDown && savegameIsNotNew) {
|
if (altDown && savegameIsNotNew) {
|
||||||
mode = MODE_PREV_SAVES
|
mode = MODE_PREV_SAVES
|
||||||
|
loadPrevGameInfo()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (full.loadables.saveAvaliable()) {
|
if (full.loadables.saveAvaliable()) {
|
||||||
@@ -242,19 +243,20 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
|||||||
super.show()
|
super.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun loadSavegameInfo() {
|
private fun loadPrevGameInfo() {
|
||||||
val players = App.savegamePlayers[full.playerButtonSelected!!.playerUUID]!!.files
|
val players = App.savegamePlayers[full.playerButtonSelected!!.playerUUID]!!.files
|
||||||
val worlds = App.savegameWorlds[full.playerButtonSelected!!.worldUUID]!!.files
|
val worlds = App.savegameWorlds[full.playerButtonSelected!!.worldUUID]!!.files
|
||||||
|
|
||||||
val playerSavesInfo = players.map { it.getSavegameMeta() }
|
val playerSavesInfo = players.map { it.getSavegameMeta() }
|
||||||
val worldSavesInfo = worlds.map { it.getSavegameMeta() }
|
val worldSavesInfo = worlds.map { it.getSavegameMeta() }
|
||||||
|
|
||||||
sortedPlayerWorldList = getChronologicalPair(playerSavesInfo, worldSavesInfo)
|
sortedPlayerWorldList = getChronologicalPair(playerSavesInfo, worldSavesInfo)
|
||||||
|
|
||||||
px48 = playerModTextboxX + (modulesTextboxW - tbw48) / 2
|
px48 = playerModTextboxX + (modulesTextboxW - tbw48) / 2
|
||||||
wx48 = worldModTextboxX + (modulesTextboxW - tbw48) / 2
|
wx48 = worldModTextboxX + (modulesTextboxW - tbw48) / 2
|
||||||
totalTBH48 = sortedPlayerWorldList.size * 32
|
totalTBH48 = sortedPlayerWorldList.size * 32
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun loadSavegameInfo() {
|
||||||
playerName = App.savegamePlayersName[full.playerButtonSelected!!.playerUUID] ?: "Player"
|
playerName = App.savegamePlayersName[full.playerButtonSelected!!.playerUUID] ?: "Player"
|
||||||
|
|
||||||
loadOrderPlayer =
|
loadOrderPlayer =
|
||||||
@@ -437,6 +439,7 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun DiskSkimmer.getSavegameMeta(): SavegameMeta {
|
private fun DiskSkimmer.getSavegameMeta(): SavegameMeta {
|
||||||
|
if (!this.initialised) this.rebuild()
|
||||||
this.getFile(SAVEGAMEINFO)!!.bytes.let {
|
this.getFile(SAVEGAMEINFO)!!.bytes.let {
|
||||||
var lastPlayTime = 0L
|
var lastPlayTime = 0L
|
||||||
var versionString = ""
|
var versionString = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user