almar wrote: Basically, if the entity has to be drawn (culling is in place), everything has to be calculated (except pathfinding, which is only calculated when the path has to be reevaluated -which depends on the movement of the other entities...-). When they are not visible they don't "move" to their destination, they just calculate the point and "jump". Also, they don't think too much. And if they are rendered they are shaded. The point is, it's very common to see a few thousand of them at the same time on screen.
The AI of your ships is supposed to simulate alive pilots, right? Most humans have a reaction time of 0.5 seconds or so. If you are calculating the visible ship AI routines every frame, your pilots have a ~0.01s reaction time. That not only is cpu-intensive, that's also a bit unrealistic
![Smile :)](./images/smilies/ms-smile.png)
.
The decision-making & map navigation, for example, are perfect candidates for re-calculating every 0.5 seconds or so.
A quick implementation would be: have an internal property called "timeSinceLastAI" internal value per ship. On each update, increment it with dt. If timeSinceLastAI >= threshold, perform full AI and reset timeSinceLastAI to 0. Otherwise, do what was decided recently (continue in the same course, acceleration, firing to the same place, etc).
This has some impact (your AI has to plan the moves for the next half-a-second instead of just the current frame, so you may have to store that information so it is available during the "no AI" time) but your cpu consumption should be smaller, especially if you AI is expensive. Of course, you have to make sure that all ships don't calculate their AI exactly on the same frame, so the AI calculation is "distributed" (maybe adding a tiny random bit to "threshold" when creating a new ship).
In addition to CPU and realism, this gives you more possibilities in the gameplay; it gives you a rough "pilot difficulty": good pilots may have 0.5 in their threshold while bad ones, or ships on the verge of collapse, will have 1.0, for example. You can have a "mental distorsion weapon" that temporarily increases the AI threshold in the target ship. And you might have resistances to mental rays depending on the race, or mental shields in ships.