Code archives/Miscellaneous/Dynamic, accurate, and smart frame limiting
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This code will delay main loop execution to provide accurate frame limiting "on the fly" based on how long the main loop takes to execute each cycle. Use any "frame per second" code to verify correct frame speed. Frame speed variance is usually within 1 fps. Not bad, eh? :) | |||||
;This code will delay main loop execution to provide accurate frame limiting ;"on the fly" based on how long the main loop takes to execute each cycle. fRate = (1000/30) ;*set second number to desired frame rate* While Not KeyHit(1) ;this code must go at the very start of the loop time1 = MilliSecs() ;time at start of processing loop ;*********************************** ;all processing loop code goes here* ;*********************************** ;this code must go at the very end of the loop time2 = MilliSecs() ;time at end of processing loop time3 = time2 - time1 ;number of miiliseconds to process loop time4 = fRate - time3 ;number of milliseconds to delay each processing loop to achieve dynamically accurate framerate Delay time4 ;delay execution Wend ;Use any "frame per second" code to verify correct frame speed. ;Frame speed variance is usually within 1 fps. Not bad, eh? :) |
Comments
| ||
Not bad, but when execution is too slow, there's no "catch up". |
| ||
is there any reason for such an effort??? FrameTimer = createtimer( FPS ) do ; mainloop waittimer FrameTimer loop the only way for a smart frame limiting would be that you reduce flip/renderworld to the moments when the needed time has passed and let the rest run in realtime |
Code Archives Forum