Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Give us some Options to cut framerate loss  (Read 1546 times)

CaptainArchmage

  • Bay Watcher
  • Profile Pic has Changed! Sorry for the Delay.
    • View Profile
Give us some Options to cut framerate loss
« on: June 13, 2013, 07:02:35 pm »

I've done a search, and this hasn't come up. To reduce the framerate loss, Dwarf Fortress should have some options that allow the player to increase framerate, but simplifying the way the game works or reducing the number of calculations made.

Framerate drop comes from pathing, item count, unit count, liquids, embark volume, and contaminants.

Simplification comes from changing the number of ticks between which the game has to run calculations. There will be an option in the raws to set this number.

Item check: Item check will be run either when a dwarf or other creature needs to use an item, or after a certain number of ticks set in the INIT files. Another INIT option will see items left unused for a long period of time get allocated to a "reserve list" which only gets checked if in-use items are unavailable, or every month, or if the items are ordered to be traded or dumped or melted.

Pathfinding: (not sure if this already happens) Pathfinding is run for a unit when it wants to go somewhere (i.e. for a job or to idle out), when it hits an obstacle, or when the pathfinding counter runs down. The number of ticks to elapse before pathfinding is run again is set in the raws.

Liquid pathfinding: Recheck fluid movement when there is a new disturbance in the fluid, or when the required number of ticks elapses.

Yes, this will create some strange behaviour if your counters are set particularly high. Dwarves, for example, may choose a less efficient path or crawl over one another. Fluids may behave strangely. However, this will not usually kill a fortress. Players have been OK with more serious suboptimal A.I. decisions in the past. Framerate, however, always kills fortresses.

In order to save on RAM use, another INIT option will have the data of items not in regular use dumped to the drive, and then recovered when needed. Because the data will not be needed frequently, the slow access time will not be relevant.

I think players will be OK with, say, a large number of calculations regarding reserve items being done once a month.

Applying these options may allow us to run 100-year or 1000 year fortresses much more easily.


I'd also like to bring this to the attention of those involved in DFhack. It may be possible to create an unofficial implementation of this, I know some people have already implemented their own algorithms, for example with the "digging invaders" hack.

That has been a suggestion for a long time and there's no sign of it being implemented yet, so someone eventually made a DFhack version to fill it in. There's also a lot of bug-fixing patches from DFhack now. It will be a worthwhile effort.
« Last Edit: June 13, 2013, 07:21:22 pm by CaptainArchmage »
Logged
Given current events, I've altered my profile pic and I'm sorry it took so long to fix. If you find the old one on any of my accounts elsewhere on the internet, let me know by message (along with the specific site) and I'll fix. Can't link the revised avatar for some reason.

Tacyn

  • Bay Watcher
    • View Profile
Re: Give us some Options to cut framerate loss
« Reply #1 on: June 14, 2013, 05:22:37 am »


Pathfinding: (not sure if this already happens) Pathfinding is run for a unit when it wants to go somewhere (i.e. for a job or to idle out), when it hits an obstacle, or when the pathfinding counter runs down. The number of ticks to elapse before pathfinding is run again is set in the raws.


Another way to reduce pathfinding could be  to abstract walking.
Instead of a dwarf walking step by step to his destination, he would "teleport" there.
However this would still take the same amount of time as walking would plus a little extra to compensate collisions.
The dwarf simply vanishes when he has found a path and reappears at the destination after the necessary time.
For the implementation the game only has to save for each abstracted dwarf origination, destination, and departure time.
If the game is pause during that time, the path is recomputed and he reappears at an appropriate point between destination and start point.

Of course you don't want an empty fortress with dwarf blinking in and out.
Therefore, this only happens if the framerate begins to drop, which is usually when the fortress has over 100 occupants already.
Hence a few less visible dwarfs won't be noticed much.
Preferably abstraction is applied to low priority activities first.
For example pets and idle dwarfs first, then dwarfs going to eat, drink, sleep and on break
 and lastly hauling jobs. 


Also don't forget temperature calculations also cut into framerate.
Currently the only option is to turn it off completely, when unfortunately magma  no longer burns stuff.
I would like an option to have magma and fire still destroy and burn non-safe material on contact, but with the costly calculations turned off.


 


« Last Edit: June 14, 2013, 05:27:10 am by Tacyn »
Logged

Di

  • Bay Watcher
    • View Profile
Re: Give us some Options to cut framerate loss
« Reply #2 on: June 14, 2013, 10:05:03 am »

Pathfinding: (not sure if this already happens) Pathfinding is run for a unit when it wants to go somewhere (i.e. for a job or to idle out), when it hits an obstacle
Well, how else do you think it can work? It only recalculates path when creature gets interrupted or bridge is raised\lowered somewhere in the fort. Hence cats and goblins bump into doors with their heads before realizing it's closed.
And liquid doesn't pathfind it is calculated via different mechanism.

The dwarf simply vanishes when he has found a path and reappears at the destination after the necessary time.
So how's that is going to ease pathfinding if  dwarf still needs to find a way.
Logged
Quote from: Creamcorn
Dwarf Fortress: Where you meet the limit of your imagination, moral compass, sanity and CPU processor.
http://www.bay12forums.com/smf/index.php?topic=103080.0 Fix sober vampires!
http://www.bay12forums.com/smf/index.php?topic=91442.0 Dwarven Cognitive Science

CaptainArchmage

  • Bay Watcher
  • Profile Pic has Changed! Sorry for the Delay.
    • View Profile
Re: Give us some Options to cut framerate loss
« Reply #3 on: June 14, 2013, 01:04:37 pm »

Pathfinding: (not sure if this already happens) Pathfinding is run for a unit when it wants to go somewhere (i.e. for a job or to idle out), when it hits an obstacle
Well, how else do you think it can work? It only recalculates path when creature gets interrupted or bridge is raised\lowered somewhere in the fort. Hence cats and goblins bump into doors with their heads before realizing it's closed.
And liquid doesn't pathfind it is calculated via different mechanism.

The dwarf simply vanishes when he has found a path and reappears at the destination after the necessary time.
So how's that is going to ease pathfinding if  dwarf still needs to find a way.

I haven't actually checked how often the dwarves need to pathfind. I noticed them walking into locked doors, but I have also noticed some conscious collision avoidance to avoid ending up on the same tile as another creature. However, if creatures only needed to pathfind in those scenarios, why does it suck the framerate? Does it actually have a significant effect on framerate?

The item trouble is still a serious issue though, and I think it can be sorted out. During the dragon succession game, some bugged-out reactions produced about 2,500 items or so, and that significantly reduced the framerate. If items are only checked over every n ticks, or at the end of every week or month, then the framerate loss from this would be much lower.
Logged
Given current events, I've altered my profile pic and I'm sorry it took so long to fix. If you find the old one on any of my accounts elsewhere on the internet, let me know by message (along with the specific site) and I'll fix. Can't link the revised avatar for some reason.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Give us some Options to cut framerate loss
« Reply #4 on: June 14, 2013, 07:26:43 pm »

Yes, it has a very significant effect on framerate. If items were only checked every so often, that would cause issues with, well, items not really being usable between those times; if they were to be checked only when someone uses them, there would have to be a check every tick to see if someone is using them.

CaptainArchmage

  • Bay Watcher
  • Profile Pic has Changed! Sorry for the Delay.
    • View Profile
Re: Give us some Options to cut framerate loss
« Reply #5 on: June 18, 2013, 12:10:27 am »

Yes, it has a very significant effect on framerate. If items were only checked every so often, that would cause issues with, well, items not really being usable between those times; if they were to be checked only when someone uses them, there would have to be a check every tick to see if someone is using them.

Actually, if the item is carried then there's a note on the unit that should say "carrying this item" with what appendage.

Otherwise, the only reason to check whether someone is using the item is when some creature is getting a job or refreshing the graphical display or something like that. I do not thing jobs happen that frequently to cause serious FPS decay.

With ageing and wear and other checks if those were done at longer intervals, there would be less decay.
Logged
Given current events, I've altered my profile pic and I'm sorry it took so long to fix. If you find the old one on any of my accounts elsewhere on the internet, let me know by message (along with the specific site) and I'll fix. Can't link the revised avatar for some reason.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Give us some Options to cut framerate loss
« Reply #6 on: June 18, 2013, 03:08:24 am »

Aging is checked monthly at fastest, I'm pretty sure...

Sizik

  • Bay Watcher
    • View Profile
Re: Give us some Options to cut framerate loss
« Reply #7 on: June 18, 2013, 03:19:43 pm »

I think implicit forbidding and automatic offloading of hidden items (except those in buildings) would be a good idea.
Logged
Skyscrapes, the Tower-Fortress, finally complete!
Skyscrapes 2, repelling the zombie horde!