For RESHOOT R I tried several ways of speeding up collission detection, and now end up with this solution:
- Polling CLXDAT for a some very basic checks, for example if the player sprite is in contact with other sprites and / or background
- If yes, in case of player sprite collision, code checks player position with bounding boxes of other objects using the 68020s CMP2-command. RESHOOT R is AGA-only, so why not. This results in a very small query loop:
Code:
move objcount,d7
bra chkPlyColLoop
chkPlyCol
; bounding box for colcheck
move.w objectListX(a3),d1; loop through list of objects, get x-coord
sub.w a4,d1 ; sub players x coord / preloaded earlier
cmp2.w (plyBoundBox,pc),d1
bcs.b chkPlyColLoop
move.w objectListY(a3),d0; get y-coords of objects
sub a5,d0; sub players y coord
cmp2.w (plyBoundBox+4,pc),d0
bcc.b spriteHit; collision detected
chkPlyColLoop
dbra.b d7,chkPlyCol
....
plyBoundBox ; collission box
dc.w -31,-24 ; x-bound left / right
dc.w -46,-38 ; y-bound up / down
There are a bunch of other optimizations to speed things up:
- Code builds list of bounding box coords for each hitable (!) object each frame. This list structured in such a way that it is small and enables fast comparisons between players bullets and hitable objects with cmp2
- Player vs. background collision. Background is structured in such a way that only collisions between Player Sprite and Bitplane 1 triggers CLXDAT. So the player ship can go over some terrain and hit explosions without any further cpu overhead. Only if player sprite hits Bitplane 1, further bounding box check is needed