Skip to content

Commit d95b9b8

Browse files
committed
gif texture chores
1 parent a1c1078 commit d95b9b8

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

common/src/main/kotlin/com/lambda/graphics/texture/AnimatedTexture.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.lambda.graphics.texture
1919

2020
import com.lambda.graphics.buffer.pixel.PixelBuffer
21-
import com.lambda.util.Communication.logError
2221
import com.lambda.util.LambdaResource
2322
import com.lambda.util.stream
2423
import org.lwjgl.BufferUtils
@@ -29,7 +28,7 @@ import java.nio.ByteBuffer
2928
class 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

Comments
 (0)