The codes become quite unclean. Here's the most horrible thing in it at the moment:
void OnNodeWantsToChangePosition(INode n, float x, float y)
{
this.RemoveNode((T)n);
n.UnsafeSetPosition(x, y);
this.AddNode((T)n);
}
Not very elegant casts that really shouldn't be required. Moving through a quadtree isn't very efficent, which is cool because they're generally for static stuff (my items). So when to move something in a quad I take it out of the tree, changes it position then replace it in the tree.
Still quite busy - I'll be going to Tokyo on the 31st for five days before returning to Old Bilayati. Upon arriving I guess I'll be quite busy again for a while. And soon I'll start University doing a masters in game programming - I'm considering doing a write up of all lectures here, so that's something to look forward to.
2 comments:
Hey man, I read your blog every now and then and you're going about this the wrong way.
The entities need to contain a reference to the quadtree node they're in. Then when they move, you check if the node still contains them, then and only then should you replace them in the tree - or cheat a little like I do and just move them up one and let the next update reposition them further if it needs to.
That way, you don't have all these tree-searches every frame, for every single moving entity.
Cheers, I've stopped messing with this now and am using a different approach but I do know when I was using it I wasn't really sure if I was doing the best thing!
Cheers.
(I may come back to it at one point, if so than I'll definitely take your advice.)
Post a Comment