mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
improve palette performance, improve hud performance
This commit is contained in:
parent
0f0441d409
commit
7fcda64a8d
@ -21,6 +21,8 @@ class ArrayPaletteData(
|
||||
val elementBits: Int,
|
||||
override val size: Int,
|
||||
) : PaletteData {
|
||||
private val singleValueMask = (1 shl elementBits) - 1
|
||||
private val valuesPerLong = Long.SIZE_BITS / elementBits
|
||||
private lateinit var data: LongArray
|
||||
|
||||
init {
|
||||
@ -34,17 +36,14 @@ class ArrayPaletteData(
|
||||
|
||||
(bits + (Long.SIZE_BITS - 1)) / Long.SIZE_BITS // divide up
|
||||
} else {
|
||||
val elementsPerLong = Long.SIZE_BITS / elementBits
|
||||
(size + elementsPerLong - 1) / elementsPerLong
|
||||
(size + valuesPerLong - 1) / valuesPerLong
|
||||
}
|
||||
data = buffer.readLongArray(longs)
|
||||
}
|
||||
|
||||
override operator fun get(index: Int): Int {
|
||||
val individualValueMask = (1 shl elementBits) - 1
|
||||
|
||||
var blockId: Long = if (versionId < LONG_BIT_SPLITTING_VERSION) {
|
||||
val startLong = index * elementBits / Long.SIZE_BITS
|
||||
val blockId: Long = if (versionId < LONG_BIT_SPLITTING_VERSION) {
|
||||
val startLong = index * valuesPerLong
|
||||
val startOffset = index * elementBits % Long.SIZE_BITS
|
||||
val endLong = ((index + 1) * elementBits - 1) / Long.SIZE_BITS
|
||||
|
||||
@ -55,14 +54,12 @@ class ArrayPaletteData(
|
||||
data[startLong] ushr startOffset or (data[endLong] shl endOffset)
|
||||
}
|
||||
} else {
|
||||
val startLong = index / (Long.SIZE_BITS / elementBits)
|
||||
val startOffset = index % (Long.SIZE_BITS / elementBits) * elementBits
|
||||
val startLong = index / valuesPerLong
|
||||
val startOffset = index % valuesPerLong * elementBits
|
||||
data[startLong] ushr startOffset
|
||||
}
|
||||
|
||||
blockId = blockId and individualValueMask.toLong()
|
||||
|
||||
return blockId.toInt()
|
||||
return blockId.toInt() and singleValueMask
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -14,8 +14,9 @@
|
||||
package de.bixilon.minosoft.gui.rendering.gui.hud
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.collections.CollectionUtil.synchronizedMapOf
|
||||
import de.bixilon.kutil.collections.CollectionUtil.lockMapOf
|
||||
import de.bixilon.kutil.collections.CollectionUtil.toSynchronizedMap
|
||||
import de.bixilon.kutil.collections.map.LockMap
|
||||
import de.bixilon.minosoft.config.key.KeyActions
|
||||
import de.bixilon.minosoft.config.key.KeyBinding
|
||||
import de.bixilon.minosoft.config.key.KeyCodes
|
||||
@ -41,7 +42,7 @@ class HUDManager(
|
||||
) : GUIElementDrawer, Initializable {
|
||||
val renderWindow = guiRenderer.renderWindow
|
||||
|
||||
private val hudElements: MutableMap<ResourceLocation, HUDElement> = synchronizedMapOf()
|
||||
private val hudElements: LockMap<ResourceLocation, HUDElement> = lockMapOf()
|
||||
|
||||
override var lastTickTime = 0L
|
||||
|
||||
@ -72,12 +73,14 @@ class HUDManager(
|
||||
}
|
||||
|
||||
fun onMatrixChange() {
|
||||
for (element in hudElements.toSynchronizedMap().values) {
|
||||
hudElements.lock.acquire()
|
||||
for (element in hudElements.values) {
|
||||
if (element is LayoutedGUIElement<*>) {
|
||||
element.element.forceApply()
|
||||
}
|
||||
element.apply()
|
||||
}
|
||||
hudElements.lock.release()
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
@ -104,7 +107,9 @@ class HUDManager(
|
||||
}
|
||||
|
||||
fun draw() {
|
||||
drawElements(hudElements.toSynchronizedMap().values)
|
||||
hudElements.lock.acquire()
|
||||
drawElements(hudElements.values)
|
||||
hudElements.lock.release()
|
||||
}
|
||||
|
||||
operator fun <T : HUDElement> get(hudBuilder: HUDBuilder<T>): T? {
|
||||
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.other
|
||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatColors
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.TextComponent
|
||||
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
|
||||
@ -41,7 +42,7 @@ class BreakProgressHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer),
|
||||
override fun draw() {
|
||||
val breakProgress = breakInteractionHandler.breakProgress
|
||||
if (breakProgress <= 0 || breakProgress >= 1.0) {
|
||||
textElement.text = ""
|
||||
textElement.text = ChatComponent.EMPTY
|
||||
this.percent = -1
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user