{"id":11883,"date":"2011-06-08T05:30:45","date_gmt":"2011-06-08T10:30:45","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=11883"},"modified":"2011-06-08T05:31:06","modified_gmt":"2011-06-08T10:31:06","slug":"project-frontier-2-paging-data","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=11883","title":{"rendered":"Project Frontier #2: Paging Data"},"content":{"rendered":"<p>Coming up with rules and systems and algorithms to generate content is hard enough, but added to that challenge is the fact that we don&#8217;t have the benefit of any sort of pre-processing.  If you&#8217;ve ever used a level editor, you know those things can eat a ton of time.  They can take the data, cull out what isn&#8217;t needed, pre-compute the expensive stuff, and package things in a nice, organized way so that when the game is running, it can pull data off the disk and put it right to work.<\/p>\n<p>With procedural stuff, you&#8217;ve got to do that work <em>while the game is running<\/em>. Without slowing things down.  This moves all of that complexity into the game, and makes the system more complicated by requiring that it be done piecemeal. If you&#8217;ve played Minecraft, you&#8217;ve probably noticed the heavy lurch you get when the game has to generate some new landscape for you.  I&#8217;m going to face that same problem with this project.<\/p>\n<p>But I&#8217;m getting ahead of myself.  First, a bit about how my program creates the terrain.  First, it takes that low-level topography I generated in the previous step:<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier2_3.jpg' class='insetimage'   alt='frontier2_3.jpg' title='frontier2_3.jpg'\/><\/td><\/tr><\/table><\/p>\n<p><!--more-->Very bland, of course. We don&#8217;t want to generate an entire continent of endless speed bumps, so we also have some topographical data stretched out over a much larger scale:<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier2_4.jpg' class='insetimage'   alt='frontier2_4.jpg' title='frontier2_4.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Note how this looks kind of mechanical.  You can see large, flat surfaces everywhere. By itself, this would make the continent feel sort of like the whole world was made from geometric primitives.  But if we combine the two data sets:<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier2_5.jpg' class='insetimage'   alt='frontier2_5.jpg' title='frontier2_5.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>I&#8217;ve exaggerated the hills for effect.  The large hills give the world shape, the small ones give it detail. Together they make something roughly presentable. From now on, I&#8217;ll be calling these two sets the &#8220;topography&#8221; and the &#8220;detail&#8221;.<\/p>\n<p>How it works is this:<\/p>\n<p>The world is divided into regions.  Some regions will have strong topography, normal detail.  Others will have muted topography, but strong detail.  I can exaggerate one data set over the other to create different landscapes.  (Low rolling hills, flat deserts, spiky mountains.)  Each region also has an overall height bias, so that I can shove some of them into the sea and lift others up.  Right now the regions are hard-coded, but eventually I&#8217;ll have some sort of logic to generate them as well.  Eventually, regions will also have different coloring.<\/p>\n<p>As you move around the world, it generates this landscape.  Some logic goes into figuring out what the surfaces should be.  Flat spots should be grassy.  Hilly spots should be dirt. Steep bits should be rock.  Stuff touching the water should be sand.  These sections of terrain are generated in pages.  Eventually, they&#8217;ll be saved to disk once they&#8217;re generated, in much the same way that Minecraft does. <\/p>\n<p>Then it comes time to turn this data into actual polygons for rendering. <\/p>\n<p>Currently, the program will just add more terrain as you run along, forever. Well, not <em>forever<\/em>. But it will happily churn them out until you run out of memory.  It doesn&#8217;t clean out data yet, so once something is in memory, it stays there. Josh joked that it&#8217;s now officially a game.  &#8220;See how far you get before it crashes. You want to play on easy mode? Buy more memory.&#8221;  <\/p>\n<p>Running out of memory is kind of abrupt. The program runs fine until the moment I have too much texture data, at which point the framerate drops from 90, to 5.  I pushed it once and nearly brought down my machine. It took a loooong time to bring up the task manager and kill the program.  <\/p>\n<p>Still, that means I got the high score!<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier2_6.jpg' class='insetimage'   alt='frontier2_6.jpg' title='frontier2_6.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Yes, I am aware that it looks horrible and bland. Next time we&#8217;ll liven it up with proper variety.  And maybe look into fixing that memory hoarding problem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Coming up with rules and systems and algorithms to generate content is hard enough, but added to that challenge is the fact that we don&#8217;t have the benefit of any sort of pre-processing. If you&#8217;ve ever used a level editor, you know those things can eat a ton of time. They can take the data, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-11883","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/11883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11883"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/11883\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}