…what a trainwreck of a thread, holy shit.
First thing, your quadtree is basically getting ass-raped with a cactus right now with how you place your monsters, this structure is not ideal at all for an ever growing straight line of enemies. Try placing them randomly in a fixed size square region, that’ll suit your quadtree way better and is a more realistic representation of how they’ll be placed later in the real game anyway.
I mean this part:
new Vector2(0, 5 * count)
Try this instead:
new Vector2(random(min_X,max_X), random(min_Y,max_Y))
Second thing, where the hell is your main game loop, you didn’t post it here right? How is anybody going to be able to help you without that crucial piece of information?
The most interesting parts are how you check your units for processing and how you handle the quadtree, please post the whole thing.
Third thing, do you really think it is a good idea to make the quad-tree only as big as your screen, why do you even need the quadtree then?
new QuadTreeNode(0, new Rectangle(0, 0, Main.V_SCREEN_WIDTH / game.UNIT_SCALE, Main.V_SCREEN_HEIGHT / game.UNIT_SCALE));
Make it as big as your game world instead!
Fourth thing, implement some static global counter that counts how often certain methods (monster.idle()/update()/render() and whatever) are called per frame, so that you know what gets invoked how often. Do this for the monsters methods and everything else that gets called repeatedly.
Or use the profiler: [quote]Again, you need to profile to see what’s taking up the most time.
[/quote]
Listen to him, he’s right! You didn’t profile method calls/execution times yet. Instead you’ve just shown us instance counts.
My spidey-sense tells me you’re simply processing too many entities way too often, 200K is a lot.
entitiesToCheck = new Array<Creature>(true, QuadTreeNode.MAX_ENTITIES);
Does this line mean you “check” (whatever that means, we don’t know, post your code…) every entity? This is the perfect recipe for long execution times.
Just doing a simple check per entity is enough to bring down frame-times with your entity-count.