<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MUA Games &#187; joust</title>
	<atom:link href="http://muagames.com/tag/joust/feed/" rel="self" type="application/rss+xml" />
	<link>http://muagames.com</link>
	<description>Indy Game Dev FTW</description>
	<lastBuildDate>Fri, 09 Sep 2011 16:00:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Optimization Get!</title>
		<link>http://muagames.com/2008/10/11/optimization-get/</link>
		<comments>http://muagames.com/2008/10/11/optimization-get/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 08:51:52 +0000</pubDate>
		<dc:creator>Keeyai</dc:creator>
				<category><![CDATA[Bonk]]></category>
		<category><![CDATA[joust]]></category>
		<category><![CDATA[procedural]]></category>

		<guid isPermaLink="false">http://muagames.com/?p=57</guid>
		<description><![CDATA[Much to report! The last few days have been fruitful &#8211; now we have a minimap, stars, a better sky gradient, textured ground, and some optimization. Minimap: The minimap is a simple but effective &#8212; it is actually a scaled down version of the map picture from the previous post, with a little box that [...]]]></description>
			<content:encoded><![CDATA[<p>Much to report! The last few days have been fruitful &#8211; now we have a minimap, stars, a better sky gradient, textured ground, and some optimization.</p>
<p><strong>Minimap:</strong><br />
The minimap is a simple but effective &#8212; it is actually a scaled down version of the map picture from the previous post, with a little box that shows the current location. It really helps show the scale of the world while you are flying around in it.</p>
<p><strong>Stars:</strong><br />
The stars were taken almost straight from MUA Space, a demo game for the framework. They are randomly placed in the sky tiles, with more stars per tile the higher it goes, until the top (black) tiles are quite &#8216;starry&#8217;. The stars vary slightly in size and twinkle. Simple, but nice.</p>
<p><div id="attachment_58" class="wp-caption alignnone" style="width: 160px"><a href="http://muagames.com/wordpress/wp-content/uploads/2008/10/stars-lvl167.png"><img src="http://muagames.com/wordpress/wp-content/uploads/2008/10/stars-lvl167-150x150.png" alt="Sky at Level 167" title="stars-lvl167" width="150" height="150" class="size-thumbnail wp-image-58" /></a><p class="wp-caption-text">Sky at Level 167</p></div><br />
<div id="attachment_59" class="wp-caption alignnone" style="width: 160px"><a href="http://muagames.com/wordpress/wp-content/uploads/2008/10/stars-lvl188.png"><img src="http://muagames.com/wordpress/wp-content/uploads/2008/10/stars-lvl188-150x150.png" alt="Sky at Level 188" title="stars-lvl188" width="150" height="150" class="size-thumbnail wp-image-59" /></a><p class="wp-caption-text">Sky at Level 188</p></div><br />
<div id="attachment_60" class="wp-caption alignnone" style="width: 160px"><a href="http://muagames.com/wordpress/wp-content/uploads/2008/10/stars-lvl216.png"><img src="http://muagames.com/wordpress/wp-content/uploads/2008/10/stars-lvl216-150x150.png" alt="Sky at Level 216" title="stars-lvl216" width="150" height="150" class="size-thumbnail wp-image-60" /></a><p class="wp-caption-text">Sky at Level 216</p></div><br />
<div id="attachment_61" class="wp-caption alignnone" style="width: 160px"><a href="http://muagames.com/wordpress/wp-content/uploads/2008/10/stars-lvl249.png"><img src="http://muagames.com/wordpress/wp-content/uploads/2008/10/stars-lvl249-150x150.png" alt="Sky at Level 249" title="stars-lvl249" width="150" height="150" class="size-thumbnail wp-image-61" /></a><p class="wp-caption-text">Sky at Level 249</p></div></p>
<p><strong>Ground Texture:</strong><br />
Next, I replaced the old placeholder ground code that made that boring brown texture. Now, the generated terrain becomes an alpha image used as a mask with the underground image to texture the tile. It works really well and the entire operation only takes about .01 seconds. I botched the ground texture itself &#8212; it doesn&#8217;t exactly wrap right, but otherwise you can see it working nicely here.<br />
<div id="attachment_62" class="wp-caption alignnone" style="width: 310px"><a href="http://muagames.com/wordpress/wp-content/uploads/2008/10/ground-texture.png"><img src="http://muagames.com/wordpress/wp-content/uploads/2008/10/ground-texture-300x225.png" alt="Ground Texture" title="ground-texture" width="300" height="225" class="size-medium wp-image-62" /></a><p class="wp-caption-text">Ground Texture</p></div></p>
<p><strong>Optimization:</strong><br />
This was a big one. After adding the new things, particularly the texturing, the on-the-fly generation of tiles I was doing was causing tiny little blips in the FPS. It wasn&#8217;t much, but it WAS noticeable. I have a pretty good machine, so I knew I needed to iron this out. I cut out ugly parts of code where I could, but the operations themselves are pretty heavy (terrain generation, texturing, converting from PIL images to Pyglet textures), so I needed to take it a step further. Two steps actually &#8211; I approached the optimization in 2 ways.</p>
<p>First, and by far the most important, was splitting up the loading tasks into distinct phases and spreading them out across frames. Before I was loading the entire tile (for a ground tile this means generating the terrain heightmap, applying the ground texture via a mask, generating the sky color and applying it, then converting it to a Pyglet sprite) when it was initialized, which was way too slow. Each of the surface tiles were taking about .03 seconds, and I am loading 3 tiles at a time (I briefly had some code to only load 2 at a time, but I took that out because it was poorly written. If I need to, I&#8217;ll go back and do that again).</p>
<p>So, I wrote a new tile class that handles all its own loading. The idea is simple enough &#8211; each tile has a stack of &#8216;steps&#8217; it needs to do to be fully loaded. Some require just one step like underground tiles (copy the cached underground texture), and some require a long series of them like surface tiles (generate terrain array, create terrain mask, apply background sky texture, use mask to apply ground texture over terrain, convert image to texture for rendering). On the very first step, the tile gets its tile type from the main map and sets the necessary steps accordingly. Now, each frame, if there are still steps left in the todo stack, it pops one off and processes it. The tile comes a little closer to being fully loaded, and it only takes as much time as one step, instead of all of them together. When the to-do stack is empty, the tile is finished, and it just renders itself like normal.</p>
<p>While that took care of my frame lag problem, my design made me worried about wasting some loading. Here is my MS Paint explanation of the how the map loads tiles as the player moves.</p>
<div id="attachment_63" class="wp-caption alignnone" style="width: 310px"><a href="http://muagames.com/wordpress/wp-content/uploads/2008/10/9tilerendering.jpg"><img src="http://muagames.com/wordpress/wp-content/uploads/2008/10/9tilerendering-300x231.jpg" alt="How the 9 rendered tiles change as the player moves" title="9 Tile Rendering" width="300" height="231" class="size-medium wp-image-63" /></a><p class="wp-caption-text">How the 9 rendered tiles change as the player moves</p></div>
<p>In the situation above, the player is now on the far left of the new center tile (f). If it moves just one pixel back to the left, the process happens again in reverse &#8211; dropping the JKL column and reloading the tiles for ADG. So wasteful!</p>
<p>Solution: Caching. Now the map keeps around the last handful of tiles it drops. When the user crosses to the right and ADG gets dropped, they get saved. If the user then comes back to the left (without going too much further away), those tiles are still available and the map can just use the saved copies (fast) instead of generating new ones (very slow).</p>
<p><strong>Map tasks still ahead:</strong></p>
<ul>
<li>clouds</li>
<li>platforms</li>
<li>regions &#038; their specific terrain</li>
<li>foilage</li>
<li>wrapping the world</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://muagames.com/2008/10/11/optimization-get/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Procedural World &#8211; Loading and Rendering</title>
		<link>http://muagames.com/2008/10/07/procedural-world-loading-and-rendering/</link>
		<comments>http://muagames.com/2008/10/07/procedural-world-loading-and-rendering/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 13:03:39 +0000</pubDate>
		<dc:creator>Keeyai</dc:creator>
				<category><![CDATA[Bonk]]></category>
		<category><![CDATA[joust]]></category>
		<category><![CDATA[persistent world]]></category>
		<category><![CDATA[procedural]]></category>
		<category><![CDATA[terrain]]></category>

		<guid isPermaLink="false">http://muagames.com/?p=52</guid>
		<description><![CDATA[The joust game (still no name yet &#8211; working on that!) has come a long way in the last two days. I used the tool in my previous post to select 2 world layouts I wanted, then joined them together to form one solid map of the world ground level. I then rigged the program [...]]]></description>
			<content:encoded><![CDATA[<p>The joust game (still no name yet &#8211; working on that!) has come a long way in the last two days. I used the tool in my previous post to select 2 world layouts I wanted, then joined them together to form one solid map of the world ground level. I then rigged the program to use the values from that when generating the terrain for each individual tile so they all line up nicely with each other. I also added in a simple gradient for the sky, so it starts off very pale blue then gets darker and darker as you get higher and higher. Soon I&#8217;ll add stars and clouds, but even this simple stuff I have so far has turned out very nice.</p>
<p>Currently I have the world set at 1000 tiles wide and 250 tiles tall. Each tile is 800&#215;600 at the moment (subject to change!), which makes the world map 800,000 pixels wide and 150,000 pixels tall. That is a huge amount of real estate, so I expect it will be more than enough for our needs, even if we get a few hundred players (crossing fingers).</p>
<p>Naturally, the player is only going to see a tiny slice of this massive world at a time, so we don&#8217;t want to waste any time or memory loading and storing any more than we have to. I&#8217;ve been pretty frugal and decided to load only the tile the player is on and the 8 tiles surrounding it. As the player moves, the game automatically throws away the tiles in the other direction and loads new ones where the player is headed. I was worried this much processing would introduce some lag (remember the client&#8217;s computer has to generate and render the terrain on the fly), but as you can see in the video below, it runs very smoothly.</p>
<p>This is how the game renders the world to the player. These nine tiles are loaded and displayed, with the screen starting centered around the middle tile (Middle Center). If, for example, the player moved to the left, the nine tiles would move to the right as a group. When the player crossed from Middle Center into Middle Left, the game would throw away the three tiles in the Right column, move the other two columns over, and load three new tiles for the new left. The player never notices and the game never has more than the nine tiles loaded at once.</p>
<div id="attachment_53" class="wp-caption alignnone" style="width: 310px"><a href="http://muagames.com/wordpress/wp-content/uploads/2008/10/joust-renderingworld.png"><img src="http://muagames.com/wordpress/wp-content/uploads/2008/10/joust-renderingworld-300x225.png" alt="9 Tiles of Rendering" title="9 Tiles of Rendering" width="300" height="225" class="size-medium wp-image-53" /></a><p class="wp-caption-text">9 Tiles of Rendering</p></div>
<p>Here is a simple video of the system in action (if you follow the link and watch it at the youtube site, you can see my annotations explaining things a bit more). You can see how the tiles work together to make it appear that the entire world has already been loaded. The line on the screen is from the center to the mouse position, which is how I control the scroll direction and scroll speed (further from center = go faster). The video simply flies around a bit following the procedural terrain, then takes off at top speed vertically, climbing all the way to the top of the map (250 tiles high) to show off the gradient of the sky. Unfortunately, clouds, stars, and platforms are not yet implemented, so the sky is pretty lonely. Still, you can get a glimpse of just how big this world is.</p>
<p><a href="http://muagames.com/2008/10/07/procedural-world-loading-and-rendering/"><em>Click here to view the embedded video.</em></a></p>
<p>After I got this working, I created a tool to generate a small &#8216;world map&#8217; image so I could get (and show) an overview of the world as a whole. It is scaled down from the actual game world by a factor of 1/100, but that still makes it a giant image at 8000&#215;1500 pixels. My first attempt at the code had the world map rendering the 250,000 tiles (!) in just under 3 DAYS. That wouldn&#8217;t do at all, so I jumped in and optimized everything I could and wrote some code to cache the sky gradient and the underground texture. After that and lots of fiddling, I now have it down to about 100 seconds (a respectable 2500 tiles/second).</p>
<p>Here is scaled down version of the world map &#8211; this one is &#8216;only&#8217; 1600&#215;300. Click to open it, or <a href="http://muagames.com/wordpress/wp-content/uploads/2008/10/worldmap.png">follow this link to check out the full map</a>.</p>
<div id="attachment_54" class="wp-caption alignnone" style="width: 310px"><a href="http://muagames.com/wordpress/wp-content/uploads/2008/10/smaller.png"><img src="http://muagames.com/wordpress/wp-content/uploads/2008/10/smaller-300x56.png" alt="Scaled down world map" title="Scaled down world map" width="300" height="56" class="size-thumbnail wp-image-54" /></a><p class="wp-caption-text">Scaled down world map</p></div>
]]></content:encoded>
			<wfw:commentRss>http://muagames.com/2008/10/07/procedural-world-loading-and-rendering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Joust &#8211; It Begins</title>
		<link>http://muagames.com/2008/10/05/joust-it-begins/</link>
		<comments>http://muagames.com/2008/10/05/joust-it-begins/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 09:48:40 +0000</pubDate>
		<dc:creator>Keeyai</dc:creator>
				<category><![CDATA[Bonk]]></category>
		<category><![CDATA[joust]]></category>
		<category><![CDATA[persistent world]]></category>
		<category><![CDATA[procedural]]></category>
		<category><![CDATA[terrain]]></category>

		<guid isPermaLink="false">http://muagames.com/?p=39</guid>
		<description><![CDATA[As I mentioned in my last post, which was incidentally also my first post, we are just starting up a big project based on the old school arcade game joust. We are taking the rider-on-flying-mount and the insta-kill dynamics and expanding upon them to create a large, multiplayer, persistent world. It is a big project [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my last post, which was incidentally also my first post, we are just starting up a big project based on the old school arcade game joust. We are taking the rider-on-flying-mount and the insta-kill dynamics and expanding upon them to create a large, multiplayer, persistent world. It is a big project to be sure, but exciting enough to get a couple people interested in it, which is really the goal.</p>
<p>One of the key features of the game is the large world it takes place in. We (the design team) want a really big world, but I (the one who has to actually do it) certainly don&#8217;t want to hand edit/model the terrain and platforms that would go into creating it. So, in comes step 1/1000 &#8211; <a href="http://en.wikipedia.org/wiki/Procedural_generation">procedural terrain generation</a>. Basically, the goal is to create an algorithm that can be used to automatically create each piece of the world, as broken down into &#8217;tiles&#8217;. To manage memory, we want to only load the tiles surrounding the player&#8217;s current position, so the algorithm needs to be able to get just the tiles we need and render them in real time.</p>
<p>The first thing I did was create a terrain generation algorithm to make simple, smooth ground for a single tile. For this I used a technique called &#8216;midpoint displacement&#8217;. It sounds fancy, but it is actually a very simple algorithm where you simply bisect a line and adjust its middle by a random number over and over until you get terrain. I set it up to seed the random number generator first so I could create exactly the same tile by just passing in the same seed. This also means that it generates <em>different</em> tiles for each new seed. Each tile has a unique location in the world, so by passing that in as the seed, I effectively have a function that will create every tile in the game! Simple, but cool!</p>
<p>I also added in a region dynamic so I can break the world into regions and the tiles within those regions will get created with different parameters. For example, mountain tiles will be generated with more steep cliffs, while plains tiles will be mostly flat.</p>
<p>Behold, some random heightmaps for tiles! The first three were created with exactly the same parameters, but different seed values. Note, these are NOT rendered ground tiles &#8211; this is just a silhouette of the 2D landscape for each tile. The last three are more random tiles, but this time I have tweaked the generation parameters to give much smoother terrain.<br />
</p>
<p>This is great so far, but it is still missing something. At the moment, all the tiles start and end at the same height, which is totally boring and unpractical for the game itself. What we need instead is a way to add variety to all their end points while making sure each tile lines up with the ones on either side of it. I still didn&#8217;t want to do this by hand though, so I decided to just make another algorithm. This one does exactly the same thing, except instead of telling the program where to render land, it tells each tile how high to go when generating terrain.</p>
<p>This controls the shape of the entire world, and since there is only one of them, it is important to pick a good one. To make it easier on myself, I created a little &#8216;world viewer&#8217; program that generates these world maps and displays them along with all the parameters used to create it. It also allows me to zoom in and out to inspect certain areas, change parameters on the fly, and drag the map itself around for better viewing. You can see it in action below:</p>
<p><a href="http://muagames.com/2008/10/05/joust-it-begins/"><em>Click here to view the embedded video.</em></a></p>
<p>Next time: putting the tiles together to create one huge map, then picking regions and texturing the tiles so they look like ground instead of weird lines.</p>
]]></content:encoded>
			<wfw:commentRss>http://muagames.com/2008/10/05/joust-it-begins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

