Mercurial > MadButterfly
annotate src/animate.c @ 122:17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 15 Sep 2008 20:33:06 +0800 |
parents | 5df7403b6fbc |
children | 9e2316dc6ecb |
rev | line source |
---|---|
111 | 1 /*! \file |
2 * \brief Animation tools. | |
3 * | |
117 | 4 * \sa \ref ani |
111 | 5 */ |
6 /*! \page ani What is Animation? | |
41 | 7 * |
117 | 8 * Animation is a program to move, resize, rotate, ..., changing |
9 * graphics on the output screen. | |
10 * | |
11 * \image html program.png | |
12 * | |
41 | 13 * XXX: Program is a sequence of actions duration a perior. |
14 * Actions are grouped into words. A program defines | |
15 * the order and time of playing of words. A word | |
16 * defines how long to perform a set of actions. Actions | |
17 * in a word are performed concurrently. | |
45 | 18 * |
19 * Animation shapes are updated periodically. Every action | |
20 * are working with start, step, and stop 3 calls. start is | |
21 * called when start time the word, contain it, due. step is | |
22 * called periodically in duration of playing time start at | |
23 * 'start time'. When the clock run out the playing time of | |
24 * a word, it call stop of actions in the word. | |
111 | 25 * |
26 * A program is driven by a timer. Once a program is started, it registers | |
27 * with timer for periodic running. \ref mb_tman_t is timer of | |
28 * MadButterfly. The update frequence is 10fps by default, now. | |
29 * | |
117 | 30 * \section use_progm How to Use Animation Program? |
31 * Following code block creates a program with 2 words. First word is | |
32 * started immediately after the program been started. It is consisted | |
33 * for 1 second. Second word is started 1 second after the program been | |
34 * started. It is consisted for 2 seconds. There are 2 action in | |
35 * first word, they shift graphics managed by coord1 & coord2 by (50,50) and | |
36 * (-50,50) pixels, respectly. The shifting is performed incrementally | |
37 * in 1 second. Second word shifts coord1 and coord2, too. And, graphics | |
38 * managed by coord3 are hidden at end of the word. At end of code in the | |
39 * block, mb_progm_start() starts the program. 3rd argument of | |
40 * mb_progm_start() must be current wall time. | |
41 * | |
42 * \code | |
43 * progm = mb_progm_new(10, &rdman); | |
44 * | |
45 * MB_TIMEVAL_SET(&start, 0, 0); | |
46 * MB_TIMEVAL_SET(&playing, 1, 0); | |
47 * word = mb_progm_next_word(progm, &start, &playing); | |
48 * | |
49 * act = mb_shift_new(50, 50, coord1, word); | |
50 * act = mb_shift_new(-50, 50, coord2, word); | |
51 * | |
52 * MB_TIMEVAL_SET(&start, 1, 0); | |
53 * MB_TIMEVAL_SET(&playing, 2, 0); | |
54 * word = mb_progm_next_word(progm, &start, &playing); | |
55 * | |
56 * act = mb_shift_new(0, 20, coord1, word); | |
57 * act = mb_shift_new(0, -20, coord2, word); | |
58 * act = mb_visibility_new(VIS_HIDDEN, coord3, word); | |
59 * | |
60 * gettimeofday(&tv, NULL); | |
61 * MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); | |
62 * mb_progm_start(progm, tman, &mbtv); | |
63 * \endcode | |
64 * | |
65 * | |
66 * \sa \ref animate.c | |
41 | 67 */ |
68 #include <stdio.h> | |
69 #include <stdlib.h> | |
70 #include <string.h> | |
71 #include "mb_types.h" | |
72 #include "redraw_man.h" | |
73 #include "mb_timer.h" | |
74 #include "animate.h" | |
75 | |
76 | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
77 #define STEP_INTERVAL 90000 |
41 | 78 #define ASSERT(x) |
79 | |
80 /*! \brief A word is a set of concurrent actions in a program. | |
81 */ | |
82 struct _mb_word { | |
83 mb_timeval_t start_time; /*!< time to start the word */ | |
84 mb_timeval_t playing_time; /*!< time duration of playing */ | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
85 mb_timeval_t abs_start, abs_stop; |
41 | 86 STAILQ(mb_action_t) actions; |
87 }; | |
88 | |
89 /*! \brief A program describe a series of actions to animate shapes. | |
51 | 90 * |
91 * first_playing is an index to one of words. It always points to | |
92 * the first of words that is playing or waiting for playing. | |
41 | 93 */ |
94 struct _mb_progm { | |
95 redraw_man_t *rdman; | |
96 | |
46 | 97 mb_timeval_t start_time; |
41 | 98 int first_playing; /*!< first playing word. */ |
99 mb_tman_t *tman; | |
100 | |
101 int n_words; | |
102 int max_words; | |
103 mb_word_t words[1]; | |
104 }; | |
105 | |
119 | 106 /*! \brief Create a program object. |
107 * | |
108 * \param max_words is maximum number of words the program can hold. | |
109 * \param rdman is a rdman that show graphics manipulated by it. | |
110 */ | |
41 | 111 mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) { |
112 mb_progm_t *progm; | |
113 int i; | |
114 | |
115 progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) + | |
116 (sizeof(mb_word_t) * (max_words - 1))); | |
117 if(progm == NULL) | |
118 return NULL; | |
119 | |
120 progm->rdman = rdman; | |
121 progm->n_words = 0; | |
122 progm->max_words = max_words; | |
123 for(i = 0; i < max_words; i++) | |
124 STAILQ_INIT(progm->words[i].actions); | |
125 return progm; | |
126 } | |
127 | |
128 void mb_progm_free(mb_progm_t *progm) { | |
129 int n_words; | |
130 mb_word_t *word; | |
131 mb_action_t *cur_act; | |
132 int i; | |
133 | |
134 n_words = progm->n_words; | |
135 for(i = 0; i < n_words; i++) { | |
136 word = progm->words + i; | |
137 for(cur_act = STAILQ_HEAD(word->actions); | |
138 cur_act != NULL; | |
139 cur_act = STAILQ_HEAD(word->actions)) { | |
140 STAILQ_REMOVE(word->actions, mb_action_t, next, cur_act); | |
141 cur_act->free(cur_act); | |
142 } | |
143 } | |
144 free(progm); | |
145 } | |
146 | |
147 /*! \brief Add a new word into a program. | |
148 * | |
149 * The start time of new word should bigger or equal to last one. | |
150 * The time should be specified in incremental order. | |
151 */ | |
152 mb_word_t *mb_progm_next_word(mb_progm_t *progm, | |
153 const mb_timeval_t *start, | |
154 const mb_timeval_t *playing) { | |
155 mb_word_t *word; | |
156 if(progm->n_words >= progm->max_words) | |
157 return NULL; | |
158 if(progm->n_words && | |
159 MB_TIMEVAL_LATER(&progm->words[progm->n_words - 1].start_time, start)) | |
160 return NULL; | |
161 word = progm->words + progm->n_words++; | |
43
6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
162 MB_TIMEVAL_CP(&word->start_time, start); |
6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
163 MB_TIMEVAL_CP(&word->playing_time, playing); |
41 | 164 return word; |
165 } | |
166 | |
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
111
diff
changeset
|
167 void mb_word_add_action(mb_word_t *word, mb_action_t *act) { |
41 | 168 STAILQ_INS_TAIL(word->actions, mb_action_t, next, act); |
169 } | |
170 | |
171 static void mb_word_start(mb_word_t *word, const mb_timeval_t *tmo, | |
172 const mb_timeval_t *now, redraw_man_t *rdman) { | |
42 | 173 mb_action_t *act; |
174 | |
175 for(act = STAILQ_HEAD(word->actions); | |
176 act != NULL; | |
177 act = STAILQ_NEXT(mb_action_t, next, act)) { | |
178 act->start(act, tmo, &word->playing_time, rdman); | |
179 } | |
41 | 180 } |
181 | |
182 static void mb_word_step(mb_word_t *word, const mb_timeval_t *tmo, | |
183 const mb_timeval_t *now, redraw_man_t *rdman) { | |
42 | 184 mb_action_t *act; |
185 | |
186 for(act = STAILQ_HEAD(word->actions); | |
187 act != NULL; | |
188 act = STAILQ_NEXT(mb_action_t, next, act)) { | |
189 act->step(act, tmo, rdman); | |
190 } | |
41 | 191 } |
192 | |
193 static void mb_word_stop(mb_word_t *word, const mb_timeval_t *tmo, | |
194 const mb_timeval_t *now, redraw_man_t *rdman) { | |
42 | 195 mb_action_t *act; |
196 | |
197 for(act = STAILQ_HEAD(word->actions); | |
198 act != NULL; | |
199 act = STAILQ_NEXT(mb_action_t, next, act)) { | |
200 act->stop(act, tmo, rdman); | |
201 } | |
41 | 202 } |
203 | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
204 /*! \brief Time stepping for a program. |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
205 * |
46 | 206 * Any two actions in concurrent words never change the same attribute. |
207 * Start time of words in a program are specified in incremental order. | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
208 * |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
209 * \note Program will take a big step at last monent. It is because |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
210 * mb_progm_step() running mb_word_stop() if the word being stop |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
211 * between now and next_tmo. It is not obviously if time stepping |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
212 * small. |
46 | 213 */ |
41 | 214 static void mb_progm_step(const mb_timeval_t *tmo, |
120 | 215 const mb_timeval_t *now, |
216 void *arg) { | |
41 | 217 mb_progm_t *progm = (mb_progm_t *)arg; |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
218 mb_timeval_t next_tmo; |
41 | 219 mb_word_t *word; |
220 mb_timer_t *timer; | |
221 int i; | |
222 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
223 MB_TIMEVAL_SET(&next_tmo, 0, STEP_INTERVAL); |
120 | 224 MB_TIMEVAL_ADD(&next_tmo, now); |
41 | 225 |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
226 /* _step() or _stop() words that in playing. */ |
41 | 227 i = progm->first_playing; |
228 for(word = progm->words + i; | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
229 i < progm->n_words && MB_TIMEVAL_LATER(tmo, &word->abs_start); |
41 | 230 word = progm->words + ++i) { |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
231 if(MB_TIMEVAL_LATER(tmo, &word->abs_stop)) |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
232 continue; |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
233 if(MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop)) |
46 | 234 mb_word_stop(word, tmo, now, progm->rdman); |
235 else | |
41 | 236 mb_word_step(word, tmo, now, progm->rdman); |
237 } | |
238 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
239 /* Start words that their abs_start is in duration |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
240 * from now to timeout for next update. |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
241 */ |
41 | 242 for(word = progm->words + i; |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
243 i < progm->n_words && MB_TIMEVAL_LATER(&next_tmo, &word->abs_start); |
41 | 244 word = progm->words + ++i) { |
245 mb_word_start(word, tmo, now, progm->rdman); | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
246 if(MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop)) |
46 | 247 mb_word_stop(word, tmo, now, progm->rdman); |
41 | 248 } |
249 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
250 /* Find a new first_playing if any consequence words, following current |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
251 * first_playing word, are stoped. |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
252 */ |
46 | 253 i = progm->first_playing; |
254 for(word = progm->words + i; | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
255 i < progm->n_words && MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop); |
46 | 256 word = progm->words + ++i) { |
257 progm->first_playing++; | |
258 } | |
259 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
260 /* Setup timeout for next update. */ |
41 | 261 if(progm->first_playing < progm->n_words) { |
42 | 262 word = progm->words + progm->first_playing; |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
263 if(MB_TIMEVAL_LATER(&word->abs_start, &next_tmo)) |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
264 MB_TIMEVAL_CP(&next_tmo, &word->abs_start); |
46 | 265 timer = mb_tman_timeout(progm->tman, &next_tmo, |
266 mb_progm_step, progm); | |
41 | 267 } |
268 } | |
269 | |
270 void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, | |
271 mb_timeval_t *now) { | |
272 mb_timer_t *timer; | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
273 mb_word_t *word; |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
274 int i; |
41 | 275 |
276 if(progm->n_words == 0) | |
277 return; | |
278 | |
279 progm->tman = tman; | |
43
6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
280 MB_TIMEVAL_CP(&progm->start_time, now); |
41 | 281 progm->first_playing = 0; |
282 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
283 for(i = 0; i < progm->n_words; i++) { |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
284 word = progm->words + i; |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
285 MB_TIMEVAL_CP(&word->abs_start, &word->start_time); |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
286 MB_TIMEVAL_ADD(&word->abs_start, now); |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
287 MB_TIMEVAL_CP(&word->abs_stop, &word->abs_start); |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
288 MB_TIMEVAL_ADD(&word->abs_stop, &word->playing_time); |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
289 } |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
290 |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
291 if(MB_TIMEVAL_EQ(&progm->words[0].abs_start, now)) { |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
292 mb_progm_step(now, now, progm); |
41 | 293 return; |
294 } | |
295 | |
48
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
296 timer = mb_tman_timeout(tman, &progm->words[0].abs_start, |
bdf711cbf0fb
Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents:
47
diff
changeset
|
297 mb_progm_step, progm); |
41 | 298 ASSERT(timer != NULL); |
299 } | |
300 | |
42 | 301 void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) { |
302 } | |
303 | |
50 | 304 #ifdef UNITTEST |
305 | |
306 #include <CUnit/Basic.h> | |
307 | |
308 typedef struct _mb_dummy mb_dummy_t; | |
309 | |
310 struct _mb_dummy { | |
311 mb_action_t action; | |
312 int id; | |
313 int *logidx; | |
314 int *logs; | |
315 }; | |
316 | |
317 | |
318 static void mb_dummy_start(mb_action_t *act, | |
319 const mb_timeval_t *now, | |
320 const mb_timeval_t *playing_time, | |
321 redraw_man_t *rdman) { | |
322 mb_dummy_t *dummy = (mb_dummy_t *)act; | |
323 | |
324 dummy->logs[(*dummy->logidx)++] = dummy->id; | |
325 } | |
326 | |
327 static void mb_dummy_step(mb_action_t *act, | |
328 const mb_timeval_t *now, | |
329 redraw_man_t *rdman) { | |
330 mb_dummy_t *dummy = (mb_dummy_t *)act; | |
331 | |
332 dummy->logs[(*dummy->logidx)++] = dummy->id; | |
333 } | |
334 | |
335 static void mb_dummy_stop(mb_action_t *act, | |
336 const mb_timeval_t *now, | |
337 redraw_man_t *rdman) { | |
338 mb_dummy_t *dummy = (mb_dummy_t *)act; | |
339 | |
340 dummy->logs[(*dummy->logidx)++] = dummy->id; | |
341 } | |
342 | |
343 static void mb_dummy_free(mb_action_t *act) { | |
344 free(act); | |
345 } | |
346 | |
347 mb_action_t *mb_dummy_new(int id, int *logidx, int *logs, mb_word_t *word) { | |
348 mb_dummy_t *dummy; | |
349 | |
350 dummy = (mb_dummy_t *)malloc(sizeof(mb_dummy_t)); | |
351 if(dummy == NULL) | |
352 return NULL; | |
353 | |
354 dummy->id = id; | |
355 dummy->logidx = logidx; | |
356 dummy->logs = logs; | |
357 | |
358 dummy->action.start = mb_dummy_start; | |
359 dummy->action.step = mb_dummy_step; | |
360 dummy->action.stop = mb_dummy_stop; | |
361 dummy->action.free = mb_dummy_free; | |
362 | |
363 mb_word_add_action(word, (mb_action_t *)dummy); | |
364 | |
365 return (mb_action_t *)dummy; | |
366 } | |
367 | |
368 void test_animate_words(void) { | |
369 mb_progm_t *progm; | |
370 mb_word_t *word; | |
371 mb_action_t *acts[4]; | |
372 mb_tman_t *tman; | |
373 mb_timeval_t tv1, tv2, now, tmo_after; | |
374 int logcnt = 0; | |
375 int logs[256]; | |
376 int r; | |
377 | |
378 tman = mb_tman_new(); | |
379 CU_ASSERT(tman != NULL); | |
380 | |
381 progm = mb_progm_new(3, NULL); | |
382 CU_ASSERT(progm != NULL); | |
383 | |
384 MB_TIMEVAL_SET(&tv1, 1, 0); | |
385 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3); | |
386 word = mb_progm_next_word(progm, &tv1, &tv2); | |
387 CU_ASSERT(word != NULL); | |
388 acts[0] = mb_dummy_new(0, &logcnt, logs, word); | |
389 CU_ASSERT(acts[0] != NULL); | |
390 | |
391 MB_TIMEVAL_SET(&tv1, 1, STEP_INTERVAL * 4 / 3); | |
392 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL / 3); | |
393 word = mb_progm_next_word(progm, &tv1, &tv2); | |
394 CU_ASSERT(word != NULL); | |
395 acts[1] = mb_dummy_new(1, &logcnt, logs, word); | |
396 CU_ASSERT(acts[1] != NULL); | |
397 | |
398 MB_TIMEVAL_SET(&tv1, 1, STEP_INTERVAL * 2); | |
399 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3); | |
400 word = mb_progm_next_word(progm, &tv1, &tv2); | |
401 CU_ASSERT(word != NULL); | |
402 acts[2] = mb_dummy_new(2, &logcnt, logs, word); | |
403 CU_ASSERT(acts[2] != NULL); | |
404 | |
405 MB_TIMEVAL_SET(&now, 0, 0); | |
406 mb_progm_start(progm, tman, &now); | |
407 | |
408 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
409 CU_ASSERT(r == 0); | |
410 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 1 && | |
411 MB_TIMEVAL_USEC(&tmo_after) == 0); | |
412 | |
413 /* 1.0s */ | |
414 MB_TIMEVAL_ADD(&now, &tmo_after); | |
415 mb_tman_handle_timeout(tman, &now); | |
416 CU_ASSERT(logcnt == 1); | |
417 | |
418 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
419 CU_ASSERT(r == 0); | |
420 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
421 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
422 | |
423 /* 1.1s */ | |
424 MB_TIMEVAL_ADD(&now, &tmo_after); | |
425 mb_tman_handle_timeout(tman, &now); | |
426 CU_ASSERT(logcnt == 4); | |
427 | |
428 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
429 CU_ASSERT(r == 0); | |
430 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
431 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
432 | |
433 /* 1.2s */ | |
434 MB_TIMEVAL_ADD(&now, &tmo_after); | |
435 mb_tman_handle_timeout(tman, &now); | |
436 CU_ASSERT(logcnt == 6); | |
437 | |
438 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
439 CU_ASSERT(r == 0); | |
440 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
441 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
442 | |
443 /* 1.3s */ | |
444 MB_TIMEVAL_ADD(&now, &tmo_after); | |
445 mb_tman_handle_timeout(tman, &now); | |
446 CU_ASSERT(logcnt == 8); | |
447 | |
448 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
449 CU_ASSERT(r == 0); | |
450 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
451 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
452 | |
453 /* 1.4s */ | |
454 MB_TIMEVAL_ADD(&now, &tmo_after); | |
455 mb_tman_handle_timeout(tman, &now); | |
456 CU_ASSERT(logcnt == 9); | |
457 | |
458 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
459 CU_ASSERT(r == 0); | |
460 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 && | |
461 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL); | |
462 | |
463 /* 1.5s */ | |
464 MB_TIMEVAL_ADD(&now, &tmo_after); | |
465 mb_tman_handle_timeout(tman, &now); | |
466 CU_ASSERT(logcnt == 10); | |
467 | |
468 r = mb_tman_next_timeout(tman, &now, &tmo_after); | |
469 CU_ASSERT(r == -1); | |
470 | |
471 mb_progm_free(progm); | |
472 mb_tman_free(tman); | |
473 } | |
474 | |
475 CU_pSuite get_animate_suite(void) { | |
476 CU_pSuite suite; | |
477 | |
478 suite = CU_add_suite("Suite_animate", NULL, NULL); | |
479 if(suite == NULL) | |
480 return NULL; | |
481 | |
482 CU_ADD_TEST(suite, test_animate_words); | |
483 | |
484 return suite; | |
485 } | |
486 | |
487 #endif /* UNITTEST */ |