1818package com.lambda.graphics.texture
1919
2020import com.lambda.graphics.buffer.pixel.PixelBuffer
21- import com.lambda.util.Communication.logError
2221import com.lambda.util.LambdaResource
2322import com.lambda.util.stream
2423import org.lwjgl.BufferUtils
@@ -29,7 +28,7 @@ import java.nio.ByteBuffer
2928class AnimatedTexture (path : LambdaResource ) : Texture(image = null ) {
3029 private val pbo: PixelBuffer
3130 private val gif: ByteBuffer // Do NOT free this pointer
32- private val frameDurations: IntArray
31+ private val frameDurations: IntArray // Array of frame duration milliseconds as ints
3332 val channels: Int
3433 val frames: Int
3534
@@ -39,13 +38,12 @@ class AnimatedTexture(path: LambdaResource) : Texture(image = null) {
3938 private var currentFrame = 0
4039 private var lastUpload = 0L
4140
42- override fun bind (slot : Int ) {
43- update()
44- super .bind(slot)
45- }
41+ override fun bind (slot : Int ) { update(); super .bind(slot) }
4642
4743 fun update () {
48- if (System .currentTimeMillis() - lastUpload >= frameDurations[currentFrame]) {
44+ val now = System .currentTimeMillis()
45+
46+ if (now - lastUpload >= frameDurations[currentFrame]) {
4947 // This is cool because instead of having a buffer for each frame we can
5048 // just move the frame's block on each update
5149 // 0 memory allocation and few cpu cycles
@@ -54,12 +52,10 @@ class AnimatedTexture(path: LambdaResource) : Texture(image = null) {
5452 .limit(blockSize * (currentFrame + 1 ))
5553
5654 pbo.upload(slice, offset = 0 )
57- ?.let { err -> logError(" Error uploading to PBO" , err) }
58-
5955 gif.clear()
6056
6157 currentFrame = (currentFrame + 1 ) % frames
62- lastUpload = System .currentTimeMillis()
58+ lastUpload = now
6359 }
6460 }
6561
0 commit comments