|
|
So, playing with particles recently, I noticed a small* problem.
"Fixing" your timestep, such that it is always processed in increments of some
arbitrary value, greatly increases the quality of your simulation. When dt
seconds have passed, and your timestep is the arbitrary value ts, then
while (dt > ts)
step(ts)
dt -= ts
The fun part comes up when the time required to do a simulation step is greater
than the time stepped (ts). This situation results in a negative feedback
loop; the greater dt is, the more steps you must take, meaning dt for the next
frame will be even greater, meaning even more steps must be taken, meaning...
What this means, in practice, is that as the number of particles increase you
will see an expected decrease in framerate until you cross the line where you
enter this loop. After that, each frame takes longer than the previous. In
the simulation I've been playing with recently, this means that my framerate
will drop quite smoothly from 75 to 20, and then suddenly plummet down to 5,
then 2, then...
Naturally, this threw me for a loop until I figured it out :)
Fortunately, there's a simple solution for this. While "fixing" your timestep
provides a valuable increase in the quality of your simulation, the solution is
to simply make a step using whatever dt you have. That is,
if (dt > ts*5)
step(dt)
else
while (dt > ts)
step(ts)
dt -= ts
The 5 above was chosen at random, and can be modified to suit individual
simulations.
Anyway, since I find negative feedback loops in performance situations to be
interesting problems to solve, I thought others here might also be interested
in hearing about this.
*For some random definition of "small".
Post a reply to this message
|
|