Mercurial > MadButterfly
comparison src/animate.c @ 128:07dc9ec71221
Fix the problem that animate.c can not pass testcases
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 16 Sep 2008 16:46:30 +0800 |
parents | ad5ab8e61c2b |
children | ba581d8a4b9b |
comparison
equal
deleted
inserted
replaced
127:d2cc7400c971 | 128:07dc9ec71221 |
---|---|
109 * \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. |
110 * \param rdman is a rdman that show graphics manipulated by it. | 110 * \param rdman is a rdman that show graphics manipulated by it. |
111 */ | 111 */ |
112 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) { |
113 mb_progm_t *progm; | 113 mb_progm_t *progm; |
114 #ifndef UNITTEST | |
114 ob_factory_t *factory; | 115 ob_factory_t *factory; |
116 #endif /* UNITTEST */ | |
115 int i; | 117 int i; |
116 | 118 |
117 progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) + | 119 progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) + |
118 (sizeof(mb_word_t) * (max_words - 1))); | 120 (sizeof(mb_word_t) * (max_words - 1))); |
119 if(progm == NULL) | 121 if(progm == NULL) |
120 return NULL; | 122 return NULL; |
121 | 123 |
122 progm->rdman = rdman; | 124 progm->rdman = rdman; |
123 | 125 |
126 #ifndef UNITTEST | |
124 factory = rdman_get_ob_factory(rdman); | 127 factory = rdman_get_ob_factory(rdman); |
125 progm->complete = subject_new(factory, progm, OBJT_PROGM); | 128 progm->complete = subject_new(factory, progm, OBJT_PROGM); |
129 #endif /* UNITTEST */ | |
126 | 130 |
127 progm->n_words = 0; | 131 progm->n_words = 0; |
128 progm->max_words = max_words; | 132 progm->max_words = max_words; |
129 for(i = 0; i < max_words; i++) | 133 for(i = 0; i < max_words; i++) |
130 STAILQ_INIT(progm->words[i].actions); | 134 STAILQ_INIT(progm->words[i].actions); |
133 | 137 |
134 void mb_progm_free(mb_progm_t *progm) { | 138 void mb_progm_free(mb_progm_t *progm) { |
135 int n_words; | 139 int n_words; |
136 mb_word_t *word; | 140 mb_word_t *word; |
137 mb_action_t *cur_act; | 141 mb_action_t *cur_act; |
142 #ifndef UNITTEST | |
138 ob_factory_t *factory; | 143 ob_factory_t *factory; |
144 #endif /* UNITTEST */ | |
139 int i; | 145 int i; |
140 | 146 |
141 n_words = progm->n_words; | 147 n_words = progm->n_words; |
142 for(i = 0; i < n_words; i++) { | 148 for(i = 0; i < n_words; i++) { |
143 word = progm->words + i; | 149 word = progm->words + i; |
147 STAILQ_REMOVE(word->actions, mb_action_t, next, cur_act); | 153 STAILQ_REMOVE(word->actions, mb_action_t, next, cur_act); |
148 cur_act->free(cur_act); | 154 cur_act->free(cur_act); |
149 } | 155 } |
150 } | 156 } |
151 | 157 |
158 #ifndef UNITTEST | |
152 factory = rdman_get_ob_factory(progm->rdman); | 159 factory = rdman_get_ob_factory(progm->rdman); |
153 subject_free(factory, progm->complete); | 160 subject_free(factory, progm->complete); |
161 #endif /* UNITTEST */ | |
154 | 162 |
155 free(progm); | 163 free(progm); |
156 } | 164 } |
157 | 165 |
158 /*! \brief Add a new word into a program. | 166 /*! \brief Add a new word into a program. |
224 */ | 232 */ |
225 static void mb_progm_step(const mb_timeval_t *tmo, | 233 static void mb_progm_step(const mb_timeval_t *tmo, |
226 const mb_timeval_t *now, | 234 const mb_timeval_t *now, |
227 void *arg) { | 235 void *arg) { |
228 mb_progm_t *progm = (mb_progm_t *)arg; | 236 mb_progm_t *progm = (mb_progm_t *)arg; |
237 #ifndef UNITTEST | |
229 ob_factory_t *factory; | 238 ob_factory_t *factory; |
230 mb_progm_complete_t comp_evt; | 239 mb_progm_complete_t comp_evt; |
240 #endif /* UNITTEST */ | |
231 mb_timeval_t next_tmo; | 241 mb_timeval_t next_tmo; |
232 mb_word_t *word; | 242 mb_word_t *word; |
233 mb_timer_t *timer; | 243 mb_timer_t *timer; |
234 int i; | 244 int i; |
235 | 245 |
276 if(MB_TIMEVAL_LATER(&word->abs_start, &next_tmo)) | 286 if(MB_TIMEVAL_LATER(&word->abs_start, &next_tmo)) |
277 MB_TIMEVAL_CP(&next_tmo, &word->abs_start); | 287 MB_TIMEVAL_CP(&next_tmo, &word->abs_start); |
278 timer = mb_tman_timeout(progm->tman, &next_tmo, | 288 timer = mb_tman_timeout(progm->tman, &next_tmo, |
279 mb_progm_step, progm); | 289 mb_progm_step, progm); |
280 } else { | 290 } else { |
291 #ifndef UNITTEST | |
281 factory = rdman_get_ob_factory(progm->rdman); | 292 factory = rdman_get_ob_factory(progm->rdman); |
282 comp_evt.event.type = EVT_PROGM_COMPLETE; | 293 comp_evt.event.type = EVT_PROGM_COMPLETE; |
283 comp_evt.event.tgt = comp_evt.event.cur_tgt = progm->complete; | 294 comp_evt.event.tgt = comp_evt.event.cur_tgt = progm->complete; |
284 comp_evt.progm = progm; | 295 comp_evt.progm = progm; |
285 subject_notify(factory, progm->complete, &comp_evt.event); | 296 subject_notify(factory, progm->complete, &comp_evt.event); |
297 #endif /* UNITTEST */ | |
286 } | 298 } |
287 } | 299 } |
288 | 300 |
289 void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, | 301 void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, |
290 mb_timeval_t *now) { | 302 mb_timeval_t *now) { |