Dammit, I spent too much time writing code again. On the other hand, we now have spatial hashing working, and reasonably fast.