{"id":19,"date":"2018-05-29T15:36:55","date_gmt":"2018-05-29T15:36:55","guid":{"rendered":"https:\/\/vanderhydeus.wordpress.com\/?p=19"},"modified":"2021-07-30T17:12:39","modified_gmt":"2021-07-30T17:12:39","slug":"entity-component-system-architecture","status":"publish","type":"post","link":"https:\/\/vanderhyde.us\/index.php\/2018\/05\/29\/entity-component-system-architecture\/","title":{"rendered":"Entity-Component-System architecture"},"content":{"rendered":"<p>Recently I have been learning about the Entity-Component-System architecture for video game programming. I think it will help out with my &#8220;World&#8217;s Tiniest RTS&#8221; game. I learned about it <a href=\"http:\/\/gameprogrammingpatterns.com\/component.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>, in Robert Nystrom&#8217;s <em>Game Programming Patterns<\/em>. I also heard on the Exploding Rabbit <a href=\"http:\/\/explodingrabbit.com\/exploding-rabbit-podcast-2-the-exploding-rabbit-hole-of-code-architecture-1186\/\">podcast<\/a> how Jay Pavlina (of Super Mario Bros. Crossover fame) uses the pattern. Here is my Clojure code for it, currently:<\/p>\n<pre>(defn create-game []\n  {:entities {}})\n\n(defn create-entity []\n  [(java.util.UUID\/randomUUID)\n   {}])\n\n(defn add-entity [game entity]\n  (update-in game [:entities] conj entity))\n\n(defn add-component [game entity com data]\n  (assoc-in game [:entities (first entity) com] data))\n\n;;example\n(let [e1 (create-entity)]\n  (-&gt;\n    (create-game)\n    (add-entity e1)\n    (add-component e1 :position [3 4])\n    (add-component e1 :name \"ball\")))\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Recently I have been learning about the Entity-Component-System architecture for video game programming. I think it will help out with my &#8220;World&#8217;s Tiniest RTS&#8221; game. I learned about it here, in Robert Nystrom&#8217;s Game Programming Patterns. I also heard on the Exploding Rabbit podcast how Jay Pavlina (of Super Mario Bros. Crossover fame) uses the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[5,7],"_links":{"self":[{"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/posts\/19"}],"collection":[{"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":1,"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/posts\/19\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vanderhyde.us\/index.php\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}