{"id":93,"date":"2011-10-12T18:09:37","date_gmt":"2011-10-12T18:09:37","guid":{"rendered":"http:\/\/www.zombox.net\/?p=93"},"modified":"2012-07-04T21:56:01","modified_gmt":"2012-07-04T21:56:01","slug":"under-the-hood","status":"publish","type":"post","link":"http:\/\/www.zombox.net\/?p=93","title":{"rendered":"Under the hood&#8230;."},"content":{"rendered":"<p>Someone in the <a href=\"http:\/\/forum.unity3d.com\/threads\/106503-Zombox?p=713841#post713562\">Unity forums<\/a> asked me how Zombox maintains performance even with all the active colliders and rigidbodies within the environment. I figured it would be a good time to explain some of what goes on behind the scenes in the Zombox engine.<\/p>\n<p>The game uses a fairly complex pooling system I wrote to create the environment.<\/p>\n<p>Firstly, because everything in the game procedurally generated from a small set of prefabs, I can easily enable\/disable anything that is not directly within the view frustum. Not just disable its renderer&#8230;but literally remove it completely, and use its gameobject to create something that *is* in screenspace. This means the total number of active rigidbody\/static colliders in the game is limited to what&#8217;s visible in screen space, because only a finite set of gameobjects are used to create everything. The entire city features over 350 buildings (each with many walls, props, etc&#8230;.about 40,000 different &#8220;pieces&#8221; are required to create the whole city), many roads, rivers, etc&#8230;but all of that is generated using only 300 gameobjects, which are recycled constantly. This keeps the game running really fast and there are no load times in the huge sprawling environment once the initial city-generation load time is passed (and that initial load time only takes a few seconds).<\/p>\n<p><!--more--><\/p>\n<p>Secondly, the pooling system also manages the number of active non-kinematic rigidbodies, so that I can easily control the max number of rigidbodies in the game at any time. The downside is that the same small group of rigidbodies are recycled for new zombie\/building\/environment chunks that are generated, so as new chunks pop in (like when a wall is crumbled, or a zombie is killed), old chunks pop out. But generally this effect isn&#8217;t that noticeable and doesn&#8217;t detract from the gameplay.<\/p>\n<p>I think I&#8217;ve got about 30 rigidbodies in the building-debris-rigidbody pooling system, a dozen in the zombie-limb pooling system and a few more in the environment-debris pooling system. With all of those rigidbodies active and colliding, the game runs at about 20-30 fps on the iPhone 3GS, and 30+ fps on the iPhone 4.<\/p>\n<p>The following gif showing the environment pooling system in action. The white lines represent zombie paths, and the roofs are disabled so you can easily see all the objects necessary to build all the walls of each building.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone\" title=\"Zombox gameobject pooling system\" src=\"http:\/\/www.zombox.net\/stuff\/zombox_cap_05.gif\" alt=\"\" width=\"480\" height=\"320\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Someone in the Unity forums asked me how Zombox maintains performance even with all the active colliders and rigidbodies within the environment. I figured it would be a good time to explain some of what goes on behind the scenes in the Zombox engine. The game uses a fairly complex pooling system I wrote to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zombox.net\/index.php?rest_route=\/wp\/v2\/posts\/93"}],"collection":[{"href":"http:\/\/www.zombox.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zombox.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zombox.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zombox.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=93"}],"version-history":[{"count":8,"href":"http:\/\/www.zombox.net\/index.php?rest_route=\/wp\/v2\/posts\/93\/revisions"}],"predecessor-version":[{"id":95,"href":"http:\/\/www.zombox.net\/index.php?rest_route=\/wp\/v2\/posts\/93\/revisions\/95"}],"wp:attachment":[{"href":"http:\/\/www.zombox.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zombox.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zombox.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}