diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-11 15:14:52 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-11 15:14:52 +0200 |
| commit | adaa36dbec1ce9aaafd61873b9d3d898a8c240cf (patch) | |
| tree | 4c81e8f5983c3d696a636e2cc433ce7c0a9c3dd8 /tests/timer.lua | |
| parent | 1d310e6ecb6e156598337612f16573d9cd284f5e (diff) | |
| download | lanes-adaa36dbec1ce9aaafd61873b9d3d898a8c240cf.tar.gz lanes-adaa36dbec1ce9aaafd61873b9d3d898a8c240cf.tar.bz2 lanes-adaa36dbec1ce9aaafd61873b9d3d898a8c240cf.zip | |
Bring all interesting fixes from the C++ implementation back into the C implementation
Diffstat (limited to 'tests/timer.lua')
| -rw-r--r-- | tests/timer.lua | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/tests/timer.lua b/tests/timer.lua index ec23cee..73ecb93 100644 --- a/tests/timer.lua +++ b/tests/timer.lua | |||
| @@ -18,13 +18,14 @@ end | |||
| 18 | 18 | ||
| 19 | local T1= "1s" -- these keys can be anything... | 19 | local T1= "1s" -- these keys can be anything... |
| 20 | local T2= "5s" | 20 | local T2= "5s" |
| 21 | local PING_DURATION = 20 | ||
| 21 | 22 | ||
| 22 | local step= {} | 23 | local step= {} |
| 23 | 24 | ||
| 24 | lanes.timer( linda, T1, 1.0, 1.0 ) | 25 | lanes.timer( linda, T1, 1.0, 1.0 ) |
| 25 | step[T1]= 1.0 | 26 | step[T1]= 1.0 |
| 26 | 27 | ||
| 27 | PRINT( "\n*** Timers every second (not synced to wall clock) ***\n" ) | 28 | PRINT( "\n*** Starting 1s Timer (not synced to wall clock) ***\n" ) |
| 28 | 29 | ||
| 29 | local v_first | 30 | local v_first |
| 30 | local v_last= {} -- { [channel]= num } | 31 | local v_last= {} -- { [channel]= num } |
| @@ -46,14 +47,15 @@ while true do | |||
| 46 | -- do not make measurements, first round is not 5secs due to wall clock adjustment | 47 | -- do not make measurements, first round is not 5secs due to wall clock adjustment |
| 47 | T2_first_round= false | 48 | T2_first_round= false |
| 48 | else | 49 | else |
| 49 | assert( math.abs(v-v_last[channel]- step[channel]) < 0.02 ) | 50 | local dt = math.abs(v-v_last[channel]- step[channel]) |
| 51 | assert( dt < 0.02, "channel " .. channel .. " is late: " .. dt) | ||
| 50 | end | 52 | end |
| 51 | end | 53 | end |
| 52 | 54 | ||
| 53 | if not v_first then | 55 | if not v_first then |
| 54 | v_first= v | 56 | v_first= v |
| 55 | elseif v-v_first > 3.0 and (not step[T2]) then | 57 | elseif v-v_first > 3.0 and (not step[T2]) then |
| 56 | PRINT( "\n*** Adding timers every 5 second (synced to wall clock) ***\n" ) | 58 | PRINT( "\n*** Starting 5s timer (synced to wall clock) ***\n" ) |
| 57 | 59 | ||
| 58 | -- The first event can be in the past (just cut seconds down to 5s) | 60 | -- The first event can be in the past (just cut seconds down to 5s) |
| 59 | -- | 61 | -- |
| @@ -63,7 +65,7 @@ while true do | |||
| 63 | lanes.timer( linda, T2, date, 5.0 ) | 65 | lanes.timer( linda, T2, date, 5.0 ) |
| 64 | step[T2]= 5.0 | 66 | step[T2]= 5.0 |
| 65 | 67 | ||
| 66 | elseif v-v_first > 10 then -- exit condition | 68 | elseif v-v_first > PING_DURATION then -- exit condition |
| 67 | break | 69 | break |
| 68 | end | 70 | end |
| 69 | v_last[channel]= v | 71 | v_last[channel]= v |
| @@ -80,7 +82,7 @@ PRINT( "\n*** Listing timers ***\n" ) | |||
| 80 | local r = lanes.timers() -- list of {linda, key, {}} | 82 | local r = lanes.timers() -- list of {linda, key, {}} |
| 81 | for _,t in ipairs( r) do | 83 | for _,t in ipairs( r) do |
| 82 | local linda, key, timer = t[1], t[2], t[3] | 84 | local linda, key, timer = t[1], t[2], t[3] |
| 83 | print( tostring( linda), key, timer[1], timer[2]) | 85 | print( tostring( linda), key, timer[1], timer[2]) |
| 84 | end | 86 | end |
| 85 | 87 | ||
| 86 | 88 | ||
