annotate src/shift.c @ 840:048cc704bef7

Merge dirty_pcache_area_coords and zeroing_coords. Also interleave zeroing and updating pcache_area tasks. To zeroing a cached coord, pcache_area of descendants cached coords must be updated before zeroing. But, updating pcache_area of a cached coord must be performed after zeroing the coord. So, they are interleaved. dirty_pcache_area_coords are removed from redraw_man_t. It is merged to zeroing_coords.
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 17 Sep 2010 12:21:36 +0800
parents 586e50f82c1f
children
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 194
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 194
diff changeset
2 // vim: sw=4:ts=8:sts=4
116
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <stdio.h>
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <stdlib.h>
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <string.h>
186
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
6 #include "mb_animate.h"
116
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 static float comp_mb_timeval_ratio(const mb_timeval_t *a,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 const mb_timeval_t *b) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 float ratio;
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 ratio = (float)MB_TIMEVAL_SEC(a) * 1000000.0 + (float)MB_TIMEVAL_USEC(a);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 ratio /= (float)MB_TIMEVAL_SEC(b) * 1000000.0 + (float)MB_TIMEVAL_USEC(b);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 return ratio;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 }
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 typedef struct _mb_shift mb_shift_t;
117
Thinker K.F. Li <thinker@branda.to>
parents: 116
diff changeset
18 /*! \brief Animation action for relative shift a coordination. */
116
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 struct _mb_shift {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 mb_action_t action;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 co_aix x, y;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 coord_t *coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 mb_timeval_t start_time;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 co_aix saved_matrix[6];
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 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
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_shift_start(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 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
33 redraw_man_t *rdman) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 mb_shift_t *shift = (mb_shift_t *)act;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 coord_t *coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 MB_TIMEVAL_CP(&shift->start_time, now);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 coord = shift->coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 memcpy(&shift->saved_matrix, coord->matrix, sizeof(co_aix[6]));
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 shift->playing_time = playing_time;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 }
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 static void mb_shift_step(mb_action_t *act, const mb_timeval_t *now,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 redraw_man_t *rdman) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 mb_shift_t *shift = (mb_shift_t *)act;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 mb_timeval_t diff;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 coord_t *coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 float ratio;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 194
diff changeset
50
116
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 MB_TIMEVAL_CP(&diff, now);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 MB_TIMEVAL_DIFF(&diff, &shift->start_time);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 ratio = comp_mb_timeval_ratio(&diff, shift->playing_time);
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 coord = shift->coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 coord->matrix[2] = shift->saved_matrix[2] + shift->x * ratio;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 coord->matrix[5] = shift->saved_matrix[5] + shift->y * ratio;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 rdman_coord_changed(rdman, coord);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 }
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 static void mb_shift_stop(mb_action_t *act, const mb_timeval_t *now,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 redraw_man_t *rdman) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 mb_shift_t *shift = (mb_shift_t *)act;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 coord_t *coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 coord = shift->coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 coord->matrix[2] = shift->saved_matrix[2] + shift->x;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 coord->matrix[5] = shift->saved_matrix[5] + shift->y;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 rdman_coord_changed(rdman, coord);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 }
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 static void mb_shift_free(mb_action_t *act) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 free(act);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 }
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 mb_action_t *mb_shift_new(co_aix x, co_aix y, coord_t *coord,
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 mb_word_t *word) {
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 mb_shift_t *shift;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 shift = (mb_shift_t *)malloc(sizeof(mb_shift_t));
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 if(shift == NULL)
194
45d9a1e2764d Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
85 return NULL;
116
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 shift->x = x;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 shift->y = y;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 shift->coord = coord;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 shift->action.start = mb_shift_start;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 shift->action.step = mb_shift_step;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 shift->action.stop = mb_shift_stop;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 shift->action.free = mb_shift_free;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95
154
6ce68c1f7405 Tank can fire bullet.
Thinker K.F. Li <thinker@branda.to>
parents: 117
diff changeset
96 /*! \note mb_shift_new() will add itself to the specified word. */
116
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 mb_word_add_action(word, (mb_action_t *)shift);
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 return (mb_action_t *)shift;
1d74eb3861b7 move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 }