cpu.resource(pc-i386) Get this compile again, with acpica.library
[AROS.git] / rom / graphics / sortglist.c
blob1e55ccffd556b3b35dbba7a91e55d8fe2628526e
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function SortGList()
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_LH1(void, SortGList,
19 /* SYNOPSIS */
20 AROS_LHA(struct RastPort *, rp, A1),
22 /* LOCATION */
23 struct GfxBase *, GfxBase, 25, Graphics)
25 /* FUNCTION
26 Sort the current gel list by the y and x coordinates of it's
27 elements.
28 You have to call this routine prior to calling DoCollision()
29 of DrawGList or make sure that the list is sorted!
31 INPUTS
32 rp = pointer to RastPort that has an GelsInfo linked to it
34 RESULT
36 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
43 InitGels(), DrawGList(), DoCollision(), graphics/rastport.h
45 INTERNALS
47 HISTORY
49 *****************************************************************************/
51 AROS_LIBFUNC_INIT
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;
69 Coord = NewCoord;
70 } else {
71 struct VSprite * tmpVSprite = CorrectVSprite->PrevVSprite;
72 /*
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;
95 } else {
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;
113 AROS_LIBFUNC_EXIT
115 } /* SortGList */