annotate src/visibility.c @ 151:d11aa8fc06c7

Fix bug of tanks do not show at right places. Since we avoid to dirty a subtree if root of a subtree have been dirty or hidden, it make children that was added into coord tree after a coord be dirty do not be marked with COF_DIRTY flag. To fix it, when a new coord is created, the parent is checked and mark new coord with COF_DIRTY flag if the parent is dirty. It forces new coords to be cleaned and transformed to right places.
author Thinker K.F. Li <thinker@branda.to>
date Fri, 26 Sep 2008 17:42:16 +0800
parents 1d74eb3861b7
children c7e5b8779bb5
rev   line source
116
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <stdlib.h>
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include "animate.h"
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 typedef struct _mb_visibility mb_visibility_t;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 struct _mb_visibility {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 mb_action_t action;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 int visibility;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 coord_t *coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 };
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 static void mb_visibility_start(mb_action_t *act,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 const mb_timeval_t *now,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 const mb_timeval_t *playing_time,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 redraw_man_t *rdman) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 mb_visibility_t *visibility = (mb_visibility_t *)act;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 switch(visibility->visibility) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 case VIS_VISIBLE:
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 coord_show(visibility->coord);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 break;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 case VIS_HIDDEN:
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 coord_hide(visibility->coord);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 break;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 }
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 rdman_coord_changed(rdman, visibility->coord);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 }
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 static void mb_visibility_step(mb_action_t *act,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 const mb_timeval_t *now,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 redraw_man_t *rdman) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 }
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 static void mb_visibility_stop(mb_action_t *act,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 const mb_timeval_t *now,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 redraw_man_t *rdman) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 }
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 static void mb_visibility_free(mb_action_t *act) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 free(act);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 }
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 mb_action_t *mb_visibility_new(int visib, coord_t *coord,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 mb_word_t *word) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 mb_visibility_t *visibility;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 visibility = (mb_visibility_t *)malloc(sizeof(mb_visibility_t));
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 if(visibility == NULL)
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 return NULL;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 visibility->visibility = visib;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 visibility->coord = coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 visibility->action.start = mb_visibility_start;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 visibility->action.step = mb_visibility_step;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 visibility->action.stop = mb_visibility_stop;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 visibility->action.free = mb_visibility_free;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 mb_word_add_action(word, (mb_action_t *)visibility);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 return (mb_action_t *)visibility;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 }
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64