Spare-time game development for me is primarily a learning exercise. If I get a game out the other end then that’s great, but I’m more interested in what I learn along the way. I’ve been reading through old entries on Noel Llopis (co-creator of Amazing Alex/Casey’s Contraptions)’s blog, Games From Within and was inspired by his comments on unit testing and TDD and thought I’d try out TDD in my own project. The interface for some of my low level code had gotten pretty nasty so I thought I’d throw it all out and start again. This is a strange luxury of personal projects, and the reason I never end up finishing anything. I guess I’ll leave shipping games to my day job. This also presented a perfect opportunity to really familiarise myself with Xcode I recently bought a MacBook Air and until now my experience with Xcode has primarily been a process of getting a project to compile for iOS and never changing anything ever again. Integrating projects to run unit tests after a compile which would interrupt the build process would allow me to explore some of the more advanced features of the IDE.
My Xcode workspace currently takes this shape:
- Engine – non-game-specific, re-usable code. This is where all my entity/component base classes live, along with some re-usable components and subsystems
- EngineTests – unit tests for the engine code
- GameLib – game code library. This is where all the game-specific code goes
- GameLibTests – unit tests for the game code
- Cocos2dx – the cross platform graphics framework I’m using
- UnitTest++ – unit testing framework
- GLM – GLSL-like C++ library for vectors/matrices/etc
- Game launcher – the platform-specific entry point for the game. Used to make a window, set up the render context, etc
All of these projects except the launcher and the test projects compile to a shared library to keep everything nice and modular – the tests projects use the same .a file as the game launcher itself.
This is all currently building a Mac binary, but switching over to iOS or Android should just be a matter of adding a new target for the appropriate platform and changing a couple of its settings for the most-part everything will just work. There’s no game yet but that’ll come in time!
Update: Just to potentially make this post useful to someone, I thought I’d share something that I had to wrestle with briefly trying to set this all up. In Xcode, if you run your unit tests as a pre-build phase of your Scheme, the return code will be ignored and it won’t count as a build error, so any unit tests which fail will do so silently. I have a Target for my game setup which has a Run Script build phase on it, which is just the path to the Product produced by unit test project, and the Scheme is setup to build the game and the unit tests. This way the build will show errors if any unit tests fail.
