sorta working unsafesvecarray; and then issue #26 is fucking shit up

This commit is contained in:
minjaesong
2019-06-22 04:16:03 +09:00
parent b45caebda0
commit 64bbe6b53b
7 changed files with 283 additions and 78 deletions

View File

@@ -0,0 +1,41 @@
package net.torvald.gdx.graphics
import net.torvald.UnsafeHelper
/**
* Created by minjaesong on 2019-06-21.
*/
internal class UnsafeCvecArray(val width: Int, val height: Int) {
val TOTAL_SIZE_IN_BYTES = 16L * width * height
val array = UnsafeHelper.allocate(TOTAL_SIZE_IN_BYTES)
private inline fun toAddr(x: Int, y: Int) = 16L * (y * width + x)
fun zerofill() = UnsafeHelper.unsafe.setMemory(this.array.ptr, TOTAL_SIZE_IN_BYTES, 0)
init {
zerofill()
}
fun getR(x: Int, y: Int) = array.getFloat(toAddr(x, y))
fun getG(x: Int, y: Int) = array.getFloat(toAddr(x, y) + 4)
fun getB(x: Int, y: Int) = array.getFloat(toAddr(x, y) + 8)
fun getA(x: Int, y: Int) = array.getFloat(toAddr(x, y) + 12)
fun setR(x: Int, y: Int, value: Float) { array.setFloat(toAddr(x, y), value) }
fun setG(x: Int, y: Int, value: Float) { array.setFloat(toAddr(x, y) + 4, value) }
fun setB(x: Int, y: Int, value: Float) { array.setFloat(toAddr(x, y) + 8, value) }
fun setA(x: Int, y: Int, value: Float) { array.setFloat(toAddr(x, y) + 12, value) }
fun max(x: Int, y: Int, other: Cvec) {
setR(x, y, maxOf(getR(x, y), other.r))
setG(x, y, maxOf(getG(x, y), other.g))
setB(x, y, maxOf(getB(x, y), other.b))
setA(x, y, maxOf(getA(x, y), other.a))
}
fun destroy() = this.array.destroy()
}