Code archives/Graphics/RefreshRate

This code has been declared by its author to be Public Domain code.

Download source code

RefreshRate by Teddyfles2001
Returns the current monitor refresh rate.
; RefreshRate()
; Returns the current monitor refresh rate.
; By Geert Jan Alsem
; http://geertjan.vze.com
;
; Updated version of a crappy RefreshRate() function I once wrote.
; Actually, this one is a bit strange too. Basicly it measures how
; long a VWait takes 100 times. However, it only uses the last 20
; times to calculate the result. Now the strange thing is that if
; I remove the seemingly useless first 80 runs, the function
; doesn't work as well as it does now. Apparently it needs to warm
; up first... or something...
;
; Anyway, it's a pretty useless function anyway. Just use
; WaitTimer if you want to make a game run at the same speed on
; any refresh rate.


Function RefreshRate()
  Repeat
    rr_timer = MilliSecs()
    VWait
    rr_timer = MilliSecs() - rr_timer
    If rr_count > 79 Then rr_total# = rr_total# + 1000 / Float(rr_timer)
    rr_count = rr_count + 1
  Until rr_count = 100
  Return rr_total#/20
End Function

Comments

DrToxic2014
This is a good Function, I like how it works. perfect for my current program I'm writing.

Do you mind if I suggest this small edit? We know how many times we want the Function to run, so why not For instead of Repeat. Then we can lose a line.

For rr_count=0 To 100
rr_timer = MilliSecs()
VWait
rr_timer = MilliSecs() - rr_timer
If rr_count > 80 Then rr_total# = rr_total# + 1000 / Float(rr_timer)
Next
Return rr_total#/20


Floyd2014
This doesn't work for me as VWait does nothing, i.e. does not wait.


RustyKristi2014
It looks like VWait is like Vertical Sync. My FPS is limited to 60 when I set this on. Also, the screen tearing is fixed when enabled..


DrToxic2014
VWait does work. It is the difference between my program registering 60 FPS (VWait) and 2147483648 FPS (No VWait).

Honestly, the between the values is the VWait instruction.


RGR2015
RustyKristi wrote: It looks like VWait is like Vertical Sync.

It does not even look like ... It is ... Actually you can find it in the Docs:
VWait [frames]
Parameters
[frames] = optional number of frames to wait. Default is 1 frame.

Description
VWait will cause the CPU to wait for the next (or specified number of) vertical blank event on the monitor


Matty2015
Personally I would have done it differently....simply had a timed pause of 1 or 2 seconds and count the number of times vwait runs....then average it.


Code Archives Forum