@@ -27,15 +27,18 @@ import solve.scene.controller.SceneController
27
27
import solve.scene.model.VisualizationFrame
28
28
import solve.utils.ceilToInt
29
29
import java.util.concurrent.CopyOnWriteArrayList
30
+ import kotlin.io.path.nameWithoutExtension
30
31
import kotlin.math.abs
32
+ import kotlin.math.max
31
33
import kotlin.math.min
32
34
33
35
class FramesRenderer (
34
36
window : Window
35
37
) : Renderer(window) {
36
38
private data class LoadedBufferFrameData (
37
39
val textureData : Texture2DData ,
38
- val bufferIndex : Int
40
+ val bufferIndex : Int ,
41
+ val name : String
39
42
)
40
43
41
44
override val maxBatchSize = 1000
@@ -56,7 +59,7 @@ class FramesRenderer(
56
59
private val framesRatio: Float
57
60
get() = framesWidth.toFloat() / framesHeight.toFloat()
58
61
59
- private var cameraLastGridCellPosition = getScreenCenterGridCellPosition ()
62
+ private var cameraLastGridCellPosition = getScreenTopLeftGridCellPosition ()
60
63
61
64
private val bufferFramesToUpload = CopyOnWriteArrayList <LoadedBufferFrameData >(mutableListOf ())
62
65
private val framesLoadingCoroutineScope = CoroutineScope (Dispatchers .Default )
@@ -77,6 +80,7 @@ class FramesRenderer(
77
80
}
78
81
79
82
this .gridWidth = min(gridWidth, selectedFrames.count())
83
+ haveNewFramesSelection = true
80
84
}
81
85
82
86
fun setNewSceneFrames (frames : List <VisualizationFrame >) {
@@ -112,7 +116,7 @@ class FramesRenderer(
112
116
shaderProgram.uploadVector2i(BuffersSizeUniformName , buffersSize)
113
117
shaderProgram.uploadInt(TexturesArrayUniformName , 0 )
114
118
shaderProgram.uploadFloat(TexturesRatioUniformName , framesRatio)
115
- shaderProgram.uploadVector2f(CameraPositionUniformName , getScreenCenterGridCellPosition ().toFloatVector())
119
+ shaderProgram.uploadVector2f(CameraPositionUniformName , getScreenTopLeftGridCellPosition ().toFloatVector())
116
120
}
117
121
118
122
override fun createNewBatch (zIndex : Int ) =
@@ -154,7 +158,7 @@ class FramesRenderer(
154
158
}
155
159
156
160
private fun enableVirtualization () {
157
- cameraLastGridCellPosition = getScreenCenterGridCellPosition ()
161
+ cameraLastGridCellPosition = getScreenTopLeftGridCellPosition ()
158
162
isVirtualizationEnabled = true
159
163
}
160
164
@@ -173,7 +177,7 @@ class FramesRenderer(
173
177
}
174
178
175
179
private fun updateBuffersTextures () {
176
- val cameraGridCellPosition = getScreenCenterGridCellPosition ()
180
+ val cameraGridCellPosition = getScreenTopLeftGridCellPosition ()
177
181
if (cameraGridCellPosition != cameraLastGridCellPosition) {
178
182
loadNewTexturesToBuffers(cameraGridCellPosition)
179
183
}
@@ -194,30 +198,26 @@ class FramesRenderer(
194
198
val rectHeight: Int
195
199
if (gridCellPositionDelta.x != 0 ) {
196
200
rectWidth = abs(gridCellPositionDelta.x)
197
- rectHeight = buffersSize.y
201
+ rectHeight = min( buffersSize.y, gridHeight)
198
202
} else {
199
203
rectHeight = abs(gridCellPositionDelta.y)
200
- rectWidth = buffersSize.x
204
+ rectWidth = min( buffersSize.x, gridWidth)
201
205
}
202
206
val newFramesRect = IntRect (
203
207
if (gridCellPositionDelta.x > 0 ) {
204
208
cameraPosition.x + buffersSize.x - gridCellPositionDelta.x
205
209
} else {
206
- cameraPosition.x
210
+ max( 0 , cameraPosition.x)
207
211
},
208
212
if (gridCellPositionDelta.y > 0 ) {
209
213
cameraPosition.y + buffersSize.y - gridCellPositionDelta.y
210
214
} else {
211
- cameraPosition.y
215
+ max( 0 , cameraPosition.y)
212
216
},
213
217
rectWidth,
214
218
rectHeight
215
219
)
216
- if (newFramesRect.x0 > 0 && newFramesRect.x1 < gridWidth &&
217
- newFramesRect.y0 > 0 && newFramesRect.y1 < gridHeight
218
- ) {
219
220
loadRectFramesToBuffers(newFramesRect)
220
- }
221
221
}
222
222
223
223
private fun getFramesAtRect (rect : IntRect ): List <List <VisualizationFrame >> {
@@ -245,17 +245,22 @@ class FramesRenderer(
245
245
}
246
246
247
247
val buffersOffset = Vector2i (framesRect.x0 % buffersSize.x, framesRect.y0 % buffersSize.y)
248
+ val uploadedBuffersIndices = mutableSetOf<Int >()
248
249
249
250
for (y in 0 until rectFrames.count()) {
250
251
for (x in 0 until rectFrames[y].count()) {
251
252
val textureBuffersIndex =
252
253
((buffersOffset.y + y) % buffersSize.y) * buffersSize.x + (buffersOffset.x + x) % buffersSize.x
254
+ if (uploadedBuffersIndices.contains(textureBuffersIndex))
255
+ continue
256
+
253
257
uploadFrameToBuffersArray(rectFrames[y][x], textureBuffersIndex)
258
+ uploadedBuffersIndices.add(textureBuffersIndex)
254
259
}
255
260
}
256
261
}
257
262
258
- private fun getScreenCenterGridCellPosition (): Vector2i {
263
+ private fun getScreenTopLeftGridCellPosition (): Vector2i {
259
264
val cameraGridCellPosition = Vector2f (window.camera.position.x / framesRatio, window.camera.position.y)
260
265
return (cameraGridCellPosition - Vector2f (buffersSize) / 2f ).toIntVector()
261
266
}
@@ -291,7 +296,7 @@ class FramesRenderer(
291
296
return @launch
292
297
}
293
298
294
- bufferFramesToUpload.add(LoadedBufferFrameData (textureData, index))
299
+ bufferFramesToUpload.add(LoadedBufferFrameData (textureData, index, frame.imagePath.nameWithoutExtension ))
295
300
}
296
301
}
297
302
0 commit comments