Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Optimize VfsFile.readCubeMap #603

Merged
merged 1 commit into from
Apr 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions korge/src/commonMain/kotlin/com/soywiz/korge3d/SkyBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import com.soywiz.korag.AG
import com.soywiz.korag.shader.*
import com.soywiz.korim.bitmap.NativeImage
import com.soywiz.korim.format.readNativeImage
import com.soywiz.korio.async.async
import com.soywiz.korio.async.asyncImmediately
import com.soywiz.korio.file.*
import com.soywiz.korio.file.std.resourcesVfs
import com.soywiz.korma.geom.*
import kotlinx.coroutines.coroutineScope
import kotlin.coroutines.coroutineContext

interface CubeMap {
val right: NativeImage
Expand All @@ -27,13 +31,19 @@ suspend fun cubeMapFromResourceDirectory(directory: String, ext: String): CubeMa
}

suspend fun VfsFile.readCubeMap(ext: String): CubeMap {
val rightImage = this["right.$ext"].readNativeImage()
val leftImage = this["left.$ext"].readNativeImage()
val topImage = this["top.$ext"].readNativeImage()
val bottomImage = this["bottom.$ext"].readNativeImage()
val backImage = this["back.$ext"].readNativeImage()
val frontImage = this["front.$ext"].readNativeImage()
return CubeMapSimple(rightImage, leftImage, topImage, bottomImage, backImage, frontImage)
val file = this
return coroutineScope {
val rightImage = async { file["right.$ext"].readNativeImage() }
val leftImage = async { file["left.$ext"].readNativeImage() }
val topImage = async { file["top.$ext"].readNativeImage() }
val bottomImage = async { file["bottom.$ext"].readNativeImage() }
val backImage = async { file["back.$ext"].readNativeImage() }
val frontImage = async { file["front.$ext"].readNativeImage() }
CubeMapSimple(
rightImage.await(), leftImage.await(), topImage.await(),
bottomImage.await(), backImage.await(), frontImage.await()
)
}
}

class CubeMapSimple(
Expand Down