code wiki / (root) / nx_animation_timeline_test.nx

nx_animation_timeline_test.nx source

↩ module page · 54 lines · 1824 B

1// nx_animation_timeline_test.nx -- smoke for nx_animation_timeline. 2 3import "nx_syscalls.nx" 4import "nx_animation_timeline.nx" 5 6func main() -> i64 { 7 let t: *NxTimeline = nx_timeline_new(8) 8 if t.count != 0 { return 1 } 9 10 // Empty timeline samples to 0 11 if nx_timeline_sample(t, 1000) != 0 { return 2 } 12 13 // Add 3 keyframes: (1000us, 0), (2000us, 1024), (3000us, 0) 14 nx_timeline_add_keyframe(t, 1000, 0) 15 nx_timeline_add_keyframe(t, 2000, 1024) 16 nx_timeline_add_keyframe(t, 3000, 0) 17 if t.count != 3 { return 3 } 18 if nx_timeline_duration_us(t) != 2000 { return 4 } 19 20 // Out-of-order rejected 21 if nx_timeline_add_keyframe(t, 500, 99) != NX_AT_ERR_OUT_OF_ORDER { return 5 } 22 23 // Pre-first sample returns first value (0) 24 if nx_timeline_sample(t, 500) != 0 { return 6 } 25 26 // At first keyframe exactly: 0 27 if nx_timeline_sample(t, 1000) != 0 { return 7 } 28 29 // Midway between 1000 and 2000: (1500, ?) -> 512 (half of 1024) 30 if nx_timeline_sample(t, 1500) != 512 { return 8 } 31 32 // At peak: 2000us -> 1024 33 if nx_timeline_sample(t, 2000) != 1024 { return 9 } 34 35 // Midway 2000..3000: 2500 -> 512 36 if nx_timeline_sample(t, 2500) != 512 { return 10 } 37 38 // Past last: returns last value (0) 39 if nx_timeline_sample(t, 9999) != 0 { return 11 } 40 41 // Loop sampling at duration 2000us 42 // now_us=1500 -> sample at 1500%2000=1500 43 if nx_timeline_sample_loop(t, 1500, 2000) != 512 { return 12 } 44 // now_us=3500 -> sample at 3500%2000=1500 45 if nx_timeline_sample_loop(t, 3500, 2000) != 512 { return 13 } 46 47 // FULL 48 let small: *NxTimeline = nx_timeline_new(2) 49 nx_timeline_add_keyframe(small, 1000, 0) 50 nx_timeline_add_keyframe(small, 2000, 100) 51 if nx_timeline_add_keyframe(small, 3000, 200) != NX_AT_ERR_FULL { return 14 } 52 53 return 0 54}