mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
optimize registries after loading
This could/should make performance better?
This commit is contained in:
parent
d95e508219
commit
42a94ab3d1
@ -22,7 +22,7 @@ import de.bixilon.minosoft.data.registries.registries.registry.Registry
|
||||
class BlockEntityTypeRegistry(
|
||||
parentRegistry: BlockEntityTypeRegistry? = null,
|
||||
) : Registry<BlockEntityType<*>>(parentRegistry, codec = BlockEntityType) {
|
||||
private val blockTypeMap: MutableMap<Block, BlockEntityType<*>> = mutableMapOf()
|
||||
private val blockTypeMap: MutableMap<Block, BlockEntityType<*>> = HashMap()
|
||||
|
||||
operator fun get(block: Block): BlockEntityType<*>? {
|
||||
val parentRegistry = super.parent as BlockEntityTypeRegistry?
|
||||
|
@ -48,4 +48,6 @@ interface AbstractRegistry<T> : Iterable<T>, Clearable, Parentable<AbstractRegis
|
||||
override fun iterator(): Iterator<T> {
|
||||
return RegistryIterator(this)
|
||||
}
|
||||
|
||||
fun optimize() = Unit
|
||||
}
|
||||
|
@ -86,4 +86,8 @@ class BlockStateRegistry(var flattened: Boolean) : AbstractRegistry<BlockState?>
|
||||
}
|
||||
|
||||
override fun addItem(resourceLocation: ResourceLocation, id: Int?, data: JsonObject, registries: Registries?) = Broken()
|
||||
|
||||
override fun optimize() {
|
||||
idMap.trim()
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ open class Registry<T : RegistryItem>(
|
||||
) : AbstractRegistry<T> {
|
||||
protected val idValueMap: Int2ObjectOpenHashMap<T> = Int2ObjectOpenHashMap()
|
||||
protected val valueIdMap: Object2IntOpenHashMap<T> = Object2IntOpenHashMap()
|
||||
protected val resourceLocationMap: MutableMap<ResourceLocation, T> = mutableMapOf()
|
||||
protected val resourceLocationMap: MutableMap<ResourceLocation, T> = HashMap()
|
||||
|
||||
override val size: Int
|
||||
get() {
|
||||
@ -158,4 +158,9 @@ open class Registry<T : RegistryItem>(
|
||||
override fun noParentIterator(): Iterator<T> {
|
||||
return resourceLocationMap.values.iterator()
|
||||
}
|
||||
|
||||
override fun optimize() {
|
||||
idValueMap.trim()
|
||||
valueIdMap.trim()
|
||||
}
|
||||
}
|
||||
|
@ -81,4 +81,9 @@ class ResourceLocationRegistry(
|
||||
override fun noParentIterator(): Iterator<ResourceLocation> {
|
||||
return idValueMap.values.iterator()
|
||||
}
|
||||
|
||||
override fun optimize() {
|
||||
idValueMap.trim()
|
||||
valueIdMap.trim()
|
||||
}
|
||||
}
|
||||
|
@ -81,4 +81,9 @@ class RecipeRegistry(
|
||||
recipeResourceLocationMap[recipe] = resourceLocation
|
||||
}
|
||||
}
|
||||
|
||||
override fun optimize() {
|
||||
idValueMap.trim()
|
||||
valueIdMap.trim()
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,14 @@ object RegistriesUtil {
|
||||
worker.work(latch)
|
||||
}
|
||||
|
||||
fun Registries.optimize(latch: CountUpAndDownLatch) {
|
||||
val worker = UnconditionalWorker()
|
||||
for (field in types.values) {
|
||||
worker += { field.get(this).unsafeCast<Registry<*>>().optimize() }
|
||||
}
|
||||
worker.work(latch)
|
||||
}
|
||||
|
||||
|
||||
fun Registries.clear() {
|
||||
for (field in clearable) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user