mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-13 23:26:07 +09:00
sorta working unsafesvecarray; and then issue #26 is fucking shit up
This commit is contained in:
41
src/net/torvald/gdx/graphics/UnsafeCvecArray.kt
Normal file
41
src/net/torvald/gdx/graphics/UnsafeCvecArray.kt
Normal 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()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user