January 26, 2021, 06:43:31 AM

Author Topic: [bb] RefreshRate by Teddyfles [ 1+ years ago ]  (Read 401 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] RefreshRate by Teddyfles [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : RefreshRate
Author : Teddyfles
Posted : 1+ years ago

Description : Returns the current monitor refresh rate.

Code :
Code: BlitzBasic
  1. ; RefreshRate()
  2. ; Returns the current monitor refresh rate.
  3. ; By Geert Jan Alsem
  4. ; http://geertjan.vze.com
  5. ;
  6. ; Updated version of a crappy RefreshRate() function I once wrote.
  7. ; Actually, this one is a bit strange too. Basicly it measures how
  8. ; long a VWait takes 100 times. However, it only uses the last 20
  9. ; times to calculate the result. Now the strange thing is that if
  10. ; I remove the seemingly useless first 80 runs, the function
  11. ; doesn't work as well as it does now. Apparently it needs to warm
  12. ; up first... or something...
  13. ;
  14. ; Anyway, it's a pretty useless function anyway. Just use
  15. ; WaitTimer if you want to make a game run at the same speed on
  16. ; any refresh rate.
  17.  
  18.  
  19. Function RefreshRate()
  20.   Repeat
  21.     rr_timer = MilliSecs()
  22.     VWait
  23.     rr_timer = MilliSecs() - rr_timer
  24.     If rr_count > 79 Then rr_total# = rr_total# + 1000 / Float(rr_timer)
  25.     rr_count = rr_count + 1
  26.   Until rr_count = 100
  27.   Return rr_total#/20
  28. End Function


Comments :


DrToxic(Posted 1+ years ago)

 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


Floyd(Posted 1+ years ago)

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


RustyKristi(Posted 1+ years ago)

 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..


DrToxic(Posted 1+ years ago)

 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.


RGR(Posted 1+ years ago)

 <div class="quote"> RustyKristi wrote: It looks like VWait is like Vertical Sync. </div>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.  DescriptionVWait will cause the CPU to wait for the next (or specified number of) vertical blank event on the monitor


Matty(Posted 1+ years ago)

 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.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal