2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Graphics function SortGList()
8 #include <graphics/gels.h>
9 #include <graphics/rastport.h>
10 #include "graphics_intern.h"
12 /*****************************************************************************
15 #include <proto/graphics.h>
17 AROS_LH1(void, SortGList
,
20 AROS_LHA(struct RastPort
*, rp
, A1
),
23 struct GfxBase
*, GfxBase
, 25, Graphics
)
26 Sort the current gel list by the y and x coordinates of it's
28 You have to call this routine prior to calling DoCollision()
29 of DrawGList or make sure that the list is sorted!
32 rp = pointer to RastPort that has an GelsInfo linked to it
43 InitGels() DrawGList() DoCollision() graphics/rastport.h
49 *****************************************************************************/
52 AROS_LIBBASE_EXT_DECL(struct GfxBase
*,GfxBase
)
54 struct VSprite
* CorrectVSprite
= rp
-> GelsInfo
-> gelHead
;
55 struct VSprite
* CurVSprite
= CorrectVSprite
-> NextVSprite
;
57 LONG Coord
= JOIN_XY_COORDS( CorrectVSprite
-> X
, CorrectVSprite
-> Y
);
59 while ( NULL
!= CurVSprite
) {
60 LONG NewCoord
= JOIN_XY_COORDS( CurVSprite
-> X
, CurVSprite
-> Y
);
62 if (0 != CurVSprite
->VSBob
)
63 CurVSprite
->VSBob
->Flags
&= ~BDRAWN
;
65 if (Coord
<= NewCoord
) {
66 /* sorting is not necessary for this VSprite */
67 CorrectVSprite
= CurVSprite
;
68 CurVSprite
= CurVSprite
-> NextVSprite
;
72 struct VSprite
* tmpVSprite
= CorrectVSprite
->PrevVSprite
;
74 The CurVSprite is at the wrong position. It has to appear
75 somewhere earlier in the list.
78 /* unlink it from it's current position */
79 CorrectVSprite
-> NextVSprite
= CurVSprite
-> NextVSprite
;
80 if (NULL
!= CurVSprite
-> NextVSprite
)
81 CurVSprite
-> NextVSprite
-> PrevVSprite
= CorrectVSprite
;
83 /* insert CurVSprite at some previous place */
85 while ( ( NULL
!= tmpVSprite
) &&
86 ( JOIN_XY_COORDS(tmpVSprite
-> X
, tmpVSprite
-> Y
) > NewCoord
) )
87 tmpVSprite
= tmpVSprite
-> PrevVSprite
;
89 if (NULL
== tmpVSprite
) {
90 /* our CurVSprite becomes the fist one in the list */
91 /* Due to the head VSprite this should never happen!!! */
92 rp
->GelsInfo
->gelHead
->PrevVSprite
= CurVSprite
;
93 CurVSprite
->NextVSprite
= rp
->GelsInfo
->gelHead
;
94 CurVSprite
->PrevVSprite
= NULL
;
95 rp
->GelsInfo
->gelHead
= CurVSprite
;
97 /* link it into the list *after* the tmpVSprite */
98 CurVSprite
->PrevVSprite
= tmpVSprite
;
99 CurVSprite
->NextVSprite
= tmpVSprite
->NextVSprite
;
101 if (NULL
!= tmpVSprite
->NextVSprite
)
102 tmpVSprite
->NextVSprite
->PrevVSprite
= CurVSprite
;
104 tmpVSprite
->NextVSprite
= CurVSprite
;
107 /* set the new CurVSprite */
108 CurVSprite
= CorrectVSprite
-> NextVSprite
;
110 } /* while ( NULL != CurVSprite ) */
112 rp
->GelsInfo
->gelTail
= CorrectVSprite
;