NintenJoe/zol — pull request #28 by jhalstead85 (2014-04-09 21:00:15+00:00)
Title: Fixed #27 (Collision glitches w/ moving objects)

When I constructed the dictionary, the objects were hashed to cells
according to their position at that instant. However, the objects are all
moving (i.e. changing cells) every few frames. So while the broad
phase action of getting the nearby object for Object 1 took into account
Object 1's new positon, it often used the stale data (i.e. the original
locations of all objects) in the dictionary to compare against. Thus, a
moving Object 1 would collide with a moving Object 2 iff Object 2 was in
its original cell.

The solution, which I missed in the original paper [0] I read, is to
update the dictionary every frame. I've implemented this through an
update function in the spatial dictionary, which completely rebuilds
the dictionary when called, and I added basic testing to detect
regressions. I update the spatial dictionary in the GameWorld's update
function before getting the collisions for that frame.

In the future, the implementation could be optimized by only updating the
dynamic objects (i.e not the walls/etc) aor only updating the objects
that have moved each frame.

[0] http://www.cs.ucf.edu/~jmesit/publications/scsc%202005.pdf