Entity Systems for Objective-C (iPhone)…prologue

I’ve just started a new game project for iPad which I hope will end up with a commercial release. At Red Glasses, we’ve got comparitively few projects for the next couple of months. If anything comes in, I’m expecting one of the other coders can pick it up, and I can concentrate on this in-house iPad game.

Schedule: 1. Prototype; 2. Refine

I wrote the first prototype this weekend – it looks like a very basic Flight Control right now (the game design is trying to do something novel with FC mechanics – I like that control system, but I think we can do a lot more with it than people have done so far).

Now it’s time to implement some of the novel mechanics, and prototyping our core game design. This will mean creating a lot of game-logic, lots of behaviours, etc. And so … I’d really like to use an Entity System.

Objective-C: the bad bits of C … without the good bits of C

The thought of building an ES without templating makes me weep.

Unfortunately, Obj-C continues to show it’s age/mediocrity/general-lack-of-usefulness: it’s finally (this year!) acquired an implementation of closures, but it still doesn’t have generic classes.

NB: *I believe* it doesn’t have generics; it might have, but I’ve not noticed them in any ObjC projects, code, libraries, etc. A quick google came up with nothing.

ES without generic classes is like OOP in Perl: techically possible, but liable to contain a lot of painful bugs which a compiler would have spotted for you … and contain a *lot* of boiler-plate code you really shouldn’t need to write in this day and age.

I could fix all this with C++ – it has probably the world’s best implementation of generic classes. It’s not perfect, but IME it’s the best overall balance of functionality.

Unfortunately, unlike C, Obj-C is incompatible with C++.

What next?

Ideas and suggestions are *very* welcome…

Assuming I can get an ES to work on iPhone, I’ll be blogging it. I’ll aim to open-source the ES I build.

I’ve had a quick look at using C++ classes and objects in ObjC. Using the objects has a lot of boilerplate code from Apple, that looks pretty good (but painfully verbose :( ).

…but using the *classes* appears pretty horrific. Since ObjC doesn’t have any kind of generics (that’s how we got to this point :)), it can’t handle those parts of C++ in a meaningful way.

Then again, since Obj-C is *very* dynamic as a language, I might be able to do something cunning with passing around NSClass instances / references. Combine that with runtime method dispatch / message-passing, and *maybe* I can code a decent C++ ES … while using ObjC to write logic that acts on the data from that ES, without having to write so many extra lines of code that the “saving” is lost.

As I said … ideas welcomed!

19 thoughts on “Entity Systems for Objective-C (iPhone)…prologue”

Comments are closed.