English Amiga Board

Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

Thread Tools
Old Yesterday, 14:33   #101
Registered User
Master484's Avatar
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 321
This sounds like a good use case for macros - effectively automated loop unrolling, where you can leave your code referencing the macro, and the compiler will insert the subroutine at compile time for you.
Yeah I know about macros, and some day I'll probably try to learn how to use them.

I need to check the syntax but you should be able to replace the direction change "multiplication by - 1" with a negation and an addition (dir = (~dir) + 1). Assuming two's complement.
I'll check if this is possible, but I'm not sure if that sort of variable change trick from positive to negative and vice versa can be done.

I only ask because some times I know it seems strange but seems to be quicker sometimes than spaghetti, especially when you have loops in loops.
Hmm, I don't know why that would happen, but I guess it's possible, and this is one thing that could be tested.

That's just absurd. Are there any edge cases RectsHit must handle? Otherwise I can't understand how Acid Software could come up with a library routine that is slower than basic.
The 4 IF method means the technique where 4 nested IF..End IFs are used, and where the checks dont progress to the next IF unless the previous IF was true.

Although RectsHit is faster in the case where the collision actually happens, in most non-collision cases the 4 IFs is faster.

I made a quick test that compared RectsHit against the 4 IF.

x = 5
y = 5
a = 5
b = 5


If RectsHit (x,y,16,16,a,b,16,16) then hit = 1

If x + 20 > a
 If x < a + 20
  If y +20 > b
   If y < b +20
    hit = 1
   End If
  End If
 End If
End If

loop + 1

Until loop = 1000
Results for RectsHit:

Hit happens = Frame 3 Vpos at 240
No hit = Frame 3 Vpos at 80

Results for 4 IF method:

4 IFs processed, hit happens = Frame 4 Vpos at 28
4 IFs processed, no hit = Frame 3 Vpos at 274
3 IFs processed, no hit = Frame 3 Vpos at 106
2 IFs processed, no hit = Frame 2 Vpos at 239
1 IF processed, no hit = Frame 2 Vpos at 67


So only if the checks progress to the 3rd IF, then RectsHit is faster.

But when you have a scenario where bullets randomly bounce in screen, then the first IF always eliminates approximately half of the bullets.

Because the first IF makes an "is bullet right side larger than target left side" check, then all smaller x values cause a fail, and the checks dont progress past the first IF. On a scenario where all bullets and objects are at random places in the screen, this means that about 50 % of the bullets will fail this first test.

And for those 50 % of bullets that pass the first test, then comes the second IF, that checks "is bullet left side smaller than target right side". This second check eliminates almost all cases in the screen, because with these X checks we have actually cheked entire two halves of the screen, and only a very small "corridor" still remains between the targets left and right wall + some small offsets.

And the 3rd and 4th IF checks only happen for those objects that are inside this corridor. This is the worst case scenario, and the point where speed starts to drop in comparison to RectsHit. But it happens so rarely, that it doesn't matter.


Another benefit of the 4 IF is that you can have many versions that check things in different order. For example if player bullets travel upwards only, then for them it makes sense to make the "Is bullet top side smaller than target bottom side" first, to maximize the cases where the checks stop at the first IF.
Master484 is offline  
AdSense AdSense  
Old Yesterday, 17:08   #102
Bo Bo

Retro1234's Avatar
Join Date: Jun 2006
Location: 5150
Posts: 3,907
4 IF method lol - Bounding Box and it should be more like 8 IFs or the use of up/down symbol or your checking 1 box against only one point of the other box.

I still find it unlikely to be faster than inbuilt collision.

Last edited by Retro1234; Yesterday at 17:14.
Retro1234 is offline  
AdSense AdSense  

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
SetCol/DoColl-How to test collisions with different sprites against different colors? Shatterhand Coders. Blitz Basic 1 12 January 2017 18:51
Quickest code.... Galahad/FLT Coders. Asm / Hardware 10 01 January 2017 17:23
[REQ:ASM] Sprite collisions basics jman Coders. Tutorials 5 03 September 2011 00:07
What is the quickest way Doc Mindie support.WinUAE 6 17 October 2007 21:15
Disable Sprite Collisions DeAdLy_cOoKiE Retrogaming General Discussion 4 24 March 2006 17:56

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 02:02.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.05822 seconds with 15 queries