Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to korlibs 6.0.0-alpha7 #2253

Merged
merged 9 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fun Project.allDependantProjects(): Set<Project> {
val out = LinkedHashSet<Project>()
val explored = LinkedHashSet<Project>()
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
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
8 changes: 5 additions & 3 deletions korge-core/src@jvm/korlibs/render/awt/BaseAwtGameWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion korge-ipc/src/main/kotlin/korlibs/korge/ipc/KorgeIPC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion korge-sandbox/src/samples/MainBVH.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions korge-sandbox/src/samples/MainCompression.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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"])
Expand Down
4 changes: 2 additions & 2 deletions korge-sandbox/src/samples/MainEmojiColrv1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 12 additions & 5 deletions korge-sandbox/src/samples/MainTiledBackground.kt
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions korge-sandbox/src/samples/MainTilemapTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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("")
Expand Down Expand Up @@ -103,17 +104,17 @@ 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)
val dist = (p - center).length
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
}
Expand Down
85 changes: 2 additions & 83 deletions korge/src/korlibs/korge/view/tiles/TileMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,68 +20,13 @@ 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,
var smoothing: Boolean = true,
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 <T> lock(block: () -> T): T {
lock()
try {
return block()
} finally {
unlock()
}
}

private var tileWidth: Float = 0f
private var tileHeight: Float = 0f

Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion korge/src/korlibs/korge/view/vector/GpuShapeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions korge/test/korlibs/korge/view/tiles/TileMapTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
}
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down