Mercurial > MadButterfly
changeset 43:6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 09 Aug 2008 08:27:56 +0800 |
parents | e3295c07faa9 |
children | 7d9af44f095b |
files | src/animate.c src/mb_timer.h src/timer.c |
diffstat | 3 files changed, 19 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/animate.c Sat Aug 09 08:06:45 2008 +0800 +++ b/src/animate.c Sat Aug 09 08:27:56 2008 +0800 @@ -108,8 +108,8 @@ MB_TIMEVAL_LATER(&progm->words[progm->n_words - 1].start_time, start)) return NULL; word = progm->words + progm->n_words++; - memcpy(&word->start_time, start, sizeof(mb_timeval_t)); - memcpy(&word->playing_time, playing, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&word->start_time, start); + MB_TIMEVAL_CP(&word->playing_time, playing); return word; } @@ -159,14 +159,14 @@ mb_timer_t *timer; int i; - memcpy(&diff, tmo, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&diff, tmo); MB_TIMEVAL_DIFF(&diff, &progm->start_time); i = progm->first_playing; for(word = progm->words + i; i < progm->n_words && MB_TIMEVAL_LATER(&diff, &word->start_time); word = progm->words + ++i) { - memcpy(&w_stp_tm, &progm->start_time, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&w_stp_tm, &progm->start_time); MB_TIMEVAL_ADD(&w_stp_tm, &word->start_time); MB_TIMEVAL_ADD(&w_stp_tm, &word->playing_time); if(MB_TIMEVAL_LATER(&w_stp_tm, tmo)) @@ -182,7 +182,7 @@ MB_TIMEVAL_SET(&next_tmo, 0, STEP_INTERVAL); MB_TIMEVAL_ADD(&next_tmo, tmo); - memcpy(&diff, &next_tmo, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&diff, &next_tmo); MB_TIMEVAL_DIFF(&diff, &progm->start_time); for(word = progm->words + i; i < progm->n_words && MB_TIMEVAL_LATER(&diff, &word->start_time); @@ -193,7 +193,7 @@ /* Setup next timeout. */ if(progm->first_playing < progm->n_words) { word = progm->words + progm->first_playing; - memcpy(&w_stp_tm, &word->start_time, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&w_stp_tm, &word->start_time); MB_TIMEVAL_ADD(&w_stp_tm, &progm->start_time); if(MB_TIMEVAL_LATER(&w_stp_tm, &next_tmo)) @@ -205,7 +205,7 @@ ASSERT(timer != NULL); } - memcpy(&progm->last_time, tmo, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&progm->last_time, tmo); } void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, @@ -217,11 +217,11 @@ return; progm->tman = tman; - memcpy(&progm->start_time, now, sizeof(mb_timeval_t)); - memcpy(&progm->last_time, now, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&progm->start_time, now); + MB_TIMEVAL_CP(&progm->last_time, now); progm->first_playing = 0; - memcpy(&next_time, &progm->words[0].start_time, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&next_time, &progm->words[0].start_time); MB_TIMEVAL_ADD(&next_time, now); if(!MB_TIMEVAL_LATER(&next_time, now)) { mb_progm_step(&next_time, now, progm); @@ -263,7 +263,7 @@ mb_shift_t *shift = (mb_shift_t *)act; coord_t *coord; - memcpy(&shift->start_time, now, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&shift->start_time, now); coord = shift->coord; memcpy(&shift->saved_matrix, coord->matrix, sizeof(co_aix[6])); shift->playing_time = playing_time; @@ -277,7 +277,7 @@ float ratio; - memcpy(&diff, now, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&diff, now); MB_TIMEVAL_DIFF(&diff, &shift->start_time); ratio = comp_mb_timeval_ratio(&diff, shift->playing_time);
--- a/src/mb_timer.h Sat Aug 09 08:06:45 2008 +0800 +++ b/src/mb_timer.h Sat Aug 09 08:27:56 2008 +0800 @@ -30,6 +30,11 @@ (_tv)->tv_sec = _sec; \ (_tv)->tv_usec = _usec; \ } while(0) +#define MB_TIMEVAL_CP(_tv1, _tv2) \ + do { \ + (_tv1)->tv_sec = (_tv2)->tv_sec; \ + (_tv1)->tv_usec = (_tv2)->tv_usec; \ + } while(0) #define MB_TIMEVAL_SEC(_tv) ((_tv)->tv_sec) #define MB_TIMEVAL_USEC(_tv) ((_tv)->tv_usec) #define MB_TIMEVAL_LATER(a, b) \
--- a/src/timer.c Sat Aug 09 08:06:45 2008 +0800 +++ b/src/timer.c Sat Aug 09 08:27:56 2008 +0800 @@ -53,7 +53,7 @@ if(timer == NULL) return NULL; - memcpy(&timer->tmo, tmo, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(&timer->tmo, tmo); timer->hdlr = hdlr; timer->arg = arg; @@ -96,7 +96,7 @@ return OK; } - memcpy(tmo_after, &timer->tmo, sizeof(mb_timeval_t)); + MB_TIMEVAL_CP(tmo_after, &timer->tmo); MB_TIMEVAL_DIFF(tmo_after, now); return OK;