As it turns out, the major issue with chunk generation producing wrong chunks was an off-by-one error, and it only happened in one chunk generation direction, which is why it appeared to intermittent. The fix was simple, just mirror what I’d done for the other direction.
With that out of the way, on to updating the various draw functions to only draw what’s inside the viewport. The first task was a fix for guessing at a viewport before it has already been created, because that’s how my code works with cocos2d.
Only drawing in the active viewport turned out to be relatively easy, save for a silly mistake in copying and pasting code that left me wondering why it wasn’t working properly. Normally this is the sort of thing I’d have amended the commit to be the fixed version, but that seemed like it wasn’t in the spirit of what I’m doing.
Above is an image demonstrating this pruning in action. There are more buildings, more terrain hexes, more network connections and more safe area outlines off the bottom of the image that aren’t being shown. This uses the code I wrote yesterday to determine a superset of hexes covering the viewport, draws the hexes from that layer that are in the set, and prunes the rest. This means that the game can scroll more than a few chunks without slowly to a crawl.
Other than some alignment issues on certain chunk boundaries creating a visible seam, which is certainly yet another rounding error, I think most everything I need to get done on the base display side is done. Now to start implementing things that require the basics be working.
I decided to implement fog-of-war next. It sort of works, but slows the game down to a crawl when it’s actually being drawn. I don’t know if I’m doing something wrong, or if I’ve hit a maximum number of layers that cocos2d performs well with, so I disabled it for now. Not being able to build buildings and networks in areas that aren’t visible has not been implemented yet.
From a design standpoint, I’d like the fog of war to be partially transparent, so that things underneath can be seen, but setting opacity for the fog sprites didn’t seem to do anything.