Capping frame rate in 3D
-
- User
- Posts: 10
- Joined: Mon Oct 07, 2024 9:15 am
Capping frame rate in 3D
I know about SetFrameRate(), which limits (on the upper end) the frame rate of FlipBuffers() in 2D, but it seems there is not an equivalent function for 3D (to limit the number of times RenderWorld() is called per second). Do I have to implement this frame rate cap myself? If so, what's the "best" way to do it? Measure the elapsed time since the last RenderWorld() then do a Delay() if this frame is too soon after the previous frame?
-
- Addict
- Posts: 2345
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Capping frame rate in 3D
Why would you want to do this? FlipBuffers() is necessary for RenderWorld() to be displayed, isn't it? Delaying twice per frame isn't needed.
[Edit]
Ok I know now why maybe: you want the physics to be calculated closer to the actual flip buffers to reduce physical stutter?
But you may want to replace ElapsedMilliseconds with high performance counters.
Still I just wouldn't limit it at all.
[Edit]
Ok I know now why maybe: you want the physics to be calculated closer to the actual flip buffers to reduce physical stutter?
Code: Select all
...
LastFlip = ElapsedMilliseconds()
TargetFreq = 60
TargetWavelength = 1000 / 60
Repeat
...
While ElapsedMilliseconds() - LastFlip < TargetWavelength
Delay(10)
Wend
RenderWorld()
FlipBuffers()
LastFlip = ElapsedMilliseconds()
Until Quit
...
Still I just wouldn't limit it at all.
bye,
Daniel
Daniel
-
- User
- Posts: 10
- Joined: Mon Oct 07, 2024 9:15 am
Re: Capping frame rate in 3D
Oh, I see. Was just starting to read up on 3D and hadn't noticed that FlipBuffers() is used with RenderWorld(). That answers my question, thanks.
Re: Capping frame rate in 3D
Here is my solution:
Code: Select all
Procedure.i Timer(deltatime.i)
Static.i LastTick
If ElapsedMilliseconds()-LastTick>deltatime.i
LastTick=ElapsedMilliseconds()
ProcedureReturn(#True)
EndIf
ProcedureReturn(#False)
EndProcedure
OpenConsole("Timer")
Define.i nticks,nmainloop
;MAIN LOOP
Repeat
;In a fictional game, here would be the input check, event handling.
;This part would run multiple times between renders, if movements are here, those should be adjusted with elapsed time.
;Alternatively movements might happen just before render
nmainloop+1
;...RENDER
If timer(200)
;in a fictional game, here would be the renderworld(): displaysprites(): Flipbuffers()
;deltatime would be 16, roughly ~60 FPS (1000 ms / target FPS)
nticks+1
PrintN("Ticked "+Str(nticks)+" times. Main Loop iterations:"+Str(nmainloop))
Delay(1) ;Here we only give back time to the OS after the "render" tick, so there is more processing power in the main loop.
;If you don't want/need that, you can switch this with a main loop delay.
EndIf
;...
;Delay(1)
ForEver
-
- User
- Posts: 10
- Joined: Mon Oct 07, 2024 9:15 am
Re: Capping frame rate in 3D
Thanks a lot, miso - that really helps. Very nice solution, and I like that the other operations can happen at a higher frequency than the renders.
Re: Capping frame rate in 3D
Your welcome.
A little side note: Delaying affects your CPU usage. More frequent delaying reduces CPU load, but gives you less computing time.
Try to switch the two delaying part, and check your CPU load in your OS.
A little side note: Delaying affects your CPU usage. More frequent delaying reduces CPU load, but gives you less computing time.
Try to switch the two delaying part, and check your CPU load in your OS.