mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
use fragmented list, fix fragmented list bugs
This commit is contained in:
parent
1c0b3f1265
commit
a96b520331
@ -19,7 +19,7 @@ import org.lwjgl.system.MemoryUtil.memFree
|
||||
import java.nio.FloatBuffer
|
||||
|
||||
object FloatListUtil {
|
||||
const val PREFER_FRAGMENTED = false
|
||||
const val PREFER_FRAGMENTED = true
|
||||
|
||||
val FLOAT_PUT_METHOD = ExceptionUtil.catchAll { FloatBuffer::class.java.getMethod("put", Int::class.java, FloatBuffer::class.java, Int::class.java, Int::class.java) }
|
||||
const val DEFAULT_INITIAL_SIZE = 1000
|
||||
|
@ -100,7 +100,7 @@ class FragmentedArrayFloatList(
|
||||
if (tryPush(fragment)) indexOffset--
|
||||
|
||||
|
||||
if (array.size - offset <= remaining) {
|
||||
if (array.size - offset < remaining) {
|
||||
// everything copied
|
||||
size += array.size
|
||||
return
|
||||
@ -130,7 +130,7 @@ class FragmentedArrayFloatList(
|
||||
offset += copy
|
||||
if (tryPush(fragment)) indexOffset--
|
||||
|
||||
if (position - offset <= remaining) {
|
||||
if (position - offset < remaining) {
|
||||
// everything copied
|
||||
size += position
|
||||
return
|
||||
@ -239,6 +239,10 @@ class FragmentedArrayFloatList(
|
||||
}
|
||||
val buffer = memAllocFloat(size)
|
||||
forEach { it.copy(buffer) }
|
||||
if (buffer.position() != this.size) {
|
||||
// TODO: this should never happen, remove this check
|
||||
throw Exception("Position mismatch: ${buffer.position()}, expected $size")
|
||||
}
|
||||
this.buffer = buffer
|
||||
return buffer
|
||||
}
|
||||
|
@ -440,6 +440,31 @@ abstract class AbstractFloatListTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clear() {
|
||||
val list = create()
|
||||
list.add(1.0f)
|
||||
list.add(2.0f)
|
||||
list.clear()
|
||||
assertEquals(0, list.toArray().size)
|
||||
list.add(3.0f)
|
||||
list.add(4.0f)
|
||||
assertContentEquals(floatArrayOf(3.0f, 4.0f), list.toArray())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clearBig() {
|
||||
val list = create()
|
||||
list.add(1.0f)
|
||||
list.add(FloatArray(1000) { 1.0f + it })
|
||||
list.add(FloatArray(2000) { 1001.0f + it })
|
||||
list.clear()
|
||||
assertEquals(0, list.toArray().size)
|
||||
list.add(3.0f)
|
||||
list.add(4.0f)
|
||||
assertContentEquals(floatArrayOf(3.0f, 4.0f), list.toArray())
|
||||
}
|
||||
|
||||
private fun wrap(vararg array: Float): FloatBuffer {
|
||||
val buffer = FloatBuffer.wrap(array)
|
||||
buffer.position(array.size)
|
||||
|
Loading…
x
Reference in New Issue
Block a user