Jump to content

Synchronize function call with display refresh timings


Recommended Posts

Hello,


I am trying to figure out how to synchronize a function call in my script with my display's refresh timings, and would appreciate some ideas on how to achieve this.

I have previously always just limited the frequency of function calls to a specific time interval.
For example:

$FrameTimer = TimerInit()
$FrameTimes = 40

While 1

    DoSomething()
    
    If TimerDiff($FrameTimer) >= $FrameTimes Then
        UpdateUI()
        FrameTimer = TimerInit()
    EndIf
    
WEnd

This approach reduces flickering and all, but it's not as sophisticated as I'd like.
Unfortunately I was unable to find any forum posts that address this topic, so here's mine. (also my first post on the forum)

 

Is it possible to "read" when the display is going to be refreshed, or am I wasting my time?

 

Thanks in advance!

Link to post
Share on other sites

I don't know what to tell you about the "refresh rate" part, while on calling a function at time intervals, instead of continuously checking the elapsed time (If TimerDiff .....) you could either use the AdlibRegister command or the _WinAPI_SetTimer function. The first (AdlibRegister) is not executed while the script is displaying a blocking function (e.g. MsgBox, InputBox, WinWait, WinWaitClose etc.) while the second (_WinAPI_SetTimer) does not have this limitation. Here is a simple example of using _WinAPI_SetTimer:

#include <WinAPISys.au3>

; get handle of a user-defined function.
Global $hTimerProc = DllCallbackRegister('_UpdateUI', 'none', '')

; set the function call timer
Global $iTimerID = _WinAPI_SetTimer(0, 0, 500, DllCallbackGetPtr($hTimerProc))

MsgBox(0, 'MsgBox', "I'm a blocking function" & @CRLF & _
        "nevertheless the callback function is still called " & @CRLF & _
        "...see the dot progression in the console output...")

; clear on exit
_WinAPI_KillTimer(0, $iTimerID)
DllCallbackFree($hTimerProc)

; function called by a timer.
; It is also run while a blocking function is shown
; (e.g. MsgBox, InputBox, WinWait, WinWaitClose etc.)
;
Func _UpdateUI()
    ConsoleWrite('.') ; just to show something ...
EndFunc   ;==>_UpdateUI

 

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to post
Share on other sites

WOW! I am way to unfamiliar with the WinAPI Tools. This will be a HUGE improvement on a few of my most recent scripts!
I am not planning on making a videogame or anything that would need the proper V-Sync, so for the most part, this is actually the solution I needed.
Thanks @Chimp!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...