Compare commits

...

2 Commits

Author SHA1 Message Date
Andrew Glaze
af3be8d93d fix cross-platform compatability 2024-08-22 21:45:47 -04:00
Andrew Glaze
df8be993f7 impl frame timing 2024-08-22 21:19:11 -04:00

View File

@ -40,9 +40,16 @@ let keyMap = [
SDLK_s : JoypadButton.BUTTON_B
]
var timer = Date.now.addingTimeInterval(0.01666)
var frame = Frame()
let bus = Bus(rom: rom, joypad1: joypad1) { ppu in
let bus = Bus(rom: rom, joypad1: joypad1) { ppu in
Render.render(ppu, frame: frame)
// wait here until 16.66 ms have passed
// i would use clock_nanosleep but that isn't available cross platform
if timer.timeIntervalSinceNow > 0 {
usleep(UInt32(timer.timeIntervalSinceNow * 1000000))
}
timer.addTimeInterval(0.01666)
SDL_UpdateTexture(texture, nil, frame.data, 256 * 3)
SDL_RenderCopy(canvas, texture, nil, nil)
SDL_RenderPresent(canvas)