{"id":11874,"date":"2011-06-06T05:37:07","date_gmt":"2011-06-06T10:37:07","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=11874"},"modified":"2011-06-06T05:39:36","modified_gmt":"2011-06-06T10:39:36","slug":"project-frontier-1-getting-started","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=11874","title":{"rendered":"Project Frontier #1: Getting Started"},"content":{"rendered":"<p>I&#8217;m still sulking about what happened to <a href=\"?p=11809\">my book<\/a>.  In the interim, I&#8217;ve decided to do some coding.  Remember project Hex? That was <a href=\"?p=9644\">this thing<\/a>:<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/hex_edges15.jpg' class='insetimage'   alt='hex_edges15.jpg' title='hex_edges15.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>I liked the way the first stages of project Hex <a href=\"?p=9844\">turned out<\/a>.  While a few people had artistic criticisms of it, the idea and the implementation were solid. I want to try the same thing, only making a more conventional first-person style engine.  This is <em>far<\/em> more ambitious.   Here are my new goals:<\/p>\n<p><!--more--><\/p>\n<ol>\n<li>Use the established pixelated, quasi-8-bit graphics.\n<\/li>\n<li>The world should be vast. Maybe not Minecraft &#8220;bigger than the actual Earth&#8221; sort of vast, but big.  Basically, I want to be free to adjust the size of the world based on what seems &#8220;fun&#8221;.  Maybe this will be <a href=\"?p=6597\">Fuel-sized<\/a>. Maybe smaller. But I need to design this engine with the idea that it should be able to handle lots and lots of data in bulk.\n<\/li>\n<li>Procedurally generated world.  Because that&#8217;s my thing.\n<\/li>\n<li>Variety. I don&#8217;t want ten thousand square miles of same-y terrain.  Lots of different lighting, coloring, texturing, topography, etc.\n<\/li>\n<li>Decent view distance. The world should feel vast.\n<\/li>\n<li>Should run acceptably on old hardware. (For now, this just means keeping the GPU, CPU, and memory usage low.  Whether it <em>actually<\/em> runs well on old hardware is another matter, but I want to make sure I don&#8217;t cut off low-end machines by design.)\n<\/li>\n<li>It should be as platform-agnostic as possible. Okay, I&#8217;m working in Microsoft Visual Studio 2010, so this is Windows native.  But I don&#8217;t want to load up the guts of my engine with Microsoft-specific code.  I&#8217;ll be using <a href=\"http:\/\/www.libsdl.org\/\">SDL<\/a>, and <a href=\"http:\/\/nehe.gamedev.net\/\">OpenGL<\/a>.\n<\/li>\n<\/ol>\n<p>This is much too ambitious.  It&#8217;s a starry-eyed pipe dream, doomed to failure. Let&#8217;s get started.<\/p>\n<p>I spend the first couple of hours ripping the hex-based logic out of project hex and building it up again based on square grids. I also rip out the cheapo RTS-style camera and replace it with a proper &#8220;flycam&#8221;.  <\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier_start1.jpg' class='insetimage'   alt='frontier_start1.jpg' title='frontier_start1.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>You know, I don&#8217;t like to add visual gloss until I have the underlying system working right, but right now it&#8217;s hard to see the topography. So, I drop in some basic lighting. Note that this is using the standard OpenGL lighting model, nothing fancy.  I have no idea how my lighting system will work long term, but this is good enough for now.  (See <a href=\"?p=146\">this post<\/a> for a bit about what I might have to deal with if I decide to make my own lighting system.)<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier_start2.jpg' class='insetimage'   alt='frontier_start2.jpg' title='frontier_start2.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>It seems to have lost a great deal of its charm in the move from overhead hex map to where we are now.  It&#8217;s less cartoon-ish and vibrant. We can worry about that later.  Note that my hills are now generated by sine waves. Those suck. Let&#8217;s fix that.<\/p>\n<p>First up, I import a few blobs of hill-types smears that I doodled by hand:<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier_start4.jpg' class='insetimage'   alt='frontier_start4.jpg' title='frontier_start4.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Compared to the sine wave hills, these are <del datetime=\"2011-06-05T01:21:15+00:00\">much better<\/del> still completely awful. Hills are not shaped like noise. Hills are not usually shaped like domes.  (Unless they are small or man-made.)  On any kind of respectable scale, erosion has its way with the land and the sides of hills end up shaped sort of like tree roots.  It will have arms that reach out, with steeper sections between them. <\/p>\n<p>The easiest way to achieve this is to run an erosion simulation on it. No, really. Erosion simulation. Just a bit. What you do is this:<\/p>\n<ol>\n<li>Pass over the map one &#8220;pixel&#8221; at a time, performing the following process on each space:\n<\/li>\n<li>Drop an imaginary water droplet onto the current space.\n<\/li>\n<li>Now look around, and see which of the neighboring spaces is lowest. Move the droplet to that space.\n<\/li>\n<li>Every time the droplet moves, chip a bit of elevation away from where it was.\n<\/li>\n<li>Once the droplet arrives at a space where it can no longer move down, abandon it and drop the next one. Repeat until you&#8217;ve passed over the entire map.\n<\/li>\n<\/ol>\n<p>There&#8217;s a quality vs. performance cost associated here. It&#8217;s better to pass over the map many times, taking only a slight bit of land away with each pass. But if you&#8217;re in a hurry, you can run over the whole thing just once and take a bigger chunk away.  The land ends up looking a little &#8220;jaggy&#8221; when you do this.  The slow way gives much more realistic erosion shapes. <\/p>\n<p>Simple. Cheap. I&#8217;ve done this sort of thing before, and I can say that erosion systems are very prone to <a href=\"?p=1200\">oversimulation<\/a>.  You CAN write one that takes into account sediment, and the different ways in which rock and dirt erode, and the effect of flowing water on steep slopes as opposed to gradual ones. Likely as not, it will be tough to balance those behaviors well enough to produce useful results, but if you DO manage it, you&#8217;ll end up with geography that looks 10% better than the cheapo system I outlined above.  If all you need is a bit of topography that can look presentable, then there&#8217;s no reason to waste your time and CPU making a deep simulation.  <\/p>\n<p>The result?<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier_start3.jpg' class='insetimage'   alt='frontier_start3.jpg' title='frontier_start3.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Eh.  Better than a poke in the eye.  The world is still set to a (small) fixed size.  It loads up all the data at startup, and displays a fixed-size world.  Next time we&#8217;ll add paging so it can build the world as we go. And maybe do something about it being so dang ugly. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m still sulking about what happened to my book. In the interim, I&#8217;ve decided to do some coding. Remember project Hex? That was this thing: I liked the way the first stages of project Hex turned out. While a few people had artistic criticisms of it, the idea and the implementation were solid. I want [&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-11874","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\/11874","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=11874"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/11874\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}