diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/mesh/SingleChunkMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/mesh/SingleChunkMesh.kt index 8907294cbe..f5c15ca2d2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/mesh/SingleChunkMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/mesh/SingleChunkMesh.kt @@ -32,19 +32,18 @@ class SingleChunkMesh(context: RenderContext, initialCacheSize: Int, onDemand: B val transformedUV = texture.renderData.transformUV(uv).array data.add(position) data.add(transformedUV) - data.add(texture.renderData.shaderTextureId.buffer()) - data.add(((light shl 24) or tintColor).buffer()) + data.add( + texture.renderData.shaderTextureId.buffer(), + (((light shl 24) or tintColor).buffer()) + ) } fun addVertex(x: Float, y: Float, z: Float, uv: FloatArray, texture: Texture, shaderTextureId: Float, lightTint: Float) { data.ensureSize(WorldMeshStruct.FLOATS_PER_VERTEX) val transformedUV = texture.renderData.transformUV(uv) - data.add(x) - data.add(y) - data.add(z) + data.add(x, y, z) data.add(transformedUV) - data.add(shaderTextureId) - data.add(lightTint) + data.add(shaderTextureId, lightTint) } override fun compareTo(other: SingleChunkMesh): Int { diff --git a/src/main/java/de/bixilon/minosoft/util/collections/floats/FragmentedArrayFloatList.kt b/src/main/java/de/bixilon/minosoft/util/collections/floats/FragmentedArrayFloatList.kt index 6cf2367387..1f4796703b 100644 --- a/src/main/java/de/bixilon/minosoft/util/collections/floats/FragmentedArrayFloatList.kt +++ b/src/main/java/de/bixilon/minosoft/util/collections/floats/FragmentedArrayFloatList.kt @@ -51,9 +51,9 @@ class FragmentedArrayFloatList( } private fun grow(size: Int): FloatBuffer { - checkFinished() + if (finished) throw IllegalStateException() if (limit - this.size >= size) { - return this.incomplete.first() + return this.incomplete[0] } val grow = if (nextGrowStep < size) { (size / nextGrowStep + 1) * nextGrowStep @@ -78,6 +78,27 @@ class FragmentedArrayFloatList( invalidateOutput() } + fun add(value1: Float, value2: Float) { + var buffer = grow(2) + buffer.put(value1); if (tryPush(buffer)) buffer = grow(1) + buffer.put(value2) + + size += 2 + tryPush(buffer) + invalidateOutput() + } + + fun add(value1: Float, value2: Float, value3: Float) { + var buffer = grow(3) + buffer.put(value1); if (tryPush(buffer)) buffer = grow(2) + buffer.put(value2); if (tryPush(buffer)) buffer = grow(1) + buffer.put(value3) + + size += 3 + tryPush(buffer) + invalidateOutput() + } + private fun tryPush(fragment: FloatBuffer): Boolean { if (fragment.position() != fragment.limit()) { return false