mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
world rendering: reduce memory footprint, improve performance
This commit is contained in:
parent
f9e779e6ee
commit
dce90431ee
@ -142,32 +142,31 @@ enum class BlockProperties {
|
|||||||
val map: MutableMap<String, MutableList<BlockProperties>> = mutableMapOf()
|
val map: MutableMap<String, MutableList<BlockProperties>> = mutableMapOf()
|
||||||
|
|
||||||
for (value in values()) {
|
for (value in values()) {
|
||||||
val list = map.getOrPut(value.group) { mutableListOf() }
|
map.getOrPut(value.group) { mutableListOf() } += value
|
||||||
list.add(value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return@run map
|
return@run map
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parseProperty(group: String, value: Any): Pair<BlockProperties, Any> {
|
fun parseProperty(group: String, value: Any): Pair<BlockProperties, Any> {
|
||||||
PROPERTIES[group]?.let {
|
val properties = PROPERTIES[group] ?: throw IllegalArgumentException("Can not find group: $group, expected value $value")
|
||||||
var retProperty: BlockProperties? = null
|
|
||||||
var retValue: Any? = null
|
|
||||||
|
|
||||||
for (blockProperty in it) {
|
var property: BlockProperties? = null
|
||||||
retValue = try {
|
var retValue: Any? = null
|
||||||
blockProperty.serializer.deserialize(value)
|
|
||||||
} catch (exception: Throwable) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
retProperty = blockProperty
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retProperty == null || retValue == null) {
|
for (blockProperty in properties) {
|
||||||
throw IllegalArgumentException("Can not parse value $value for group $group")
|
retValue = try {
|
||||||
|
blockProperty.serializer.deserialize(value)
|
||||||
|
} catch (exception: Throwable) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
return Pair(retProperty, retValue)
|
property = blockProperty
|
||||||
} ?: throw IllegalArgumentException("Can not find group: $group, expected value $value")
|
}
|
||||||
|
|
||||||
|
if (property == null || retValue == null) {
|
||||||
|
throw IllegalArgumentException("Can not parse value $value for group $group")
|
||||||
|
}
|
||||||
|
return Pair(property, retValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ interface ChatComponentRenderer<T : ChatComponent> {
|
|||||||
|
|
||||||
val textMesh = mesh.textMesh!!
|
val textMesh = mesh.textMesh!!
|
||||||
val primitives = calculatePrimitiveCount(text)
|
val primitives = calculatePrimitiveCount(text)
|
||||||
textMesh.data.ensureSize(primitives * textMesh.order.size * SingleWorldMesh.SectionArrayMeshStruct.FLOATS_PER_VERTEX)
|
textMesh.data.ensureSize(primitives * textMesh.order.size * SingleWorldMesh.WorldMeshStruct.FLOATS_PER_VERTEX)
|
||||||
|
|
||||||
val consumer = WorldGUIConsumer(textMesh, matrix, light)
|
val consumer = WorldGUIConsumer(textMesh, matrix, light)
|
||||||
render3dFlat(renderWindow, Vec2i(), scale, maxSize, consumer, text, light)
|
render3dFlat(renderWindow, Vec2i(), scale, maxSize, consumer, text, light)
|
||||||
|
@ -47,10 +47,12 @@ class BakedFace(
|
|||||||
color.g *= ((tint shr 8) and 0xFF) / RGBColor.COLOR_FLOAT_DIVIDER
|
color.g *= ((tint shr 8) and 0xFF) / RGBColor.COLOR_FLOAT_DIVIDER
|
||||||
color.b *= (tint and 0xFF) / RGBColor.COLOR_FLOAT_DIVIDER
|
color.b *= (tint and 0xFF) / RGBColor.COLOR_FLOAT_DIVIDER
|
||||||
}
|
}
|
||||||
val rgb = color.rgb
|
|
||||||
|
val textureShaderId = Float.fromBits(texture.renderData.shaderTextureId)
|
||||||
|
val tintLight = Float.fromBits(color.rgb or (light shl 24))
|
||||||
for ((index, textureIndex) in meshToUse.order) {
|
for ((index, textureIndex) in meshToUse.order) {
|
||||||
val indexOffset = index * 3
|
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, rgb, light)
|
meshToUse.addVertex(positions[indexOffset + 0] + position[0], positions[indexOffset + 1] + position[1], positions[indexOffset + 2] + position[2], uv[textureIndex], texture, textureShaderId, tintLight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ class SignBlockEntityRenderer(
|
|||||||
for (line in sign.lines) {
|
for (line in sign.lines) {
|
||||||
primitives += ChatComponentRenderer.calculatePrimitiveCount(line)
|
primitives += ChatComponentRenderer.calculatePrimitiveCount(line)
|
||||||
}
|
}
|
||||||
textMesh.data.ensureSize(primitives * textMesh.order.size * SingleWorldMesh.SectionArrayMeshStruct.FLOATS_PER_VERTEX)
|
textMesh.data.ensureSize(primitives * textMesh.order.size * SingleWorldMesh.WorldMeshStruct.FLOATS_PER_VERTEX)
|
||||||
|
|
||||||
for (line in sign.lines) {
|
for (line in sign.lines) {
|
||||||
ChatComponentRenderer.render3dFlat(renderWindow, textPosition, TEXT_SCALE, Vec3(0.0f, -yRotation, 0.0f), Vec2i(SIGN_MAX_WIDTH * TEXT_SCALE, Font.TOTAL_CHAR_HEIGHT * TEXT_SCALE), mesh, line, light)
|
ChatComponentRenderer.render3dFlat(renderWindow, textPosition, TEXT_SCALE, Vec3(0.0f, -yRotation, 0.0f), Vec2i(SIGN_MAX_WIDTH * TEXT_SCALE, Font.TOTAL_CHAR_HEIGHT * TEXT_SCALE), mesh, line, light)
|
||||||
|
@ -20,10 +20,11 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTex
|
|||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
||||||
|
|
||||||
class SingleWorldMesh(renderWindow: RenderWindow, initialCacheSize: Int, onDemand: Boolean = false) : Mesh(renderWindow, SectionArrayMeshStruct, initialCacheSize = initialCacheSize, onDemand = onDemand) {
|
class SingleWorldMesh(renderWindow: RenderWindow, initialCacheSize: Int, onDemand: Boolean = false) : Mesh(renderWindow, WorldMeshStruct, initialCacheSize = initialCacheSize, onDemand = onDemand) {
|
||||||
var distance: Float = 0.0f // Used for sorting
|
var distance: Float = 0.0f // Used for sorting
|
||||||
|
|
||||||
fun addVertex(position: FloatArray, uv: Vec2, texture: AbstractTexture, tintColor: Int, light: Int) {
|
fun addVertex(position: FloatArray, uv: Vec2, texture: AbstractTexture, tintColor: Int, light: Int) {
|
||||||
|
data.ensureSize(WorldMeshStruct.FLOATS_PER_VERTEX)
|
||||||
val transformedUV = texture.renderData.transformUV(uv)
|
val transformedUV = texture.renderData.transformUV(uv)
|
||||||
data.add(position[0])
|
data.add(position[0])
|
||||||
data.add(position[1])
|
data.add(position[1])
|
||||||
@ -34,13 +35,25 @@ class SingleWorldMesh(renderWindow: RenderWindow, initialCacheSize: Int, onDeman
|
|||||||
data.add(Float.fromBits(tintColor or (light shl 24)))
|
data.add(Float.fromBits(tintColor or (light shl 24)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addVertex(x: Float, y: Float, z: Float, uv: Vec2, texture: AbstractTexture, shaderTextureId: Float, tintLight: Float) {
|
||||||
|
data.ensureSize(WorldMeshStruct.FLOATS_PER_VERTEX)
|
||||||
|
val transformedUV = texture.renderData.transformUV(uv)
|
||||||
|
data.add(x)
|
||||||
|
data.add(y)
|
||||||
|
data.add(z)
|
||||||
|
data.add(transformedUV.x)
|
||||||
|
data.add(transformedUV.y)
|
||||||
|
data.add(shaderTextureId)
|
||||||
|
data.add(tintLight)
|
||||||
|
}
|
||||||
|
|
||||||
data class SectionArrayMeshStruct(
|
|
||||||
|
data class WorldMeshStruct(
|
||||||
val position: Vec3,
|
val position: Vec3,
|
||||||
val uv: Vec2,
|
val uv: Vec2,
|
||||||
val indexLayerAnimation: Int,
|
val indexLayerAnimation: Int,
|
||||||
val tintLight: Int,
|
val tintLight: Int,
|
||||||
) {
|
) {
|
||||||
companion object : MeshStruct(SectionArrayMeshStruct::class)
|
companion object : MeshStruct(WorldMeshStruct::class)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user