mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
fix some bugs in fragmented array list
This commit is contained in:
parent
c377500214
commit
1c0b3f1265
@ -19,7 +19,7 @@ import org.lwjgl.system.MemoryUtil.memFree
|
|||||||
import java.nio.FloatBuffer
|
import java.nio.FloatBuffer
|
||||||
|
|
||||||
class FragmentedArrayFloatList(
|
class FragmentedArrayFloatList(
|
||||||
initialSize: Int = FloatListUtil.DEFAULT_INITIAL_SIZE,
|
growStep: Int = FloatListUtil.DEFAULT_INITIAL_SIZE,
|
||||||
) : AbstractFloatList(), DirectArrayFloatList {
|
) : AbstractFloatList(), DirectArrayFloatList {
|
||||||
var complete: MutableList<FloatBuffer> = ArrayList()
|
var complete: MutableList<FloatBuffer> = ArrayList()
|
||||||
var incomplete: MutableList<FloatBuffer> = ArrayList()
|
var incomplete: MutableList<FloatBuffer> = ArrayList()
|
||||||
@ -32,9 +32,9 @@ class FragmentedArrayFloatList(
|
|||||||
private var unloaded = false
|
private var unloaded = false
|
||||||
|
|
||||||
private val nextGrowStep = when {
|
private val nextGrowStep = when {
|
||||||
initialSize <= 0 -> FloatListUtil.DEFAULT_INITIAL_SIZE
|
growStep <= 0 -> FloatListUtil.DEFAULT_INITIAL_SIZE
|
||||||
initialSize <= 100 -> 100
|
growStep <= 100 -> 100
|
||||||
else -> initialSize
|
else -> growStep
|
||||||
}
|
}
|
||||||
|
|
||||||
private var output: FloatArray? = null
|
private var output: FloatArray? = null
|
||||||
@ -42,6 +42,9 @@ class FragmentedArrayFloatList(
|
|||||||
|
|
||||||
|
|
||||||
override fun ensureSize(needed: Int) {
|
override fun ensureSize(needed: Int) {
|
||||||
|
if (needed == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
grow(needed)
|
grow(needed)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,12 +86,10 @@ class FragmentedArrayFloatList(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun add(array: FloatArray) {
|
override fun add(array: FloatArray) {
|
||||||
// TODO: copy incomplete to complete
|
|
||||||
if (array.isEmpty()) return
|
if (array.isEmpty()) return
|
||||||
invalidateOutput()
|
invalidateOutput()
|
||||||
|
|
||||||
var offset = 0
|
var offset = 0
|
||||||
size += array.size
|
|
||||||
var indexOffset = 0
|
var indexOffset = 0
|
||||||
for (index in 0 until incomplete.size) {
|
for (index in 0 until incomplete.size) {
|
||||||
val fragment = incomplete[index + indexOffset]
|
val fragment = incomplete[index + indexOffset]
|
||||||
@ -99,26 +100,27 @@ class FragmentedArrayFloatList(
|
|||||||
if (tryPush(fragment)) indexOffset--
|
if (tryPush(fragment)) indexOffset--
|
||||||
|
|
||||||
|
|
||||||
if (array.size <= remaining) {
|
if (array.size - offset <= remaining) {
|
||||||
// everything copied
|
// everything copied
|
||||||
|
size += array.size
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
size += offset
|
||||||
val length = array.size - offset
|
val length = array.size - offset
|
||||||
val next = grow(length)
|
val next = grow(length)
|
||||||
next.put(array, offset, length)
|
next.put(array, offset, length)
|
||||||
|
size += length
|
||||||
next.position(length)
|
next.position(length)
|
||||||
tryPush(next)
|
tryPush(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun add(buffer: FloatBuffer) {
|
override fun add(buffer: FloatBuffer) {
|
||||||
// TODO: copy incomplete to complete
|
|
||||||
if (buffer.position() == 0) return
|
if (buffer.position() == 0) return
|
||||||
invalidateOutput()
|
invalidateOutput()
|
||||||
|
|
||||||
var offset = 0
|
var offset = 0
|
||||||
val position = buffer.position()
|
val position = buffer.position()
|
||||||
size += position
|
|
||||||
var indexOffset = 0
|
var indexOffset = 0
|
||||||
for (index in 0 until incomplete.size) {
|
for (index in 0 until incomplete.size) {
|
||||||
val fragment = incomplete[index + indexOffset]
|
val fragment = incomplete[index + indexOffset]
|
||||||
@ -128,15 +130,18 @@ class FragmentedArrayFloatList(
|
|||||||
offset += copy
|
offset += copy
|
||||||
if (tryPush(fragment)) indexOffset--
|
if (tryPush(fragment)) indexOffset--
|
||||||
|
|
||||||
if (position <= remaining) {
|
if (position - offset <= remaining) {
|
||||||
// everything copied
|
// everything copied
|
||||||
|
size += position
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
size += offset
|
||||||
val length = position - offset
|
val length = position - offset
|
||||||
val next = grow(length)
|
val next = grow(length)
|
||||||
buffer.copy(offset, next, 0, length)
|
buffer.copy(offset, next, 0, length)
|
||||||
next.position(length)
|
next.position(length)
|
||||||
|
size += length
|
||||||
tryPush(next)
|
tryPush(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user