aentwist / gamedriver

Lightweight cross-platform image matching tools focused on automation
GNU General Public License v3.0
0 stars 1 forks source link

Fix inaccurate timeouts #1

Closed aentwist closed 6 days ago

aentwist commented 1 week ago

Timeouts are currently measured by,

for timeout / refresh_rate times do
    is_done <- body()
    if is_done then break
    wait refresh_rate
end for

However, the execution time of the body is not always negligible. Especially for small refresh rates the body time becomes extremely significant, in some cases ~6-60x the refresh rate. In these cases the wall time of the timeout is proportionally affected. That is, timeouts become 6-60x longer than specified.

Instead timeouts should be measured using a pure wall time approach,

t_start <- get_time()
t_end <- get_time()
while t_end - t_start < timeout do
    is_done <- body()
    if is_done then break
    wait refresh_rate

    t_end <- get_time()
end while

By factoring in the body time, this should keep them accurate.

aentwist commented 1 week ago

The suggested fix has an inaccurate refresh rate

aentwist commented 6 days ago

:tada: This issue has been resolved in version 1.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: