Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Idea for saving on Pathfinding CPU usage  (Read 1579 times)

spokehedz

  • Bay Watcher
  • Boy Genius
    • View Profile
Idea for saving on Pathfinding CPU usage
« on: February 07, 2010, 06:54:40 pm »

Most of the time, the path from point A to B is pretty static. Sure, there are some incidentals like when a item is misplaced or if the bridge raises... But 99% of the time, it is just A-to-B in the shortest path possible.

Last I remember, DF recalculates the path with every step, does it not? If it does, why don't we just recalculate whenever an object gets in our way?

Also, if the dorfs would learn the rule of "walk on the right side" of a hallway then a lot of the congestion that we have now in hallways would be eliminated. It just seems logical--even though this game is not strictly about logic, it still tries to apply it as much as it can.

And lastly, if we could have pre-calculated routes that are highly traveled (such as where the booze is held) then it would also help a bunch.
Logged
Quote from: LordBaxter
Once a stair fell, and rather than knock him one or two z levels down, as usually was the case, he went rolling down the central staircase, hit the bottom and exploded.

Safe-Keeper

  • Bay Watcher
  • "Situation normal; all ****ed up"
    • View Profile
    • FS Mod tester
Re: Idea for saving on Pathfinding CPU usage
« Reply #1 on: February 07, 2010, 07:01:07 pm »

Quote
And lastly, if we could have pre-calculated routes that are highly traveled (such as where the booze is held) then it would also help a bunch.
Does the use of traffic zones or whatever they're called help matters, CPU wise?
Logged
"Sieging humans brought some war polar bears, and one of them started a camp fire. Highly trained!" --Today One accidentally introduces the panserbjørn into Dwarf Fortress lore

Aquillion

  • Bay Watcher
    • View Profile
Re: Idea for saving on Pathfinding CPU usage
« Reply #2 on: February 07, 2010, 08:43:45 pm »

Last I remember, DF recalculates the path with every step, does it not? If it does, why don't we just recalculate whenever an object gets in our way?
Pretty sure it calculates in advance and recalculates if you hit something, actually.  I've seen dwarves walk up to a recently-forbidden door, stop, then recalculate their path, say.
Logged
We don't want another cheap fantasy universe, we want a cheap fantasy universe generator. --Toady One

garfield751

  • Bay Watcher
  • Aaauuugggghhhh!
    • View Profile
Re: Idea for saving on Pathfinding CPU usage
« Reply #3 on: February 07, 2010, 09:29:40 pm »

I have something to add to this. why not have the game calculate paths while the game is paused? like if you suddenly unforbid or mark a giant pile of stone for dumping, the game should calculate paths for idle dwarves. to prevent the massive lag that this could make, there would be a cap of how many dwarves the game would calculate paths for at one time, while paused.

Grendus

  • Bay Watcher
    • View Profile
Re: Idea for saving on Pathfinding CPU usage
« Reply #4 on: February 07, 2010, 09:59:05 pm »

I have something to add to this. why not have the game calculate paths while the game is paused? like if you suddenly unforbid or mark a giant pile of stone for dumping, the game should calculate paths for idle dwarves. to prevent the massive lag that this could make, there would be a cap of how many dwarves the game would calculate paths for at one time, while paused.

Except the tasks haven't been assigned yet. Unless the game wants to make predictions about which dwarf will be assigned which task, which is risky because most reasons for pausing are caused by things that add new, possibly higher priority tasks, it doesn't know which paths to calculate, and calculating paths for every dwarf for every task, even with limits, would be a waste of cpu resources.
Logged
A quick guide to surviving your first few days in CataclysmDDA:
http://www.bay12forums.com/smf/index.php?topic=121194.msg4796325;topicseen#msg4796325

garfield751

  • Bay Watcher
  • Aaauuugggghhhh!
    • View Profile
Re: Idea for saving on Pathfinding CPU usage
« Reply #5 on: February 07, 2010, 10:07:44 pm »

Well you have alot more computer rescorces when the game is paused then unpaused so i think this will balance it out some what, also i was thinking that whatever the game assigns to said dwarf, gets done before moveing onto more inportant tasks.

Rotten

  • Bay Watcher
    • View Profile
Re: Idea for saving on Pathfinding CPU usage
« Reply #6 on: February 08, 2010, 12:22:06 am »

I have something to add to this. why not have the game calculate paths while the game is paused? like if you suddenly unforbid or mark a giant pile of stone for dumping, the game should calculate paths for idle dwarves. to prevent the massive lag that this could make, there would be a cap of how many dwarves the game would calculate paths for at one time, while paused.

Except the tasks haven't been assigned yet. Unless the game wants to make predictions about which dwarf will be assigned which task, which is risky because most reasons for pausing are caused by things that add new, possibly higher priority tasks, it doesn't know which paths to calculate, and calculating paths for every dwarf for every task, even with limits, would be a waste of cpu resources.
Also the game would jump around a lot then, for example you're running a fort with 300 dwarves at 5 FPS or so, then you pause and grab a drink or similar. Every path gets calculated and you unpause half an hour later to 60 or 70 FPS for a second or two before dropping like a stone again. Would annoy people (i.e., me) a lot.
Logged
True, but at a certain velocity the resulting explosion expels invader-bits at fatal speeds. You don't want to be dropping trogdolyte-shaped shrapnel bombs into your boneworks.
Only in Dwarf Fortress...

QuakeIV

  • Bay Watcher
  • Cant resist... must edit post.
    • View Profile
Re: Idea for saving on Pathfinding CPU usage
« Reply #7 on: February 08, 2010, 12:50:17 pm »

When i thought about pathing optimizations, i thought, if the dwarf need to get from point A to point B. Lets frist draw a perfectly straight line between them for the dwarf to try to use to path there. If it bumps into something, it modifys the path, realtime, ultimately turning right or left around the object, then continuing on their way until they bump into something else. They could experiment with this, figuring out where everything is for a while, the hallways and such, then store a rough path of how to get to various places. They could call up the memory of this path, start taking it when they need to get from A to B, then simply dogde around obstacles, and continue on their merry way.

There are some obvious problems with this, but i was just throwing it out.
Logged
GENERATION 9: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
I wish my grass was emo, then it would cut itself.
Quote from: Jesus
Quote from: The Big Fat Carp
Jesus, you broke the site!
Sorry, Bro.
link to quote

lucusLoC

  • Bay Watcher
    • View Profile
Re: Idea for saving on Pathfinding CPU usage
« Reply #8 on: February 11, 2010, 02:57:10 am »

Logged
Quantum dumps are proof of "memory" being a perfectly normal dimension in DF. ~Gazz

Draco18s

  • Bay Watcher
    • View Profile
Re: Idea for saving on Pathfinding CPU usage
« Reply #9 on: February 11, 2010, 03:13:23 pm »

ultimately turning right or left around the object

Which way do you turn?  How do you deal with "bumping into the floor"?

Strait line silly pathing is not good in this instance.
Logged