diff --git a/buildSrc/src/main/kotlin/korlibs/korge/gradle/ProjectDependencyTree.kt b/buildSrc/src/main/kotlin/korlibs/korge/gradle/ProjectDependencyTree.kt index de2eb6e79a..f8e127d5a2 100644 --- a/buildSrc/src/main/kotlin/korlibs/korge/gradle/ProjectDependencyTree.kt +++ b/buildSrc/src/main/kotlin/korlibs/korge/gradle/ProjectDependencyTree.kt @@ -24,7 +24,7 @@ fun Project.allDependantProjects(): Set { val out = LinkedHashSet() val explored = LinkedHashSet() while (toExplore.isNotEmpty()) { - val item = toExplore.removeLast() + val item = toExplore.removeAt(toExplore.size - 1) if (item in explored) continue val directDependencies = item.directDependantProjects() explored += item diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bc5f47c945..ea7fad47e6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ kotlinx-coroutines = "1.9.0-RC" kotlinx-serialization = "1.7.0" kotlinx-atomicfu = "0.24.0" -korlibs = "6.0.0-alpha5" +korlibs = "6.0.0-alpha7" #korlibs = "999.0.0.999" kotlinx-benchmark = "0.4.7" diff --git a/korge-core/src@darwin/korlibs/render/DefaultGameWindowIos.kt b/korge-core/src@darwin/korlibs/render/DefaultGameWindowIos.kt index ace56b8629..2211559f7b 100644 --- a/korge-core/src@darwin/korlibs/render/DefaultGameWindowIos.kt +++ b/korge-core/src@darwin/korlibs/render/DefaultGameWindowIos.kt @@ -83,7 +83,7 @@ abstract class KorgwBaseNewAppDelegate { private fun forceGC() { logger.info {"Collecting GC..." } - val time = measureTime { + val time = kotlin.time.measureTime { KmemGC.collect() // Forces collection when going to background to release resources to the app } logger.info {"Collected in $time" } diff --git a/korge-core/src@jvm/korlibs/render/awt/BaseAwtGameWindow.kt b/korge-core/src@jvm/korlibs/render/awt/BaseAwtGameWindow.kt index 20973635d5..f25b6162db 100644 --- a/korge-core/src@jvm/korlibs/render/awt/BaseAwtGameWindow.kt +++ b/korge-core/src@jvm/korlibs/render/awt/BaseAwtGameWindow.kt @@ -21,8 +21,10 @@ import java.awt.datatransfer.* import java.awt.event.* import java.awt.event.KeyEvent import java.awt.event.MouseEvent +import kotlin.time.Duration import javax.swing.* import kotlin.system.* +import kotlin.time.measureTime abstract class BaseAwtGameWindow( override val ag: AGOpengl @@ -205,9 +207,9 @@ abstract class BaseAwtGameWindow( //gl.clearColor(1f, 1f, 1f, 1f) //gl.clear(gl.COLOR_BUFFER_BIT) - var gamePadTime: TimeSpan = 0.milliseconds - var frameTime: TimeSpan = 0.milliseconds - var finishTime: TimeSpan = 0.milliseconds + var gamePadTime: Duration = 0.milliseconds + var frameTime: Duration = 0.milliseconds + var finishTime: Duration = 0.milliseconds val totalTime = measureTime { frameTime = measureTime { frame() diff --git a/korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPC.kt b/korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPC.kt index b1627f718c..526d8f3eb4 100644 --- a/korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPC.kt +++ b/korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPC.kt @@ -117,7 +117,7 @@ class KorgeIPC(val path: String = KorgeIPCInfo.DEFAULT_PATH, val isServer: Boole val availableEvents get() = synchronized(_events) { _events.size } fun writeEvent(e: IPCPacket) { - println("writeEvent: $e") + //println("writeEvent: $e") synchronized(connectedSockets) { for (socket in connectedSockets) { socket.writePacket(e) diff --git a/korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPCSocket.kt b/korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPCSocket.kt index 7dda39e56b..7ec8adaef5 100644 --- a/korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPCSocket.kt +++ b/korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPCSocket.kt @@ -223,7 +223,9 @@ class IPCPacket( fun ReadableByteChannel.readFull(dst: ByteBuffer) { while (dst.remaining() > 0) { val read = read(dst) - if (read <= 0) error("Couldn't read") + if (read <= 0) { + throw ClosedChannelException() + } } } diff --git a/korge-sandbox/src/samples/MainBVH.kt b/korge-sandbox/src/samples/MainBVH.kt index 61742810b3..ca040cf29a 100644 --- a/korge-sandbox/src/samples/MainBVH.kt +++ b/korge-sandbox/src/samples/MainBVH.kt @@ -61,7 +61,7 @@ class MainBVH : Scene() { var rayObjectsSize = 0 var rectangleObjectsSize = 0 val allObjects = bvh.search(Rectangle(0.0, 0.0, width, height)) - val time = measureTime { + val time = kotlin.time.measureTime { val rayObjects = bvh.intersect(ray) val rectangleObjects = bvh.search(selectedRectangle) for (result in allObjects) result.value?.alphaF = 0.2f diff --git a/korge-sandbox/src/samples/MainCompression.kt b/korge-sandbox/src/samples/MainCompression.kt index 8b92939eb0..5c3b619b8d 100644 --- a/korge-sandbox/src/samples/MainCompression.kt +++ b/korge-sandbox/src/samples/MainCompression.kt @@ -18,7 +18,7 @@ class MainCompression : Scene() { val mem = MemoryVfsMix() val zipFile = localVfs("c:/temp", async = true)["1.zip"] val zipBytes = zipFile.readAll() - println("ELAPSED TIME [NATIVE]: " + measureTime { + println("ELAPSED TIME [NATIVE]: " + kotlin.time.measureTime { //localVfs("c:/temp")["1.zip"].openAsZip()["2012-07-15-wheezy-raspbian.img"].copyTo(mem["test.img"]) //localVfs("c:/temp")["iTunes64Setup.zip"].openAsZip().listSimple().first().copyTo(mem["test.out"]) //localVfs("c:/temp")["iTunes64Setup.zip"].readAll().openAsync().openAsZip().listSimple().first().copyTo(mem["test.out"]) @@ -29,7 +29,7 @@ class MainCompression : Scene() { DummyAsyncOutputStream ) }) - println("ELAPSED TIME [PORTABLE]: " + measureTime { + println("ELAPSED TIME [PORTABLE]: " + kotlin.time.measureTime { //localVfs("c:/temp")["1.zip"].openAsZip()["2012-07-15-wheezy-raspbian.img"].copyTo(mem["test.img"]) //localVfs("c:/temp")["iTunes64Setup.zip"].openAsZip().listSimple().first().copyTo(mem["test.out"]) //localVfs("c:/temp")["iTunes64Setup.zip"].readAll().openAsync().openAsZip().listSimple().first().copyTo(mem["test.out"]) diff --git a/korge-sandbox/src/samples/MainEmojiColrv1.kt b/korge-sandbox/src/samples/MainEmojiColrv1.kt index c2272d9ad7..aea88c0951 100644 --- a/korge-sandbox/src/samples/MainEmojiColrv1.kt +++ b/korge-sandbox/src/samples/MainEmojiColrv1.kt @@ -40,7 +40,7 @@ class MainEmojiColrv1 : Scene() { val shape = buildShape { buildText() } //println(shape.toSvg()) - println("native rendered in..." + measureTime { + println("native rendered in..." + kotlin.time.measureTime { cpuGraphics { it.xy(0, 200) it.useNativeRendering = true @@ -49,7 +49,7 @@ class MainEmojiColrv1 : Scene() { it.redrawIfRequired() } }) - println("non-native rendered in..." + measureTime { + println("non-native rendered in..." + kotlin.time.measureTime { cpuGraphics { it.xy(0, 350) it.useNativeRendering = false diff --git a/korge-sandbox/src/samples/MainTiledBackground.kt b/korge-sandbox/src/samples/MainTiledBackground.kt index e4a46490ae..bd41bfc72e 100644 --- a/korge-sandbox/src/samples/MainTiledBackground.kt +++ b/korge-sandbox/src/samples/MainTiledBackground.kt @@ -1,10 +1,8 @@ package samples -import korlibs.datastructure.* import korlibs.image.bitmap.* import korlibs.image.format.* import korlibs.image.tiles.* -import korlibs.image.tiles.TileMapRepeat import korlibs.io.file.std.* import korlibs.korge.scene.* import korlibs.korge.view.* @@ -14,11 +12,20 @@ class MainTiledBackground : Scene() { override suspend fun SContainer.sceneMain() { val tileset = TileSet( - TileSetTileInfo(0, bitmap("korge.png").toBMP32().scaleLinear(0.5, 0.5).slice()), - TileSetTileInfo(1, bitmap("korim.png").toBMP32().scaleLinear(0.5, 0.5).slice()), + listOf( + TileSetTileInfo(0, bitmap("korge.png").toBMP32().scaleLinear(0.5, 0.5).slice()), + TileSetTileInfo(1, bitmap("korim.png").toBMP32().scaleLinear(0.5, 0.5).slice()), + ), //TileSetTileInfo(1, Bitmap32(256, 256, Colors.MEDIUMAQUAMARINE).premultipliedIfRequired().slice()) ) - val tilemap = tileMap(IntArray2(2, 2, intArrayOf(0, 1, 1, 0)), repeatX = TileMapRepeat.REPEAT, repeatY = TileMapRepeat.REPEAT, tileset = tileset) + println(tileset.get(0)) + println(tileset.get(1)) + val tileMapData = TileMapData(2, 2, tileset, repeatX = TileMapRepeat.REPEAT, repeatY = TileMapRepeat.REPEAT) + tileMapData[0, 0] = Tile(0) + tileMapData[1, 0] = Tile(1) + tileMapData[0, 1] = Tile(1) + tileMapData[1, 1] = Tile(0) + val tilemap = tileMap(tileMapData) tilemap.x += 300 tilemap.y += 300 addFastUpdater { diff --git a/korge-sandbox/src/samples/MainTilemapTest.kt b/korge-sandbox/src/samples/MainTilemapTest.kt index e56297eaf1..da54125837 100644 --- a/korge-sandbox/src/samples/MainTilemapTest.kt +++ b/korge-sandbox/src/samples/MainTilemapTest.kt @@ -12,6 +12,7 @@ import korlibs.korge.view.align.* import korlibs.korge.view.camera.* import korlibs.korge.view.tiles.* import korlibs.math.geom.* +import korlibs.memory.* import korlibs.number.* import kotlin.math.* import kotlin.random.* @@ -29,7 +30,7 @@ class MainTilemapTest : Scene() { //filters(IdentityFilter) solidRect(width, height, Colors["#3e0000"]) val cameraContainer = cameraContainer(Size(width, height)) { - tilemap = tileMap(donutMap, tileSet).centerOn(this) + tilemap = tileMap(donutMap.copy(tileSet = tileSet)).centerOn(this) }//.filters(BlurFilter()) cameraContainer.cameraY = -80.0 * mapSize val statusOverlay = text("") @@ -103,9 +104,9 @@ class MainTilemapTest : Scene() { private fun makeDonutMap( mapWidth: Int, tileSet: TileSet - ): IntArray2 { + ): TileMapData { val rand = Random(3) - val mapValues2 = IntArray2(mapWidth, mapWidth, 0) + val mapValues2 = TileMapData(mapWidth, mapWidth, TileSet.EMPTY) val center = Point(mapWidth / 2, mapWidth / 2) for (x in 0 until mapWidth) for (y in 0 until mapWidth) { val p = Point(x, y) @@ -113,7 +114,7 @@ class MainTilemapTest : Scene() { val onDisc = dist < mapWidth / 2 val tooClose = dist < (mapWidth / 2) * 0.7 mapValues2[x, y] = - if (onDisc && !tooClose) 1 + rand.nextInt(tileSet.tilesMap.size - 1) else 0 + Tile(if (onDisc && !tooClose) 1 + rand.nextInt(tileSet.tilesMap.size - 1) else 0) } return mapValues2 } diff --git a/korge/src/korlibs/korge/view/tiles/TileMap.kt b/korge/src/korlibs/korge/view/tiles/TileMap.kt index 547ea157a3..5417048d72 100644 --- a/korge/src/korlibs/korge/view/tiles/TileMap.kt +++ b/korge/src/korlibs/korge/view/tiles/TileMap.kt @@ -20,38 +20,6 @@ inline fun Container.tileMap( callback: @ViewDslMarker TileMap.() -> Unit = {}, ) = TileMap(map, map.tileSet, smoothing, map.tileSet.tileSize).repeat(map.repeatX, map.repeatY).addTo(this, callback) -@Deprecated("Use TileMapInfo variant instead") -inline fun Container.tileMap( - map: IStackedIntArray2, - tileset: TileSet, - repeatX: TileMapRepeat = TileMapRepeat.NONE, - repeatY: TileMapRepeat = repeatX, - smoothing: Boolean = true, - tileSize: SizeInt = tileset.tileSize, - callback: @ViewDslMarker TileMap.() -> Unit = {}, -) = TileMap(map, tileset, smoothing, tileSize).repeat(repeatX, repeatY).addTo(this, callback) - -@Deprecated("Use TileMapInfo variant instead") -inline fun Container.tileMap( - map: IntArray2, - tileset: TileSet, - repeatX: TileMapRepeat = TileMapRepeat.NONE, - repeatY: TileMapRepeat = repeatX, - smoothing: Boolean = true, - tileSize: SizeInt = tileset.tileSize, - callback: @ViewDslMarker TileMap.() -> Unit = {}, -) = TileMap(map, tileset, smoothing, tileSize).repeat(repeatX, repeatY).addTo(this, callback) - -@PublishedApi -@Deprecated("Use TileMapInfo variant instead") -internal fun Bitmap32.toIntArray2() = IntArray2(width, height, ints) - -@Deprecated("Use korlibs.image.tiles.TileMapRepeat instead", replaceWith = ReplaceWith("korlibs.image.tiles.TileMapRepeat")) -typealias TileMapRepeat = korlibs.image.tiles.TileMapRepeat - -@Deprecated("Use korlibs.image.tiles.Tile instead", replaceWith = ReplaceWith("korlibs.image.tiles.Tile")) -typealias TileInfo = korlibs.image.tiles.Tile - class TileMap( var map: TileMapData = TileMapData(1, 1), tileset: TileSet = map.tileSet, @@ -59,29 +27,6 @@ class TileMap( var tileSize: SizeInt = tileset.tileSize, //) : BaseTileMap(intMap, smoothing, staggerAxis, staggerIndex, tileSize) { ) : View() { - @Deprecated("Use map instead", level = DeprecationLevel.WARNING) - var stackedIntMap: IStackedIntArray2 - get() = map.data.asInt() - set(value) { map = TileMapData(value.asLong()) } - - // Analogous to Bitmap32.locking - @Deprecated("Not required anymore") - fun lock() { - } - @Deprecated("Not required anymore") - fun unlock() { - //map.contentVersion++ - } - @Deprecated("Not required anymore") - inline fun lock(block: () -> T): T { - lock() - try { - return block() - } finally { - unlock() - } - } - private var tileWidth: Float = 0f private var tileHeight: Float = 0f @@ -421,10 +366,8 @@ class TileMap( var tileset: TileSet = tileset set(value) { if (field === value) return - lock { - field = value - updatedTileSet() - } + field = value + updatedTileSet() } private fun updatedTileSet() { @@ -436,30 +379,6 @@ class TileMap( tileHeight = tileset.height.toFloat() } - @Deprecated("Use TileMapInfo variant instead") - constructor( - map: IStackedIntArray2, - tileset: TileSet, - smoothing: Boolean = true, - tileSize: SizeInt = tileset.tileSize, - ) : this(TileMapData(map.asLong()), tileset, smoothing, tileSize) - - @Deprecated("Use TileMapInfo variant instead") - constructor( - map: IntArray2, - tileset: TileSet, - smoothing: Boolean = true, - tileSize: SizeInt = tileset.tileSize, - ) : this(map.toStacked(), tileset, smoothing, tileSize) - - @Deprecated("Use TileMapInfo variant instead") - constructor( - map: Bitmap32, - tileset: TileSet, - smoothing: Boolean = true, - tileSize: SizeInt = tileset.tileSize, - ) : this(map.toIntArray2().toStacked(), tileset, smoothing, tileSize) - fun pixelHitTest(x: Int, y: Int, direction: HitTestDirection): Boolean { //if (x < 0 || y < 0) return false // Outside bounds if (x < 0 || y < 0) return true // Outside bounds diff --git a/korge/src/korlibs/korge/view/vector/GpuShapeView.kt b/korge/src/korlibs/korge/view/vector/GpuShapeView.kt index 6dc4eabb7c..eed5744ecc 100644 --- a/korge/src/korlibs/korge/view/vector/GpuShapeView.kt +++ b/korge/src/korlibs/korge/view/vector/GpuShapeView.kt @@ -195,7 +195,7 @@ open class GpuShapeView( //println("doRequireTexture=$doRequireTexture") - val time = measureTime { + val time = kotlin.time.measureTime { if (doRequireTexture) { //val currentRenderBuffer = ctx.ag.currentRenderBufferOrMain val currentFrameBuffer = ctx.ag.mainFrameBuffer diff --git a/korge/test/korlibs/korge/view/tiles/TileMapTest.kt b/korge/test/korlibs/korge/view/tiles/TileMapTest.kt index 33d2e4831a..f573e8260d 100644 --- a/korge/test/korlibs/korge/view/tiles/TileMapTest.kt +++ b/korge/test/korlibs/korge/view/tiles/TileMapTest.kt @@ -10,6 +10,8 @@ import korlibs.image.tiles.* import korlibs.math.geom.* import korlibs.math.geom.collider.* import korlibs.math.geom.shape.* +import korlibs.memory.* +import korlibs.number.* import kotlin.test.* class TileMapTest { @@ -18,7 +20,7 @@ class TileMapTest { viewsLog { val log = it.ag as AGLog log.logFilter = { str, kind -> kind != AGBaseLog.Kind.DRAW_DETAILS && kind != AGBaseLog.Kind.SHADER } - views.stage.tileMap(IntArray2(16, 16) { 0 }, TileSet.fromBitmapSlices(32, 32, listOf(Bitmap32(32, 32, premultiplied = true).slice()))).scale(0.1) + views.stage.tileMap(TileMapData(IntArray2(16, 16) { 0 }, TileSet.fromBitmapSlices(32, 32, listOf(Bitmap32(32, 32, premultiplied = true).slice())))).scale(0.1) it.views.render() } } @@ -27,11 +29,11 @@ class TileMapTest { fun testHitTest() { val tileSet = TileSet(intMapOf( 0 to TileSetTileInfo(0, Bitmap32(16, 16, premultiplied = true).slice(), collision = TileShapeInfoImpl(HitTestDirectionFlags.NONE, Rectangle(0, 0, 16, 16).toShape2D(), Matrix())), - 1 to TileSetTileInfo(0, Bitmap32(16, 16, premultiplied = true).slice(), collision = TileShapeInfoImpl(HitTestDirectionFlags.NONE, EmptyShape2D, Matrix())), - 2 to TileSetTileInfo(0, Bitmap32(16, 16, premultiplied = true).slice(), collision = TileShapeInfoImpl(HitTestDirectionFlags.ALL, EmptyShape2D, Matrix())), - 3 to TileSetTileInfo(0, Bitmap32(16, 16, premultiplied = true).slice(), collision = TileShapeInfoImpl(HitTestDirectionFlags.ALL, Rectangle(0, 0, 16, 16).toShape2D(), Matrix())), + 1 to TileSetTileInfo(1, Bitmap32(16, 16, premultiplied = true).slice(), collision = TileShapeInfoImpl(HitTestDirectionFlags.NONE, EmptyShape2D, Matrix())), + 2 to TileSetTileInfo(2, Bitmap32(16, 16, premultiplied = true).slice(), collision = TileShapeInfoImpl(HitTestDirectionFlags.ALL, EmptyShape2D, Matrix())), + 3 to TileSetTileInfo(3, Bitmap32(16, 16, premultiplied = true).slice(), collision = TileShapeInfoImpl(HitTestDirectionFlags.ALL, Rectangle(0, 0, 16, 16).toShape2D(), Matrix())), )) - val map = TileMap(SparseChunkedStackedIntArray2(StackedIntArray2(IntArray2(2, 2, intArrayOf(0, 1, 2, 3)))), tileSet) + val map = TileMap(TileMapData(SparseChunkedStackedInt53Array2(StackedInt53Array2(Int53Array2(2, 2, int53ArrayOf(0, 1, 2, 3)))), tileSet)) assertEquals(false, map.pixelHitTest(5, 5, HitTestDirection.DOWN)) assertEquals(false, map.pixelHitTest(16 + 5, 5, HitTestDirection.DOWN)) assertEquals(false, map.pixelHitTest(5, 16 + 5, HitTestDirection.DOWN)) diff --git a/korge/test@jvm/korlibs/korge/view/tiles/TileMapViewScreenshotTest.kt b/korge/test@jvm/korlibs/korge/view/tiles/TileMapViewScreenshotTest.kt index 4802cc39c3..2bc7b99fef 100644 --- a/korge/test@jvm/korlibs/korge/view/tiles/TileMapViewScreenshotTest.kt +++ b/korge/test@jvm/korlibs/korge/view/tiles/TileMapViewScreenshotTest.kt @@ -8,6 +8,8 @@ import korlibs.korge.testing.* import korlibs.korge.view.* import korlibs.math.geom.* import korlibs.math.geom.slice.* +import korlibs.memory.* +import korlibs.number.* import kotlin.test.* class TileMapViewScreenshotTest { @@ -21,7 +23,8 @@ class TileMapViewScreenshotTest { TileSetTileInfo(0, Bitmap32(133, 173, Colors.RED.premultiplied).slice()), TileSetTileInfo(1, Bitmap32(133, 173, Colors.GREEN.premultiplied).slice()), ) - val tilemap = tileMap(IntArray2(2, 2, intArrayOf(0, 1, 1, 0)), repeatX = TileMapRepeat.REPEAT, repeatY = TileMapRepeat.REPEAT, tileset = tileset) + + val tilemap = tileMap(TileMapData(StackedInt53Array2(Int53Array2(2, 2, int53ArrayOf(0, 1, 1, 0))), repeatX = TileMapRepeat.REPEAT, repeatY = TileMapRepeat.REPEAT, tileSet = tileset)) tilemap.xy(3000, 1500) assertScreenshot(this, "offsetInfiniteTilemap", includeBackground = false)