| 5 | import field.graphics.FastJPEG |
| 6 | import field.graphics.Texture |
| 7 | |
| 8 | class TwinTextureCache(unit: Int, private val source: ImageCache) { |
| 9 | |
| 10 | |
| 11 | private val a: ByteBuffer |
| 12 | val textureA: Texture |
| 13 | private val b: ByteBuffer |
| 14 | val textureB: Texture |
| 15 | |
| 16 | internal var q = FastJPEG() |
| 17 | |
| 18 | internal var playing = false |
| 19 | var isDirty = false |
| 20 | internal set |
| 21 | |
| 22 | internal var time: Double = 0.toDouble() |
| 23 | internal var lastTime = -100.0 |
| 24 | internal var alpha = 0.5 |
| 25 | |
| 26 | internal var cA = -1 |
| 27 | internal var cB = -1 |
| 28 | |
| 29 | var autoDirectionSet = false |
| 30 | |
| 31 | internal var LEFT = 0 |
| 32 | internal var RIGHT = 0 |
| 33 | |
| 34 | init { |
| 35 | |
| 36 | a = ByteBuffer.allocateDirect(source.width * source.height * 3) |
| 37 | b = ByteBuffer.allocateDirect(source.width * source.height * 3) |
| 38 | |
| 39 | textureA = Texture(Texture.TextureSpecification.byte3(unit, source.width, source.height, a, true, false)) |
| 40 | textureB = Texture(Texture.TextureSpecification.byte3(unit + 1, source.width, source.height, b, true, false)) |
| 41 | |
| 42 | textureA.setIsDoubleBuffered(false) |
| 43 | textureB.setIsDoubleBuffered(false) |
| 44 | } |
| 45 | |
| 46 | fun getAlpha(): Float { |
| 47 | return Math.max(0.0, Math.min(1.0, alpha)).toFloat() |
| 48 | } |
| 49 | |
| 50 | fun setPlaying(p: Boolean) { |
| 51 | if (p && !playing) { |
| 52 | source.prerollAndWait(time.toInt()) |
| 53 | } |
| 54 | this.playing = p |
| 55 | } |
| 56 | |
| 57 | |
| 58 | var lastBytes: ByteBuffer? = null |
| 59 | |
| 60 | fun setTime(t: Double) { |
| 61 | |
| 62 | if (t == lastTime) |
| 63 | return |
| 64 | if (t.toInt() == lastTime.toInt()) { |
no test coverage detected