never post init font twice

This commit is contained in:
Moritz Zwerger 2023-11-05 19:07:35 +01:00
parent d92bc3fdec
commit 3254d1823f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 16 additions and 7 deletions

View File

@ -19,15 +19,15 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
class BitmapCodeRenderer( class BitmapCodeRenderer(
override val texture: Texture, override val texture: Texture,
override var uvStart: Vec2, override val uvStart: Vec2,
override var uvEnd: Vec2, override val uvEnd: Vec2,
override val width: Float, override val width: Float,
override val height: Float, override val height: Float,
override val ascent: Float, override val ascent: Float,
) : AscentedCodePointRenderer { ) : AscentedCodePointRenderer {
fun updateArray() { fun updateArray() {
uvStart = uvStart * texture.array.uvEnd uvStart *= texture.array.uvEnd
uvEnd = uvEnd * texture.array.uvEnd uvEnd *= texture.array.uvEnd
} }
} }

View File

@ -38,6 +38,7 @@ import java.util.stream.IntStream
class BitmapFontType( class BitmapFontType(
val chars: Int2ObjectOpenHashMap<CodePointRenderer>, val chars: Int2ObjectOpenHashMap<CodePointRenderer>,
) : PostInitFontType { ) : PostInitFontType {
private var postInit = false
init { init {
chars.trim() chars.trim()
@ -48,10 +49,12 @@ class BitmapFontType(
} }
override fun postInit(latch: AbstractLatch) { override fun postInit(latch: AbstractLatch) {
if (postInit) return
for (char in chars.values) { for (char in chars.values) {
if (char !is BitmapCodeRenderer) continue if (char !is BitmapCodeRenderer) continue
char.updateArray() char.updateArray()
} }
postInit = true
} }

View File

@ -36,11 +36,14 @@ import java.io.InputStream
class LegacyUnicodeFontType( class LegacyUnicodeFontType(
val chars: Array<UnicodeCodeRenderer?>, val chars: Array<UnicodeCodeRenderer?>,
) : PostInitFontType { ) : PostInitFontType {
private var postInit = false
override fun postInit(latch: AbstractLatch) { override fun postInit(latch: AbstractLatch) {
if (postInit) return
for (char in chars) { for (char in chars) {
char?.updateArray() char?.updateArray()
} }
postInit = true
} }
override fun get(codePoint: Int): UnicodeCodeRenderer? { override fun get(codePoint: Int): UnicodeCodeRenderer? {

View File

@ -30,6 +30,9 @@ import java.io.InputStream
import javax.imageio.ImageIO import javax.imageio.ImageIO
object TextureUtil { object TextureUtil {
private val COMPONENTS_4 = intArrayOf(0, 1, 2, 3)
private val COMPONENTS_3 = intArrayOf(0, 1, 2)
private val COMPONENTS_1 = intArrayOf(0, 0, 0)
fun ResourceLocation.texture(): ResourceLocation { fun ResourceLocation.texture(): ResourceLocation {
return this.extend(prefix = "textures/", suffix = ".png") return this.extend(prefix = "textures/", suffix = ".png")
@ -58,9 +61,9 @@ object TextureUtil {
val dataOutput = DataOutputStream(byteOutput) val dataOutput = DataOutputStream(byteOutput)
val samples = when (image.raster.numBands) { val samples = when (image.raster.numBands) {
4 -> intArrayOf(0, 1, 2, 3) 4 -> COMPONENTS_4
3 -> intArrayOf(0, 1, 2) 3 -> COMPONENTS_3
else -> intArrayOf(0, 0, 0) else -> COMPONENTS_1
} }
for (y in 0 until image.height) { for (y in 0 until image.height) {