Skip to content

Commit

Permalink
codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-sts committed Mar 11, 2024
1 parent 3664522 commit ac30bc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import solve.rendering.engine.utils.toIntVector
import solve.scene.controller.SceneController
import solve.scene.model.VisualizationFrame
import solve.utils.ceilToInt
import java.util.Date
import java.util.concurrent.CopyOnWriteArrayList
import kotlin.io.path.nameWithoutExtension
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
Expand All @@ -38,7 +38,7 @@ class FramesRenderer(
private data class LoadedBufferFrameData(
val textureData: Texture2DData,
val bufferIndex: Int,
val name: String
val time: Long
)

override val maxBatchSize = 1000
Expand Down Expand Up @@ -169,9 +169,13 @@ class FramesRenderer(
}

private fun uploadLoadedFramesToBuffers() {
bufferFramesToUpload.forEach { frame ->
val uploadedFramesIndices = mutableSetOf<Int>()
bufferFramesToUpload.sortedBy { it.time }.forEach { frame ->
bufferFramesToUpload.remove(frame)
bufferFramesArrayTexture?.uploadTexture(frame.textureData, frame.bufferIndex)
if (!uploadedFramesIndices.contains(frame.bufferIndex)) {
bufferFramesArrayTexture?.uploadTexture(frame.textureData, frame.bufferIndex)
uploadedFramesIndices.add(frame.bufferIndex)
}
Texture2D.freeData(frame.textureData)
}
}
Expand Down Expand Up @@ -217,7 +221,7 @@ class FramesRenderer(
rectWidth,
rectHeight
)
loadRectFramesToBuffers(newFramesRect)
loadRectFramesToBuffers(newFramesRect)
}

private fun getFramesAtRect(rect: IntRect): List<List<VisualizationFrame>> {
Expand Down Expand Up @@ -251,8 +255,9 @@ class FramesRenderer(
for (x in 0 until rectFrames[y].count()) {
val textureBuffersIndex =
((buffersOffset.y + y) % buffersSize.y) * buffersSize.x + (buffersOffset.x + x) % buffersSize.x
if (uploadedBuffersIndices.contains(textureBuffersIndex))
if (uploadedBuffersIndices.contains(textureBuffersIndex)) {
continue
}

uploadFrameToBuffersArray(rectFrames[y][x], textureBuffersIndex)
uploadedBuffersIndices.add(textureBuffersIndex)
Expand Down Expand Up @@ -289,14 +294,15 @@ class FramesRenderer(
}

private fun uploadFrameToBuffersArray(frame: VisualizationFrame, index: Int) {
val loadTime = Date().time
framesLoadingCoroutineScope.launch {
val textureData = Texture2D.loadData(frame.imagePath.toString())
if (textureData == null) {
println("The read texture is null!")
return@launch
}

bufferFramesToUpload.add(LoadedBufferFrameData(textureData, index, frame.imagePath.nameWithoutExtension))
bufferFramesToUpload.add(LoadedBufferFrameData(textureData, index, loadTime))
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/solve/scene/view/SceneView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class SceneView : View() {

override val root = canvas.canvas

private val projectChangedEventHandler = InvalidationListener {

}
private val sceneChangedEventHandler = InvalidationListener {
if (SceneFacade.lastVisualizationKeepSettings) {
canvas.setFramesSelection(controller.scene.frames)
Expand All @@ -55,7 +52,6 @@ class SceneView : View() {
}

private fun addSceneFramesBindings() {
SceneFacade.lastVisualizationKeepSettingsProperty.addListener(projectChangedEventHandler)
controller.sceneProperty.addListener(sceneChangedEventHandler)
}

Expand Down

0 comments on commit ac30bc7

Please sign in to comment.