Hello,
I have build a region quadtree class which manages itself, without having to insert objects to it every frame.
This is the first time I build a Quadtree, also my first template class in C++.
It tracks objects bounding rect every frame and update their position in the quadtree.
The quadtree has infinite levels.
Quadtree.h
http://pastebin.com/0LjAHgM7
Qtree.inl
http://pastebin.com/S6vHFCyk
I've tried to make it the fastest possible.
It only updates objects positions, and remove wrecks when a quadtree is marked for removal.
If you want to use this quadtree:
-You simply need a class which has "getBoundingRect()" method which returns a floatrect.
-you insert your objects once, and call "manage()" method every frame
know that the quadtree has probably some bugs, I did not test it to much.
there is no collision system yet, you have to implement it yourself
------------------
My goal is to make the Quadtree 99% self managed, I mean we only insert objects, and update it, then we do not care about it.
When I delete an object, I have also to remove it from the quadtree.
I'd like that the quadtree checks every frame if every of his objects still points to something, if not it removes it automatically.
So we won't have to remove ourselves.
I've heard that we can do this combining shared_ptr and weak_ptr but it seems complex...
your advices are welcome
UPDATE:
-no more template
-It now handles collisions and sends you a collision set
Quadtree.h :
http://pastebin.com/R07dXQJKQuadtree.cpp :
http://pastebin.com/hPBCLReDBoundable.h :
http://pastebin.com/1W2fbPP7And I've made a little demo for testing, you can download it here:
https://www.dropbox.com/s/gtlhyv5xedhywhm/Quadtree.rarMouse wheel -> changes the limit of objects in quadtrees
Left mouse button -> Adds one object
E key -> Adds 100 objects
R -> Activates / Deactivates random size objects
X -> Clear the quadtree
C -> Activates / Deactivates collision
the performance is not perfect but it's OK