r4493@vps: verhaegs | 2007-04-19 14:44:00 -0400
[AROS.git] / rom / graphics / animate.c
blobaf65a4d0c409a9c6a96b509c715d7b1bdc34cd8c
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function Animate()
6 Lang: english
7 */
8 #include <graphics/gels.h>
9 #include <graphics/rastport.h>
10 #include "graphics_intern.h"
12 /*****************************************************************************
14 NAME */
15 #include <proto/graphics.h>
17 AROS_LH2(void, Animate,
19 /* SYNOPSIS */
20 AROS_LHA(struct AnimOb **, anKey, A0),
21 AROS_LHA(struct RastPort *, rp, A1),
23 /* LOCATION */
24 struct GfxBase *, GfxBase, 27, Graphics)
26 /* FUNCTION
27 Animate every AnimOb in the list. In particular do the following:
28 - update location and velocities
29 - call AnimOb's special routine if supplied
30 - for every component of the Anim ob do:
31 - switch to new sequence if current sequence times out
32 - call the special routine of the component if supplied
33 - set the the coordinates of the VSprite of this
34 sequence to whatever these routines cause
36 INPUT
37 anKey = address of a pointer to the first AnimOb in the list
38 (same address that was passed to AddAnimOb!)
39 rp = pointer to a valid RastPort structure
41 RESULT
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
50 AddAnimOb() graphics/rastport.h graphics/gels.h
52 INTERNALS
54 HISTORY
56 *****************************************************************************/
58 AROS_LIBFUNC_INIT
59 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
61 struct AnimOb * CurAnimOb = *anKey;
62 struct AnimComp * CurAnimComp;
64 /* Animate every object in the list */
65 while (NULL != CurAnimOb)
67 /* advance the clock */
68 CurAnimOb -> Clock += 1;
70 /* store old position */
71 CurAnimOb -> AnOldY = CurAnimOb -> AnY;
72 CurAnimOb -> AnOldX = CurAnimOb -> AnX;
74 CurAnimOb -> AnY += CurAnimOb -> YVel;
75 CurAnimOb -> AnX += CurAnimOb -> XVel;
77 CurAnimOb -> YVel += CurAnimOb -> YAccel;
78 CurAnimOb -> XVel += CurAnimOb -> XAccel;
80 /* Call the special routine of this AnimOb */
81 if (NULL != CurAnimOb -> AnimORoutine)
82 (CurAnimOb -> AnimORoutine)();
84 /* Now let's animate all it's components */
85 CurAnimComp = CurAnimOb -> HeadComp;
87 while (NULL != CurAnimComp)
89 long coord;
90 struct AnimComp * CurSeqAnimComp = CurAnimComp;
91 struct VSprite * CurVSprite, * NewVSprite;
93 /* decrease the timer */
94 CurSeqAnimComp -> Timer -= 1;
96 /* if the timer is 0 then the sequence has timed out ->
97 prepare the next sequence and set the bob of the current
98 sequence to be removed from the gel list. */
100 CurVSprite = CurSeqAnimComp -> AnimBob -> BobVSprite;
102 if (0 == CurSeqAnimComp -> Timer)
104 /* if this was the first component of the AnimOb then
105 change the head-pointer to the next sequence */
106 if (CurSeqAnimComp == CurAnimOb -> HeadComp)
107 CurAnimOb -> HeadComp = CurSeqAnimComp -> NextSeq;
109 /* initilize the NextComp and PrevComp pointers of the next
110 sequence to the values of the current sequence */
111 CurSeqAnimComp -> NextSeq -> NextComp = CurSeqAnimComp -> NextComp;
112 CurSeqAnimComp -> NextSeq -> PrevComp = CurSeqAnimComp -> PrevComp;
114 /* initilize the NextComp pointer of the previous component
115 - if existing - to point to the next sequence */
116 if (CurSeqAnimComp -> PrevComp)
117 CurSeqAnimComp -> PrevComp -> NextComp = CurSeqAnimComp -> NextSeq;
119 /* initilize the PrevComp pointer of the next component
120 - if existing - to point to the next sequence */
121 if (CurSeqAnimComp -> NextComp)
122 CurSeqAnimComp -> NextComp -> PrevComp = CurSeqAnimComp -> NextSeq;
124 /* init the timer of the next sequence */
126 CurSeqAnimComp -> NextSeq -> Timer = CurSeqAnimComp -> NextSeq -> TimeSet;
127 AddBob(CurSeqAnimComp -> NextSeq -> AnimBob, rp);
129 /* get the VSprite of the new sequence, we need it a few times */
130 NewVSprite = CurSeqAnimComp -> NextSeq -> AnimBob -> BobVSprite;
132 NewVSprite -> OldY = CurVSprite -> Y;
133 NewVSprite -> OldX = CurVSprite -> X;
135 /* as this sequence is complete we might have to add the
136 * RingX/YTrans to AnX/Y if the appropriate flags was set
138 if (0 != (CurSeqAnimComp -> Flags & RINGTRIGGER))
140 CurAnimOb -> AnY += CurAnimOb -> RingYTrans;
141 CurAnimOb -> AnX += CurAnimOb -> RingXTrans;
144 /* calculate the coordinates of the VSprite
145 * here [0.5 .. 1.4999] is rounded to 1
146 * [1.5 .. 2.4999] is rounded to 2 and so on
148 coord = (CurSeqAnimComp -> NextSeq -> YTrans + CurAnimOb -> AnY ) >> 5;
149 /* for better accuracy */
150 if (0 != (coord & 1))
151 coord += 2;
152 NewVSprite -> Y = (coord >> 1);
154 coord = (CurSeqAnimComp -> NextSeq -> XTrans + CurAnimOb -> AnX ) >> 5;
155 /* for better accuracy */
156 if (0 != (coord & 1))
157 coord += 2;
158 NewVSprite -> X = (coord >> 1);
160 CurVSprite -> Y = 0x8001;
161 CurVSprite -> X = 0x8001;
162 /* Remove the Bob from the gel list =
163 Mark the bob of the current sequence to be removed during
164 the next call of DrawGList(). DrawGList() will first
165 restore the old background where the bob is now and then
166 unlink the bob from the gel list. If double buffering is
167 used it will take two calls to DrawGList() to remove the
168 bob completely from the list. */
169 RemBob(CurSeqAnimComp -> AnimBob);
171 else
173 /* move (animate) the bob (actually the VSprite) that belongs
174 to this sequence */
175 /* do NOT change OldY/X -> leave this up to DrawGList() */
176 coord = ( CurSeqAnimComp -> YTrans +
177 CurAnimOb -> AnY ) >> 5;
178 /* for better accuracy */
179 if (0 != (coord & 1))
180 coord += 2;
181 CurVSprite -> Y = (coord >> 1);
183 coord = ( CurSeqAnimComp -> XTrans +
184 CurAnimOb -> AnX ) >> 5;
185 /* for better accuracy */
186 if (0 != (coord & 1))
187 coord += 2;
188 CurVSprite -> X = (coord >> 1);
192 /* call this componentent's special routine if supplied
193 * !!! this routine might give me a result but I don't know
194 * for sure and what would I do with the result???
196 if (NULL != CurSeqAnimComp -> AnimCRoutine)
197 (CurSeqAnimComp -> AnimCRoutine)();
199 /* animate the next component of this object in the list */
200 CurAnimComp = CurAnimComp -> NextComp;
203 /* advance to the next object in list */
204 CurAnimOb = CurAnimOb -> NextOb;
207 AROS_LIBFUNC_EXIT
208 } /* Animate */