From fe27e1f1856c60e1582ee14338dd6d80f6f347ec Mon Sep 17 00:00:00 2001 From: toxicity Date: Fri, 19 Apr 2024 03:24:43 +0900 Subject: [PATCH] Updates speed. --- .../kotlin/kr/toxicity/hud/BetterHudImpl.kt | 6 +- .../hud/manager/DatabaseManagerImpl.kt | 2 + .../kr/toxicity/hud/manager/ShaderManager.kt | 3 +- .../kr/toxicity/hud/pack/PackGenerator.kt | 12 ++-- .../main/kotlin/kr/toxicity/hud/util/Files.kt | 71 ++++++++++++------- .../shaders/core/rendertype_text.fsh | 24 ------- 6 files changed, 62 insertions(+), 56 deletions(-) delete mode 100644 dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_text.fsh diff --git a/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt index a27d1faf..0e015d4d 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt @@ -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) { @@ -256,6 +258,8 @@ class BetterHudImpl: BetterHud() { onReload = false consumer.accept(ReloadResult(ReloadState.FAIL, System.currentTimeMillis() - time)) } + }.handle { _, e -> + e.printStackTrace() } } } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/DatabaseManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/DatabaseManagerImpl.kt index dd02168a..da9575ca 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/DatabaseManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/DatabaseManagerImpl.kt @@ -161,6 +161,8 @@ object DatabaseManagerImpl: BetterHudManager, DatabaseManager { warn("Reason: ${e.message}") } callback() + }.handle { _, e -> + e.printStackTrace() } } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManager.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManager.kt index 0aa827fc..8c3b8aad 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManager.kt @@ -189,8 +189,9 @@ object ShaderManager: BetterHudManager { warn("Reason: ${e.message}") } callback() + }.handle { _, e -> + e.printStackTrace() } - } override fun end() { diff --git a/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt index f91ff5b1..2fe5adc7 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt @@ -19,7 +19,7 @@ object PackGenerator { val pathLength = build.path.length + 1 val locationMap = TreeMap(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) } @@ -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) } } @@ -110,8 +112,10 @@ object PackGenerator { fun addTask(dir: Iterable, byteArray: () -> ByteArray) { val str = dir.joinToString("/") - tasks.computeIfAbsent(str) { - PackFile(str, byteArray) + synchronized(tasks) { + tasks.computeIfAbsent(str) { + PackFile(str, byteArray) + } } } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt b/dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt index 74e2f8eb..03fe3d31 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt @@ -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) } @@ -33,18 +28,6 @@ fun File.forEachAllFolder(block: (File) -> Unit) { } } -fun File.forEachAllFolderAsync(block: (File) -> Unit, callback: () -> Unit) { - fun getAll(file: File): List { - 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() @@ -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 { + 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>() + 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) + } } \ No newline at end of file diff --git a/dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_text.fsh b/dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_text.fsh deleted file mode 100644 index 3fe46019..00000000 --- a/dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_text.fsh +++ /dev/null @@ -1,24 +0,0 @@ -#version 150 - -#moj_import - -uniform sampler2D Sampler0; - -uniform vec4 ColorModulator; -uniform float FogStart; -uniform float FogEnd; -uniform vec4 FogColor; - -in float vertexDistance; -in vec4 vertexColor; -in vec2 texCoord0; - -out vec4 fragColor; - -void main() { - vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator; - if (color.a < 0.1) { - discard; - } - fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); -}