TurboMagic 92 Posted July 30, 2020 For some research we need to create an Android app with a precisely timed output of colored rectangles/bars. Unfortunately TTimer has a too big jitter. I need a low interval (if possible < 10ms) and unless my code in the timer event runs for longer than the interval the timer events should come precisely and not sometimes after 10ms (given a 10ms interval is set) and sometimes after 11 or 12 ms). Share this post Link to post
Dalija Prasnikar 1396 Posted July 31, 2020 You need different architecture to achieve such timing. Timer is not precise enough and even if you can make it precise, there will always be other events that will mess up your timer schedule. You need a some kind of game loop. Basically, you should not rely on timer to calculate and paint your screen, you need to trigger paint event with delta time and based on that time (elapsed from last paint) you will calculate positions and render your screen. Some starting point: https://gamedev.stackexchange.com/questions/651/how-should-i-write-a-main-game-loop Share this post Link to post
TurboMagic 92 Posted August 10, 2020 Thanks for this reply. In German Delphipraxis somebody posted this link: https://developer.android.com/games/develop/gameloops But I couldn't find any Delphi implementation yet. It seems to integrate deep into OpenGL or Vulkan. Share this post Link to post
TurboMagic 92 Posted August 10, 2020 For us it is sufficient to swap color of a rectangle. Today we tried something with the bitmap of a TImage which has a clear method where you can specify the new color. That might be sufficient, if the timer would be more jitter free. Thus we call it from a secondary thread as TBitmap is thread-safe nowadays. Question is how to "time" such a thread on Android precisely enough? Do busy waiting with TStopWatch until the necessary time is elapsed? Or is there something better? Share this post Link to post
Dave Nottage 557 Posted August 10, 2020 5 hours ago, TurboMagic said: But I couldn't find any Delphi implementation yet There's a Delphi implementation of Choreographer in Alcinoe: https://github.com/Zeus64/alcinoe/blob/master/source/ALFmxAni.pas If I were doing development where timing of display output is crucial (such as a game), I'd do something similar Share this post Link to post