Mercurial > MadButterfly
comparison src/animate.c @ 123:9e2316dc6ecb
Program completion events
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 16 Sep 2008 14:19:26 +0800 |
parents | 17e97e92b76e |
children | ad5ab8e61c2b |
comparison
equal
deleted
inserted
replaced
122:17e97e92b76e | 123:9e2316dc6ecb |
---|---|
95 redraw_man_t *rdman; | 95 redraw_man_t *rdman; |
96 | 96 |
97 mb_timeval_t start_time; | 97 mb_timeval_t start_time; |
98 int first_playing; /*!< first playing word. */ | 98 int first_playing; /*!< first playing word. */ |
99 mb_tman_t *tman; | 99 mb_tman_t *tman; |
100 subject_t *complete; /*!< notify when a program is completed. */ | |
100 | 101 |
101 int n_words; | 102 int n_words; |
102 int max_words; | 103 int max_words; |
103 mb_word_t words[1]; | 104 mb_word_t words[1]; |
104 }; | 105 }; |
108 * \param max_words is maximum number of words the program can hold. | 109 * \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 * \param rdman is a rdman that show graphics manipulated by it. |
110 */ | 111 */ |
111 mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) { | 112 mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) { |
112 mb_progm_t *progm; | 113 mb_progm_t *progm; |
114 ob_factory_t *factory; | |
113 int i; | 115 int i; |
114 | 116 |
115 progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) + | 117 progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) + |
116 (sizeof(mb_word_t) * (max_words - 1))); | 118 (sizeof(mb_word_t) * (max_words - 1))); |
117 if(progm == NULL) | 119 if(progm == NULL) |
118 return NULL; | 120 return NULL; |
119 | 121 |
120 progm->rdman = rdman; | 122 progm->rdman = rdman; |
123 | |
124 factory = rdman_get_ob_factory(rdman); | |
125 progm->complete = subject_new(factory, progm, OBJT_PROGM); | |
126 | |
121 progm->n_words = 0; | 127 progm->n_words = 0; |
122 progm->max_words = max_words; | 128 progm->max_words = max_words; |
123 for(i = 0; i < max_words; i++) | 129 for(i = 0; i < max_words; i++) |
124 STAILQ_INIT(progm->words[i].actions); | 130 STAILQ_INIT(progm->words[i].actions); |
125 return progm; | 131 return progm; |
213 */ | 219 */ |
214 static void mb_progm_step(const mb_timeval_t *tmo, | 220 static void mb_progm_step(const mb_timeval_t *tmo, |
215 const mb_timeval_t *now, | 221 const mb_timeval_t *now, |
216 void *arg) { | 222 void *arg) { |
217 mb_progm_t *progm = (mb_progm_t *)arg; | 223 mb_progm_t *progm = (mb_progm_t *)arg; |
224 ob_factory_t *factory; | |
225 mb_progm_complete_t comp_evt; | |
218 mb_timeval_t next_tmo; | 226 mb_timeval_t next_tmo; |
219 mb_word_t *word; | 227 mb_word_t *word; |
220 mb_timer_t *timer; | 228 mb_timer_t *timer; |
221 int i; | 229 int i; |
222 | 230 |
262 word = progm->words + progm->first_playing; | 270 word = progm->words + progm->first_playing; |
263 if(MB_TIMEVAL_LATER(&word->abs_start, &next_tmo)) | 271 if(MB_TIMEVAL_LATER(&word->abs_start, &next_tmo)) |
264 MB_TIMEVAL_CP(&next_tmo, &word->abs_start); | 272 MB_TIMEVAL_CP(&next_tmo, &word->abs_start); |
265 timer = mb_tman_timeout(progm->tman, &next_tmo, | 273 timer = mb_tman_timeout(progm->tman, &next_tmo, |
266 mb_progm_step, progm); | 274 mb_progm_step, progm); |
275 } else { | |
276 factory = rdman_get_ob_factory(progm->rdman); | |
277 comp_evt.event.type = EVT_PROGM_COMPLETE; | |
278 comp_evt.event.tgt = comp_evt.event.cur_tgt = progm->complete; | |
279 comp_evt.progm = progm; | |
280 subject_notify(factory, progm->complete, &comp_evt.event); | |
267 } | 281 } |
268 } | 282 } |
269 | 283 |
270 void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, | 284 void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, |
271 mb_timeval_t *now) { | 285 mb_timeval_t *now) { |
297 mb_progm_step, progm); | 311 mb_progm_step, progm); |
298 ASSERT(timer != NULL); | 312 ASSERT(timer != NULL); |
299 } | 313 } |
300 | 314 |
301 void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) { | 315 void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) { |
316 } | |
317 | |
318 /*! \brief Return event subject for completion of a program. | |
319 */ | |
320 subject_t *mb_progm_get_complete(mb_progm_t *progm) { | |
321 return progm->complete; | |
302 } | 322 } |
303 | 323 |
304 #ifdef UNITTEST | 324 #ifdef UNITTEST |
305 | 325 |
306 #include <CUnit/Basic.h> | 326 #include <CUnit/Basic.h> |