Post by (X) on May 24, 2023 21:08:22 GMT 1
Looking for a millisecond timer in GFA? Check out GFA's TimerQ!
Here is the result of not knowing something already exists and effectively trying to re-invent the wheel.
You may have come to the conclusion that the maximum event trigger rate of the standard Timer control provided by GFA or other Basic program editors can not exceed ~60 Hz or a period of about 16 ms.
Here is a proof of concept for a millisecond resolution timer library made accessible to GFA by simply including the attached GFA library into any GFA-BASIC 32 for Windows program with the statement: $Lib "Lib_Timer_ms".
You will need the compiled ' Lib_Timer_ms.lg32' file in the same directory as your application or the same path as your other GFA libs.
Here is a proof of concept for a millisecond resolution timer library made accessible to GFA by simply including the attached GFA library into any GFA-BASIC 32 for Windows program with the statement: $Lib "Lib_Timer_ms".
You will need the compiled ' Lib_Timer_ms.lg32' file in the same directory as your application or the same path as your other GFA libs.
The "Lib_Timer_ms" library is a 'wrapper' for the winmm.dll timer related Microsoft API functions:
Declare Function timeGetTime Lib "winmm" () As Long
Declare Function timeBeginPeriod Lib "winmm" (ByVal p%) As Long
Declare Function timeSetEvent Lib "winmm" ( _
ByVal uDelay%, _
ByVal uResolution%, _
ByVal lpCallback_Procedure As Handle, _
ByVal user%, _
ByVal fEvent%) As Long
Declare Function timeKillEvent Lib "winmm" (ByVal id%) As Long
Declare Function timeEndPeriod Lib "winmm" (ByVal p%) As Long
I've tried to see how much I can put into the lib to leave the minimum necessary declarations in the main code.
This demo illustrates that all you need to do is:
Import the lib.
Call init:
-milliseconds_per_frame,
-frame_count,
-mode(Oneshot or Periodic) and
-the procedure_address for the procedure that will be called each frame.
Call start and
Wait for the timer to finish or
Call stop.
Improvements...
1) A point and click input form to help set these parameters more intuitively.
2) Find a way to manage multiple timers probably using an array.
3) Better error management.
4) Better documentation & help
This demo illustrates that all you need to do is:
Import the lib.
Call init:
-milliseconds_per_frame,
-frame_count,
-mode(Oneshot or Periodic) and
-the procedure_address for the procedure that will be called each frame.
Call start and
Wait for the timer to finish or
Call stop.
Improvements...
1) A point and click input form to help set these parameters more intuitively.
2) Find a way to manage multiple timers probably using an array.
3) Better error management.
4) Better documentation & help
Any hints that might help improve this lib would be greatly appreciated.