mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
rendering: reduce memory usage and peaks
This commit is contained in:
parent
99fb1c35ef
commit
191c2e665e
@ -125,6 +125,7 @@ abstract class Element(val hudRenderer: HUDRenderer) {
|
||||
cache.z = z
|
||||
val maxZ = forceRender(offset, z, cache, options)
|
||||
cache.maxZ = maxZ
|
||||
cache.data.finalize()
|
||||
this.cache = cache
|
||||
cacheUpToDate = true
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ abstract class Mesh(
|
||||
|
||||
fun load() {
|
||||
buffer = renderWindow.renderSystem.createVertexBuffer(struct, data.toArray(), primitiveType)
|
||||
_data = null
|
||||
buffer.init()
|
||||
vertices = buffer.vertices
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ class ArrayFloatList(
|
||||
private val initialSize: Int = DEFAULT_INITIAL_SIZE,
|
||||
) {
|
||||
private var data: FloatArray = FloatArray(initialSize)
|
||||
var finalized: Boolean = false
|
||||
private set
|
||||
val limit: Int
|
||||
get() = data.size
|
||||
var size = 0
|
||||
@ -33,13 +35,21 @@ class ArrayFloatList(
|
||||
private var output: FloatArray = FloatArray(0)
|
||||
private var outputUpToDate = false
|
||||
|
||||
private fun checkFinalized() {
|
||||
if (finalized) {
|
||||
throw IllegalStateException("ArrayFloatList is already finalized!")
|
||||
}
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
checkFinalized()
|
||||
size = 0
|
||||
outputUpToDate = false
|
||||
output = FloatArray(0)
|
||||
}
|
||||
|
||||
private fun ensureSize(needed: Int) {
|
||||
checkFinalized()
|
||||
if (limit - size >= needed) {
|
||||
return
|
||||
}
|
||||
@ -65,10 +75,15 @@ class ArrayFloatList(
|
||||
outputUpToDate = false
|
||||
}
|
||||
|
||||
fun addAll(floats: ArrayFloatList) {
|
||||
ensureSize(floats.size)
|
||||
System.arraycopy(floats.data, 0, data, size, floats.size)
|
||||
size += floats.size
|
||||
fun addAll(floatList: ArrayFloatList) {
|
||||
ensureSize(floatList.size)
|
||||
val source = if (floatList.finalized) {
|
||||
floatList.output
|
||||
} else {
|
||||
floatList.data
|
||||
}
|
||||
System.arraycopy(source, 0, data, size, floatList.size)
|
||||
size += floatList.size
|
||||
}
|
||||
|
||||
private fun checkOutputArray() {
|
||||
@ -85,6 +100,12 @@ class ArrayFloatList(
|
||||
return output
|
||||
}
|
||||
|
||||
fun finalize() {
|
||||
finalized = true
|
||||
checkOutputArray()
|
||||
data = FloatArray(0)
|
||||
}
|
||||
|
||||
|
||||
private companion object {
|
||||
private const val DEFAULT_INITIAL_SIZE = 1000
|
||||
|
Loading…
x
Reference in New Issue
Block a user