Today

Small bugfixes today, mostly.  Biggest one was finally fixing a bug which was resulting in monsters, devs, and characters seemingly randomly not being drawn, depending on which direction the camera was facing.

Turns out that I’d inserted them into the octree incorrectly, and it was treating all of them as though they were sitting at the center of the world.  If you happened to be looking roughly in that direction, then the game would draw them, regardless of where in the world they actually were.  If you were looking away from the middle of the world, it wouldn’t draw them no matter where they actually were.  This was often leading to situations where these objects would seemingly randomly pop in and out of existence, as you slowly turned the camera.

(quick tech explanation:  An “octree” is a method of dividing up space, commonly used in some types of 3D video games.  The basic idea is to think of your 3D world as a big cube, with stuff inside it.  Now, mentally divide up your cube into eight smaller cubes; one in each corner of that larger cube, and all touching at the very middle.  Now mentally divide up each of those cubes into eight more cubes.  Repeat until you’re dizzy.

When you move an object around in the world, you check those cubes to find the smallest one which completely surrounds the object, and store the object inside that cube.  The benefit of doing this is that if you have (for example) 10,000 objects moving around in your world, each stored inside the smallest cube which surrounds it, you don’t actually need to draw all 10,000 objects (very expensive for the graphics card!), and you don’t have to check whether  each of the 10,000 objects can be seen by the camera and thus needs to be drawn (very expensive for the CPU!);  instead, you can just check whether the camera could see the individual cubes.  If a cube is within the camera’s field of view, then you draw all of the objects inside it.  If a cube is outside the camera’s field of view, then you know that all the objects (and other cubes!) inside that cube are also outside the camera’s field of view, and so don’t need to be drawn.

2D games will sometimes use a “quadtree” approach, which is very much like this, except using squares which are each made up of four smaller squares, instead of cubes which are each made up of eight smaller cubes.)