Mercurial > MadButterfly
diff src/animate.c @ 1044:5d4bc2a93c09
Merge from refine_backend_if branch
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 23 Nov 2010 11:58:04 +0800 |
parents | 63f2f1daf5d3 |
children | e415c55b4a0d |
line wrap: on
line diff
--- a/src/animate.c Tue Nov 23 08:04:09 2010 +0800 +++ b/src/animate.c Tue Nov 23 11:58:04 2010 +0800 @@ -26,7 +26,7 @@ * a word, it call stop of actions in the word. * * A program is driven by a timer. Once a program is started, it registers - * with timer for periodic running. \ref mb_tman_t is timer of + * with timer for periodic running. \ref mb_timer_man_t is timer of * MadButterfly. The update frequence is 10fps by default, now. * * \section use_progm How to Use Animation Program? @@ -61,7 +61,7 @@ * * gettimeofday(&tv, NULL); * MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); - * mb_progm_start(progm, tman, &mbtv); + * mb_progm_start(progm, timer_man, &mbtv); * \endcode * * @@ -98,9 +98,9 @@ mb_timeval_t start_time; int first_playing; /*!< first playing word. */ - mb_tman_t *tman; + mb_timer_man_t *timer_man; subject_t *complete; /*!< notify when a program is completed. */ - mb_timer_t *cur_timer; + int cur_timer; int n_words; int max_words; @@ -139,6 +139,7 @@ progm->max_words = max_words; for(i = 0; i < max_words; i++) STAILQ_INIT(progm->words[i].actions); + progm->cur_timer = -1; return progm; } @@ -233,7 +234,8 @@ * between now and next_tmo. It is not obviously if time stepping * small. */ -static void mb_progm_step(const mb_timeval_t *tmo, +static void mb_progm_step(int timer_hdl, + const mb_timeval_t *tmo, const mb_timeval_t *now, void *arg) { mb_progm_t *progm = (mb_progm_t *)arg; @@ -289,8 +291,8 @@ word = progm->words + progm->first_playing; if(MB_TIMEVAL_LATER(&word->abs_start, &next_tmo)) MB_TIMEVAL_CP(&next_tmo, &word->abs_start); - timer = mb_tman_timeout(progm->tman, &next_tmo, - mb_progm_step, progm); + timer = mb_timer_man_timeout(progm->timer_man, &next_tmo, + mb_progm_step, progm); progm->cur_timer = timer; } else { /* Make program to complete. */ @@ -300,20 +302,20 @@ comp_evt.progm = progm; subject_notify(progm->complete, &comp_evt.event); #endif /* UNITTEST */ - progm->cur_timer = NULL; + progm->cur_timer = -1; } } -void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, +void mb_progm_start(mb_progm_t *progm, mb_timer_man_t *timer_man, mb_timeval_t *now) { - mb_timer_t *timer; + int timer; mb_word_t *word; int i; if(progm->n_words == 0) return; - progm->tman = tman; + progm->timer_man = timer_man; MB_TIMEVAL_CP(&progm->start_time, now); progm->first_playing = 0; @@ -326,13 +328,13 @@ } if(MB_TIMEVAL_EQ(&progm->words[0].abs_start, now)) { - mb_progm_step(now, now, progm); + mb_progm_step(-1, now, now, progm); return; } - timer = mb_tman_timeout(tman, &progm->words[0].abs_start, - mb_progm_step, progm); - ASSERT(timer != NULL); + timer = mb_timer_man_timeout(timer_man, &progm->words[0].abs_start, + mb_progm_step, progm); + ASSERT(timer != -1); /* We need timer to abort it. */ progm->cur_timer = timer; @@ -343,13 +345,13 @@ mb_progm_abort(progm); MB_TIMEVAL_SET(&infi, 0x7fffffff,0); - mb_progm_step(&progm->start_time, &infi,progm); + mb_progm_step(-1, &progm->start_time, &infi,progm); } void mb_progm_abort(mb_progm_t *progm) { /*! \todo Make sure abort release resources. */ - if(progm->cur_timer) { - mb_tman_remove(progm->tman, progm->cur_timer); - progm->cur_timer = NULL; + if(progm->cur_timer != -1) { + mb_timer_man_remove(progm->timer_man, progm->cur_timer); + progm->cur_timer = -1; } } @@ -375,6 +377,7 @@ #ifdef UNITTEST +#include "mb_backend_utils.h" #include <CUnit/Basic.h> typedef struct _mb_dummy mb_dummy_t; @@ -441,14 +444,17 @@ mb_progm_t *progm; mb_word_t *word; mb_action_t *acts[4]; + mb_timer_man_t *timer_man; mb_tman_t *tman; mb_timeval_t tv1, tv2, now, tmo_after; int logcnt = 0; int logs[256]; int r; - tman = mb_tman_new(); - CU_ASSERT(tman != NULL); + timer_man = mb_timer_man_new(&tman_timer_factory); + CU_ASSERT(timer_man != -1); + + tman = tman_timer_man_get_tman(timer_man); progm = mb_progm_new(3, NULL); CU_ASSERT(progm != NULL); @@ -475,7 +481,7 @@ CU_ASSERT(acts[2] != NULL); MB_TIMEVAL_SET(&now, 0, 0); - mb_progm_start(progm, tman, &now); + mb_progm_start(progm, timer_man, &now); r = mb_tman_next_timeout(tman, &now, &tmo_after); CU_ASSERT(r == 0); @@ -541,7 +547,7 @@ CU_ASSERT(r == -1); mb_progm_free(progm); - mb_tman_free(tman); + mb_timer_man_free(&tman_timer_factory, timer_man); } CU_pSuite get_animate_suite(void) {