The biggest resource hog for any RTS game is pathfinding. If you have many units selected and click to set their destination on a far side of the map, trying to find a path for each unit at the one time causes extreme lag while the pathfinding does it job.
I have come up with a solution to this problem by splitting up the load over multiple game loops. So basically I only find a path for a small number of the units within any given frame, thus freeing up time for other events and for the game to not lag. The only downside to this is that units wont move right away, they will all move once the pathfinding is finished for all units (usually within 5-10 frames so maybe 0.1 to 0.2 second delay at the most). I think the pros outweight the cons here.
I have a test application running as we speak testing 500 units moving around a small 16x16 grid. Each unit is assigned a random grid position as its destination and moves towards it. Once it reaches its destination, it find another one, and so on. I am getting framerate of 80-90 FPS on my quad core, which also includes drawing the 500units on screen and all other events. When I change the number of units to 300 I getting about 180-200 FPS. Not bad at all I say.
|