From 64d44608b0e48d74d1ac69722b42f9093dfd7b36 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sun, 21 Mar 2021 19:09:54 +0100 Subject: [PATCH] rendering: fix some hud bugs, change some huds things --- .../de/bixilon/minosoft/data/world/World.kt | 2 +- .../minosoft/gui/rendering/font/Font.kt | 2 +- .../minosoft/gui/rendering/font/FontChar.kt | 6 +-- .../rendering/hud/atlas/HUDAtlasElement.kt | 4 +- .../gui/rendering/hud/atlas/Vec2Binding.kt | 2 +- .../elements/debug/HUDWorldDebugElement.kt | 1 + .../hud/elements/primitive/ImageElement.kt | 16 ++++---- .../hud/elements/primitive/TextElement.kt | 2 +- .../gui/rendering/textures/Texture.kt | 4 +- .../gui/rendering/textures/TextureArray.kt | 2 +- .../assets/minosoft/mapping/atlas.json | 38 +++++++++---------- 11 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/data/world/World.kt b/src/main/java/de/bixilon/minosoft/data/world/World.kt index 97e606d8f..0092aafd3 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/World.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/World.kt @@ -23,7 +23,7 @@ import java.util.* import java.util.concurrent.ConcurrentHashMap /** - * Collection of chunks + * Collection of chunks and more */ class World { val chunks = ConcurrentHashMap() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/Font.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/Font.kt index 9fe95eb41..00c73d6d0 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/Font.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/Font.kt @@ -56,7 +56,7 @@ class Font { for (provider in providers) { for (char in provider.chars.values) { - char.calculateUV(provider.width, char.texture.arraySinglePixelSize, char.texture.arraySinglePixelSize) // ToDo: Unicode: With should pe plus 1 + char.calculateUV(provider.width, char.texture.arraySinglePixelFactor) // ToDo: Unicode: With should pe plus 1 } } loaded = true diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontChar.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontChar.kt index 76250c3bf..94872af7f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontChar.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontChar.kt @@ -33,8 +33,8 @@ data class FontChar( override val size = Vec2i(endPixel - startPixel, height) - fun calculateUV(letterWidth: Int, atlasWidthSinglePixel: Float, atlasHeightSinglePixel: Float) { - uvStart = Vec2(atlasWidthSinglePixel * (letterWidth * column + startPixel), atlasHeightSinglePixel * (height * row)) - uvEnd = Vec2(atlasWidthSinglePixel * (letterWidth * column + endPixel), atlasHeightSinglePixel * (height * (row + 1))) + fun calculateUV(letterWidth: Int, arraySinglePixelFactor: Vec2) { + uvStart = Vec2(letterWidth * column + startPixel, height * row) * arraySinglePixelFactor + uvEnd = Vec2(letterWidth * column + endPixel, height * (row + 1)) * arraySinglePixelFactor } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/atlas/HUDAtlasElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/atlas/HUDAtlasElement.kt index 19c49bad9..4506c57ed 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/atlas/HUDAtlasElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/atlas/HUDAtlasElement.kt @@ -33,8 +33,8 @@ data class HUDAtlasElement( fun postInit() { - uvStart = Vec2(binding.start) * texture.arraySinglePixelSize - uvEnd = (Vec2(binding.end) - Vec2(0, 1)) * texture.arraySinglePixelSize + uvStart = Vec2(binding.start) * texture.arraySinglePixelFactor + uvEnd = Vec2(binding.end) * texture.arraySinglePixelFactor } companion object { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/atlas/Vec2Binding.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/atlas/Vec2Binding.kt index 327ca6cba..d5e374284 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/atlas/Vec2Binding.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/atlas/Vec2Binding.kt @@ -22,7 +22,7 @@ data class Vec2Binding( val start: Vec2i, val end: Vec2i, ) { - val size: Vec2i = glm.abs(Vec2i(start - end)) + 1 + val size: Vec2i = glm.abs(start - end) companion object { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/debug/HUDWorldDebugElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/debug/HUDWorldDebugElement.kt index e038d936f..6087f19e9 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/debug/HUDWorldDebugElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/debug/HUDWorldDebugElement.kt @@ -22,6 +22,7 @@ import de.bixilon.minosoft.util.UnitFormatter class HUDWorldDebugElement(hudRenderer: HUDRenderer) : DebugScreen(hudRenderer) { private val camera = hudRenderer.renderWindow.camera + private val brandText = text("§cMinosoft 0.1-pre1") private val fpsText = text("TBA") private val timingsText = text("TBA") private val chunksText = text("TBA") diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/primitive/ImageElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/primitive/ImageElement.kt index 3e47fff1c..e91b989cc 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/primitive/ImageElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/primitive/ImageElement.kt @@ -59,15 +59,15 @@ class ImageElement( val realZ = RenderConstants.HUD_Z_COORDINATE + RenderConstants.HUD_Z_COORDINATE_Z_FACTOR * (this.z + z) - fun addVertex(position: Vec2, textureUV: Vec2) { - cache.addVertex(Vec3(position, realZ), textureUV, textureLike?.texture, tintColor) + fun addVertex(positionX: Float, positionY: Float, textureUV: Vec2) { + cache.addVertex(Vec3(positionX, positionY, realZ), textureUV, textureLike?.texture, tintColor) } - addVertex(Vec2(modelStart.x, modelStart.y), Vec2(uvStart.x, uvStart.y)) - addVertex(Vec2(modelStart.x, modelEnd.y), Vec2(uvStart.x, uvEnd.y)) - addVertex(Vec2(modelEnd.x, modelStart.y), Vec2(uvEnd.x, uvStart.y)) - addVertex(Vec2(modelStart.x, modelEnd.y), Vec2(uvStart.x, uvEnd.y)) - addVertex(Vec2(modelEnd.x, modelEnd.y), Vec2(uvEnd.x, uvEnd.y)) - addVertex(Vec2(modelEnd.x, modelStart.y), Vec2(uvEnd.x, uvStart.y)) + addVertex(modelStart.x, modelStart.y, Vec2(uvStart.x, uvStart.y)) + addVertex(modelStart.x, modelEnd.y, Vec2(uvStart.x, uvEnd.y)) + addVertex(modelEnd.x, modelStart.y, Vec2(uvEnd.x, uvStart.y)) + addVertex(modelStart.x, modelEnd.y, Vec2(uvStart.x, uvEnd.y)) + addVertex(modelEnd.x, modelEnd.y, Vec2(uvEnd.x, uvEnd.y)) + addVertex(modelEnd.x, modelStart.y, Vec2(uvEnd.x, uvStart.y)) } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/primitive/TextElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/primitive/TextElement.kt index 1cccd40d7..6336d46b2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/primitive/TextElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/hud/elements/primitive/TextElement.kt @@ -50,7 +50,7 @@ class TextElement( Vec2i(0, Font.CHAR_HEIGHT) } else { val textSize = Vec2i(0, 0) - text.prepareRender(Vec2i(0, 1), Vec2i(), font, this, this.z + z + 1, textSize) + text.prepareRender(Vec2i(1, 1), Vec2i(), font, this, this.z + z + 1, textSize) if (background) { drawBackground(textSize + 1, z) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/textures/Texture.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/textures/Texture.kt index f30d875eb..de89211f6 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/textures/Texture.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/textures/Texture.kt @@ -39,7 +39,7 @@ class Texture( lateinit var properties: ImageProperties - var arraySinglePixelSize = 1.0f + var arraySinglePixelFactor = Vec2(1.0f, 1.0f) var buffer: ByteBuffer? = null @@ -51,7 +51,7 @@ class Texture( transparency = texture.transparency uvEnd = texture.uvEnd properties = ImageProperties() - arraySinglePixelSize = texture.arraySinglePixelSize + arraySinglePixelFactor = texture.arraySinglePixelFactor isLoaded = true } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt index c9fa89d20..d25bf53a5 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt @@ -66,7 +66,7 @@ class TextureArray(val allTextures: MutableList) { y = size.y.toFloat() / arrayResolution ) - texture.arraySinglePixelSize = 1.0f / arrayResolution + texture.arraySinglePixelFactor = Vec2(1.0f / arrayResolution, 1.0f / (arrayResolution + 1)) // ToDo: Why +1 ?? Still not working right texture.arrayLayer = it.size diff --git a/src/main/resources/assets/minosoft/mapping/atlas.json b/src/main/resources/assets/minosoft/mapping/atlas.json index b99725aba..24b91f679 100644 --- a/src/main/resources/assets/minosoft/mapping/atlas.json +++ b/src/main/resources/assets/minosoft/mapping/atlas.json @@ -4,43 +4,43 @@ "versions": { "567": { "start": [0, 0], - "end": [181, 21], + "end": [182, 22], "slots": { "0": { "start": [3, 3], - "end": [18, 18] + "end": [19, 19] }, "1": { "start": [23, 3], - "end": [38, 18] + "end": [39, 19] }, "2": { "start": [43, 3], - "end": [58, 18] + "end": [59, 19] }, "3": { "start": [63, 3], - "end": [78, 18] + "end": [79, 19] }, "4": { "start": [83, 3], - "end": [98, 18] + "end": [99, 19] }, "5": { "start": [103, 3], - "end": [118, 18] + "end": [119, 19] }, "6": { "start": [123, 3], - "end": [138, 18] + "end": [139, 19] }, "7": { "start": [143, 3], - "end": [158, 18] + "end": [159, 19] }, "8": { "start": [163, 3], - "end": [178, 18] + "end": [179, 19] } } } @@ -51,11 +51,11 @@ "versions": { "567": { "start": [0, 22], - "end": [23, 45], + "end": [24, 46], "slots": { "0": { "start": [5, 5], - "end": [20, 20] + "end": [21, 21] } } } @@ -66,7 +66,7 @@ "versions": { "0": { "start": [0, 0], - "end": [15, 15] + "end": [16, 16] } } }, @@ -75,7 +75,7 @@ "versions": { "0": { "start": [0, 64], - "end": [181, 68] + "end": [182, 69] } } }, @@ -84,7 +84,7 @@ "versions": { "0": { "start": [0, 69], - "end": [181, 73] + "end": [182, 74] } } }, @@ -93,7 +93,7 @@ "versions": { "0": { "start": [16, 0], - "end": [24, 8] + "end": [25, 9] } } }, @@ -102,7 +102,7 @@ "versions": { "0": { "start": [25, 0], - "end": [33, 8] + "end": [34, 9] } } }, @@ -111,7 +111,7 @@ "versions": { "0": { "start": [52, 0], - "end": [60, 8] + "end": [61, 9] } } }, @@ -120,7 +120,7 @@ "versions": { "0": { "start": [61, 0], - "end": [69, 8] + "end": [70, 9] } } }