CleverRaven/Cataclysm-DDA — pull request #10211 by wormingdead (2014-11-26 10:31:05+00:00)
Title: [WIP] [CR] Scent matrix shrink: reduce from SEEX * MAPSIZE to scent diameter

This PR reduces all local matrices in `update_scent()` to the minimum required size. If you remember me from my previous attempted change to `update_scent()`, this one is better and worse.

The good news: This change is much more obviously good for performance and caching. The only change is a reduction in memory used by the local variables; there are a few new const variables, but they are all ints and just for conversion between the global (grscent) coordinates and the local matrix coordinates (now that they are different sizes).

Unfortunately, there is two things that worry me. First, as previously mentioned, there are now two sets of coordinates, which makes the code that much harder to read. It's just one more thing making scent hard to work with. It doesn't help that I couldn't figure out how to split the change into multiple commits.

Second is that the code does not seem to play well with Hardened Gentoo's stack smashing detection. The default release build uses `-Os`, which causes this change to crash the game with a `**stack smashing detected**` after a single turn in-game. I then tried changing `-Os` to `-O2` and the error did not occur. I knew to do this because it is apparently a known [issue (Gentoo wiki)](http://wiki.gentoo.org/wiki/Hardened/FAQ#Why_don.27t_my_programs_work_when_I_use_CFLAGS.3D.22-O3.22_and_hardened_gcc.3F). I guess another solution would be to use `-fno-stack-protector`, but I don't know if changing the build flags is acceptable or even viable. And the fact that this hasn't been a problem previously makes me suspicious of my code even though I've triple-checked it.

Please let me know what you think, thanks.