2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Graphics function DoCollision()
8 #include <graphics/rastport.h>
9 #include <graphics/gels.h>
11 #include "graphics_intern.h"
13 /*****************************************************************************
16 #include <proto/graphics.h>
18 AROS_LH1(void, DoCollision
,
21 AROS_LHA(struct RastPort
*, rp
, A1
),
24 struct GfxBase
*, GfxBase
, 18, Graphics
)
27 Tests each gel in gel list for boundary and gel-to-gel collisions.
28 If a collision happens the collision handling routine is called.
29 The gel list must be sorted by y,x order.
32 rp - pointer to RastPort
49 ******************************************************************************/
53 struct VSprite
* CurVSprite
, * _CurVSprite
;
56 if (NULL
!= rp
->GelsInfo
)
58 CurVSprite
= rp
->GelsInfo
->gelHead
->NextVSprite
;
59 if (CurVSprite
->Flags
& VSPRITE
)
64 while (NULL
!= CurVSprite
->NextVSprite
)
66 _CurVSprite
= CurVSprite
->NextVSprite
;
69 * As long as they can overlap vertically..
71 while (NULL
!= _CurVSprite
&&
72 (CurVSprite
->Y
+ CurVSprite
->Height
- 1) >= _CurVSprite
->Y
)
75 * Do these two overlap horizontally ???
77 if (_CurVSprite
->Flags
& VSPRITE
)
83 ((CurVSprite
->X
>_CurVSprite
->X
+(_CurVSprite
->Width
<<_shift
)-1) ||
84 (CurVSprite
->X
+(CurVSprite
->Width
<<shift
)-1<_CurVSprite
->X
))
88 * Must test the collision masks!!
89 * Phew, this is not going to be easy.
91 int collision
= FALSE
;
92 int dy
= _CurVSprite
->Y
- CurVSprite
->Y
;
93 UWORD
* collmask
= CurVSprite
->CollMask
;
94 UWORD
* _collmask
= _CurVSprite
->CollMask
;
95 unsigned short wordsperline
;
96 unsigned short _wordsperline
;
98 int offset
, _offset
= 0;
102 * I will hold the CurVSprite's collision mask still
103 * and adjust/shift the collision mask of _CurVSprite.
104 * If any and'ing results with non-zero, there is a
107 if (CurVSprite
->Flags
& VSPRITE
)
108 wordsperline
= CurVSprite
->Width
>> 4; // should be 1
110 wordsperline
= CurVSprite
->Width
;
112 if (_CurVSprite
->Flags
& VSPRITE
)
113 _wordsperline
= _CurVSprite
->Width
>> 4; // should be 1
115 _wordsperline
= _CurVSprite
->Width
;
120 * _CurVSprite is lower than CurVSprite
122 i
= wordsperline
* dy
;
123 line
= _CurVSprite
->Y
;
127 _i
= _wordsperline
* dy
;
128 line
= CurVSprite
->Y
;
131 offset
= _CurVSprite
->X
- CurVSprite
->X
;
134 _offset
= (-offset
) >> 4;
135 _scroll
= (-offset
) & 0xf;
141 * _CurVSprite is further to the right than
144 _scroll
= -(offset
& 0xf);
149 * _scroll > 0 means shift the bits to the RIGHT!
151 while ((line
< ( CurVSprite
->Height
+ CurVSprite
->Y
)) &&
152 (line
< (_CurVSprite
->Height
+_CurVSprite
->Y
)) )
154 int curindex
= offset
;
155 int _curindex
= _offset
;
156 while ( curindex
< wordsperline
&&
157 _curindex
< _wordsperline
)
161 if (collmask
[curindex
+i
] & (_collmask
[_curindex
+_i
] >> _scroll
) )
167 if (curindex
> wordsperline
)
170 if (collmask
[curindex
+i
] & (_collmask
[_curindex
+_i
] << (16-_scroll
)))
180 if (collmask
[curindex
+i
] & _collmask
[_curindex
+_i
])
190 if (collmask
[curindex
+i
] & (_collmask
[_curindex
+_i
] << (-_scroll
)))
196 if (_curindex
> _wordsperline
)
199 if (collmask
[curindex
+i
] & (_collmask
[_curindex
+_i
] >> (16+_scroll
)))
214 UWORD mask
= CurVSprite
->MeMask
& _CurVSprite
->HitMask
;
216 while (i
< 16 && 0 != mask
)
220 if (rp
->GelsInfo
->collHandler
&&
221 rp
->GelsInfo
->collHandler
->collPtrs
[i
])
222 rp
->GelsInfo
->collHandler
->collPtrs
[i
]( CurVSprite
,
231 _CurVSprite
= _CurVSprite
->NextVSprite
;
233 CurVSprite
= CurVSprite
->NextVSprite
;