Skip to content

Commit

Permalink
WIP SDL
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jul 4, 2024
1 parent 4b9c1ac commit 849ff3b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
25 changes: 25 additions & 0 deletions korge-core/src/korlibs/sdl/SDL.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package korlibs.sdl

import korlibs.annotations.*
import korlibs.ffi.*

val SDLPath by lazy {
//"https://github.com/libsdl-org/SDL/releases/download/release-2.30.5/SDL2-2.30.5-win32-x64.zip"
//"SDL"
"C:\\temp\\SDL2.dll"
}

@KeepNames
open class SDL : FFILib(SDLPath) {
companion object {
const val SDL_WINDOWPOS_UNDEFINED = 0x1FFF0000
const val SDL_WINDOWPOS_CENTERED = 0x2FFF0000
}

val SDL_Init: (flags: Int) -> Int by func()
val SDL_CreateWindow: (title: String, x: Int, y: Int, w: Int, h: Int, flags: Int) -> FFIPointer by func()
val SDL_ShowWindow: (window: FFIPointer) -> Unit by func()
val SDL_RaiseWindow: (window: FFIPointer) -> Unit by func()
val SDL_PollEvent: (event: FFIPointer) -> Boolean by func()
val SDL_Quit: () -> Unit by func()
}
36 changes: 36 additions & 0 deletions korge-core/test/korlibs/sdl/SDLTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package korlibs.sdl

import korlibs.concurrent.thread.*
import korlibs.ffi.*
import korlibs.io.async.*
import korlibs.time.*
import kotlinx.coroutines.*
import kotlin.test.*

class SDLTest {
@Ignore
@Test
fun test() = suspendTest {
val sdl = SDL()
try {
sdl.SDL_Init(0)
val window = sdl.SDL_CreateWindow("hello world", SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, 300, 300, 2)
sdl.SDL_ShowWindow(window)
sdl.SDL_RaiseWindow(window)

val event = CreateFFIMemory(1024)
for (n in 0 until 1000) {
event.usePointer {
while (sdl.SDL_PollEvent(it)) {
println(it.getS32(0))
}
//NativeThread.sleep(1.milliseconds)
delay(1.milliseconds)
}
}
sdl.SDL_Quit()
} finally {
//sdl.close() // @TODO: enable after korlibs -alpha8
}
}
}

0 comments on commit 849ff3b

Please sign in to comment.