Mercurial > MadButterfly
comparison include/mb_types.h @ 232:527894c2ad39
Add functions for collision test.
- mb_obj_pos_is_in() test if two coords and their descendants are overlaid.
- mb_objs_is_overlay() test if a point is covered by another mb_obj_t.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 21 Dec 2008 23:30:00 +0800 |
parents | 29e1b2bffe4c |
children | 65cabbdd5284 |
comparison
equal
deleted
inserted
replaced
231:2637519e2bd7 | 232:527894c2ad39 |
---|---|
53 ((mb_obj_t *)(obj))->obj_type = type; \ | 53 ((mb_obj_t *)(obj))->obj_type = type; \ |
54 } while(0) | 54 } while(0) |
55 #define mb_obj_destroy(obj) | 55 #define mb_obj_destroy(obj) |
56 #define mb_obj_prop_store(obj) (&(obj)->props) | 56 #define mb_obj_prop_store(obj) (&(obj)->props) |
57 | 57 |
58 | |
58 /* @} */ | 59 /* @} */ |
59 | 60 |
60 /*! \brief Base of paint types. | 61 /*! \brief Base of paint types. |
61 * | 62 * |
62 * Paints should be freed by users by calling rdman_paint_free() of | 63 * Paints should be freed by users by calling rdman_paint_free() of |
101 subject_t *mouse_event; | 102 subject_t *mouse_event; |
102 }; | 103 }; |
103 #define GEF_DIRTY 0x1 | 104 #define GEF_DIRTY 0x1 |
104 #define GEF_HIDDEN 0x2 /*!< The geo is hidden. */ | 105 #define GEF_HIDDEN 0x2 /*!< The geo is hidden. */ |
105 #define GEF_FREE 0x4 | 106 #define GEF_FREE 0x4 |
107 #define GEF_OV_DRAW 0x8 /*!< To flag drawed for a overlay testing. */ | |
106 | 108 |
107 extern int is_overlay(area_t *r1, area_t *r2); | 109 extern int is_overlay(area_t *r1, area_t *r2); |
108 extern void area_init(area_t *area, int n_pos, co_aix pos[][2]); | 110 extern void area_init(area_t *area, int n_pos, co_aix pos[][2]); |
109 extern void geo_init(geo_t *g); | 111 extern void geo_init(geo_t *g); |
110 extern void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]); | 112 extern void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]); |
114 #define geo_set_shape(g, sh) do {(g)->shape = sh;} while(0) | 116 #define geo_set_shape(g, sh) do {(g)->shape = sh;} while(0) |
115 #define _geo_is_in(a, s, w) ((a) >= (s) && (a) < ((s) + (w))) | 117 #define _geo_is_in(a, s, w) ((a) >= (s) && (a) < ((s) + (w))) |
116 #define geo_pos_is_in(g, _x, _y) \ | 118 #define geo_pos_is_in(g, _x, _y) \ |
117 (_geo_is_in(_x, (g)->cur_area->x, (g)->cur_area->w) && \ | 119 (_geo_is_in(_x, (g)->cur_area->x, (g)->cur_area->w) && \ |
118 _geo_is_in(_y, (g)->cur_area->y, (g)->cur_area->h)) | 120 _geo_is_in(_y, (g)->cur_area->y, (g)->cur_area->h)) |
121 #define geo_get_area(g) ((g)->cur_area) | |
119 | 122 |
120 | 123 |
121 /*! \brief A coordination system. | 124 /*! \brief A coordination system. |
122 * | 125 * |
123 * It have a transform function defined by matrix to transform | 126 * It have a transform function defined by matrix to transform |
179 extern co_aix coord_trans_size(coord_t *co, co_aix size); | 182 extern co_aix coord_trans_size(coord_t *co, co_aix size); |
180 extern void compute_aggr_of_coord(coord_t *coord); | 183 extern void compute_aggr_of_coord(coord_t *coord); |
181 extern void update_aggr_matrix(coord_t *start); | 184 extern void update_aggr_matrix(coord_t *start); |
182 extern coord_t *preorder_coord_subtree(coord_t *root, coord_t *last); | 185 extern coord_t *preorder_coord_subtree(coord_t *root, coord_t *last); |
183 extern coord_t *postorder_coord_subtree(coord_t *root, coord_t *last); | 186 extern coord_t *postorder_coord_subtree(coord_t *root, coord_t *last); |
184 extern void preorder_coord_skip_subtree(coord_t *subroot); | |
185 #define preorder_coord_skip_subtree(sub) \ | 187 #define preorder_coord_skip_subtree(sub) \ |
186 do { (sub)->flags |= COF_SKIP_TRIVAL; } while(0) | 188 do { (sub)->flags |= COF_SKIP_TRIVAL; } while(0) |
187 #define coord_hide(co) \ | 189 #define coord_hide(co) \ |
188 do { \ | 190 do { \ |
189 (co)->flags |= COF_HIDDEN; \ | 191 (co)->flags |= COF_HIDDEN; \ |
190 } while(0) | 192 } while(0) |
191 #define coord_show(co) do { co->flags &= ~COF_HIDDEN; } while(0) | 193 #define coord_show(co) do { co->flags &= ~COF_HIDDEN; } while(0) |
192 #define coord_get_mouse_event(coord) ((coord)->mouse_event) | 194 #define coord_get_mouse_event(coord) ((coord)->mouse_event) |
195 #define FOR_COORDS_POSTORDER(coord, cur) \ | |
196 for((cur) = postorder_coord_subtree((coord), NULL); \ | |
197 (cur) != NULL; \ | |
198 (cur) = postorder_coord_subtree((coord), (cur))) | |
199 #define FOR_COORDS_PREORDER(coord, cur) \ | |
200 for((cur) = (coord); \ | |
201 (cur) != NULL; \ | |
202 (cur) = preorder_coord_subtree((coord), (cur))) | |
193 | 203 |
194 /*! \brief Coord operation function | 204 /*! \brief Coord operation function |
195 * These functions are used to move and scale the coord_t. Programmers should use these functions instead of using the matrix directly. | 205 * These functions are used to move and scale the coord_t. Programmers should use these functions instead of using the matrix directly. |
196 * The x,y,sx,sy are all in co_aix type. | 206 * The x,y,sx,sy are all in co_aix type. |
197 * | 207 * |
201 #define coord_set_scaley(ci,sy) do {(co)->matrux[3] = sy;} while(0) | 211 #define coord_set_scaley(ci,sy) do {(co)->matrux[3] = sy;} while(0) |
202 #define coord_scalex(ci) ((co)->matrix[0]) | 212 #define coord_scalex(ci) ((co)->matrix[0]) |
203 #define coord_scaley(ci) ((co)->matrix[3]) | 213 #define coord_scaley(ci) ((co)->matrix[3]) |
204 #define coord_x(ci) ((co)->matrix[2]) | 214 #define coord_x(ci) ((co)->matrix[2]) |
205 #define coord_y(ci) ((co)->matrix[5]) | 215 #define coord_y(ci) ((co)->matrix[5]) |
216 #define FOR_COORD_MEMBERS(coord, geo) \ | |
217 for(geo = STAILQ_HEAD((coord)->members); \ | |
218 geo != NULL; \ | |
219 geo = STAILQ_NEXT(geo_t, coord_next, geo)) | |
220 #define coord_get_area(coord) ((coord)->cur_area) | |
206 | 221 |
207 /*! \brief A grahpic shape. | 222 /*! \brief A grahpic shape. |
208 * | 223 * |
209 * \dot | 224 * \dot |
210 * digraph G { | 225 * digraph G { |
236 } while(0) | 251 } while(0) |
237 #define sh_show(sh) \ | 252 #define sh_show(sh) \ |
238 do { \ | 253 do { \ |
239 (sh)->geo->flags &= ~GEF_HIDDEN; \ | 254 (sh)->geo->flags &= ~GEF_HIDDEN; \ |
240 } while(0) | 255 } while(0) |
256 #define sh_get_geo(sh) ((sh)->geo) | |
241 | 257 |
242 | 258 |
243 /*! \brief A sprite is a set of graphics that being an object in animation. | 259 /*! \brief A sprite is a set of graphics that being an object in animation. |
244 * | 260 * |
245 * A sprite include graphics comprise an object. For example, a tank, in | 261 * A sprite include graphics comprise an object. For example, a tank, in |