ID:154209
 
I've got some of the basics down for ants but am noticing that calling 100 ants from your colony and having them swarm arround you isn't the most CPU friendly thing in the world. I don't want to sacrifice numbers overall because having one super ant just doesn't work as well as 10 weaker ants.

Anyway, any ideas on how to deal with this problem? I was thinking of having summoned ants organize into units that move together as they follow you then when you release them they split up again. This would temporarily decrease numbers but not in the big picture.
Anyway, any ideas on how to deal with this problem? I was thinking of having summoned ants organize into units that move together as they follow you then when you release them they split up again. This would temporarily decrease numbers but not in the big picture.

I think the biggest solution is to make your ants slower and dumber.

That's the advantage of an insect-AI. ;-)
In response to Spuzzum
150 slow dumb ants aren't really CPU friendly either :p

Although slowing them down couldn't hurt :p

Right now my AI is fairly large but I think it is divided well enough that no particular ant is thinking too much. I have it divided into tasks and modes. Tasks are fight, gather, follow, and nurse. Then each task is divided into different modes like search, return, exit, and so on.
In response to English
Well, I would suggest that in your AI update routine, you have a check to see if world.cpu is at a certain amount and, if so, not do their behavior. Additionally, make sure any AI calls are staggered so you are not overloading the processor with simultaneous calls.

Minor things, but I don't really know how to improve the performance of that many distinct callers... Maybe group ants into a hierarchy of "brain groups" where on overbrain datum does the processing and just updates the individual ants?

-James
In response to English
Jmurph has good ideas, particularly in staggering calls to the AI. I have one more:

If an ant commits to a certain task, bypass all other AI for a short time (a few ticks) while they advance the task, then return to it. Have a short-version proc for things like meandering to a destination, for example, that will only fall back on the AI after a timeout period or if an obstacle is discovered.

Think of it this way: An ant decides to follow a scent trail to possible food, which is 200 tiles away (though she doesn't know that). Examining the scent trail, and her current direction, she determines that the food is roughly northeast (though maybe it's north by northeast), and heads off in a generally northeast direction (maybe 45 degrees off either way on any given step) for about 6 tiles. Then she samples the scent again. The exception is if she hits a rock or another obstacle blocking her path. (You could also add in a "frustration factor" where an ant trying to traverse a particularly difficult obstacle where the 6-step rule would fail could gradually reduce its steps to 1 until it got out of the conundrum. Each step would take a little time anyway, so reducing an ant to checking its path every 6 steps would drastically reduce load time for any kind of "go from A to B" task.

Lummox JR
In response to Lummox JR
I think that idea deserves merit because it sounds a little like real life also.