Skip to content

Commit

Permalink
Updates speed.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Apr 18, 2024
1 parent 427ff72 commit fe27e1f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 56 deletions.
6 changes: 5 additions & 1 deletion dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ class BetterHudImpl: BetterHud() {

fun managerReload() {
if (index.current < managers.size) {
val manager = managers[index.current++]
val manager = synchronized(index) {
managers[index.current++]
}
info("Loading ${manager.javaClass.simpleName}...")
synchronized(manager) {
manager.reload(resource) {
Expand All @@ -256,6 +258,8 @@ class BetterHudImpl: BetterHud() {
onReload = false
consumer.accept(ReloadResult(ReloadState.FAIL, System.currentTimeMillis() - time))
}
}.handle { _, e ->
e.printStackTrace()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ object DatabaseManagerImpl: BetterHudManager, DatabaseManager {
warn("Reason: ${e.message}")
}
callback()
}.handle { _, e ->
e.printStackTrace()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ object ShaderManager: BetterHudManager {
warn("Reason: ${e.message}")
}
callback()
}.handle { _, e ->
e.printStackTrace()
}

}

override fun end() {
Expand Down
12 changes: 8 additions & 4 deletions dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object PackGenerator {
val pathLength = build.path.length + 1
val locationMap = TreeMap<String, File>(Comparator.reverseOrder())
fun getAllLocation(file: File) {
locationMap[file.path.substring(pathLength, file.path.length)] = file
locationMap[file.path.substring(pathLength)] = file
file.listFiles()?.forEach {
getAllLocation(it)
}
Expand All @@ -29,7 +29,9 @@ object PackGenerator {
}
PLUGIN.loadAssets("pack") { a, i ->
val replace = a.replace('/','\\')
(locationMap.remove(replace) ?: File(build, replace)).outputStream().buffered().use { os ->
(locationMap.remove(replace) ?: File(build, replace).apply {
parentFile.mkdirs()
}).outputStream().buffered().use { os ->
i.copyTo(os)
}
}
Expand Down Expand Up @@ -110,8 +112,10 @@ object PackGenerator {

fun addTask(dir: Iterable<String>, byteArray: () -> ByteArray) {
val str = dir.joinToString("/")
tasks.computeIfAbsent(str) {
PackFile(str, byteArray)
synchronized(tasks) {
tasks.computeIfAbsent(str) {
PackFile(str, byteArray)
}
}
}

Expand Down
71 changes: 45 additions & 26 deletions dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ fun File.ifNotExist(message: String) = apply {
if (!exists()) throw RuntimeException(message)
}

fun File.clearFolder() = apply {
deleteRecursively()
mkdir()
}

fun File.forEach(block: (File) -> Unit) {
listFiles()?.forEach(block)
}
Expand All @@ -33,18 +28,6 @@ fun File.forEachAllFolder(block: (File) -> Unit) {
}
}

fun File.forEachAllFolderAsync(block: (File) -> Unit, callback: () -> Unit) {
fun getAll(file: File): List<File> {
return if (file.isDirectory) {
file.listFiles()?.map { subFile ->
getAll(subFile)
}?.sum() ?: ArrayList()
} else {
listOf(file)
}
}
getAll(this).forEachAsync(block, callback)
}

fun File.forEachAsync(block: (File) -> Unit, callback: () -> Unit) {
listFiles()?.toList()?.forEachAsync(block, callback) ?: return callback()
Expand All @@ -65,16 +48,52 @@ fun File.forEachAllYaml(block: (File, String, ConfigurationSection) -> Unit) {
}
}
fun File.forEachAllYamlAsync(block: (File, String, ConfigurationSection) -> Unit, callback: () -> Unit) {
forEachAllFolderAsync({
if (it.extension == "yml") {
runCatching {
it.toYaml().forEachSubConfiguration { s, configurationSection ->
block(it, s, configurationSection)
fun getAll(file: File): List<File> {
return if (file.isDirectory) {
file.listFiles()?.map { subFile ->
getAll(subFile)
}?.sum() ?: ArrayList()
} else {
listOf(file)
}
}
val list = getAll(this).filter {
it.extension == "yml"
}.mapNotNull {
runCatching {
val yaml = it.toYaml()
val list = ArrayList<Pair<String, ConfigurationSection>>()
yaml.getKeys(false).forEach {
yaml.getConfigurationSection(it)?.let { section ->
list.add(it to section)
}
}
if (list.isNotEmpty()) it to list else null
}.getOrElse { e ->
warn("Unable to load this yml file: ${it.name}")
warn("Reason: ${e.message}")
null
}
}
if (list.isEmpty()) {
callback()
return
}
val index = TaskIndex(list.sumOf {
it.second.size
})
list.forEach {
it.second.forEach { pair ->
CompletableFuture.runAsync {
runCatching {
block(it.first, pair.first, pair.second)
}.onFailure { e ->
e.printStackTrace()
}
synchronized(index) {
if (++index.current == index.max) callback()
}
}.onFailure { e ->
warn("Unable to load this yml file: ${it.name}")
warn("Reason: ${e.message}")
}
}
}, callback)
}
}

This file was deleted.

0 comments on commit fe27e1f

Please sign in to comment.