Update caches less often by introducing dirty flags.

Note: This still needs some testing, since it's possible I've missed some place where the dirty flags need to be set.

Basically, before all the caches were being updated regardless of whether anything changed. This commit introduces some very, very careful and global checks that track whether anything changed whatsoever. Hint: A lot of the time, it didn't. The performance improvement in the common case of strolling about in broad daylight is quite significant.

Without patch:
![without-optimization](https://cloud.githubusercontent.com/assets/902211/2622770/73023770-bcc8-11e3-8f30-6a6d4856893e.png)

With patch:
![optimization](https://cloud.githubusercontent.com/assets/902211/2622769/6b43cae4-bcc8-11e3-81d8-fd9727664b08.png)

Notice how in the first case, the individual update cache functions are called every single time build_map_cache() is called. This adds up! With the patch, however, the dirty flag is set only very rarely, and so a lot of calls are saved, leading to a ~80% performance improvement for this particular function.