Collision Detection - Need optimization/faster method
Hey everyone, ive been working on a small space/rpg type game for the last week or so, and ive come to a pretty big problem. In my game i need to check for collisions between players/projectiles and player/pickups. the problem is there are (at least in the small demonstration version ive made so far) 999 players, 999 projectiles, and 999 pickups which need to be checked. the total number of loops alone in my collision detection sub is 998001 loops, with 2 fairly complex calculations per loop. At its current status, it takes about 2.5 seconds just to go through one loop on an Athlon 64 3700+ 2.2ghz cpu.
I need ideas/examples on a MUCH faster/more efficient way of checking for collisions. I check the distance between the objects in my game and subtract each radius because most of the objects in the game are circular, and those that arent are small enough to be considered so. so distance is an easy enough way of checking for collisions in this game at least.
here is my current sub for collision detection
VB Code:
Public Sub check_for_collisions()
'check for collissions between player/projectile and player/pickup
Im thinking i may just have to cut back to a max of 99 or so entities of each (player, station, projectiles and pickups even tho only projectiles and pickups are used in this sub (as well as players)) but i wanted to make this a very large scale game, with almost so many things to explore you would never be at the same place twice.
So, if anyone could help me that would be more than greatly appreciated.
Id rather not give the whole source to the game, but attached is a compiled version of what i have so far without collision detection enabled (so its actually playable XD). All that happens right now in the version attached is 999 of each type of entity is spawned, and fly in random directions (except for AI player (pirates, traders, police), they just have a simple AI which makes them follow you (or try to) around.
PS. In order to make it run, you need to put PBGL.dll in your c:\windows\system32 folder and then in start>run or command prompt type "regsvr32 c:\windows\system32\pbgl.dll". PBGL.dll is a "Picture Box Graphics Library" that i wrote to make it easier to do things with picture boxes like using transparent bitblt and other pretty simple drawing operations. Oh, and as i mention that i think it should be stated that all things in the game are rendered with bitblt.
PSS: when running the game please tell me the framerate you get (in the lower right hand corner of the window) and your pc specs (processor at least). I need to make sure my code to control the framerate is working right. It should be a constant 32, if it goes below 32 dont worry, its pretty demanding (yes, i need to work on it a bit more) but if it goes over 32 let me know because that would be another bug to fix...