improve memory usage and performance a bit

This commit is contained in:
Bixilon 2022-05-26 14:41:50 +02:00
parent 877f212cee
commit eccca7d29b
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 13 additions and 10 deletions

View File

@ -25,7 +25,6 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTex
class CharData(
private val renderWindow: RenderWindow,
val char: Int,
val texture: AbstractTexture?,
val width: Int,
val scaledWidth: Int,

View File

@ -99,7 +99,6 @@ class BitmapFontProvider(
val charData = CharData(
renderWindow = renderWindow,
char = char,
texture = texture,
width = width,
scaledWidth = scaledWidth,

View File

@ -24,7 +24,7 @@ import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class LegacyUnicodeFontProvider(
private val renderWindow: RenderWindow,
renderWindow: RenderWindow,
data: Map<String, Any>,
) : FontProvider {
private val chars: Array<CharData?> = arrayOfNulls(1 shl Char.SIZE_BITS)
@ -68,7 +68,6 @@ class LegacyUnicodeFontProvider(
val charData = CharData(
renderWindow = renderWindow,
char = char,
texture = texture,
width = width,
scaledWidth = scaledWidth,

View File

@ -34,10 +34,9 @@ class SpaceFontProvider(
data["advances"]?.toJsonObject()?.let {
for ((charData, spacing) in it) {
val char = charData.codePoints().iterator().nextInt()
chars[char] = CharData(renderWindow, char, null, spacing.toInt(), spacing.toInt(), Vec2.EMPTY, Vec2.EMPTY)
chars[char] = CharData(renderWindow, null, spacing.toInt(), spacing.toInt(), Vec2.EMPTY, Vec2.EMPTY)
}
}
}
override fun postInit(latch: CountUpAndDownLatch) = Unit

View File

@ -27,7 +27,7 @@ import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh
class BakedFace(
override val sizeStart: Vec2,
override val sizeEnd: Vec2,
val positions: Array<Vec3>,
val positions: FloatArray,
val uv: Array<Vec2>,
val shade: Float,
val tintIndex: Int,
@ -48,8 +48,8 @@ class BakedFace(
color.b *= (tint and 0xFF) / RGBColor.COLOR_FLOAT_DIVIDER
}
for ((index, textureIndex) in meshToUse.order) {
val indexPosition = positions[index].array
meshToUse.addVertex(floatArrayOf(indexPosition[0] + position[0], indexPosition[1] + position[1], indexPosition[2] + position[2]), uv[textureIndex], texture, color.rgb, light)
val indexOffset = index * 3
meshToUse.addVertex(floatArrayOf(positions[indexOffset + 0] + position[0], positions[indexOffset + 1] + position[1], positions[indexOffset + 2] + position[2]), uv[textureIndex], texture, color.rgb, light)
}
}
}

View File

@ -133,10 +133,17 @@ class UnbakedBlockStateModel(
Directions.WEST, Directions.EAST -> 0.6f
}
}
val floatPositions = FloatArray(4 * 3) // positions.size * 3
for ((index, position) in positions.withIndex()) {
floatPositions[index * 3 + 0] = position.x
floatPositions[index * 3 + 1] = position.y
floatPositions[index * 3 + 2] = position.z
}
val bakedFace = BakedFace(
sizeStart = sizeStart,
sizeEnd = sizeEnd,
positions = positions,
positions = floatPositions,
uv = texturePositions,
shade = shade,
tintIndex = face.tintIndex,