100 Experience Points
An Adventure in Indie Game Development

Day 75: 3 May 2013

For the first day in a very long time, I felt like I made significant progress. And along multiple fronts too. As I write these words, a new update is being deployed to the server. Again, for those of you who are just joining us, the URL for the “daily” downloads is http://100ExperiencePoints.com/daily/100XP-Setup.exe.

Here’s what I accomplished. First, I got the new hulls up and running. You now basically have three sizes to work with. I think before it’s all said and done, the larger cruiser hull will be adjusted to be a little tougher (and slower) and the smaller frigate hull will be adjusted to be a little lighter. I hope to someday get to a round of rebalancing between the various ship parts, and if you’ve got any insight into what’s working for you or not, I’d love to hear.

Next, thanks to an emailer, I discovered a pretty significant bug. I suspect other people have ran into it as well, and not reported it. Basically, it’s a bug that corrupts your fleet/ship save files, which then crashes the game. There’s a way to uncorrupt them, and I intend on posting directions for how to do this (tomorrow?), but the bottom line is, if your fleet is working right now, don’t do anything else with them until you get the latest download.

Since I know a lot of people who read this blog are more interested in what it’s like to actually make a game than the actual game I’m producing, I thought it would be useful to give you some of the details about what was happening in the bug. Basically, I’ve got things set up so that whenever you open the Fleet Command screen, a new save is done. (Obviously, that isn’t perfect either.) When I do a save, the fleet is saved to one XML file, and each individual ship is saved to its own file. I call File.OpenWrite, which gives me a stream to write to. But… there’s a catch. That stream already contains the previous contents of the file. If you write less than what was already in there (which happens if you delete a ship, among other things) the old stuff is still there underneath.

It’s a bit of a gotcha. From the documentation:

If you overwrite a longer string (such as “This is a test of the OpenWrite method”) with a shorter string (such as “Second run”), the file will contain a mix of the strings (“Second runtest of the OpenWrite method”).

Boo.

Anyway, I now delete the file first, if it exists, to prevent this from happening. It should all be working now, assuming your fleet wasn’t already corrupted. If it was, stay tuned. I’ll post the solution.

And finally, some slowness has been creeping into the game lately. A big part of it is when you start decking out your ships in guns, and start firing massive amounts of missiles and torpedoes. I want to write a post about optimization soon. Probably this weekend. I actually get a lot of questions about it from my XNA site. I’ll save the juicy details for then, but to summarize, I discovered that the thing that was making the game run slowly is checking if missiles/torpedoes/rockets are inside of the bounding boxes that compose the parts of the ship.

Basically, each part is blocked out with a set of axis-aligned bounding boxes. Of course, this means that the collision detection isn’t perfect, and it’s especially problematic for surfaces that are at a steep angle from all of the coordinate planes. Also, while the bounding box is axis-aligned relative to the object/3D model itself, once you stick the object on the surface of something else, or once it’s on a ship that is turning, the bounding box isn’t axis-aligned any more.

So the process is to take the position of the projectile, perform a couple of matrix transforms to get it into the coordinate system of the axis-aligned box, and check if it’s in the box.

To speed things up (and it does make a significant difference) I build The Bounding Box to Rule Them All that encompasses the entire part. Instead of always checking against each individual bounding box (some parts have 8 or 10) I now check against The Bounding Box to Rule Them All. If, and only if, the projectile is in the big bounding box will I even bother to check the others. It’s a little collision detection trick based on hierarchical collision detection. And the good news is, I could theoretically build a bounding box around an entire ship for even more performance gains in the future if needed. (I trust you guys will let me know if you see performance problems that I’m missing.)

Anyway, that’s it for tonight. Be sure to get the new download and enjoy!

Categories