{"id":1048,"date":"2010-10-10T17:03:25","date_gmt":"2010-10-10T16:03:25","guid":{"rendered":"http:\/\/t-machine.org\/?p=1048"},"modified":"2010-10-10T17:03:25","modified_gmt":"2010-10-10T16:03:25","slug":"entity-systems-for-objective-c-iphone-prologue","status":"publish","type":"post","link":"http:\/\/new.t-machine.org\/index.php\/2010\/10\/10\/entity-systems-for-objective-c-iphone-prologue\/","title":{"rendered":"Entity Systems for Objective-C (iPhone)&#8230;prologue"},"content":{"rendered":"<p>I&#8217;ve just started a new game project for iPad which I hope will end up with a commercial release. At Red Glasses, we&#8217;ve got comparitively few projects for the next couple of months. If anything comes in, I&#8217;m expecting one of the other coders can pick it up, and I can concentrate on this in-house iPad game.<\/p>\n<h4>Schedule: 1. Prototype; 2. Refine<\/h4>\n<p>I wrote the first prototype this weekend &#8211; it looks like a very basic Flight Control right now (the game design is trying to do something novel with FC mechanics &#8211; I like that control system, but I think we can do a lot more with it than people have done so far).<\/p>\n<p>Now it&#8217;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 &#8230; I&#8217;d really like to use an Entity System.<\/p>\n<h4>Objective-C: the bad bits of C &#8230; without the good bits of C<\/h4>\n<p>The thought of building an ES without templating makes me weep.<\/p>\n<p>Unfortunately, Obj-C continues to show it&#8217;s age\/mediocrity\/general-lack-of-usefulness: it&#8217;s finally (this year!) acquired an implementation of closures, but it still doesn&#8217;t have generic classes.<\/p>\n<p>NB: *I believe* it doesn&#8217;t have generics; it might have, but I&#8217;ve not noticed them in any ObjC projects, code, libraries, etc. A quick google came up with nothing.<\/p>\n<p>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 &#8230; and contain a *lot* of boiler-plate code you really shouldn&#8217;t need to write in this day and age.<\/p>\n<p>I could fix all this with C++ &#8211; it has probably the world&#8217;s best implementation of generic classes. It&#8217;s not perfect, but IME it&#8217;s the best overall balance of functionality.<\/p>\n<p>Unfortunately, unlike C, Obj-C is incompatible with C++. <\/p>\n<h4>What next?<\/h4>\n<p>Ideas and suggestions are *very* welcome&#8230;<\/p>\n<p>Assuming I can get an ES to work on iPhone, I&#8217;ll be blogging it. I&#8217;ll aim to open-source the ES I build.<\/p>\n<p>I&#8217;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 :( ).<\/p>\n<p>&#8230;but using the *classes* appears pretty horrific. Since ObjC doesn&#8217;t have any kind of generics (that&#8217;s how we got to this point :)), it can&#8217;t handle those parts of C++ in a meaningful way.<\/p>\n<p>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 &#8230; 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 &#8220;saving&#8221; is lost.<\/p>\n<p>As I said &#8230; ideas welcomed!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve just started a new game project for iPad which I hope will end up with a commercial release. At Red Glasses, we&#8217;ve got comparitively few projects for the next couple of months. If anything comes in, I&#8217;m expecting one of the other coders can pick it up, and I can concentrate on this in-house [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,33,20],"tags":[],"_links":{"self":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/1048"}],"collection":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/comments?post=1048"}],"version-history":[{"count":0,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/1048\/revisions"}],"wp:attachment":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/media?parent=1048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/categories?post=1048"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/tags?post=1048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}