mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
replace some sets with ObjectOpenHashSet
(should improve performance at some points)
This commit is contained in:
parent
d939f3f7b1
commit
2599a641a7
@ -21,6 +21,7 @@ import de.bixilon.minosoft.assets.util.FileAssetsUtil.toAssetName
|
||||
import de.bixilon.minosoft.assets.util.FileUtil
|
||||
import de.bixilon.minosoft.assets.util.InputStreamUtil.readJson
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileNotFoundException
|
||||
@ -38,8 +39,8 @@ class DirectoryAssetsManager(
|
||||
val prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX,
|
||||
) : AssetsManager {
|
||||
private val basePath = File(rootPath).slashPath + "/" + prefix
|
||||
override val namespaces: MutableSet<String> = mutableSetOf()
|
||||
private var assets: MutableSet<ResourceLocation> = mutableSetOf()
|
||||
override val namespaces: MutableSet<String> = ObjectOpenHashSet()
|
||||
private var assets: MutableSet<ResourceLocation> = ObjectOpenHashSet()
|
||||
override var loaded: Boolean = false
|
||||
private set
|
||||
override var image: ByteArray? = null
|
||||
|
@ -18,6 +18,7 @@ import de.bixilon.minosoft.assets.AssetsManager
|
||||
import de.bixilon.minosoft.assets.util.FileAssetsUtil.toAssetName
|
||||
import de.bixilon.minosoft.assets.util.InputStreamUtil.readJson
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.util.zip.ZipInputStream
|
||||
@ -38,7 +39,7 @@ class ZipAssetsManager(
|
||||
override fun load(latch: CountUpAndDownLatch) {
|
||||
check(!loaded) { "Already loaded!" }
|
||||
|
||||
val namespaces: MutableSet<String> = mutableSetOf()
|
||||
val namespaces: MutableSet<String> = ObjectOpenHashSet()
|
||||
while (true) {
|
||||
val entry = inputStream.nextEntry ?: break
|
||||
if (entry.isDirectory) {
|
||||
|
@ -37,6 +37,7 @@ import de.bixilon.minosoft.util.json.Jackson
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
@ -96,7 +97,7 @@ class IndexAssetsManager(
|
||||
|
||||
val worker = UnconditionalWorker()
|
||||
|
||||
val hashes: MutableSet<String> = mutableSetOf()
|
||||
val hashes: MutableSet<String> = ObjectOpenHashSet()
|
||||
|
||||
for ((path, data) in assets) {
|
||||
check(data is Map<*, *>)
|
||||
|
@ -32,6 +32,7 @@ import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.MetaTypes
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.Registry
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
|
||||
class BlockRegistry(
|
||||
parent: Registry<Block>? = null,
|
||||
@ -42,7 +43,7 @@ class BlockRegistry(
|
||||
fun updateStates(block: Block, data: JsonObject, registries: Registries) {
|
||||
val properties: MutableMap<BlockProperties, MutableSet<Any>> = mutableMapOf()
|
||||
|
||||
val states: MutableSet<BlockState> = mutableSetOf()
|
||||
val states: MutableSet<BlockState> = ObjectOpenHashSet()
|
||||
for ((stateId, stateJson) in data["states"].asAnyMap()) {
|
||||
val settings = BlockStateSettings.of(registries, stateJson.unsafeCast())
|
||||
val state = if (block is BlockStateBuilder) block.buildState(settings) else AdvancedBlockState(block, settings)
|
||||
@ -53,7 +54,7 @@ class BlockRegistry(
|
||||
if (state !is PropertyBlockState) continue
|
||||
|
||||
for ((property, value) in state.properties) {
|
||||
properties.getOrPut(property) { mutableSetOf() } += value
|
||||
properties.getOrPut(property) { ObjectOpenHashSet() } += value
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ import de.bixilon.minosoft.tags.MinecraftTagTypes.ITEM
|
||||
import de.bixilon.minosoft.tags.Tag
|
||||
import de.bixilon.minosoft.tags.TagList
|
||||
import de.bixilon.minosoft.tags.TagManager
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
|
||||
object FallbackTags {
|
||||
private val tags: MutableMap<ResourceLocation, MutableMap<ResourceLocation, Set<ResourceLocation>>> = mutableMapOf()
|
||||
@ -41,7 +42,7 @@ object FallbackTags {
|
||||
private fun read(type: ResourceLocation, name: ResourceLocation): Set<ResourceLocation> {
|
||||
val content = Minosoft.MINOSOFT_ASSETS_MANAGER[ResourceLocation(name.namespace, "tags/${type.path}/${name.path}.json")].readJsonObject()["values"].asAnyCollection()
|
||||
|
||||
val set: MutableSet<ResourceLocation> = mutableSetOf()
|
||||
val set: MutableSet<ResourceLocation> = ObjectOpenHashSet()
|
||||
for (entry in content) {
|
||||
set += ResourceLocation.of(entry.toString())
|
||||
}
|
||||
@ -68,7 +69,7 @@ object FallbackTags {
|
||||
val map: MutableMap<ResourceLocation, Tag<T>> = mutableMapOf()
|
||||
|
||||
for ((name, entries) in entries) {
|
||||
val set: MutableSet<T> = mutableSetOf()
|
||||
val set: MutableSet<T> = ObjectOpenHashSet()
|
||||
for (item in entries) {
|
||||
set += registry[item] ?: continue
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ abstract class AbstractVoxelShape : Iterable<AABB> {
|
||||
}
|
||||
|
||||
operator fun plus(offset: Vec3t<out Number>): AbstractVoxelShape {
|
||||
val result: MutableSet<AABB> = mutableSetOf()
|
||||
val result: MutableSet<AABB> = ObjectOpenHashSet()
|
||||
for (aabb in this) {
|
||||
result.add(aabb + offset)
|
||||
}
|
||||
@ -48,7 +48,7 @@ abstract class AbstractVoxelShape : Iterable<AABB> {
|
||||
}
|
||||
|
||||
fun add(other: AbstractVoxelShape): AbstractVoxelShape {
|
||||
val aabbs: MutableSet<AABB> = mutableSetOf()
|
||||
val aabbs: MutableSet<AABB> = ObjectOpenHashSet()
|
||||
aabbs += this
|
||||
aabbs += other
|
||||
return VoxelShape(aabbs)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -22,6 +22,7 @@ import de.bixilon.minosoft.modding.event.events.CancelableEvent
|
||||
import de.bixilon.minosoft.modding.event.events.Event
|
||||
import de.bixilon.minosoft.modding.event.listener.EventListener
|
||||
import de.bixilon.minosoft.modding.event.listener.OneShotListener
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
import java.util.*
|
||||
|
||||
open class EventMaster(vararg parents: AbstractEventMaster) : AbstractEventMaster {
|
||||
@ -61,7 +62,7 @@ open class EventMaster(vararg parents: AbstractEventMaster) : AbstractEventMaste
|
||||
}
|
||||
parentLock.release()
|
||||
|
||||
val toRemove: MutableSet<EventListener> = mutableSetOf()
|
||||
val toRemove: MutableSet<EventListener> = ObjectOpenHashSet()
|
||||
eventInvokerLock.acquire()
|
||||
val worker = UnconditionalWorker()
|
||||
for (invoker in eventListeners) {
|
||||
|
@ -36,6 +36,7 @@ import de.bixilon.minosoft.tags.TagManager
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
|
||||
@LoadPacket
|
||||
class TagsS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
@ -91,7 +92,7 @@ class TagsS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
}
|
||||
|
||||
private fun <T : RegistryItem> PlayInByteBuffer.readTag(registry: Registry<T>): Tag<T> {
|
||||
val items: MutableSet<T> = mutableSetOf()
|
||||
val items: MutableSet<T> = ObjectOpenHashSet()
|
||||
for (id in readVarIntArray()) {
|
||||
items += registry.getOrNull(id) ?: continue
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user