Sunday, July 2, 2017

ai - How does Dwarf Fortress keep track of so many entities without losing performance?


In Dwarf Fortress you can have hundreds of Dwarves, animals, goblins, etc in game at any one time, each with their own complex AI and pathfinding routines. My question is how does this not produce noticeable slowdown? Does each Dwarf run in its own thread?



Answer



Any system which had a thread for each of so many characters would run out of resources very quickly. Threads may give you access to extra processor cores but they don't make anything intrinsically more efficient, and they come with overhead.


The simple answer is just to be efficient about processing each entity in the game.



  • Don't process every entity each frame.

  • Split processing into stuff that needs doing often and stuff that does not need doing often.

  • Spread long-running algorithms across multiple frames so that they don't block processing in other systems.

  • Ensure that efficient algorithms and data structures are used.


  • Cache the results of expensive calculations if they are likely to be used again.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...