From 48c5379c31a4041a5e47914c04fb234977a4f975 Mon Sep 17 00:00:00 2001 From: way-zer Date: Mon, 21 Feb 2022 17:30:33 +0800 Subject: [PATCH] =?UTF-8?q?(mod)=20=E4=BF=AE=E5=A4=8D`=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=B8=B8=E9=87=8F`=E5=92=8C`=E7=A7=91=E6=8A=80=E6=A0=91`?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/cf/wayzer/contentsMod/ContentsLoader.kt | 14 ++++++++++++++ .../cf/wayzer/contentsMod/MyContentLoader.kt | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/ContentsLoader.kt b/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/ContentsLoader.kt index f8897a7..2df3b91 100644 --- a/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/ContentsLoader.kt +++ b/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/ContentsLoader.kt @@ -2,6 +2,7 @@ package cf.wayzer.contentsMod import arc.func.Cons import arc.func.Prov +import arc.struct.ObjectIntMap import arc.struct.ObjectMap import arc.struct.Seq import arc.util.Log @@ -11,6 +12,7 @@ import mindustry.ctype.ContentList import mindustry.ctype.ContentType import mindustry.gen.Call import mindustry.gen.ClientPacketReliableCallPacket +import mindustry.logic.LExecutor import mindustry.mod.Mod import mindustry.net.Net import mindustry.net.Packet @@ -69,6 +71,18 @@ class ContentsLoader : Mod() { val time = measureTimeMillis { it.load() } Log.infoTag("ContentsLoader", "Loaded ${it.lastContent!!::class.qualifiedName} costs ${time}ms") } + val timeReloadConstants = measureTimeMillis { + Vars.constants.apply { + javaClass.getDeclaredField("namesToIds") + .apply { isAccessible = true } + .set(this, ObjectIntMap()) + javaClass.getDeclaredField("vars") + .apply { isAccessible = true } + .set(this, Seq(LExecutor.Var::class.java)) + init() + } + } + Log.infoTag("ContentsLoader", "Reload Vars.constants costs ${timeReloadConstants}ms") if (!Vars.headless) { val timeLoadColors = measureTimeMillis { MyContentLoader.loadColors() diff --git a/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/MyContentLoader.kt b/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/MyContentLoader.kt index 16e2fe8..8ce2a8b 100644 --- a/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/MyContentLoader.kt +++ b/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/MyContentLoader.kt @@ -14,11 +14,11 @@ import mindustry.io.SaveVersion import mindustry.mod.Mods object MyContentLoader : ContentLoader() { - class ContentContainer(val type: ContentType, val default: ContentList) { + class ContentContainer(val type: ContentType?, val default: ContentList) { var content: ContentList = default var lastContent: ContentList? = null private set - val contentMap: Seq = Vars.content.getBy(type).copy() + val contentMap: Seq = if (type == null) Seq() else Vars.content.getBy(type).copy() val nameMap = contentMap.filterIsInstance().associateByTo(mutableMapOf()) { it.name } fun maskChanged() { @@ -54,8 +54,10 @@ object MyContentLoader : ContentLoader() { ContentContainer(ContentType.bullet, Bullets()), ContentContainer(ContentType.unit, UnitTypes()), ContentContainer(ContentType.block, Blocks()), + ContentContainer(null, Loadouts()), + ContentContainer(null, TechTree()), ) - val contentMap = contents.associateBy { it.type } + val contentMap = contents.filter { it.type != null }.associateBy { it.type } override fun clear() = Unit/*throw NotImplementedError()*/ override fun createBaseContent() = throw NotImplementedError()