Bay 12 Games Forum

Dwarf Fortress => DF Suggestions => Topic started by: Explorer on February 05, 2007, 10:50:00 pm

Title: optimization suggestion
Post by: Explorer on February 05, 2007, 10:50:00 pm
I've noticed that weather and temperature do indeed eat away at precious CPU cycles. With all of the features planned, optimization will become necessary at some point.

I'm not sure how some of the various simulations are implemented, but if they're not already like this, here's a suggestion:
For evaluations such as temperature, reimplement the basic algorithm with a dt variable (amount of time for which to calculate), and instead of updating every frame, update every X number of frames, with a dt that represents the amount of time in between updates of the algorithm. It probably wouldn't be too difficult to do, and would save running the algorithm every frame at the expense of a little precision.

Basically if t is the time between frames, and you wish to calculate every n frames, your dt should simply be n*t.

So for a **very very** simplified example, in case my explanation sucked.
Say I have a cloud moving at a velocity v every cycle, and x is its position variable.
I would run this every frame:
x += v;

But... let's only update every n frames at the loss of a little precision. (n could be set in some config file). Time amount of time each frame takes up in this instance is simply 1 unit. so our dt = 1 * n = n

then our new algorithm is just:
x += v * dt
and only run it every n frames, therefore making things faster while keeping more or less the same results.

If temperature and weather are already calculated like this, just ignore this  :)

Title: Re: optimization suggestion
Post by: OldMiner on February 06, 2007, 04:58:00 pm
I think Toady's a doctor in Math, so this might be something already taken care of.  Don't let his humble demeanor fool you.

Anyhow, I believe temperature it more insiduous of a problem than weather, and it can't be skimped because important things like "fire from your clothes raises your temperature and burns you" is something that is prone to change dramatically in short periods of time, and people would be irritated both if their enemies burned too slowly and if they didn't cool down rapidly enough when they dove in a river to save their legendary speardwarf.

Title: Re: optimization suggestion
Post by: Explorer on February 06, 2007, 07:55:00 pm
The rates wouldn't actually be slower, the precision would be. And anyway... frames per update (and dt) could easily be changed in certain situations where higher precision is required... such as the player being on fire.

I know that Toady is a professor in math   :) I only have a Bachelor's in Physics with a math minor, but I specialize in computational physics. Just sharing my knowledge for the better of the project ^^

[ February 06, 2007: Message edited by: Explorer ]