r/WatchPeopleCode • Streamer • Nov 22 '20

Game Coding From Scratch - Quadtree / Octree

53 Upvotes

7 comments sorted by

3

u/ignotos Streamer Nov 22 '20

VOD link: https://www.twitch.tv/videos/812206560

In this stream we coded up a quadtree - a neat little structure which lets us efficiently track all of the objects in our game's world. These are particularly useful for collision detection, and any situation where you need to quickly identify all of the objects in a particular region.

1

u/gamebuster Nov 22 '20

Always fun. I also attempted this for collision detection in a C-based game.

2

u/ignotos Streamer Nov 23 '20

Did you find this worked out for you? One thing which can be slightly fiddly is dealing with objects which overlap the region boundaries.

1

u/gamebuster Nov 23 '20

My implementation sucked and it was still great.

I think I implemented a kdtree, which is slightly different. I regenerated the tree every tick

2

u/ignotos Streamer Nov 23 '20

Aha - yeah, I've also always regenerated the tree every tick, rather than trying to move things around in it dynamically. If lots of stuff is moving, and you're doing a reasonable number of checks with it each tick, it's usually worth the cost of doing so.

1

u/realestLink Nov 23 '20

I'm currently building a really efficient Octree that uses no pointers and uses indices and a freelist to avoid heap allocations and be cache friendly

1

u/ignotos Streamer Nov 23 '20

Oh, neat! That's pretty cool, I'd never considered flattening it like that