{"id":1175,"date":"2010-12-30T15:34:37","date_gmt":"2010-12-30T14:34:37","guid":{"rendered":"http:\/\/t-machine.org\/?p=1175"},"modified":"2011-07-31T19:45:30","modified_gmt":"2011-07-31T18:45:30","slug":"entity-system-1-objective-c","status":"publish","type":"post","link":"http:\/\/new.t-machine.org\/index.php\/2010\/12\/30\/entity-system-1-objective-c\/","title":{"rendered":"Entity System 1: Objective-C"},"content":{"rendered":"<p>(this is a simplified, but complete, version of the <a href=\"http:\/\/t-machine.org\/index.php\/2010\/05\/09\/entity-system-1-javaandroid\/\">&#8220;Entity System 1: Java\/Android&#8221;<\/a>)<\/p>\n<p>NB: this post is part of the community effort to make working, usable, free, source-examples of actual Entity Systems, found at <a href=\"http:\/\/entity-systems.wikidot.com\/\">http:\/\/entity-systems.wikidot.com\/<\/a><\/p>\n<p>Wiki link: <a href=\"http:\/\/entity-systems.wikidot.com\/rdbms-with-code-in-systems\">http:\/\/entity-systems.wikidot.com\/rdbms-with-code-in-systems<\/a><\/p>\n<p>Github source: <a href=\"https:\/\/github.com\/adamgit\/Entity-System--RDBMS-Inspired--Objective-C-\">https:\/\/github.com\/adamgit\/Entity-System&#8211;RDBMS-Inspired&#8211;Objective-C-<\/a><\/p>\n<p>I&#8217;m posting my original design notes here &#8211; also copy\/pasted to the wiki, but the wiki version will probably evolve over time. Comments on this post will be disabled &#8211; please comment direct on the wiki \/ wiki discussion pages.<\/p>\n<p>NB: the source code is in GitHub, that&#8217;s where you should download it from (will include any fixes and updates over time)<\/p>\n<h4>Concepts<\/h4>\n<p>(integer) Entity<br \/>\n(enum) ComponentType<br \/>\n(interface OR empty base-class) Component<br \/>\n(interface OR empty base-class) System<br \/>\n(class with implementation) EntityManager<\/p>\n<h4>Data Classes<\/h4>\n<h5>Entity<\/h5>\n<p>This is a non-negative integer, and uniquely identifies an entity within the ES. If you serialize your ES, this SHOULD be the same after serialization. New entities have to be assigned a new, unique, integer value when they are created. When an entity is destroyed, its integer value is freed, available for re-use.<\/p>\n<h5>ComponentType<\/h5>\n<p>This is needed because this ES is so simplistic it has no other way of identifying which Component you&#8217;re talking about when you&#8217;re looking at a single Entity.<\/p>\n<p>(richer EntitySystems MAY not need this type)<\/p>\n<h5>Component<\/h5>\n<p>This exists purely to make method-signatures type-safe. We need to know that certain objects are valid instances of a &#8220;component&#8221; (so we use this superclass to indicate that), but we also need a method that&#8217;s guaranteed to work on all those objects (see below).<\/p>\n<p>(richer EntitySystems make more use of this, and require it to be a class, but for this simple ES, you can use an interface\/header file)<\/p>\n<h5>System<\/h5>\n<p>This exists purely to contain a known method-signature that your game-loop can call once per game-tick.<\/p>\n<h4>EntitySystem Implementation Classes<\/h4>\n<h5>Each subclass of Component<\/h5>\n<p>Internally, the class has the following functions:<\/p>\n<ol>\n<li>(ComponentType) getComponentType();\n<\/ol>\n<h5>EntityManager<\/h5>\n<p>This contains:<\/p>\n<ol>\n<li>The master collections (arrays, hashmaps, whatever) that contain all the data for all the entities\n<li>Logic for creating, modifying, fetching, and deleting entities\n<li>Logic for fetching and modifying components-from-entities\n<\/ol>\n<p>Internally, the class has the following variables:<\/p>\n<ol>\n<li>MAP: from &#8220;Entity + ComponentType&#8221; to &#8220;concrete Component subclass&#8221;\n<li>LIST: all entities in existence (so it never duplicates entity-IDs!)\n<li>\n<p>Internally, the class has the following functions:<\/p>\n<ol>\n<li>(Component) getComponent( Entity, ComponentType );\n<li>(List) getAllComponentsOfType( ComponentType );\n<li>(List) getAllEntitiesPossessingComponent( ComponentType );\n<li>(void) addComponent( Entity, Component );\n<li>(int) createEntity;\n<li>(void) killEntity( Entity );\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>(this is a simplified, but complete, version of the &#8220;Entity System 1: Java\/Android&#8221;) NB: this post is part of the community effort to make working, usable, free, source-examples of actual Entity Systems, found at http:\/\/entity-systems.wikidot.com\/ Wiki link: http:\/\/entity-systems.wikidot.com\/rdbms-with-code-in-systems Github source: https:\/\/github.com\/adamgit\/Entity-System&#8211;RDBMS-Inspired&#8211;Objective-C- I&#8217;m posting my original design notes here &#8211; also copy\/pasted to the wiki, but [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[60,9,20],"tags":[],"_links":{"self":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/1175"}],"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=1175"}],"version-history":[{"count":0,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/1175\/revisions"}],"wp:attachment":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/media?parent=1175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/categories?post=1175"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/tags?post=1175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}