As my fort grows, FPS slows down. How can I, with only about 15 keyboard presses, raise FPS by upwards of 15 to 20 whenever it drops too low, and be able to repeat it multiple times? By utilizing a little-known tool that alters pathfinding algorithms.
Technical Details:Dwarves get from point A to B using A* pathfinding. The game draws a line between the two points and identifies what obstacles are in the way. It then makes the path wider on both sides, seeing if an offset will avoid the path. If it doesn't, it keeps trying until it does. If it gets around an object, it then draws a straight line from those two points, and does the process again. It ends up that a dwarf can evaluate hundreds, even thousands of individual paths while trying to haul a stone to the mason's shop. Those complex and bulk calculations are a major CPU sink. See how many paths have to be calculated in this example:
Count how many paths it takes to do a simple obstacle avoidance. That's where your FPS is going.Solution:Toady has implemented a tool to manipulate the evaluation of paths. Open your (d)esignations screen, and then hit O. That brings up the traffic command screen.
The A* pathfinding applies different 'costs' per tile. Normal tiles are worth two, while high traffic tiles are worth one, low traffic costs are five, and restricted are 25. When analyzing multiple paths that both reach the target, the algorithm will compare the costs to determine the best route. Even if one path is shorter than another, the one that is designated with high traffic tiles might be the chosen route.
If at any point A* tries a path whose cost is already greater than other options and doesn't reach a destination, it stops following that avenue, and doesn't attempt pathfinding through the high-cost areas unless no other options are available. That is the underlying concept behind increasing FPS.
Solution in Action:First, you should tell DF that when you want to make a restricted area, you want it to be a
restricted area. To do that, open up your d_init.txt file, (located in data/init/ in your DF directory), find the entry [PATH_COST] and change the 25 to 100.*
Large and open areas are CPU sinks for pathfinding. They force A* to generate many routes, and if it's a pointless room or dead-end corridor, there's no point even going down there. That's why you should cut them off.
Cutting off pointless areas with restricted traffic designations increases FPS. Take this area that was going to be a stockpile, but never got used. By cutting off the entrance, I was able to save about 5 FPS:
Filling the room also works, but I've found no difference between simply walling to filling, so I don't bother filling irregular rooms.Think of the most wide and open unused area on your map. Chances are you thought of the surface. Bonus dwarf points if you thought of the Circus, but dwarf points matter as much as Canada does, so... ... Anyway... The surface is actually a huge pathfinding sink, since there's, for the most part, very little that goes on in most of it when you're not woodcutting. So cutting off areas of the surface, or surrounding your fort's surface areas with a ring of restriction, can boost your FPS tremendously:
After designating your low traffic areas, you should notice a large FPS boost. Same goes for high traffic areas. Put high traffic areas in commonly used parts of your fortress, and your dwarves will discard other paths more, thus saving FPS.
I encourage you to play around with traffic designations. They're real handy.
Results may vary. Depending on your fort design, you might have no effects at all.Hoping this has been enlightening,
- Ace
*Credits to Madventurer for sugesting that. 'Twas a good idea.