question for you guys, what is the best way to go about calculating an automatic frameskip value? this is what i've got in the FreeBASIC version of my emulator. wondering if there's a more accurate/better method, or if there are any inherent problems in this algorithm?
this loop is right after rendering each frame:
this loop is right after rendering each frame:
Code:
Do
#Ifdef __FB_WIN32__
QueryPerformanceCounter(CPtr(Any Ptr, @curtimer))
#Else 'then it's linux
gettimeofday(@timing, NULL)
curtimer = timing.tv_usec
#EndIf
'calculate auto-frameskip
timertemp = curtimer - lasttimer
If timertemp >= (timerfreq / ((60/frameskip)\2)) Then frameskip = frameskip + 1
If timertemp < (timerfreq / 60) Then frameskip = frameskip - 1
If frameskip > 30 Then frameskip = 30 'limit max frameskip count.. if your system is THAT slow, you shouldn't even be trying this.
If frameskip < 1 Then frameskip = 1
'end auto-frameskip calcs
If timertemp >= (timerfreq / 60) Then Exit Do
#Ifdef __FB_WIN32__
SwitchToThread() 'give up remainder of CPU timeslice if we shouldn't resume yet
#EndIf
Loop
#Ifdef __FB_WIN32__
QueryPerformanceCounter(CPtr(Any Ptr, @curtimer))
#Else 'then it's linux
gettimeofday(@timing, NULL)
curtimer = timing.tv_usec
#EndIf
'calculate auto-frameskip
timertemp = curtimer - lasttimer
If timertemp >= (timerfreq / ((60/frameskip)\2)) Then frameskip = frameskip + 1
If timertemp < (timerfreq / 60) Then frameskip = frameskip - 1
If frameskip > 30 Then frameskip = 30 'limit max frameskip count.. if your system is THAT slow, you shouldn't even be trying this.
If frameskip < 1 Then frameskip = 1
'end auto-frameskip calcs
If timertemp >= (timerfreq / 60) Then Exit Do
#Ifdef __FB_WIN32__
SwitchToThread() 'give up remainder of CPU timeslice if we shouldn't resume yet
#EndIf
Loop