annotate src/animate.c @ 51:5f5bd3ac9316

documentation
author Thinker K.F. Li <thinker@branda.to>
date Sat, 09 Aug 2008 21:34:07 +0800
parents c986e45c1e91
children 59a295651480
rev   line source
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 /*! \brief Animation tools.
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 *
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 * XXX: Program is a sequence of actions duration a perior.
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 * Actions are grouped into words. A program defines
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 * the order and time of playing of words. A word
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 * defines how long to perform a set of actions. Actions
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 * in a word are performed concurrently.
45
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
8 *
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
9 * Animation shapes are updated periodically. Every action
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
10 * are working with start, step, and stop 3 calls. start is
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
11 * called when start time the word, contain it, due. step is
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
12 * called periodically in duration of playing time start at
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
13 * 'start time'. When the clock run out the playing time of
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
14 * a word, it call stop of actions in the word.
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 #include <stdio.h>
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 #include <stdlib.h>
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 #include <string.h>
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 #include "mb_types.h"
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 #include "redraw_man.h"
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 #include "mb_timer.h"
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 #include "animate.h"
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
25 #define STEP_INTERVAL 100000
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 #define ASSERT(x)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 /*! \brief A word is a set of concurrent actions in a program.
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 struct _mb_word {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 mb_timeval_t start_time; /*!< time to start the word */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 mb_timeval_t playing_time; /*!< time duration of playing */
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
33 mb_timeval_t abs_start, abs_stop;
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 STAILQ(mb_action_t) actions;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 };
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 /*! \brief A program describe a series of actions to animate shapes.
51
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
38 *
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
39 * first_playing is an index to one of words. It always points to
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
40 * the first of words that is playing or waiting for playing.
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 struct _mb_progm {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 redraw_man_t *rdman;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
45 mb_timeval_t start_time;
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 int first_playing; /*!< first playing word. */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 mb_tman_t *tman;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 int n_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 int max_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 mb_word_t words[1];
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 };
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 /*! \brief Basic class of nnimation actions.
51
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
55 *
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
56 * A action must implement following 4 functions.
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
57 * \li start,
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
58 * \li step,
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
59 * \li stop,
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
60 * \li free, and
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
61 * \li *_new().
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
62 *
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
63 * *_new() must invokes mb_word_add_action() to add new object
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
64 * as one of actions in the word specified as an argument of it.
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
65 * It also means *_new() must have an argument with type of
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
66 * (mb_word_t *).
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 struct _mb_action {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 void (*start)(mb_action_t *act,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 const mb_timeval_t *now,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 const mb_timeval_t *playing_time,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 redraw_man_t *rdman);
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
73 void (*step)(mb_action_t *act, const mb_timeval_t *now,
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
74 redraw_man_t *rdman);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
75 void (*stop)(mb_action_t *act, const mb_timeval_t *now,
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
76 redraw_man_t *rdman);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 void (*free)(mb_action_t *act);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 mb_action_t *next;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 };
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 mb_progm_t *progm;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 int i;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) +
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 (sizeof(mb_word_t) * (max_words - 1)));
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 if(progm == NULL)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 return NULL;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 progm->rdman = rdman;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 progm->n_words = 0;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 progm->max_words = max_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 for(i = 0; i < max_words; i++)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 STAILQ_INIT(progm->words[i].actions);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 return progm;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 void mb_progm_free(mb_progm_t *progm) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 int n_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 mb_word_t *word;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 mb_action_t *cur_act;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 int i;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 n_words = progm->n_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 for(i = 0; i < n_words; i++) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 word = progm->words + i;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 for(cur_act = STAILQ_HEAD(word->actions);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 cur_act != NULL;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 cur_act = STAILQ_HEAD(word->actions)) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 STAILQ_REMOVE(word->actions, mb_action_t, next, cur_act);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 cur_act->free(cur_act);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 free(progm);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 /*! \brief Add a new word into a program.
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 *
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 * The start time of new word should bigger or equal to last one.
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120 * The time should be specified in incremental order.
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 mb_word_t *mb_progm_next_word(mb_progm_t *progm,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 const mb_timeval_t *start,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 const mb_timeval_t *playing) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125 mb_word_t *word;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 if(progm->n_words >= progm->max_words)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 return NULL;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 if(progm->n_words &&
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129 MB_TIMEVAL_LATER(&progm->words[progm->n_words - 1].start_time, start))
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 return NULL;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 word = progm->words + progm->n_words++;
43
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
132 MB_TIMEVAL_CP(&word->start_time, start);
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
133 MB_TIMEVAL_CP(&word->playing_time, playing);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134 return word;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136
47
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 46
diff changeset
137 static void mb_word_add_action(mb_word_t *word, mb_action_t *act) {
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 STAILQ_INS_TAIL(word->actions, mb_action_t, next, act);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141 static void mb_word_start(mb_word_t *word, const mb_timeval_t *tmo,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 const mb_timeval_t *now, redraw_man_t *rdman) {
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
143 mb_action_t *act;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
144
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
145 for(act = STAILQ_HEAD(word->actions);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
146 act != NULL;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
147 act = STAILQ_NEXT(mb_action_t, next, act)) {
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
148 act->start(act, tmo, &word->playing_time, rdman);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
149 }
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 static void mb_word_step(mb_word_t *word, const mb_timeval_t *tmo,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 const mb_timeval_t *now, redraw_man_t *rdman) {
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
154 mb_action_t *act;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
155
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
156 for(act = STAILQ_HEAD(word->actions);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
157 act != NULL;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
158 act = STAILQ_NEXT(mb_action_t, next, act)) {
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
159 act->step(act, tmo, rdman);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
160 }
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
163 static void mb_word_stop(mb_word_t *word, const mb_timeval_t *tmo,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
164 const mb_timeval_t *now, redraw_man_t *rdman) {
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
165 mb_action_t *act;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
166
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
167 for(act = STAILQ_HEAD(word->actions);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
168 act != NULL;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
169 act = STAILQ_NEXT(mb_action_t, next, act)) {
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
170 act->stop(act, tmo, rdman);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
171 }
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
174 /*
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
175 * Any two actions in concurrent words never change the same attribute.
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
176 * Start time of words in a program are specified in incremental order.
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
177 */
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
178 static void mb_progm_step(const mb_timeval_t *tmo,
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
179 const mb_timeval_t *now,
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
180 void *arg) {
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181 mb_progm_t *progm = (mb_progm_t *)arg;
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
182 mb_timeval_t next_tmo;
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183 mb_word_t *word;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184 mb_timer_t *timer;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
185 int i;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
186
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
187 MB_TIMEVAL_SET(&next_tmo, 0, STEP_INTERVAL);
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
188 MB_TIMEVAL_ADD(&next_tmo, tmo);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
189
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
190 /* _step() or _stop() words that in playing. */
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
191 i = progm->first_playing;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
192 for(word = progm->words + i;
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
193 i < progm->n_words && MB_TIMEVAL_LATER(tmo, &word->abs_start);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 word = progm->words + ++i) {
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
195 if(MB_TIMEVAL_LATER(tmo, &word->abs_stop))
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
196 continue;
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
197 if(MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop))
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
198 mb_word_stop(word, tmo, now, progm->rdman);
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
199 else
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
200 mb_word_step(word, tmo, now, progm->rdman);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
201 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
202
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
203 /* Start words that their abs_start is in duration
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
204 * from now to timeout for next update.
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
205 */
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
206 for(word = progm->words + i;
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
207 i < progm->n_words && MB_TIMEVAL_LATER(&next_tmo, &word->abs_start);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
208 word = progm->words + ++i) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
209 mb_word_start(word, tmo, now, progm->rdman);
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
210 if(MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop))
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
211 mb_word_stop(word, tmo, now, progm->rdman);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
212 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
213
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
214 /* Find a new first_playing if any consequence words, following current
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
215 * first_playing word, are stoped.
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
216 */
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
217 i = progm->first_playing;
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
218 for(word = progm->words + i;
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
219 i < progm->n_words && MB_TIMEVAL_LATER(&next_tmo, &word->abs_stop);
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
220 word = progm->words + ++i) {
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
221 progm->first_playing++;
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
222 }
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
223
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
224 /* Setup timeout for next update. */
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
225 if(progm->first_playing < progm->n_words) {
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
226 word = progm->words + progm->first_playing;
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
227 if(MB_TIMEVAL_LATER(&word->abs_start, &next_tmo))
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
228 MB_TIMEVAL_CP(&next_tmo, &word->abs_start);
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
229 timer = mb_tman_timeout(progm->tman, &next_tmo,
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
230 mb_progm_step, progm);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
231 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
232 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
233
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234 void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
235 mb_timeval_t *now) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
236 mb_timer_t *timer;
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
237 mb_word_t *word;
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
238 int i;
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
239
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
240 if(progm->n_words == 0)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
241 return;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
242
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
243 progm->tman = tman;
43
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
244 MB_TIMEVAL_CP(&progm->start_time, now);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
245 progm->first_playing = 0;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
246
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
247 for(i = 0; i < progm->n_words; i++) {
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
248 word = progm->words + i;
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
249 MB_TIMEVAL_CP(&word->abs_start, &word->start_time);
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
250 MB_TIMEVAL_ADD(&word->abs_start, now);
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
251 MB_TIMEVAL_CP(&word->abs_stop, &word->abs_start);
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
252 MB_TIMEVAL_ADD(&word->abs_stop, &word->playing_time);
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
253 }
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
254
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
255 if(MB_TIMEVAL_EQ(&progm->words[0].abs_start, now)) {
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
256 mb_progm_step(now, now, progm);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
257 return;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
258 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
259
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
260 timer = mb_tman_timeout(tman, &progm->words[0].abs_start,
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
261 mb_progm_step, progm);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
262 ASSERT(timer != NULL);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
263 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
264
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
265 void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) {
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
266 }
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
267
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
268 typedef struct _mb_shift mb_shift_t;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
269 /*! \brief Animation action for shift a coordination. */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
270 struct _mb_shift {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
271 mb_action_t action;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
272
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
273 co_aix x, y;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
274 coord_t *coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
275
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
276 mb_timeval_t start_time;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
277 co_aix saved_matrix[6];
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
278 const mb_timeval_t *playing_time;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
279 };
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
280
51
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
281 static float comp_mb_timeval_ratio(const mb_timeval_t *a,
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
282 const mb_timeval_t *b) {
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
283 float ratio;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
284
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
285 ratio = (float)MB_TIMEVAL_SEC(a) * 1000000.0 + (float)MB_TIMEVAL_USEC(a);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
286 ratio /= (float)MB_TIMEVAL_SEC(b) * 1000000.0 + (float)MB_TIMEVAL_USEC(b);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
287 return ratio;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
288 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
289
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
290 static void mb_shift_start(mb_action_t *act,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
291 const mb_timeval_t *now,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
292 const mb_timeval_t *playing_time,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
293 redraw_man_t *rdman) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
294 mb_shift_t *shift = (mb_shift_t *)act;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
295 coord_t *coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
296
43
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
297 MB_TIMEVAL_CP(&shift->start_time, now);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
298 coord = shift->coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
299 memcpy(&shift->saved_matrix, coord->matrix, sizeof(co_aix[6]));
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
300 shift->playing_time = playing_time;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
301 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
302
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
303 static void mb_shift_step(mb_action_t *act, const mb_timeval_t *now,
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
304 redraw_man_t *rdman) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
305 mb_shift_t *shift = (mb_shift_t *)act;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
306 mb_timeval_t diff;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
307 coord_t *coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
308 float ratio;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
309
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
310
43
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
311 MB_TIMEVAL_CP(&diff, now);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
312 MB_TIMEVAL_DIFF(&diff, &shift->start_time);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
313 ratio = comp_mb_timeval_ratio(&diff, shift->playing_time);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
314
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
315 coord = shift->coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
316 coord->matrix[2] = shift->saved_matrix[2] + shift->x * ratio;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
317 coord->matrix[5] = shift->saved_matrix[5] + shift->y * ratio;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
318
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
319 rdman_coord_changed(rdman, coord);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
320 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
321
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
322 static void mb_shift_stop(mb_action_t *act, const mb_timeval_t *now,
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
323 redraw_man_t *rdman) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
324 mb_shift_t *shift = (mb_shift_t *)act;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
325 coord_t *coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
326
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
327 coord = shift->coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
328 coord->matrix[2] = shift->saved_matrix[2] + shift->x;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
329 coord->matrix[5] = shift->saved_matrix[5] + shift->y;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
330
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
331 rdman_coord_changed(rdman, coord);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
332 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
333
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
334
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
335 static void mb_shift_free(mb_action_t *act) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
336 free(act);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
337 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
338
47
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 46
diff changeset
339 mb_action_t *mb_shift_new(co_aix x, co_aix y, coord_t *coord,
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 46
diff changeset
340 mb_word_t *word) {
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
341 mb_shift_t *shift;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
342
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
343 shift = (mb_shift_t *)malloc(sizeof(mb_shift_t));
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
344 if(shift == NULL)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
345 return (mb_action_t *)shift;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
346
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
347 shift->x = x;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
348 shift->y = y;
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
349 shift->coord = coord;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
350
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
351 shift->action.start = mb_shift_start;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
352 shift->action.step = mb_shift_step;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
353 shift->action.stop = mb_shift_stop;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
354 shift->action.free = mb_shift_free;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
355
47
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 46
diff changeset
356 mb_word_add_action(word, (mb_action_t *)shift);
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 46
diff changeset
357
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
358 return (mb_action_t *)shift;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
359 }
50
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
360
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
361 #ifdef UNITTEST
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
362
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
363 #include <CUnit/Basic.h>
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
364
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
365 typedef struct _mb_dummy mb_dummy_t;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
366
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
367 struct _mb_dummy {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
368 mb_action_t action;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
369 int id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
370 int *logidx;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
371 int *logs;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
372 };
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
373
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
374
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
375 static void mb_dummy_start(mb_action_t *act,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
376 const mb_timeval_t *now,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
377 const mb_timeval_t *playing_time,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
378 redraw_man_t *rdman) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
379 mb_dummy_t *dummy = (mb_dummy_t *)act;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
380
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
381 dummy->logs[(*dummy->logidx)++] = dummy->id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
382 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
383
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
384 static void mb_dummy_step(mb_action_t *act,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
385 const mb_timeval_t *now,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
386 redraw_man_t *rdman) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
387 mb_dummy_t *dummy = (mb_dummy_t *)act;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
388
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
389 dummy->logs[(*dummy->logidx)++] = dummy->id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
390 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
391
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
392 static void mb_dummy_stop(mb_action_t *act,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
393 const mb_timeval_t *now,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
394 redraw_man_t *rdman) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
395 mb_dummy_t *dummy = (mb_dummy_t *)act;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
396
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
397 dummy->logs[(*dummy->logidx)++] = dummy->id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
398 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
399
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
400 static void mb_dummy_free(mb_action_t *act) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
401 free(act);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
402 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
403
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
404 mb_action_t *mb_dummy_new(int id, int *logidx, int *logs, mb_word_t *word) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
405 mb_dummy_t *dummy;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
406
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
407 dummy = (mb_dummy_t *)malloc(sizeof(mb_dummy_t));
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
408 if(dummy == NULL)
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
409 return NULL;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
410
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
411 dummy->id = id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
412 dummy->logidx = logidx;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
413 dummy->logs = logs;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
414
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
415 dummy->action.start = mb_dummy_start;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
416 dummy->action.step = mb_dummy_step;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
417 dummy->action.stop = mb_dummy_stop;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
418 dummy->action.free = mb_dummy_free;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
419
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
420 mb_word_add_action(word, (mb_action_t *)dummy);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
421
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
422 return (mb_action_t *)dummy;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
423 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
424
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
425 void test_animate_words(void) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
426 mb_progm_t *progm;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
427 mb_word_t *word;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
428 mb_action_t *acts[4];
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
429 mb_tman_t *tman;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
430 mb_timeval_t tv1, tv2, now, tmo_after;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
431 int logcnt = 0;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
432 int logs[256];
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
433 int r;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
434
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
435 tman = mb_tman_new();
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
436 CU_ASSERT(tman != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
437
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
438 progm = mb_progm_new(3, NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
439 CU_ASSERT(progm != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
440
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
441 MB_TIMEVAL_SET(&tv1, 1, 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
442 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
443 word = mb_progm_next_word(progm, &tv1, &tv2);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
444 CU_ASSERT(word != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
445 acts[0] = mb_dummy_new(0, &logcnt, logs, word);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
446 CU_ASSERT(acts[0] != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
447
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
448 MB_TIMEVAL_SET(&tv1, 1, STEP_INTERVAL * 4 / 3);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
449 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL / 3);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
450 word = mb_progm_next_word(progm, &tv1, &tv2);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
451 CU_ASSERT(word != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
452 acts[1] = mb_dummy_new(1, &logcnt, logs, word);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
453 CU_ASSERT(acts[1] != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
454
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
455 MB_TIMEVAL_SET(&tv1, 1, STEP_INTERVAL * 2);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
456 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
457 word = mb_progm_next_word(progm, &tv1, &tv2);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
458 CU_ASSERT(word != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
459 acts[2] = mb_dummy_new(2, &logcnt, logs, word);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
460 CU_ASSERT(acts[2] != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
461
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
462 MB_TIMEVAL_SET(&now, 0, 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
463 mb_progm_start(progm, tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
464
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
465 r = mb_tman_next_timeout(tman, &now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
466 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
467 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 1 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
468 MB_TIMEVAL_USEC(&tmo_after) == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
469
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
470 /* 1.0s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
471 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
472 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
473 CU_ASSERT(logcnt == 1);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
474
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
475 r = mb_tman_next_timeout(tman, &now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
476 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
477 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
478 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
479
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
480 /* 1.1s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
481 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
482 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
483 CU_ASSERT(logcnt == 4);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
484
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
485 r = mb_tman_next_timeout(tman, &now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
486 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
487 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
488 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
489
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
490 /* 1.2s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
491 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
492 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
493 CU_ASSERT(logcnt == 6);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
494
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
495 r = mb_tman_next_timeout(tman, &now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
496 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
497 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
498 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
499
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
500 /* 1.3s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
501 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
502 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
503 CU_ASSERT(logcnt == 8);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
504
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
505 r = mb_tman_next_timeout(tman, &now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
506 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
507 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
508 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
509
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
510 /* 1.4s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
511 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
512 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
513 CU_ASSERT(logcnt == 9);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
514
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
515 r = mb_tman_next_timeout(tman, &now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
516 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
517 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
518 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
519
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
520 /* 1.5s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
521 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
522 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
523 CU_ASSERT(logcnt == 10);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
524
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
525 r = mb_tman_next_timeout(tman, &now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
526 CU_ASSERT(r == -1);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
527
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
528 mb_progm_free(progm);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
529 mb_tman_free(tman);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
530 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
531
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
532 CU_pSuite get_animate_suite(void) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
533 CU_pSuite suite;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
534
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
535 suite = CU_add_suite("Suite_animate", NULL, NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
536 if(suite == NULL)
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
537 return NULL;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
538
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
539 CU_ADD_TEST(suite, test_animate_words);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
540
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
541 return suite;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
542 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
543
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
544 #endif /* UNITTEST */