Jump to content

  • Log In with Google      Sign In   
  • Create Account

I tried making a Quadtree for collission detection but it runs really slow.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 infectedbrain   Members   -  Reputation: 157

Like
0Likes
Like

Posted 06 August 2012 - 01:36 PM

So after a few months of research and experimentation I made my first tree like data structure (its so cute). But when I put it into action in my game and rendered about 30 2d sprites it lags too much (down to 3 fps) but when I just check for collision against everything on the screen at once it never lags. I need some assistance to find out why.

I put the code on pastebin here.

If you know anything that would help that would be greatly appreciated.

Thanks in advance,
Ben

Edit: Fixed the link. I don't know why that happened.

Edited by infectedbrain, 06 August 2012 - 06:27 PM.


Sponsor:

#2 french_hustler   Members   -  Reputation: 366

Like
0Likes
Like

Posted 06 August 2012 - 03:06 PM

Your link seems broken. I get unknown paste id.

But in the end, it just comes down to basic debugging and profiling practices. You need to figure out which portion of the code is taking the most cpu cycles. The problem could be anywhere, from the tree structuring to the traversals. I would also render each quad and make sure that it looks like it should. Move objects around and make sure that splits and merges are functioning correctly. Having a visual representation is very important. If that is okay, make sure your traversals are working as they should. Perhaps step through the code with a debugger and see if you are doing redundant things. A quadtree is a decently complex system. You need to break it down in smaller parts and make sure the behavior is as intended.

The problem could also lie in your game. Maybe it's using your quadtree in a bad way (such as traversing it a lot of times per frame).

Edited by french_hustler, 06 August 2012 - 03:07 PM.


#3 WavyVirus   Members   -  Reputation: 735

Like
0Likes
Like

Posted 06 August 2012 - 03:35 PM

Hi Infected.

Pastebin gives me "Unknown Paste ID!"

#4 infectedbrain   Members   -  Reputation: 157

Like
0Likes
Like

Posted 06 August 2012 - 04:56 PM

I fixed the link. sorry about that

#5 infectedbrain   Members   -  Reputation: 157

Like
0Likes
Like

Posted 06 August 2012 - 04:58 PM

The problem could also lie in your game. Maybe it's using your quadtree in a bad way (such as traversing it a lot of times per frame).


The only way I can get it to work is by traversing it everytime something moves.. whitch is about every frame. How else can i do that.

#6 infectedbrain   Members   -  Reputation: 157

Like
0Likes
Like

Posted 06 August 2012 - 05:27 PM

Now when I make a few hundred projectiles it lags. But it never stops lagging. Its strange because I made it so that when a projectile goes off the screen it is removed from memory. I tested that and it seems to work. I am making an asteroids clone if that helps.

#7 infectedbrain   Members   -  Reputation: 157

Like
0Likes
Like

Posted 06 August 2012 - 05:32 PM

I fixed that problem. Sorry for that

#8 clb   Members   -  Reputation: 1781

Like
0Likes
Like

Posted 06 August 2012 - 05:34 PM

Looking through your implementation, a lot of it seems very weird. How are you using the code you pasted? How is the code like that creates your tree? How about the code that invokes the functions to dynamically update the tree? and how do you initiate the pairwise collision check state?

In particular the line 92 seems odd. What's going on there? Am I reading it correctly that you're testing all objects in your game level against the current node, then recursively split that node to four quadrants, and again test all objects against each node of the tree? Does line 42 iterate one index too little? Shouldn't it iterate until i < 4? Can you avoid having to use the bool cleanUp variable?
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

#9 infectedbrain   Members   -  Reputation: 157

Like
0Likes
Like

Posted 06 August 2012 - 06:27 PM

In particular the line 92 seems odd. What's going on there? Am I reading it correctly that you're testing all objects in your game level against the current node, then recursively split that node to four quadrants, and again test all objects against each node of the tree? Does line 42 iterate one index too little? Shouldn't it iterate until i < 4? Can you avoid having to use the bool cleanUp variable?


I made a change to that loop in line 92. I made it check for children then if there is no children check the actual quad. All of the iterations go through 0, 1, 2, 3 so they are all okay.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS