mirror of
https://github.com/Candygoblen123/SwiftNES.git
synced 2024-11-24 09:56:47 -06:00
impl frame timing
This commit is contained in:
parent
59e7559d77
commit
df8be993f7
@ -41,8 +41,21 @@ let keyMap = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
var frame = Frame()
|
var frame = Frame()
|
||||||
|
let time: UnsafeMutablePointer<timespec> = UnsafeMutablePointer<timespec>.allocate(capacity: 1)
|
||||||
|
clock_gettime(CLOCK_REALTIME, time)
|
||||||
|
time.pointee.tv_nsec += Int(0.01666 * 1000000000)
|
||||||
let bus = Bus(rom: rom, joypad1: joypad1) { ppu in
|
let bus = Bus(rom: rom, joypad1: joypad1) { ppu in
|
||||||
Render.render(ppu, frame: frame)
|
Render.render(ppu, frame: frame)
|
||||||
|
|
||||||
|
//wait here until 16.66 ms have passed
|
||||||
|
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, time, nil)
|
||||||
|
var nextNSec = time.pointee.tv_nsec + Int(0.01666 * 1000000000)
|
||||||
|
if nextNSec > 999999999 {
|
||||||
|
nextNSec -= 999999999
|
||||||
|
time.pointee.tv_sec += 1
|
||||||
|
}
|
||||||
|
time.pointee.tv_nsec = nextNSec
|
||||||
|
|
||||||
SDL_UpdateTexture(texture, nil, frame.data, 256 * 3)
|
SDL_UpdateTexture(texture, nil, frame.data, 256 * 3)
|
||||||
SDL_RenderCopy(canvas, texture, nil, nil)
|
SDL_RenderCopy(canvas, texture, nil, nil)
|
||||||
SDL_RenderPresent(canvas)
|
SDL_RenderPresent(canvas)
|
||||||
@ -75,3 +88,4 @@ let bus = Bus(rom: rom, joypad1: joypad1) { ppu in
|
|||||||
let cpu = CPU(bus: bus)
|
let cpu = CPU(bus: bus)
|
||||||
cpu.reset()
|
cpu.reset()
|
||||||
cpu.run()
|
cpu.run()
|
||||||
|
time.deallocate()
|
||||||
|
Loading…
Reference in New Issue
Block a user