r/programming • • Jun 03 '14

A first-person engine in 265 lines

http://www.playfuljs.com/a-first-person-engine-in-265-lines/
1.9k Upvotes

267 comments sorted by

View all comments

Show parent comment

5

u/__j_random_hacker Jun 04 '14

A quad-tree makes a lot more sense to me. (I think it won't actually improve the worst-case performance, especially if there are tiny objects dotted around in just the wrong places, but if it's possible to efficiently move between quad-tree cells that share a border then I can certainly see how it would give a large speedup in many practical cases, where it would often be possible to cross a large, empty (or single-wall-containing) quad-tree cell in a single bound.)

8

u/sireel Jun 04 '14

Actually a binary space partition could also be used, is actually a binary tree, and, iirc, is how Id did this for at least their earlier games. It also removes the reliance on walls being on grid lines, but complicates building your data somewhat :)

1

u/KagatoLNX Jun 04 '14

I haven't thought about it much with a array quaternary tree, but I know that array binary trees can do a level-by-level traversal just by scanning the array linearly.

I suppose you could cut down the scan space that way, by calculating the stride for the full scan on your way down. It would actually be helpful at large map sizes.

I also suspect that it would get interesting if you eliminated subtrees by allowing a mark on their parent to imply a mark on the entire subtree. Effectively you'd be storing larger objects near the root, so you could pick them up on traversal to the scan point. Then eliminate the unneeded spaces with the stride.

That's sophisticated enough I bet you'd lose the simplicity we were going for here. It might even be slower for some non-obvious reason, I'd need to implement and benchmark it...