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

[WIP] Major Game Window rewrite #1962

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
86a247d
Moved WindowsRegistry to korge-core
soywiz Oct 21, 2023
c83d9eb
[WIP] New Game Window (not working yet)
soywiz Oct 21, 2023
54b7572
[WIP] Much more work on New Game Window
soywiz Oct 21, 2023
c92dac0
Make common FFI support ObjectiveC code, and moved DarwinMacosGameCon…
soywiz Oct 21, 2023
db35c62
Remove memory.dyn package
soywiz Oct 21, 2023
0034073
Fixed DarwinMacosGameController
soywiz Oct 21, 2023
517e065
Improve Stopwatch internal namings
soywiz Oct 21, 2023
842b966
[WIP] More work on New Game Window
soywiz Oct 21, 2023
2c5d738
[WIP] More work on New Game Window
soywiz Oct 21, 2023
65b7d7b
[WIP] More work on New Game Window
soywiz Oct 21, 2023
3d6fa3e
[WIP] More work on New Game Window
soywiz Oct 21, 2023
d3d9d7c
Some fixes
soywiz Oct 22, 2023
f8a7171
Optimize UIButton.textColor cache
soywiz Oct 22, 2023
67434d2
Run gl.finish outside the lock
soywiz Oct 22, 2023
3c61df9
Minor
soywiz Oct 22, 2023
a581e44
Optimize MainTiledBackground
soywiz Oct 22, 2023
6198f8c
Do not GC on event loop. Fixes performance issues
soywiz Oct 22, 2023
39b2f34
Some fixes and improvements
soywiz Oct 22, 2023
095ec76
Added arraycopyStride
soywiz Oct 22, 2023
9ec074e
Added NewPlatformAudioOutput callback-based
soywiz Oct 22, 2023
31217f3
Super stable audio on MacOS by using the NewPlatformAudioOutput
soywiz Oct 22, 2023
585c253
"-XX:+IgnoreUnrecognizedVMOptions", "-XX:+UseZGC", "-XX:+ZGenerational"
soywiz Oct 22, 2023
35f3dd4
Fixes forceRenderEveryFrame=false and fixes some TextBlock & UICheckB…
soywiz Oct 22, 2023
98fda7e
Stage.GC action
soywiz Oct 22, 2023
6148692
Add DitheringFilter to the MainFilterScale sample
soywiz Oct 22, 2023
1d0d3f0
Fix some tests
soywiz Oct 22, 2023
2382d03
Added KorAtomicFloat & KorAtomicBase<T>.update
soywiz Oct 23, 2023
6f64d84
Added generic arraycopyStride
soywiz Oct 23, 2023
d1ee158
Make createNewPlatformAudioOutput accept the number of channels inste…
soywiz Oct 23, 2023
8413167
Improve atomics for JnaNewCoreAudio
soywiz Oct 23, 2023
e135e27
Make MainPolyphonic work with atomic fields to avoid concurrency issues
soywiz Oct 23, 2023
fd9bdb1
Some android GameWindow adjustments
soywiz Oct 23, 2023
94b3b74
Auto-configure a JVM logger if no handlers are configured
soywiz Oct 23, 2023
9ec4db7
Check in sandbox that injector is available in the coroutine context
soywiz Oct 23, 2023
c1e2c79
Make GameWindow Closeable
soywiz Oct 23, 2023
be87a46
Small cleanup
soywiz Oct 23, 2023
686aff8
Try to fix headless tests
soywiz Oct 23, 2023
715934f
More work
soywiz Oct 23, 2023
1da1383
More work
soywiz Oct 23, 2023
f4291f5
More work
soywiz Oct 23, 2023
0f54c2b
More work
soywiz Oct 23, 2023
5761e67
More work
soywiz Oct 23, 2023
be5f121
More work
soywiz Oct 23, 2023
91c3af8
More work
soywiz Oct 23, 2023
7901b7e
More work
soywiz Oct 23, 2023
af55612
More work
soywiz Oct 24, 2023
4a8a90c
More work
soywiz Oct 24, 2023
a8aaf77
Some cleanups
soywiz Oct 24, 2023
0060eaa
More work
soywiz Oct 24, 2023
cb9d793
More work
soywiz Oct 24, 2023
e5f274d
More work
soywiz Oct 24, 2023
964ef56
More work
soywiz Oct 24, 2023
f8cad85
Update ios-deploy to 1.12.2
soywiz Oct 24, 2023
c5629b7
Prepare for using xcrun devicectl device
soywiz Oct 24, 2023
f72a6c6
More work
soywiz Oct 24, 2023
a92bc12
More work
soywiz Oct 24, 2023
65a3b12
Some fixes
soywiz Oct 24, 2023
58f7b23
Some fixes
soywiz Oct 24, 2023
2fbdb42
Some fixes
soywiz Oct 24, 2023
882b74d
More work
soywiz Oct 24, 2023
cb1d97d
Merge
soywiz Oct 24, 2023
c236e57
Merge
soywiz Oct 24, 2023
4e18eae
Merge branch 'main' into feature/final.new.game.window
soywiz Oct 25, 2023
8478616
Merge branch 'main' into feature/final.new.game.window
soywiz Oct 25, 2023
e1214c4
Merge branch 'main' into feature/final.new.game.window
soywiz Oct 25, 2023
a61cf5c
Merge
soywiz Oct 25, 2023
b4ca120
Merge
soywiz Oct 25, 2023
a98f470
Fix JS tests
soywiz Oct 25, 2023
9355ddf
Some fixes
soywiz Oct 25, 2023
23e5dc0
Small fix
soywiz Oct 25, 2023
dd2e837
Merge branch 'main' into feature/final.new.game.window
soywiz Oct 25, 2023
ffc9888
More work
soywiz Oct 25, 2023
e67dc6b
Some fixes
soywiz Oct 25, 2023
1bf16c8
More work
soywiz Oct 25, 2023
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
10 changes: 7 additions & 3 deletions korge-core/src/android/korlibs/io/file/std/VfsAndroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ private var _vfsInitWithAndroidContextOnce: Boolean = false
var absoluteCwd = File(".").absolutePath
val tmpdir: String by lazy { System.getProperty("java.io.tmpdir") }

fun vfsInitWithAndroidContextOnce(context: Context) {
if (_vfsInitWithAndroidContextOnce) return
fun vfsInitWithAndroidContextOnce(context: Context?) {
if (_vfsInitWithAndroidContextOnce || context == null) return
_vfsInitWithAndroidContextOnce = true
absoluteCwd = context.applicationInfo.dataDir
try {
absoluteCwd = context.applicationInfo.dataDir
} catch (e: Throwable) {
e.printStackTrace()
}
}

class AndroidDeferredVfs(private val generate: (Context) -> VfsFile) : Vfs.Proxy() {
Expand Down
16 changes: 3 additions & 13 deletions korge-core/src/darwin/korlibs/io/file/std/LocalVfsNative.kt
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
package korlibs.io.file.std

import korlibs.time.*
import korlibs.io.async.*
import korlibs.io.file.*
import korlibs.io.lang.*
import korlibs.io.posix.*
import korlibs.io.process.*
import korlibs.io.stream.*
import korlibs.time.*
import kotlinx.cinterop.*
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import platform.posix.*
import kotlin.math.*
import kotlin.native.concurrent.*

@ThreadLocal
val tmpdir: String by lazy { Environment["TMPDIR"] ?: Environment["TEMP"] ?: Environment["TMP"] ?: "/tmp" }

@ThreadLocal
var customCwd: String? = null

@ThreadLocal
val nativeCwd by lazy { StandardPaths.cwd }
val nativeCwd get() = StandardPaths.cwd
val cwd: String get() = customCwd ?: nativeCwd

//@ThreadLocal
//val cwdVfs: VfsFile by lazy { DynamicRootVfs(rootLocalVfsNative) { cwd } }
val cwdVfs: VfsFile get() = rootLocalVfsNative[cwd]

@ThreadLocal
actual val standardVfs: StandardVfs = object : StandardVfs() {
override val resourcesVfs: VfsFile by lazy { applicationDataVfs.jail() }
override val resourcesVfs: VfsFile get() = applicationDataVfs.jail()
override val rootLocalVfs: VfsFile get() = applicationDataVfs
}

@ThreadLocal
actual val cacheVfs: VfsFile by lazy { MemoryVfs() }

@ThreadLocal
actual val tempVfs: VfsFile by lazy { jailedLocalVfs(tmpdir) }

actual val applicationVfs: VfsFile get() = rootLocalVfsNative[customCwd ?: StandardPaths.resourcesFolder]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import korlibs.datastructure.thread.*
actual abstract class NativeThreadLocal<T> {
private val lock = Lock()
private val perThread = LinkedHashMap<Long, T>()
actual abstract fun initialValue(): T
actual abstract fun initialValue(): T
actual fun get(): T = lock { perThread.getOrPut(NativeThread.currentThreadId) { initialValue() } }
actual fun set(value: T) { lock { perThread[NativeThread.currentThreadId] = value } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.sun.jna.*
import korlibs.ffi.osx.*
import korlibs.image.awt.*
import korlibs.image.color.*
import korlibs.internal.osx.CoreFoundation
import korlibs.io.annotations.*
import korlibs.io.file.*
import korlibs.io.file.std.*
Expand All @@ -15,29 +16,6 @@ import java.io.*
open class CoreGraphicsImageFormatProvider : AwtNativeImageFormatProvider() {
companion object : CoreGraphicsImageFormatProvider()

@Keep
object CoreFoundation {
// CFNumberGetValue(number: platform.CoreFoundation.CFNumberRef? /* = kotlinx.cinterop.CPointer<cnames.structs.__CFNumber>? */, theType: platform.CoreFoundation.CFNumberType /* = kotlin.Int */, valuePtr: kotlinx.cinterop.CValuesRef<*>?): kotlin.Boolean { /* compiled code */ }
val LIB = "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation"
val lib: NativeLibrary = NativeLibrary.getInstance("/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation")
val kCFBooleanFalse: Pointer? get() = lib.getGlobalVariableAddress("kCFBooleanFalse")
val kCFBooleanTrue: Pointer? get() = lib.getGlobalVariableAddress("kCFBooleanTrue")
//val kCFNumberIntType: Pointer? get() = lib.getGlobalVariableAddress("kCFNumberIntType")
val kCFNumberIntType: Int get() = 9

@JvmStatic external fun CFDataCreate(allocator: Pointer?, bytes: Pointer?, length: Int): Pointer?
@JvmStatic external fun CFDataCreate(allocator: Pointer?, bytes: ByteArray, length: Int): Pointer?
@JvmStatic external fun CFDataGetBytePtr(data: Pointer?): Pointer?
@JvmStatic external fun CFDictionaryCreateMutable(allocator: Pointer?, capacity: Int, keyCallbacks: Pointer?, valueCallbacks: Pointer?): Pointer?
@JvmStatic external fun CFDictionaryAddValue(theDict: Pointer?, key: Pointer?, value: Pointer?): Unit
@JvmStatic external fun CFDictionaryGetValue(dict: Pointer?, key: Pointer?): Pointer?
@JvmStatic external fun CFNumberGetValue(number: Pointer?, type: Int, holder: Pointer?)

init {
Native.register(LIB)
}
}

@Keep
object CoreGraphics {
val LIB = "/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics"
Expand Down
18 changes: 9 additions & 9 deletions korge-core/test/common/korlibs/io/concurrent/LockTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import korlibs.datastructure.lock.*
import kotlin.test.*

class LockTest {
@Test
fun test() {
val lock = Lock()
var a = 0
lock {
a++
}
assertEquals(1, a)
}
@Test
fun test() {
val lock = Lock()
var a = 0
lock {
a++
}
assertEquals(1, a)
}

@Test
fun test2() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
package korlibs.datastructure.closeable

@OptIn(ExperimentalStdlibApi::class)
interface Closeable : AutoCloseable {
//interface Closeable : AutoCloseable {
//interface Closeable : AutoCloseable {
interface Closeable {
fun close(): Unit

companion object {
operator fun invoke(callback: () -> Unit) = object : Closeable {
override fun close() = callback()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ open class SyncEventLoop(
private var thread: NativeThread? = null
open fun start(): Unit {
if (thread != null) return
thread = nativeThread {
thread = nativeThread(name = "eventLoopSync") {
runTasksForever { thread?.threadSuggestRunning == true }
}
}
Expand Down
24 changes: 8 additions & 16 deletions korge-sandbox/src/commonMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@

import korlibs.audio.sound.*
import korlibs.event.*
import korlibs.image.color.*
import korlibs.image.font.*
import korlibs.image.format.*
import korlibs.image.text.*
import korlibs.image.vector.*
import korlibs.image.vector.format.SVG
import korlibs.io.async.*
import korlibs.io.file.std.*
import korlibs.io.lang.*
import korlibs.korge.*
import korlibs.korge.input.*
import korlibs.korge.scene.*
import korlibs.korge.time.*
import korlibs.korge.tween.*
import korlibs.korge.ui.*
import korlibs.korge.view.*
import korlibs.korge.view.align.alignBottomToBottomOf
import korlibs.korge.view.align.alignLeftToLeftOf
import korlibs.korge.view.align.alignTopToTopOf
import korlibs.korge.view.align.centerXOn
import korlibs.math.geom.*
import korlibs.korge.view.align.*
import korlibs.math.interpolation.*
import korlibs.time.*
import samples.*
Expand Down Expand Up @@ -72,12 +59,14 @@ suspend fun main() = Korge(
backgroundColor = DEFAULT_KORGE_BG_COLOR,
displayMode = KorgeDisplayMode.CENTER_NO_CLIP,
debug = false,
//forceRenderEveryFrame = false
forceRenderEveryFrame = false
) {
//sceneContainer().changeTo({MainSprites10k()}); return@start
//sceneContainer().changeTo({MainGraphicsText()}); return@start
//sceneContainer().changeTo({MainUI()}); return@start

//println("Injector: ${injector()}") // Ensure injector is available as a manual test

var lastBackTime = DateTime.EPOCH
keys {
this.down(Key.BACK) {
Expand Down Expand Up @@ -135,7 +124,10 @@ suspend fun main() = Korge(
//Demo(::MainColorTransformFilter),
//Demo(::MainMasks),
//Demo(::MainShape2dScene),
Demo(::MainUIStacks),
//Demo(::MainUIStacks),
//Demo(::MainPolyphonic),
Demo(::MainSound),
//Demo(::MainTiledBackground),
//Demo(::MainSprites10k),
//Demo(::MainStressMatrixMultiplication),
//Demo(::MainSDF),
Expand Down
18 changes: 11 additions & 7 deletions korge-sandbox/src/commonMain/kotlin/samples/MainClipping.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package samples

import korlibs.image.color.*
import korlibs.image.format.*
import korlibs.io.async.*
import korlibs.io.file.std.*
import korlibs.korge.scene.*
import korlibs.korge.view.*
Expand Down Expand Up @@ -64,13 +65,16 @@ class MainClipping : Scene() {
// This shouldn't be needed since Stage.localMatrix is always the identity
onStageResized { width, height ->
//println("resized=$width, $height")
container2.removeChildren()
container2.addChild(image(container.unsafeRenderToBitmapSync(views.renderContext).also {
it.updateColors { if (it.a == 0) Colors.RED else it }
}).also {
it.x = 300.0
it.y = views.virtualHeightDouble - it.bitmap.height - 50 * escale
})
launch {
val bitmap = container.renderToBitmap(views).also {
it.updateColors { if (it.a == 0) Colors.RED else it }
}
container2.removeChildren()
container2.addChild(image(bitmap).also {
it.x = 300.0
it.y = views.virtualHeightDouble - it.bitmap.height - 50 * escale
})
}
}
}
}
Expand Down
29 changes: 14 additions & 15 deletions korge-sandbox/src/commonMain/kotlin/samples/MainColorPicker.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package samples

import korlibs.korge.input.mouse
import korlibs.korge.scene.Scene
import korlibs.korge.view.SContainer
import korlibs.korge.view.addUpdater
import korlibs.korge.view.image
import korlibs.korge.view.scale
import korlibs.korge.view.unsafeRenderToBitmapSync
import korlibs.korge.view.xy
import korlibs.image.bitmap.Bitmaps
import korlibs.image.bitmap.slice
import korlibs.image.format.readBitmap
import korlibs.io.file.std.resourcesVfs
import korlibs.image.bitmap.*
import korlibs.image.format.*
import korlibs.io.async.*
import korlibs.io.file.std.*
import korlibs.korge.input.*
import korlibs.korge.scene.*
import korlibs.korge.view.*
import korlibs.math.geom.*

class MainColorPicker : Scene() {
Expand All @@ -22,9 +17,13 @@ class MainColorPicker : Scene() {

mouse {
move {
val bmp = stage!!.unsafeRenderToBitmapSync(views!!.renderContext, Rectangle(views.stage.mousePos.x - 5.0, views.stage.mousePos.y - 5.0, 10.0, 10.0), views!!.globalToWindowScaleAvg)
magnifier.bitmap = bmp.slice()
invalidateRender()

//val bmp = stage!!.unsafeRenderToBitmapSync(views!!.renderContext, Rectangle(views.stage.mousePos.x - 5.0, views.stage.mousePos.y - 5.0, 10.0, 10.0), views!!.globalToWindowScaleAvg)
launch {
val bmp = stage!!.renderToBitmap(views!!, Rectangle(views.stage.mousePos.x - 5.0, views.stage.mousePos.y - 5.0, 10.0, 10.0), views!!.globalToWindowScaleAvg)
magnifier.bitmap = bmp.slice()
invalidateRender()
}
}
}
addUpdater {
Expand Down
15 changes: 13 additions & 2 deletions korge-sandbox/src/commonMain/kotlin/samples/MainFilterScale.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ import korlibs.korge.view.filter.*

class MainFilterScale : Scene() {
override suspend fun SContainer.sceneMain() {
val image = image(resourcesVfs["korge.png"].readBitmap()).xy(100, 100)
val bmp = resourcesVfs["korge.png"].readBitmap()
val image = image(bmp).xy(100, 100)
.filterScale(1.0)
.filters(Convolute3Filter(Convolute3Filter.KERNEL_EDGE_DETECTION))
val dithering = DitheringFilter(4.0)
val image2 = image(bmp).xy(600, 100)
.filterScale(1.0)
.filters(dithering)
//.filters(BlurFilter())
//.filters(WaveFilter())

val combo = uiSlider(value = 1.0, max = 1.0, step = 0.01).xy(400, 100).changed { image.filterScale = it }
val combo = uiSlider(value = 1.0, max = 1.0, step = 0.01).xy(400, 100).changed {
image.filterScale = it
image2.filterScale = it
}
val combo2 = uiSlider(value = 4.0, min = 1.0, max = 8.0, step = 0.1).xy(400, 50).changed {
dithering.levels = it
}
//val combo = uiComboBox(items = listOf(0.0, 0.01, 0.05, 0.075, 0.125, 0.25, 0.44, 0.5, 0.75, 0.95, 0.99, 1.0)).xy(400, 100).onSelectionUpdate { image.filterScale = it.selectedItem ?: 1.0 }

// This reproduces a bug (black right and bottom border) at least on macOS with M1
Expand Down
8 changes: 4 additions & 4 deletions korge-sandbox/src/commonMain/kotlin/samples/MainHaptic.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package samples

import korlibs.korge.scene.Scene
import korlibs.korge.scene.*
import korlibs.korge.service.haptic.*
import korlibs.korge.ui.clicked
import korlibs.korge.ui.uiButton
import korlibs.korge.view.SContainer
import korlibs.korge.ui.*
import korlibs.korge.view.*
import korlibs.render.*

class MainHaptic : Scene() {
override suspend fun SContainer.sceneMain() {
Expand Down
20 changes: 6 additions & 14 deletions korge-sandbox/src/commonMain/kotlin/samples/MainRotatedAtlas.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package samples

import korlibs.korge.scene.Scene
import korlibs.korge.view.SContainer
import korlibs.korge.view.image
import korlibs.korge.view.solidRect
import korlibs.korge.view.xy
import korlibs.image.atlas.Atlas
import korlibs.image.atlas.readAtlas
import korlibs.image.bitmap.*
import korlibs.image.color.RGBA
import korlibs.image.format.ImageOrientation
import korlibs.io.file.std.resourcesVfs
import kotlin.math.max
import kotlin.native.concurrent.ThreadLocal
import korlibs.image.atlas.*
import korlibs.image.color.*
import korlibs.io.file.std.*
import korlibs.korge.scene.*
import korlibs.korge.view.*
import kotlin.math.*

class MainRotatedAtlas : Scene() {
override suspend fun SContainer.sceneMain() {
Expand Down Expand Up @@ -68,7 +61,6 @@ class MainRotatedAtlas : Scene() {
}

class BG {
@ThreadLocal
companion object {
private val colAr = arrayOf(RGBA(240, 240, 240), RGBA(220, 220, 220))
private var cur = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package samples

import korlibs.datastructure.*
import korlibs.image.bitmap.*
import korlibs.image.atlas.*
import korlibs.image.format.*
import korlibs.image.tiles.*
import korlibs.io.file.std.*
Expand All @@ -12,9 +12,13 @@ import korlibs.korge.view.tiles.*
class MainTiledBackground : Scene() {
override suspend fun SContainer.sceneMain() {

val atlas = MutableAtlasUnit()
val korgePng = atlas.add(bitmap("korge.png").toBMP32().scaleLinear(0.5, 0.5))
val korimPng = atlas.add(bitmap("korim.png").toBMP32().scaleLinear(0.5, 0.5))

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()),
TileSetTileInfo(0, korgePng.slice),
TileSetTileInfo(1, korimPng.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)
Expand Down
Loading
Loading