Collision detection in Assembly not working at all

Page 2/2
1 |

By albs_br

Resident (64)

albs_br's picture

01-07-2020, 17:01

Really good advices, especially the second one.
I'm really newbie when it comes to assembly optimization.

At this point, I'm happy simply with things working, that's hard enough.
But when I have 30 sprites on screen, each one with 4 points to check against all others, each CPU cycle saved on this routine will be precious.
Thanks everyone.

By theNestruo

Master (155)

theNestruo's picture

01-07-2020, 18:50

Actually... a good optimization is to reduce the number of checks by knowing the size of the bounding boxes.

So instead of x>=x1 and x<=x2 (two comparisons) you can check if abs(x-xc)<=w/2 (with xc being the x_center and w being the width; or even better having half the width pre-computed).
And if there are two overlapping rectangles... well abs(xc - uc)<=(w1+w2)/2 (distance between the centers less than half of the sum of the widths).

But that will come when needed; currently, if you are a newbie, focusing on getting things working (and therefore, getting things actually done) is more than enough! Premature optimization can be time consuming (and sometimes pointless).

By albs_br

Resident (64)

albs_br's picture

02-07-2020, 04:59

And even without these optimizations my code run fast as hell. I have to use a delay routine. I have doubts if I will ever need to remove this routine.

The worst assembly code is 100x faster than the best BASIC code.

By ARTRAG

Enlighted (6396)

ARTRAG's picture

02-07-2020, 07:44

Look at the link I have attached. All sprites in Uridium have bounding boxes
Collisions between boxes are faster than testing the 4 edges against a single box
The code has both 16 bit and 8 bit implementation.

By ARTRAG

Enlighted (6396)

ARTRAG's picture

02-07-2020, 07:50

the key routine is at label CollisionCheck_8b
[code]

; CollisionCheck
;
; Calculates whether a collision occurs between two objects
; of a certain size
;
; IN: b = coordinate of object 1
; c = size of object 1
; d = coordinate of object 2
; e = size of object 2
; OUT: Carry set if collision
; CHANGES: AF
;
CollisionCheck_8b:
ld a,d ; get x2 [5]
sub b ; calculate x2-x1 [5]
jr c,.other ; jump if x2

By albs_br

Resident (64)

albs_br's picture

16-07-2020, 23:56

On line 248, I guess there is an error on comment:

sub e ; compare with size 1 [5]

Souldn't be

sub e ; compare with size 2 [5]

?

By ARTRAG

Enlighted (6396)

ARTRAG's picture

16-07-2020, 23:59

sure, it is size 2

Page 2/2
1 |