CleverRaven/Cataclysm-DDA — pull request #4591 by phaethonfire (2013-11-23 08:27:53+00:00)
Title: Better, Faster Scent

I have big ideas for how scent could be reworked, but this PR is just a simple, clean improvement on the current system. It does the following:
- adds diffusivity as a constant that can be tuned
- adds conservation of mass. In the old system, when scent diffused, it was added to the new square without being subtracted from the old one.
- improves performance by eliminating some duplicate calls to get scent values and to see if a square is "used" when diffusing out. This is reflected in a new loop that creates intermediate values. New loops are bad, but doing it this way also let me delete a loop that just did a copy step, so the total number of loops in this code stayed the same.

Scent trails aren't as wide as before, and they disappear more slowly (which both address requests from the forums). Scent trails are still limited by the scent radius, which is only 40 squares.

I tested performance of this algorithm (in a different git branch, not in this PR) by editing game.cpp to time how long it took update_scent() to run. The edits for testing performance looked like this:

#include
...
clock_t start_time = clock();
update_scent();
clock_t finis_time = clock();
running_total += ((double) (finis_time - start_time)) / CLOCKS_PER_SEC;
if (int(turn) % 100 == 0) {
debugmsg ("updating scent consumed %f seconds thus far", running_total);
}

From testing an early game character, it seems to be ~25% faster.

Note: experimental build doesn't work on Mac right now because of some warning in the JsonSerializer class. I wasn't able to double check these changes by building locally. I did copy this exact code into a slightly older experimental build and it worked. It should be ready to go. We'll see if Jenkins likes it...