Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: The Right Path - Increasing FPS via Traffic Designations  (Read 10249 times)

acetech09

  • Bay Watcher
  • Bay Watcher
    • View Profile
The Right Path - Increasing FPS via Traffic Designations
« on: July 31, 2012, 07:34:56 am »

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.
« Last Edit: July 31, 2012, 03:50:55 pm by acetech09 »
Logged
I challenge you to a game of 'Hide the Sausage', to the death.

Loud Whispers

  • Bay Watcher
  • They said we have to aim higher, so we dug deeper.
    • View Profile
    • I APPLAUD YOU SIRRAH
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #1 on: July 31, 2012, 07:46:43 am »

Heh, I was wondering when someone would make this thread. For those who for some reason or another cannot do this, changing the normal cost from 2 to 1 helps conserve FPS

MetalGear

  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #2 on: July 31, 2012, 07:50:21 am »

Interesting. What I usually do is complely cover the large ares in restricted traffic and make high traffic `roads` through them. Are you saying it`s more efficient to simply make a border of restricted traffic to seal off large areas? What about high traffic designations? How do you set those up?
Logged

hjd_uk

  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #3 on: July 31, 2012, 08:24:36 am »

Bonus Tip : In the case of old/unused open rooms. Build a door / doors to seal the area and forbid the door(s), or just wall it off again.
Logged

Madventurer

  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #4 on: July 31, 2012, 08:39:40 am »

Another Bonus Tip: Set your "Resistricted" Value to 100. They really wont go there then.
Logged
Then he made grudge wit about 20 other dwarfs (still don't know why - perhaps they were stealing his chair).

Hyndis

  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #5 on: July 31, 2012, 10:29:42 am »

I've found a new love of coastal maps.

Only the very corner of the map is touching land. The remainder of the embark space is entirely on water. This means I have only 1/16th of the usual surface area for pathing, and I get an easily defensible and small entrance to fortify.

Its vastly easier to fortify just a single corner of the map uses retracted drawbridges and walls in order to funnel all visitors to my barracks than it is to do the entire perimeter of a 4x4 embark.

With 100 dorfs and 400 animals I'm getting about 450fps right now.
Logged

Maxmurder

  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #6 on: July 31, 2012, 10:50:00 am »

Great thread!
... and i thought traffic designations were just for keeping dwarves off my traps. I will definitely be implementing this in my fort.

Say you have a open rectangular room with entrances at both the top right and bottom left corners. Dwarves move through this room regularly. How would one best optimize the pathfinding? would it be best to have a diagonal "road" of high traffic zone with restricted traffic in the corners?
Logged
The Sponge has become enraged!
Without a nervous system...
The only thing they can feel...
IS ANGER.

toomanysecrets

  • Bay Watcher
  • Jackpot.
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #7 on: July 31, 2012, 11:01:17 am »

I like to fill unused areas with 'low' or 'restricted' designations just to make sure the point gets across. Dfhack is good for this, "filltraffic" will flood-fill an area with a designation.  You have to enter "filltraffic R" or "filltraffic N" etc.
Logged

k9wazere

  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #8 on: July 31, 2012, 12:18:00 pm »

Restricted doesn't stop a dwarf pathing through it (I think).

But I'm guessing the A* algorithm has a target cost each pass (which gets incremented?), which prevents the restricted tile being considered if it pushes the current path over the target cost?

Or does it work some other way? Yeah I could Google it. But that's so much more effort than typing this reply :p
Logged

toomanysecrets

  • Bay Watcher
  • Jackpot.
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #9 on: July 31, 2012, 12:35:15 pm »

Restricted tiles don't stop anyone or anything from pathing over them. They just cost 25 movement points instead of the normal 2.
Logged

JJtoocool

  • Bay Watcher
  • Unfortunate Accident: ∞
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #10 on: July 31, 2012, 01:41:29 pm »

...and here I was thinking traffic designations reduced your FPS.

How ignorant I was! Thanks, Acetech.
Logged
Quote from: Goblin 3 to Goblin 1
I heard that I died.
Quote from: Goblin 1 to Goblin 3
It was inevitable.
Quote from: Goblin 3 to Goblin 1
Goodbye.
Quote from: Goblin 1 to Goblin 3
Goodbye.

VerdantSF

  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #11 on: July 31, 2012, 01:48:55 pm »

With 100 dorfs and 400 animals I'm getting about 450fps right now.

/drool

acetech09

  • Bay Watcher
  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #12 on: July 31, 2012, 01:52:53 pm »

Do you mean 45? - I don't even know how you would play at 450fps. Either way, it proves that pathfinding is a huge factor of CPU usage.

I just edited my post with madventurer's 100 cost suggestion. Given credits, of course ;)
Logged
I challenge you to a game of 'Hide the Sausage', to the death.

Hyndis

  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #13 on: July 31, 2012, 01:54:23 pm »

No, I mean 450 FPS.

I made the FPS cap 500.
Logged

Friendstrange

  • Bay Watcher
    • View Profile
Re: The Right Path - Increasing FPS via Traffic Designations
« Reply #14 on: July 31, 2012, 01:59:24 pm »

I will be bookmarking this thread. Maybe I can now finally breed and slaugther hundreds of animals a year without worrying about fps drop from dead animals.
Logged
Pages: [1] 2 3