http://www.blitzbasic.com/codearcs/codearcs.php?code=1065
Now, I think I understand most of it, but I have some questions.
Just to make sure I don't have the entirely wrong idea about the system here, it works by:
dividing the area into a grid, and having a TList per square, the TLists saved inside an array. When I am to check objects for collisions, I only check the objects within a grind against each other, and not against those of an outside grind. Thus, objects that are really far apart won't check collisions against each other.
---
So, as I've understood this, this is a bit-shift operation in order to quickly and effectively sort the sprites into the right sectors. But, I really don't understand exactly how it works. What does the Shr command do? the documentation didn't help me at all. >_>
Can anybody explain just how this works step by step?
---
Next, I have a bit different setup than the example game inside the code (it's just some basic sprites moving around). You see, my game doesn't a limit to the world size in any way.
I do it in a simple way. There is an X and Y for the screen, and all objects are modified according to this X and Y.
So, if the screen is at 100,100, and an object is at 150,150, then the object will be drawn at 50,50. Thus, by just adding and subtracting to the screen X and Y, we move around on an unlimited map (well, until the integer can't hold such a large number anymore ^^).
Any units outside a certain distance is deleted, preventing the massive load that would come after a while. And of course, objects are randomly created as you travel ahead, to simulate that you travel and stumble upon random stuff.
I don't see a problem, but is it possible that this can crash with the way the sectors are divided across the world? All I see that I need to do is have the sectors move as the screen does, but I don't exactly understand how the shift things works, so I might be missing out on something big here.
---
Another question. The reason why 4 sectors needs to be checked all at once is because objects may overlap some sectors, right? If so, then I understand that part, I think.
So, anyway, I had a hard time explaining some of the things here in short terms, so just give a friendly pointer if I didn't give enough information about something in order for you to answer my question, or if you need to look at my code, and not just my explanation of my code, to understand something.
Thanks in advance.
Now, I think I understand most of it, but I have some questions.
Just to make sure I don't have the entirely wrong idea about the system here, it works by:
dividing the area into a grid, and having a TList per square, the TLists saved inside an array. When I am to check objects for collisions, I only check the objects within a grind against each other, and not against those of an outside grind. Thus, objects that are really far apart won't check collisions against each other.
---
Function update_sectors(shift_x_off%, shift_y_off%) ; Reset sector linked list heads. For sx% = 0 To NUM_X_SECTORS For sy% = 0 To NUM_Y_SECTORS sector_head(sx,sy) = Null Next Next ; Put each sprite into it's sector's linked list. For spr.spriteT = Each spriteT sx = Int(spr\x + shift_x_off) Shr find_sector sy = Int(spr\y + shift_y_off) Shr find_sector spr\sector_link = sector_head(sx,sy) sector_head(sx,sy) = spr Next End Function
So, as I've understood this, this is a bit-shift operation in order to quickly and effectively sort the sprites into the right sectors. But, I really don't understand exactly how it works. What does the Shr command do? the documentation didn't help me at all. >_>
Can anybody explain just how this works step by step?
---
Next, I have a bit different setup than the example game inside the code (it's just some basic sprites moving around). You see, my game doesn't a limit to the world size in any way.
I do it in a simple way. There is an X and Y for the screen, and all objects are modified according to this X and Y.
So, if the screen is at 100,100, and an object is at 150,150, then the object will be drawn at 50,50. Thus, by just adding and subtracting to the screen X and Y, we move around on an unlimited map (well, until the integer can't hold such a large number anymore ^^).
Any units outside a certain distance is deleted, preventing the massive load that would come after a while. And of course, objects are randomly created as you travel ahead, to simulate that you travel and stumble upon random stuff.
I don't see a problem, but is it possible that this can crash with the way the sectors are divided across the world? All I see that I need to do is have the sectors move as the screen does, but I don't exactly understand how the shift things works, so I might be missing out on something big here.
---
Another question. The reason why 4 sectors needs to be checked all at once is because objects may overlap some sectors, right? If so, then I understand that part, I think.
So, anyway, I had a hard time explaining some of the things here in short terms, so just give a friendly pointer if I didn't give enough information about something in order for you to answer my question, or if you need to look at my code, and not just my explanation of my code, to understand something.
Thanks in advance.
