object.h is dead, long live object.h!
Ugh, sorry for the lack of updates, I feel like I’ve been clawing my way through a giant pile of manure and have barely gotten my head out into the air.
If you recall, my current task on SpyParty has been to get the folks at the party to be able to pick things up, like books, magazines, martinis, cigarettes, top secret plans for a nuclear device, etc. Well, steps 3 and 4 on that task were the following:
3. Add non-character dynamic items as a concept to the code.
4. Add a simple attachment system to the character AI and rendering code.
Oh boy. These look pretty simple, but since I’ve been 100% focused on getting the gameplay prototyped, the actual game code had gotten a little, shall we say, funky smelling. It was never very clean, having started from the Indie Game Jam 3 engine source code, which was not in great shape itself, but my singular focus on getting gameplay in without regard to how I got it in has made matters worse.

It became clear that I needed to clean things up before I could move forward. My friend and executive producer at Maxis, Lucy Bradshaw, used to bristle whenever a programmer would mention the word “refactoring” because it had a perfect trifecta of badness1, but it was time. I couldn’t figure out how to attach an object to another object in the old system without hacks even more heinous than I was willing to attempt.
This kind of task gets to the heart of the “game object system” issue. I’ve got a good powerpoint by Doug Church on my site on the topic, and I’m going to write more about my new system soon, but I wanted to at least post something to indicate that I’m not dead.
Briefly, I choose a fairly simple component based object system architecture. There are really two basic options when you’re doing object systems: inheritance-based and component-based. I’ll have much more to say about this later after I’ve used it for a bit and worked out the kinks, but for my usage I thought components were the way to go. These terms are pretty loose; they don’t necessarily directly correspond to C++ (or whatever) definitions when you use them in this general way.
The other thing I am finally starting to test out is my new namespace-centric coding style I’ve been simmering on for the past 5 years. I’ll also write more about that soon as well. I’ve been styleless for a long time, after becoming dissatisfied with my previous programming style, and not seeing any others I really liked.
The final thing I wanted to mention was that even after 20 years of programming, I still need constant reminders to figure out ways to keep changes small. I started writing the new object system and porting all the code over to it in one big change, and after bogging down in that for days and days, I finally rolled back to the old object system and figured out a way to incrementally change over. It’s more hacked code in the interim with the two object systems fighting for attention, but having a compiling and working piece of software you can test incrementally is so important it’s hard to overstate. I had two object.h’s in the project for a few days (the old one renamed to _object.h), but it let me move things over piecemeal and keep testing, and I was finally able to delete the old object.h last night.
Also, source code control is your friend and it saved me when I realized I’d bitten off more than I could chew in one bite during the refactor. I currently use Subversion and have for years, but have been thinking about switching to Mercurial or Bazaar. I wish these distributed systems dealt with large binary files like those found in games better, though.
- 1) refactoring takes a long time, 2) it adds bugs to the code, 3) even when it works perfectly, it has no visible improvement on the game [↩]







