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