annotate src/animate.c @ 111:8feb89b19619

More doxy
author Thinker K.F. Li <thinker@branda.to>
date Fri, 12 Sep 2008 23:43:11 +0800
parents ab028c9f0930
children 1d74eb3861b7
rev   line source
111
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
1 /*! \file
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
2 * \brief Animation tools.
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
3 *
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
4 * \sa ani
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
5 */
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
6 /*! \page ani What is Animation?
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 *
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 * XXX: Program is a sequence of actions duration a perior.
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 * Actions are grouped into words. A program defines
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 * the order and time of playing of words. A word
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 * defines how long to perform a set of actions. Actions
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 * in a word are performed concurrently.
45
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
13 *
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
14 * Animation shapes are updated periodically. Every action
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
15 * are working with start, step, and stop 3 calls. start is
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
16 * called when start time the word, contain it, due. step is
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
17 * called periodically in duration of playing time start at
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
18 * 'start time'. When the clock run out the playing time of
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
19 * a word, it call stop of actions in the word.
111
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
20 *
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
21 * A program is driven by a timer. Once a program is started, it registers
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
22 * with timer for periodic running. \ref mb_tman_t is timer of
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
23 * MadButterfly. The update frequence is 10fps by default, now.
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
24 *
8feb89b19619 More doxy
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
25 * \sa animate.c
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 #include <stdio.h>
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 #include <stdlib.h>
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 #include <string.h>
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 #include "mb_types.h"
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 #include "redraw_man.h"
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 #include "mb_timer.h"
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 #include "animate.h"
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
36 #define STEP_INTERVAL 100000
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 #define ASSERT(x)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 /*! \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
40 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 struct _mb_word {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 mb_timeval_t start_time; /*!< time to start the word */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 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
44 mb_timeval_t abs_start, abs_stop;
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 STAILQ(mb_action_t) actions;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 };
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 /*! \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
49 *
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
50 * 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
51 * 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
52 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 struct _mb_progm {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 redraw_man_t *rdman;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
56 mb_timeval_t start_time;
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 int first_playing; /*!< first playing word. */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 mb_tman_t *tman;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 int n_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 int max_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 mb_word_t words[1];
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 };
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 /*! \brief Basic class of nnimation actions.
51
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
66 *
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
67 * A action must implement following 4 functions.
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
68 * \li start,
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
69 * \li step,
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
70 * \li stop,
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
71 * \li free, and
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
72 * \li *_new().
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
73 *
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
74 * *_new() must invokes mb_word_add_action() to add new object
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
75 * 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
76 * It also means *_new() must have an argument with type of
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
77 * (mb_word_t *).
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 struct _mb_action {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 void (*start)(mb_action_t *act,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 const mb_timeval_t *now,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 const mb_timeval_t *playing_time,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 redraw_man_t *rdman);
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
84 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
85 redraw_man_t *rdman);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
86 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
87 redraw_man_t *rdman);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 void (*free)(mb_action_t *act);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 mb_action_t *next;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 };
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 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
93 mb_progm_t *progm;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 int i;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) +
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 (sizeof(mb_word_t) * (max_words - 1)));
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 if(progm == NULL)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 return NULL;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 progm->rdman = rdman;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 progm->n_words = 0;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 progm->max_words = max_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 for(i = 0; i < max_words; i++)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 STAILQ_INIT(progm->words[i].actions);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 return progm;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 void mb_progm_free(mb_progm_t *progm) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 int n_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 mb_word_t *word;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 mb_action_t *cur_act;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113 int i;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 n_words = progm->n_words;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116 for(i = 0; i < n_words; i++) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 word = progm->words + i;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 for(cur_act = STAILQ_HEAD(word->actions);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 cur_act != NULL;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120 cur_act = STAILQ_HEAD(word->actions)) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 STAILQ_REMOVE(word->actions, mb_action_t, next, cur_act);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 cur_act->free(cur_act);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125 free(progm);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 /*! \brief Add a new word into a program.
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129 *
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 * 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
131 * The time should be specified in incremental order.
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132 */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 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
134 const mb_timeval_t *start,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 const mb_timeval_t *playing) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136 mb_word_t *word;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 if(progm->n_words >= progm->max_words)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 return NULL;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 if(progm->n_words &&
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 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
141 return NULL;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 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
143 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
144 MB_TIMEVAL_CP(&word->playing_time, playing);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 return word;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147
47
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 46
diff changeset
148 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
149 STAILQ_INS_TAIL(word->actions, mb_action_t, next, act);
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_start(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->start(act, tmo, &word->playing_time, 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_step(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->step(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
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 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
175 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
176 mb_action_t *act;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
177
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
178 for(act = STAILQ_HEAD(word->actions);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
179 act != NULL;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
180 act = STAILQ_NEXT(mb_action_t, next, act)) {
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
181 act->stop(act, tmo, rdman);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
182 }
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
185 /*
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
186 * 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
187 * 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
188 */
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
189 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
190 const mb_timeval_t *now,
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
191 void *arg) {
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
192 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
193 mb_timeval_t next_tmo;
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 mb_word_t *word;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195 mb_timer_t *timer;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196 int i;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
197
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
198 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
199 MB_TIMEVAL_ADD(&next_tmo, tmo);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
200
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
201 /* _step() or _stop() words that in playing. */
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
202 i = progm->first_playing;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 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
204 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
205 word = progm->words + ++i) {
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
206 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
207 continue;
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
208 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
209 mb_word_stop(word, tmo, now, progm->rdman);
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
210 else
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
211 mb_word_step(word, tmo, now, progm->rdman);
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 /* 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
215 * 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
216 */
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
217 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
218 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
219 word = progm->words + ++i) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
220 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
221 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
222 mb_word_stop(word, tmo, now, progm->rdman);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
223 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
224
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
225 /* 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
226 * first_playing word, are stoped.
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
227 */
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
228 i = progm->first_playing;
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
229 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
230 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
231 word = progm->words + ++i) {
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
232 progm->first_playing++;
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
233 }
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
234
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
235 /* Setup timeout for next update. */
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
236 if(progm->first_playing < progm->n_words) {
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
237 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
238 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
239 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
240 timer = mb_tman_timeout(progm->tman, &next_tmo,
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 45
diff changeset
241 mb_progm_step, progm);
41
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 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
244
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
245 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
246 mb_timeval_t *now) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
247 mb_timer_t *timer;
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
248 mb_word_t *word;
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
249 int i;
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
250
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
251 if(progm->n_words == 0)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
252 return;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
253
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
254 progm->tman = tman;
43
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
255 MB_TIMEVAL_CP(&progm->start_time, now);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
256 progm->first_playing = 0;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
257
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
258 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
259 word = progm->words + i;
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
260 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
261 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
262 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
263 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
264 }
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
265
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
266 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
267 mb_progm_step(now, now, progm);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
268 return;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
269 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
270
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
271 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
272 mb_progm_step, progm);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
273 ASSERT(timer != NULL);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
274 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
275
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
276 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
277 }
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
278
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
279 typedef struct _mb_shift mb_shift_t;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
280 /*! \brief Animation action for shift a coordination. */
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
281 struct _mb_shift {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
282 mb_action_t action;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
283
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
284 co_aix x, y;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
285 coord_t *coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
286
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
287 mb_timeval_t start_time;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
288 co_aix saved_matrix[6];
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
289 const mb_timeval_t *playing_time;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
290 };
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
291
51
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
292 static float comp_mb_timeval_ratio(const mb_timeval_t *a,
5f5bd3ac9316 documentation
Thinker K.F. Li <thinker@branda.to>
parents: 50
diff changeset
293 const mb_timeval_t *b) {
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
294 float ratio;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
295
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
296 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
297 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
298 return ratio;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
299 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
300
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
301 static void mb_shift_start(mb_action_t *act,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
302 const mb_timeval_t *now,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
303 const mb_timeval_t *playing_time,
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 coord_t *coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
307
43
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
308 MB_TIMEVAL_CP(&shift->start_time, now);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
309 coord = shift->coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
310 memcpy(&shift->saved_matrix, coord->matrix, sizeof(co_aix[6]));
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
311 shift->playing_time = playing_time;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
312 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
313
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
314 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
315 redraw_man_t *rdman) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
316 mb_shift_t *shift = (mb_shift_t *)act;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
317 mb_timeval_t diff;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
318 coord_t *coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
319 float ratio;
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
43
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
322 MB_TIMEVAL_CP(&diff, now);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
323 MB_TIMEVAL_DIFF(&diff, &shift->start_time);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
324 ratio = comp_mb_timeval_ratio(&diff, shift->playing_time);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
325
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
326 coord = shift->coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
327 coord->matrix[2] = shift->saved_matrix[2] + shift->x * ratio;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
328 coord->matrix[5] = shift->saved_matrix[5] + shift->y * ratio;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
329
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
330 rdman_coord_changed(rdman, coord);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
331 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
332
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
333 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
334 redraw_man_t *rdman) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
335 mb_shift_t *shift = (mb_shift_t *)act;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
336 coord_t *coord;
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 coord = shift->coord;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
339 coord->matrix[2] = shift->saved_matrix[2] + shift->x;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
340 coord->matrix[5] = shift->saved_matrix[5] + shift->y;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
341
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
342 rdman_coord_changed(rdman, coord);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
343 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
344
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
345
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
346 static void mb_shift_free(mb_action_t *act) {
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
347 free(act);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
348 }
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
349
47
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 46
diff changeset
350 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
351 mb_word_t *word) {
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
352 mb_shift_t *shift;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
353
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
354 shift = (mb_shift_t *)malloc(sizeof(mb_shift_t));
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
355 if(shift == NULL)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
356 return (mb_action_t *)shift;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
357
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
358 shift->x = x;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
359 shift->y = y;
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
360 shift->coord = coord;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
361
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
362 shift->action.start = mb_shift_start;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
363 shift->action.step = mb_shift_step;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
364 shift->action.stop = mb_shift_stop;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
365 shift->action.free = mb_shift_free;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
366
47
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 46
diff changeset
367 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
368
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
369 return (mb_action_t *)shift;
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
370 }
50
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
371
52
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
372
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
373 #include "paint.h"
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
374 typedef struct _mb_chgcolor mb_chgcolor_t;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
375
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
376 struct _mb_chgcolor {
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
377 mb_action_t action;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
378
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
379 co_comp_t r, g, b, a;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
380 paint_t *paint;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
381
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
382 mb_timeval_t start_time;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
383 const mb_timeval_t *playing_time;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
384 co_comp_t s_r, s_g, s_b, s_a; /*!< saved RGBA values. */
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
385 };
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
386
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
387 static void mb_chgcolor_start(mb_action_t *act,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
388 const mb_timeval_t *now,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
389 const mb_timeval_t *playing_time,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
390 redraw_man_t *rdman) {
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
391 mb_chgcolor_t *chg = (mb_chgcolor_t *)act;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
392
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
393 MB_TIMEVAL_CP(&chg->start_time, now);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
394 chg->playing_time = playing_time; /* playing_time is in word,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
395 * it live time is as long as
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
396 * actions. */
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
397 paint_color_get(chg->paint,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
398 &chg->s_r, &chg->s_g,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
399 &chg->s_b, &chg->s_a);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
400 }
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
401
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
402 static void mb_chgcolor_step(mb_action_t *act,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
403 const mb_timeval_t *now,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
404 redraw_man_t *rdman) {
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
405 mb_chgcolor_t *chg = (mb_chgcolor_t *)act;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
406 mb_timeval_t diff;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
407 co_comp_t r, g, b, a;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
408 float ratio, comp;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
409
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
410 MB_TIMEVAL_CP(&diff, now);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
411 MB_TIMEVAL_DIFF(&diff, &chg->start_time);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
412 ratio = comp_mb_timeval_ratio(&diff, chg->playing_time);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
413 comp = 1 - ratio;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
414
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
415 r = chg->s_r * comp + ratio * chg->r;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
416 g = chg->s_g * comp + ratio * chg->g;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
417 b = chg->s_b * comp + ratio * chg->b;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
418 a = chg->s_a * comp + ratio * chg->a;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
419 paint_color_set(chg->paint, r, g, b, a);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
420
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
421 rdman_paint_changed(rdman, chg->paint);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
422 }
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
423
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
424 static void mb_chgcolor_stop(mb_action_t *act,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
425 const mb_timeval_t *now,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
426 redraw_man_t *rdman) {
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
427 mb_chgcolor_t *chg = (mb_chgcolor_t *)act;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
428
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
429 paint_color_set(chg->paint, chg->r, chg->g, chg->b, chg->a);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
430
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
431 rdman_paint_changed(rdman, chg->paint);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
432 }
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
433
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
434 static void mb_chgcolor_free(mb_action_t *act) {
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
435 free(act);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
436 }
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
437
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
438 mb_action_t *mb_chgcolor_new(co_comp_t r, co_comp_t g,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
439 co_comp_t b, co_comp_t a,
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
440 paint_t *paint, mb_word_t *word) {
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
441 mb_chgcolor_t *chg;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
442
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
443 chg = (mb_chgcolor_t *)malloc(sizeof(mb_chgcolor_t));
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
444 if(chg == NULL)
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
445 return NULL;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
446
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
447 chg->r = r;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
448 chg->g = g;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
449 chg->b = b;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
450 chg->a = a;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
451
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
452 chg->paint = paint;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
453
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
454 chg->action.start = mb_chgcolor_start;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
455 chg->action.step = mb_chgcolor_step;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
456 chg->action.stop = mb_chgcolor_stop;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
457 chg->action.free = mb_chgcolor_free;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
458
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
459 mb_word_add_action(word, (mb_action_t *)chg);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
460
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
461 return (mb_action_t *)chg;
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
462 }
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 51
diff changeset
463
57
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
464
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
465 typedef struct _mb_visibility mb_visibility_t;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
466
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
467 struct _mb_visibility {
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
468 mb_action_t action;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
469 int visibility;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
470 coord_t *coord;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
471 };
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
472
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
473 static void mb_visibility_start(mb_action_t *act,
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
474 const mb_timeval_t *now,
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
475 const mb_timeval_t *playing_time,
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
476 redraw_man_t *rdman) {
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
477 mb_visibility_t *visibility = (mb_visibility_t *)act;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
478
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
479 switch(visibility->visibility) {
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
480 case VIS_VISIBLE:
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
481 coord_show(visibility->coord);
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
482 break;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
483 case VIS_HIDDEN:
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
484 coord_hide(visibility->coord);
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
485 break;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
486 }
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
487 rdman_coord_changed(rdman, visibility->coord);
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
488 }
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
489
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
490 static void mb_visibility_step(mb_action_t *act,
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
491 const mb_timeval_t *now,
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
492 redraw_man_t *rdman) {
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
493 }
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
494
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
495 static void mb_visibility_stop(mb_action_t *act,
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
496 const mb_timeval_t *now,
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
497 redraw_man_t *rdman) {
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
498 }
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
499
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
500 static void mb_visibility_free(mb_action_t *act) {
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
501 free(act);
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
502 }
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
503
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
504 mb_action_t *mb_visibility_new(int visib, coord_t *coord,
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
505 mb_word_t *word) {
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
506 mb_visibility_t *visibility;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
507
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
508 visibility = (mb_visibility_t *)malloc(sizeof(mb_visibility_t));
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
509 if(visibility == NULL)
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
510 return NULL;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
511
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
512 visibility->visibility = visib;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
513 visibility->coord = coord;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
514
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
515 visibility->action.start = mb_visibility_start;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
516 visibility->action.step = mb_visibility_step;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
517 visibility->action.stop = mb_visibility_stop;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
518 visibility->action.free = mb_visibility_free;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
519
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
520 mb_word_add_action(word, (mb_action_t *)visibility);
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
521
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
522 return (mb_action_t *)visibility;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
523 }
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
524
50
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
525 #ifdef UNITTEST
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
526
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
527 #include <CUnit/Basic.h>
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
528
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
529 typedef struct _mb_dummy mb_dummy_t;
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 struct _mb_dummy {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
532 mb_action_t action;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
533 int id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
534 int *logidx;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
535 int *logs;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
536 };
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
537
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 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
540 const mb_timeval_t *now,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
541 const mb_timeval_t *playing_time,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
542 redraw_man_t *rdman) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
543 mb_dummy_t *dummy = (mb_dummy_t *)act;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
544
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
545 dummy->logs[(*dummy->logidx)++] = dummy->id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
546 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
547
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
548 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
549 const mb_timeval_t *now,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
550 redraw_man_t *rdman) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
551 mb_dummy_t *dummy = (mb_dummy_t *)act;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
552
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
553 dummy->logs[(*dummy->logidx)++] = dummy->id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
554 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
555
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
556 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
557 const mb_timeval_t *now,
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
558 redraw_man_t *rdman) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
559 mb_dummy_t *dummy = (mb_dummy_t *)act;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
560
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
561 dummy->logs[(*dummy->logidx)++] = dummy->id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
562 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
563
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
564 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
565 free(act);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
566 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
567
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
568 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
569 mb_dummy_t *dummy;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
570
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
571 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
572 if(dummy == NULL)
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
573 return NULL;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
574
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
575 dummy->id = id;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
576 dummy->logidx = logidx;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
577 dummy->logs = logs;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
578
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
579 dummy->action.start = mb_dummy_start;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
580 dummy->action.step = mb_dummy_step;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
581 dummy->action.stop = mb_dummy_stop;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
582 dummy->action.free = mb_dummy_free;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
583
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
584 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
585
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
586 return (mb_action_t *)dummy;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
587 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
588
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
589 void test_animate_words(void) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
590 mb_progm_t *progm;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
591 mb_word_t *word;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
592 mb_action_t *acts[4];
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
593 mb_tman_t *tman;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
594 mb_timeval_t tv1, tv2, now, tmo_after;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
595 int logcnt = 0;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
596 int logs[256];
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
597 int r;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
598
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
599 tman = mb_tman_new();
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
600 CU_ASSERT(tman != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
601
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
602 progm = mb_progm_new(3, NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
603 CU_ASSERT(progm != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
604
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
605 MB_TIMEVAL_SET(&tv1, 1, 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
606 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
607 word = mb_progm_next_word(progm, &tv1, &tv2);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
608 CU_ASSERT(word != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
609 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
610 CU_ASSERT(acts[0] != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
611
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
612 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
613 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL / 3);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
614 word = mb_progm_next_word(progm, &tv1, &tv2);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
615 CU_ASSERT(word != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
616 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
617 CU_ASSERT(acts[1] != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
618
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
619 MB_TIMEVAL_SET(&tv1, 1, STEP_INTERVAL * 2);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
620 MB_TIMEVAL_SET(&tv2, 0, STEP_INTERVAL * 3);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
621 word = mb_progm_next_word(progm, &tv1, &tv2);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
622 CU_ASSERT(word != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
623 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
624 CU_ASSERT(acts[2] != NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
625
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
626 MB_TIMEVAL_SET(&now, 0, 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
627 mb_progm_start(progm, tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
628
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
629 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
630 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
631 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 1 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
632 MB_TIMEVAL_USEC(&tmo_after) == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
633
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
634 /* 1.0s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
635 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
636 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
637 CU_ASSERT(logcnt == 1);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
638
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
639 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
640 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
641 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
642 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
643
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
644 /* 1.1s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
645 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
646 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
647 CU_ASSERT(logcnt == 4);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
648
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
649 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
650 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
651 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
652 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
653
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
654 /* 1.2s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
655 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
656 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
657 CU_ASSERT(logcnt == 6);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
658
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
659 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
660 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
661 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
662 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
663
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
664 /* 1.3s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
665 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
666 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
667 CU_ASSERT(logcnt == 8);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
668
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
669 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
670 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
671 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
672 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
673
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
674 /* 1.4s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
675 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
676 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
677 CU_ASSERT(logcnt == 9);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
678
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
679 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
680 CU_ASSERT(r == 0);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
681 CU_ASSERT(MB_TIMEVAL_SEC(&tmo_after) == 0 &&
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
682 MB_TIMEVAL_USEC(&tmo_after) == STEP_INTERVAL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
683
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
684 /* 1.5s */
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
685 MB_TIMEVAL_ADD(&now, &tmo_after);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
686 mb_tman_handle_timeout(tman, &now);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
687 CU_ASSERT(logcnt == 10);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
688
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
689 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
690 CU_ASSERT(r == -1);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
691
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
692 mb_progm_free(progm);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
693 mb_tman_free(tman);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
694 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
695
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
696 CU_pSuite get_animate_suite(void) {
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
697 CU_pSuite suite;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
698
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
699 suite = CU_add_suite("Suite_animate", NULL, NULL);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
700 if(suite == NULL)
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
701 return NULL;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
702
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
703 CU_ADD_TEST(suite, test_animate_words);
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
704
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
705 return suite;
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
706 }
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
707
c986e45c1e91 Unittest for animate.c
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
708 #endif /* UNITTEST */