2 Copyright © 1995-2007, 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 *****************************************************************************/
53 struct VSprite
* CorrectVSprite
= rp
-> GelsInfo
-> gelHead
;
54 struct VSprite
* CurVSprite
= CorrectVSprite
-> NextVSprite
;
56 LONG Coord
= JOIN_XY_COORDS( CorrectVSprite
-> X
, CorrectVSprite
-> Y
);
58 while ( NULL
!= CurVSprite
) {
59 LONG NewCoord
= JOIN_XY_COORDS( CurVSprite
-> X
, CurVSprite
-> Y
);
61 if (0 != CurVSprite
->VSBob
)
62 CurVSprite
->VSBob
->Flags
&= ~BDRAWN
;
64 if (Coord
<= NewCoord
) {
65 /* sorting is not necessary for this VSprite */
66 CorrectVSprite
= CurVSprite
;
67 CurVSprite
= CurVSprite
-> NextVSprite
;
71 struct VSprite
* tmpVSprite
= CorrectVSprite
->PrevVSprite
;
73 The CurVSprite is at the wrong position. It has to appear
74 somewhere earlier in the list.
77 /* unlink it from it's current position */
78 CorrectVSprite
-> NextVSprite
= CurVSprite
-> NextVSprite
;
79 if (NULL
!= CurVSprite
-> NextVSprite
)
80 CurVSprite
-> NextVSprite
-> PrevVSprite
= CorrectVSprite
;
82 /* insert CurVSprite at some previous place */
84 while ( ( NULL
!= tmpVSprite
) &&
85 ( JOIN_XY_COORDS(tmpVSprite
-> X
, tmpVSprite
-> Y
) > NewCoord
) )
86 tmpVSprite
= tmpVSprite
-> PrevVSprite
;
88 if (NULL
== tmpVSprite
) {
89 /* our CurVSprite becomes the fist one in the list */
90 /* Due to the head VSprite this should never happen!!! */
91 rp
->GelsInfo
->gelHead
->PrevVSprite
= CurVSprite
;
92 CurVSprite
->NextVSprite
= rp
->GelsInfo
->gelHead
;
93 CurVSprite
->PrevVSprite
= NULL
;
94 rp
->GelsInfo
->gelHead
= CurVSprite
;
96 /* link it into the list *after* the tmpVSprite */
97 CurVSprite
->PrevVSprite
= tmpVSprite
;
98 CurVSprite
->NextVSprite
= tmpVSprite
->NextVSprite
;
100 if (NULL
!= tmpVSprite
->NextVSprite
)
101 tmpVSprite
->NextVSprite
->PrevVSprite
= CurVSprite
;
103 tmpVSprite
->NextVSprite
= CurVSprite
;
106 /* set the new CurVSprite */
107 CurVSprite
= CorrectVSprite
-> NextVSprite
;
109 } /* while ( NULL != CurVSprite ) */
111 rp
->GelsInfo
->gelTail
= CorrectVSprite
;