aome further corrections to copyright notices.
[AROS.git] / rom / graphics / animate.c
blobe8608be91db1d94e4813dc7b22734531bfa4ada8
1 /*
2 Copyright © 1995-2007, 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
60 struct AnimOb * CurAnimOb = *anKey;
61 struct AnimComp * CurAnimComp;
63 /* Animate every object in the list */
64 while (NULL != CurAnimOb)
66 /* advance the clock */
67 CurAnimOb -> Clock += 1;
69 /* store old position */
70 CurAnimOb -> AnOldY = CurAnimOb -> AnY;
71 CurAnimOb -> AnOldX = CurAnimOb -> AnX;
73 CurAnimOb -> AnY += CurAnimOb -> YVel;
74 CurAnimOb -> AnX += CurAnimOb -> XVel;
76 CurAnimOb -> YVel += CurAnimOb -> YAccel;
77 CurAnimOb -> XVel += CurAnimOb -> XAccel;
79 /* Call the special routine of this AnimOb */
80 if (NULL != CurAnimOb -> AnimORoutine)
81 (CurAnimOb -> AnimORoutine)();
83 /* Now let's animate all it's components */
84 CurAnimComp = CurAnimOb -> HeadComp;
86 while (NULL != CurAnimComp)
88 LONG coord;
89 struct AnimComp * CurSeqAnimComp = CurAnimComp;
90 struct VSprite * CurVSprite, * NewVSprite;
92 /* decrease the timer */
93 CurSeqAnimComp -> Timer -= 1;
95 /* if the timer is 0 then the sequence has timed out ->
96 prepare the next sequence and set the bob of the current
97 sequence to be removed from the gel list. */
99 CurVSprite = CurSeqAnimComp -> AnimBob -> BobVSprite;
101 if (0 == CurSeqAnimComp -> Timer)
103 /* if this was the first component of the AnimOb then
104 change the head-pointer to the next sequence */
105 if (CurSeqAnimComp == CurAnimOb -> HeadComp)
106 CurAnimOb -> HeadComp = CurSeqAnimComp -> NextSeq;
108 /* initilize the NextComp and PrevComp pointers of the next
109 sequence to the values of the current sequence */
110 CurSeqAnimComp -> NextSeq -> NextComp = CurSeqAnimComp -> NextComp;
111 CurSeqAnimComp -> NextSeq -> PrevComp = CurSeqAnimComp -> PrevComp;
113 /* initilize the NextComp pointer of the previous component
114 - if existing - to point to the next sequence */
115 if (CurSeqAnimComp -> PrevComp)
116 CurSeqAnimComp -> PrevComp -> NextComp = CurSeqAnimComp -> NextSeq;
118 /* initilize the PrevComp pointer of the next component
119 - if existing - to point to the next sequence */
120 if (CurSeqAnimComp -> NextComp)
121 CurSeqAnimComp -> NextComp -> PrevComp = CurSeqAnimComp -> NextSeq;
123 /* init the timer of the next sequence */
125 CurSeqAnimComp -> NextSeq -> Timer = CurSeqAnimComp -> NextSeq -> TimeSet;
126 AddBob(CurSeqAnimComp -> NextSeq -> AnimBob, rp);
128 /* get the VSprite of the new sequence, we need it a few times */
129 NewVSprite = CurSeqAnimComp -> NextSeq -> AnimBob -> BobVSprite;
131 NewVSprite -> OldY = CurVSprite -> Y;
132 NewVSprite -> OldX = CurVSprite -> X;
134 /* as this sequence is complete we might have to add the
135 * RingX/YTrans to AnX/Y if the appropriate flags was set
137 if (0 != (CurSeqAnimComp -> Flags & RINGTRIGGER))
139 CurAnimOb -> AnY += CurAnimOb -> RingYTrans;
140 CurAnimOb -> AnX += CurAnimOb -> RingXTrans;
143 /* calculate the coordinates of the VSprite
144 * here [0.5 .. 1.4999] is rounded to 1
145 * [1.5 .. 2.4999] is rounded to 2 and so on
147 coord = (CurSeqAnimComp -> NextSeq -> YTrans + CurAnimOb -> AnY ) >> 5;
148 /* for better accuracy */
149 if (0 != (coord & 1))
150 coord += 2;
151 NewVSprite -> Y = (coord >> 1);
153 coord = (CurSeqAnimComp -> NextSeq -> XTrans + CurAnimOb -> AnX ) >> 5;
154 /* for better accuracy */
155 if (0 != (coord & 1))
156 coord += 2;
157 NewVSprite -> X = (coord >> 1);
159 CurVSprite -> Y = 0x8001;
160 CurVSprite -> X = 0x8001;
161 /* Remove the Bob from the gel list =
162 Mark the bob of the current sequence to be removed during
163 the next call of DrawGList(). DrawGList() will first
164 restore the old background where the bob is now and then
165 unlink the bob from the gel list. If double buffering is
166 used it will take two calls to DrawGList() to remove the
167 bob completely from the list. */
168 RemBob(CurSeqAnimComp -> AnimBob);
170 else
172 /* move (animate) the bob (actually the VSprite) that belongs
173 to this sequence */
174 /* do NOT change OldY/X -> leave this up to DrawGList() */
175 coord = ( CurSeqAnimComp -> YTrans +
176 CurAnimOb -> AnY ) >> 5;
177 /* for better accuracy */
178 if (0 != (coord & 1))
179 coord += 2;
180 CurVSprite -> Y = (coord >> 1);
182 coord = ( CurSeqAnimComp -> XTrans +
183 CurAnimOb -> AnX ) >> 5;
184 /* for better accuracy */
185 if (0 != (coord & 1))
186 coord += 2;
187 CurVSprite -> X = (coord >> 1);
191 /* call this componentent's special routine if supplied
192 * !!! this routine might give me a result but I don't know
193 * for sure and what would I do with the result???
195 if (NULL != CurSeqAnimComp -> AnimCRoutine)
196 (CurSeqAnimComp -> AnimCRoutine)();
198 /* animate the next component of this object in the list */
199 CurAnimComp = CurAnimComp -> NextComp;
202 /* advance to the next object in list */
203 CurAnimOb = CurAnimOb -> NextOb;
206 AROS_LIBFUNC_EXIT
207 } /* Animate */