Hey guys,
Been a long time since I've posted here, as life had gotten in the way. But I decided to throw some things aside and resume creating a game I was working on a while ago. I know this question has been asked many time, but I can't quite seem to find an answer that fits my question.
So I been wondering how to break up my game field, I'm currently using a grid which works quite well. But it doesn't help so much in intense areas of combat. I have my grid setup in a way that each section is 500x500 pixels large and 200x200 sections. So this means I end up with a map that is 100,000x100,000 pixels big. And it oddly works pretty well. But once an area of 500x500 ends up with a lot of objects in it, due to how combat is designed, it can get a little sluggish. Which is making me wonder if I should use a quadtree instead, but here is the problem:
Majority of the actors/units/structures/projectiles are say 5x5 to 50x50 pixels big. But then I have larger moving items that go up to 1000x1000~ pixels big. So in my Grid based collision for the the larger objects, I calculate the top left, right, bottom left, right, center and the top, bottom, left and right middle. So I can fit them into multiple grid sections so they don't skip out on collision. Now that works fine, except when I have say 500 objects in a single grid, (I sort the items so I do less collision, etc target vs player bullets only) it'll start to drag the framerate down. So this is what made me think a quad tree may be a better implementation as I'll be able to have much smaller sectors to do collision in.
Now the problem with a quadtree which I see is, how do I place the much larger objects into these smaller sections/leafs of a quad tree, so they don't get skipped out?
And the other issue is with my grid, is: a lot of the time majority of the grids end up being empty, due to the combat taking place in only 16~ grid sections at once. So it leaves me with a lot of empty grid sections, or a fair few (100~ish) with only 2 - 10 objects etc. Also there are no stationary objects, the whole world is always moving. (What I have currently does work and does what I want, I just want it even faster so I can add more items to the world while lowering collision).
So I would greatly appreciate anyone's thought on what sort of structure I could use instead, or point me to an example that does what I want, in a fairly optimized way.
Cheers,
Scott :)