Mercurial > MadButterfly
comparison src/animate.c @ 45:83ee36f19210
-
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 09 Aug 2008 11:21:52 +0800 |
parents | 6270230b9248 |
children | 46b77c92d118 |
comparison
equal
deleted
inserted
replaced
44:7d9af44f095b | 45:83ee36f19210 |
---|---|
3 * XXX: Program is a sequence of actions duration a perior. | 3 * XXX: Program is a sequence of actions duration a perior. |
4 * Actions are grouped into words. A program defines | 4 * Actions are grouped into words. A program defines |
5 * the order and time of playing of words. A word | 5 * the order and time of playing of words. A word |
6 * defines how long to perform a set of actions. Actions | 6 * defines how long to perform a set of actions. Actions |
7 * in a word are performed concurrently. | 7 * in a word are performed concurrently. |
8 * | |
9 * Animation shapes are updated periodically. Every action | |
10 * are working with start, step, and stop 3 calls. start is | |
11 * called when start time the word, contain it, due. step is | |
12 * called periodically in duration of playing time start at | |
13 * 'start time'. When the clock run out the playing time of | |
14 * a word, it call stop of actions in the word. | |
8 */ | 15 */ |
9 #include <stdio.h> | 16 #include <stdio.h> |
10 #include <stdlib.h> | 17 #include <stdlib.h> |
11 #include <string.h> | 18 #include <string.h> |
12 #include "mb_types.h" | 19 #include "mb_types.h" |
152 | 159 |
153 static void mb_progm_step(const mb_timeval_t *tmo, | 160 static void mb_progm_step(const mb_timeval_t *tmo, |
154 const mb_timeval_t *now, | 161 const mb_timeval_t *now, |
155 void *arg) { | 162 void *arg) { |
156 mb_progm_t *progm = (mb_progm_t *)arg; | 163 mb_progm_t *progm = (mb_progm_t *)arg; |
157 mb_timeval_t next_tmo, w_stp_tm, diff; | 164 mb_timeval_t next_tmo, w_stp_tm; |
165 mb_timeval_t tmo_diff, next_diff; | |
158 mb_word_t *word; | 166 mb_word_t *word; |
159 mb_timer_t *timer; | 167 mb_timer_t *timer; |
160 int i; | 168 int i; |
161 | 169 |
162 MB_TIMEVAL_CP(&diff, tmo); | 170 MB_TIMEVAL_CP(&tmo_diff, tmo); |
163 MB_TIMEVAL_DIFF(&diff, &progm->start_time); | 171 MB_TIMEVAL_DIFF(&tmo_diff, &progm->start_time); |
164 | 172 |
165 i = progm->first_playing; | 173 i = progm->first_playing; |
166 for(word = progm->words + i; | 174 for(word = progm->words + i; |
167 i < progm->n_words && MB_TIMEVAL_LATER(&diff, &word->start_time); | 175 i < progm->n_words && MB_TIMEVAL_LATER(&tmo_diff, &word->start_time); |
168 word = progm->words + ++i) { | 176 word = progm->words + ++i) { |
169 MB_TIMEVAL_CP(&w_stp_tm, &progm->start_time); | 177 MB_TIMEVAL_CP(&w_stp_tm, &progm->start_time); |
170 MB_TIMEVAL_ADD(&w_stp_tm, &word->start_time); | 178 MB_TIMEVAL_ADD(&w_stp_tm, &word->start_time); |
171 MB_TIMEVAL_ADD(&w_stp_tm, &word->playing_time); | 179 MB_TIMEVAL_ADD(&w_stp_tm, &word->playing_time); |
172 if(MB_TIMEVAL_LATER(&w_stp_tm, tmo)) | 180 if(MB_TIMEVAL_LATER(&w_stp_tm, tmo)) |
180 } | 188 } |
181 | 189 |
182 MB_TIMEVAL_SET(&next_tmo, 0, STEP_INTERVAL); | 190 MB_TIMEVAL_SET(&next_tmo, 0, STEP_INTERVAL); |
183 MB_TIMEVAL_ADD(&next_tmo, tmo); | 191 MB_TIMEVAL_ADD(&next_tmo, tmo); |
184 | 192 |
185 MB_TIMEVAL_CP(&diff, &next_tmo); | 193 MB_TIMEVAL_CP(&next_diff, &next_tmo); |
186 MB_TIMEVAL_DIFF(&diff, &progm->start_time); | 194 MB_TIMEVAL_DIFF(&next_diff, &progm->start_time); |
187 for(word = progm->words + i; | 195 for(word = progm->words + i; |
188 i < progm->n_words && MB_TIMEVAL_LATER(&diff, &word->start_time); | 196 i < progm->n_words && MB_TIMEVAL_LATER(&next_diff, &word->start_time); |
189 word = progm->words + ++i) { | 197 word = progm->words + ++i) { |
190 mb_word_start(word, tmo, now, progm->rdman); | 198 mb_word_start(word, tmo, now, progm->rdman); |
191 } | 199 } |
192 | 200 |
193 /* Setup next timeout. */ | 201 /* Setup next timeout. */ |