<?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>VectorStorm Blog &#187; Engine</title>
	<atom:link href="http://www.vectorstorm.org/category/vectorstorm/engine/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vectorstorm.org</link>
	<description>Creating games, one brightly glowing line at a time.</description>
	<lastBuildDate>Sun, 29 Jan 2012 08:25:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Profiling is fun</title>
		<link>http://www.vectorstorm.org/2011/10/09/profiling-is-fun/</link>
		<comments>http://www.vectorstorm.org/2011/10/09/profiling-is-fun/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 08:02:21 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2269</guid>
		<description><![CDATA[Actually, that&#8217;s a dirty lie. Profiling is fun when it shows you something big that&#8217;s easy to fix.  Profiling is a lot less fun when everything is equally slow.  But luckily in my case, there was something big to fix.  :) I noticed the other day that editing roads in MMORPG Tycoon 2 had become [...]]]></description>
			<content:encoded><![CDATA[<p>Actually, that&#8217;s a dirty lie.</p>
<p>Profiling is fun when it shows you something big that&#8217;s easy to fix.  Profiling is a lot less fun when everything is equally slow.  But luckily in my case, there was something big to fix.  :)</p>
<p>I noticed the other day that editing roads in MMORPG Tycoon 2 had become extremely slow.  (Well.. actually I noticed that roads didn&#8217;t draw at all.  It was only after I fixed them not drawing that I noticed that they were slow to edit).   This was odd, because I have videos of early road editing, where it hardly touched the frame rate at all on a system much slower than the one I&#8217;m using now.  So after some profiling, I found that creating their procedural geometry was taking up about 75% of the whole processing time for the frame when they were created.  This was extremely bad when editing them, especially (because they&#8217;re regenerated every frame, when they&#8217;re being edited, or when the ground under them is being edited).</p>
<p>Those of you who were at Freeplay will remember the part of my talk where I discussed optimising games, and when to do it (or rather, when not to do it).</p>
<p>For those who weren&#8217;t there, the tl;dr version is this:  don&#8217;t optimise anything unless you have timing numbers that proves it&#8217;s slow relative to the rest of your program, and against which you&#8217;ll be able to judge your progress.  Ideally, you get these numbers by using a profiler of some sort.  (Visual Studio has one built in, modern Xcode uses Instruments while old Xcode used Shark, under Linux you have gperf, etc)</p>
<p>What I didn&#8217;t say in that talk (and which I&#8217;ve regretted ever since), is that there&#8217;s a second criteria which can make it acceptable to optimise some code, even if you don&#8217;t have performance numbers.  Here is that other criteria:</p>
<p><span id="more-2269"></span></p>
<h1>Monte Carlo Profiling</h1>
<ol>
<li>Make a build of your game with optimisations turned on (a &#8220;release&#8221; build, or &#8220;retail&#8221; build, or &#8220;dist&#8221; build, or whatever you call it), but with debugging symbols still present.</li>
<li>Run this build through your debugger of choice.</li>
<li>At any time of your own choosing, pause the execution of the game, and examine the call stack shown in your debugger.</li>
<li>Repeat step 3 nine more times (for a total of ten pauses and ten callstacks).</li>
<li>If in seven of the ten total times you paused the game you were in the same area of code, then you may spend time optimising that area of code, even without first profiling it.</li>
</ol>
<p>The Monte Carlo test is basically very quick and ad hoc profiling.  Profiling does exactly this same process, but instead of doing it ten times, it does it millions of times, far faster than you&#8217;re able to do it manually.  It avoids having to go to the bother of setting up proper profiling, and will still point out anything that&#8217;s extremely slow in your code.</p>
<p>But back to my story.  In my case, I did do real profiling.  Here&#8217;s what it looked like in Instruments:</p>
<p><a href="http://www.vectorstorm.org/wp-content/uploads/2011/10/InstrumentsScreenSnapz002.jpg"><img class="aligncenter size-full wp-image-2271" title="InstrumentsScreenSnapz002" src="http://www.vectorstorm.org/wp-content/uploads/2011/10/InstrumentsScreenSnapz002.jpg" alt="" width="815" height="583" /></a><a href="http://www.vectorstorm.org/wp-content/uploads/2011/10/InstrumentsScreenSnapz002.jpg"><br />
</a><a href="http://www.vectorstorm.org/wp-content/uploads/2011/10/InstrumentsScreenSnapz001.jpg"><br />
</a>That graph is of CPU usage.  (Also, it totally breaks the site frame layout, but I don&#8217;t care.  I want you to see the details.  :) )  The spike at the start is the game starting up (and generating all the world geometry all at once).  The low part in the middle is just me looking around a bit, and then the heavy bit that I have highlighted is me editing a road &#8212; just dragging one of its endpoints around the map at random.</p>
<p>As you can see from the screenshot, it&#8217;s spending about 30% of the frame time in vsMeshMaker::BakeTriangleVertex, 20% of its time in vsFloor (called from vsMeshMaker::BakeTriangleVertex), 16% of the frame time in vsVector2D::SqLength() (also called from vsMeshMaker::BakeTriangleVertex)&#8230;  you get the idea.  Add it all up, and we were spending about 75% of our CPU time inside BakeTriangleVertex.  That BakeTriangleVertex function was really, really heavy for some reason, and I needed to figure out why.</p>
<p>Basically what vsMeshMaker::BakeTriangleVertex does is to look at all the triangle vertices in a procedurally generated model, and to decide (one at a time) whether they should be merged with other nearby vertices to make a smoothly curving surface.  The hardest part of this is actually finding other nearby vertices.  Previously, I had sped this up by dividing up space into grid squares, and storing each vertex into the appropriate grid space.  Then when I wanted to know about nearby vertices, I only had to check the other vertices in the same grid space, not every other vertices in the model.</p>
<p>But as it turns out, those grid spaces were too large, especially for large objects like roads, and so I was still comparing far too many vertices for merging.  So I increased the number of grid spaces (and made each grid space smaller, so there would be fewer vertices to test in each), so that instead of having an 8x8x8 grid and needing to test every vertex in those large squares, we have a 32x32x32 grid and only need to test every vertex in much smaller squares.  I had also noticed that very simple functions like vsFloor and vsVector3D::SqLength() were showing up in the profiling, and so made those functions inline, to hopefully reduce the cost of calling them.  This led to this graph:</p>
<p><a href="http://www.vectorstorm.org/wp-content/uploads/2011/10/InstrumentsScreenSnapz003.jpg"><img class="aligncenter size-full wp-image-2272" title="InstrumentsScreenSnapz003" src="http://www.vectorstorm.org/wp-content/uploads/2011/10/InstrumentsScreenSnapz003.jpg" alt="" width="815" height="583" /></a></p>
<p>This one is fascinating.  Notice that the amount of CPU being used has dropped substantially, compared to the previous one.  Also note that functions like &#8220;vsFloor&#8221; and &#8220;vsVector3D::SqLength&#8221; have vanished, since I made them inline (they&#8217;re now included in the caller&#8217;s time).  Increasing the resolution of my vertex lookup grid had sped things up a lot &#8212; we&#8217;re down from 75% of our frame time, down to an average of 40% of our frame time (and made a huge improvement to the frame rate).  But here&#8217;s the interesting thing that I hadn&#8217;t noticed previously:</p>
<p>Look at that graph, how it increases over time.  I wasn&#8217;t doing anything unusual in-game, just rapidly dragging one end of the road back and forth over a single area of terrain.  But the more time I spent editing the road, the slower editing became.  This eventually pointed me to a bug in my code, where some of the merging work from previous frames was being left-over to do again on all subsequent frames, even though it didn&#8217;t accomplish anything on the new frames.  So I fixed that bug, and profiled again:</p>
<p><a href="http://www.vectorstorm.org/wp-content/uploads/2011/10/InstrumentsScreenSnapz004.jpg"><img class="aligncenter size-full wp-image-2273" title="InstrumentsScreenSnapz004" src="http://www.vectorstorm.org/wp-content/uploads/2011/10/InstrumentsScreenSnapz004.jpg" alt="" width="626" height="481" /></a></p>
<p>Great!  Getting rid of that leftover repeated work brought us down from 40% frame time (on average, during a long editing session) to about 2.6% frame time, low enough that you don&#8217;t even notice a frame rate hit in-game.</p>
<p>The problem now was that my grid was so fine, that it actually uses a lot of memory.  A 32x32x32 grid has about 32,000 spaces in it, and each of those needed storage to hold an arbitrary number of vertices.  And I had one of these for every road (and indeed, every building, tree, etc).  That builds up fast!  And while 2.6% is low enough to be acceptable, I would have liked it to be even lower.  Let&#8217;s face it, my placeholder &#8220;road&#8221; model is ridiculously simple.  I&#8217;d really like this code to be much faster than it is now, to handle the much more detailed meshes that I&#8217;ll be throwing at it later.</p>
<p>So I set out to replace the grid with a new structure:  an octree.  For those who are interested, this implementation has been ported back into the main VectorStorm trunk, as VS_PointOctree.h, inside the VS/Utils/ directory.  It&#8217;s basically a tree structure which expands as more data is added to it, so it should behave far more predictably than the grid structure.  What&#8217;s more, it expands as data is added, instead of being a fixed (huge) size, which means that smaller models use much less space, exactly as you&#8217;d hope.  Profiling isn&#8217;t much different (down to about 2%), but memory usage is drastically lower.  So I call that a win.  And in future, I may return to this code to see if I can&#8217;t whittle it down even a little further, once it starts moving up into a prime spot in the profiling again.</p>
<p>I&#8217;ve also been doing other stuff recently, but I reckon that this blog post is enough of a novel already, so I&#8217;ll save the other stuff for tomorrow.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2011/10/09/profiling-is-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multithreading</title>
		<link>http://www.vectorstorm.org/2011/08/04/multithreading/</link>
		<comments>http://www.vectorstorm.org/2011/08/04/multithreading/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 14:55:29 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2156</guid>
		<description><![CDATA[Just a couple quick notes today, because I really ought to be sleeping instead of posting. Today, MMORPG Tycoon 2 has finally become a multithreaded game.  It&#8217;s not ubiquitous by any means, but it&#8217;s taken the first step;  the ground clutter is now being generated in a background thread.  The only bit of clutter-related code [...]]]></description>
			<content:encoded><![CDATA[<p>Just a couple quick notes today, because I really ought to be sleeping instead of posting.</p>
<p>Today, MMORPG Tycoon 2 has finally become a multithreaded game.  It&#8217;s not ubiquitous by any means, but it&#8217;s taken the first step;  the ground clutter is now being generated in a background thread.  The only bit of clutter-related code which is now occurring in the main thread is copying the final geometry into the buffer that OpenGL renders from.  Now all the setup work as you move around the map is being handled in separate threads.</p>
<p>This means a couple of things.  For one, it means that MMORPG Tycoon 2 can finally use a little more of the CPU time from everyone with a multi-core computer (which is just about everyone with a computer from the last six years or so), and it also means that as more tasks can be moved out into other threads, I&#8217;ll be able to do more and more processing without hurting the game&#8217;s frame rate.</p>
<p>I&#8217;ll also note that Mac OS X&#8217;s support for semaphores is half-broken, and Win32&#8242;s support for semaphores is bizarre and generally unrelated to traditional semaphores.  Makes me a sad coder.  (for the non-coders in the audience:  semaphores are a tool for synchronising multiple threads, to help keep them from stepping on each other&#8217;s toes)</p>
<p>More details tomorrow.  Or later today, I guess, technically.  And semaphores will eventually be ported back into the VectorStorm trunk, if anyone wants to look at them.  Also fixed some bugs in the vsTask class, and added features to the vsMutex.  Will need to move all those changes back to the live trunk in the near future.  Maybe over the weekend.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2011/08/04/multithreading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimisations</title>
		<link>http://www.vectorstorm.org/2011/04/23/optimisations/</link>
		<comments>http://www.vectorstorm.org/2011/04/23/optimisations/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 10:40:57 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=1973</guid>
		<description><![CDATA[So here&#8217;s a fun one for you all.  I mentioned that I had achieved some speed boosts for rendering based upon insights from gDEBugger.  On the basis of that, I&#8217;ve been setting up some more intelligent rendering code which doesn&#8217;t tell OpenGL to do something that it was already doing. In brief, what was happening [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2011/04/MMORPG-Tycoon-2ScreenSnapz001.jpg"><img class="alignnone size-medium wp-image-1974" title="MMORPG Tycoon 2ScreenSnapz001" src="http://www.vectorstorm.org/wp-content/uploads/2011/04/MMORPG-Tycoon-2ScreenSnapz001-300x173.jpg" alt="" width="300" height="173" /></a>So here&#8217;s a fun one for you all.  I mentioned that I had achieved some speed boosts for rendering based upon insights from gDEBugger.  On the basis of that, I&#8217;ve been setting up some more intelligent rendering code which doesn&#8217;t tell OpenGL to do something that it was already doing.</p>
<p>In brief, what was happening before was that MT2 (and all VectorStorm games) would render every object in the scene one at a time, setting up OpenGL to render that object individually (&#8220;Turn fog on.  Turn lighting on.  Turn zbuffer on, turn writing into color channels on, turn glow effect off, etc.&#8221;), even though 95% of those settings were the same on every object in the scene.</p>
<p>Now what happens is that each object registers those state changes onto a new object (the &#8220;vsRendererState&#8221;), and immediately before rendering, all those queued state changes are made.  Previously if (for example) the first object in a scene is using a texture and the second object is also using a texture, I&#8217;d be telling OpenGL &#8220;okay, turn on texture support&#8221;, render the first object, then &#8220;turn off texture support now&#8221;, and then &#8220;okay, turn on texture support again&#8221; before rendering the second object.  Now, it leaves texture support on until it actually starts rendering an object which isn&#8217;t using a texture;  it only changes the settings which are actually changing, instead of just naively setting everything.</p>
<p>Note that to make this work, I had to remove compiled display list support.  There&#8217;s simply no good way to keep track of OpenGL&#8217;s internal state when compiled display lists are being used.  But compiled display lists were really replaced by VBOs long ago, so this shouldn&#8217;t cause concern.  It&#8217;s similar to when I removed CPU-side shaders, and overlays.  Old technologies which have been superceded by faster, better ones.  :)</p>
<p>The screenshot today is what happens when there&#8217;s a bug in the code (in this case, not applying rendering state changes before performing post-render effects).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2011/04/23/optimisations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Yet more little updates</title>
		<link>http://www.vectorstorm.org/2011/04/18/more-little-updates-2/</link>
		<comments>http://www.vectorstorm.org/2011/04/18/more-little-updates-2/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 12:23:57 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=1969</guid>
		<description><![CDATA[The Windows version of the new VectorStorm multithreading code is now in place and working, and in the live trunk.  (Has been for about week, now;  I apparently forgot to post about it!) I&#8217;ve also been playing a bit with gDEBugger, an OpenGL profiler/analyser/etc, which is now free (was previously quite expensive to license).  It&#8217;s nowhere [...]]]></description>
			<content:encoded><![CDATA[<p>The Windows version of the new VectorStorm multithreading code is now in place and working, and in the live trunk.  (Has been for about week, now;  I apparently forgot to post about it!)</p>
<p>I&#8217;ve also been playing a bit with <a href="http://www.gremedy.com/" onclick="pageTracker._trackPageview('/outgoing/www.gremedy.com/?referer=');">gDEBugger</a>, an OpenGL profiler/analyser/etc, which is now free (was previously quite expensive to license).  It&#8217;s nowhere near <a href="http://en.wikipedia.org/wiki/PIX_(Microsoft)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/PIX_Microsoft?referer=');">PIX</a> in terms of power and insight, but it&#8217;s as close as we have under OpenGL at the moment.  And you can&#8217;t argue with the price.  And it works on all the major platforms, which is pretty awesome to see.  I&#8217;ve already made some sizeable rendering speed boosts for VectorStorm just on the basis of its insights into MMORPG Tycoon 2, and will have more in the near future.  Once I have these mostly sorted out, I&#8217;ll port them back into trunk as well.</p>
<p>This tool has also pointed out that lots of the techniques VectorStorm&#8217;s core rendering architecture use have been declared obsolete as of OpenGL 3.1.  Which surprised me, since I kind of designed VectorStorm for OpenGL 1.4 (which was the most that my ancient laptop could handle at the time);  I really didn&#8217;t think that the interfaces I was using would last all the way up to 3.1!  But it does suggest that someday I should be thinking about looking forward to the more modern revisions of OpenGL;  purging some of my old rendering architecture, and replacing it with more modern approaches.  That won&#8217;t be until after MT2, though, unless MT2 really calls for some modern rendering techniques.  (I&#8217;d really like to have some basic shadows.  But otherwise, I&#8217;m not too fussed over fancy rendering techniques for MT2).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2011/04/18/more-little-updates-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More little updates</title>
		<link>http://www.vectorstorm.org/2011/03/29/more-little-updates/</link>
		<comments>http://www.vectorstorm.org/2011/03/29/more-little-updates/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 12:22:49 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=1963</guid>
		<description><![CDATA[A bunch of little technical updates today. First, I&#8217;ve updated the VectorStorm engine so that it&#8217;ll compile successfully against iOS SDK v4.3.  I&#8217;ve also got both the standard VectorStorm Testbeds and MMORPG Tycoon 2 compiling under the newly released XCode 4.  My opinion of XCode 4 is complicated;  I can understand the general outcry from [...]]]></description>
			<content:encoded><![CDATA[<p>A bunch of little technical updates today.</p>
<p>First, I&#8217;ve updated the VectorStorm engine so that it&#8217;ll compile successfully against iOS SDK v4.3.  I&#8217;ve also got both the standard VectorStorm Testbeds and MMORPG Tycoon 2 compiling under the newly released XCode 4.  My opinion of XCode 4 is complicated;  I can understand the general outcry from many developers, but there&#8217;s lots of cool stuff in there too.  Whether the cool stuff outweighs the concerns, I&#8217;m not really sure.  But for the next couple of days, I&#8217;ll be using XCode 4 as my day-in day-out compiler to see how well I adapt.</p>
<p>Second, I&#8217;ve begun implementing some threading primitives into VectorStorm.  These are not yet compiling under Windows (since Microsoft has an entirely different threading model than UNIX-based systems), but I do now have both mutexes and threads working under OS X.  I&#8217;ll get the Windows version working tomorrow.  These little tools are going to be critical for MMORPG Tycoon 2, due to the amount of processing that it has to do;  it&#8217;s just going to be a lot easier to put some of that work into a separate thread.</p>
<p>Do be aware, though, that none of the rest of VectorStorm is written to be threadsafe.  These multithreading classes should really only be used for simple tasks that don&#8217;t involve calling into the various VectorStorm libraries at all.  If you have lots of calculations to be done in the background, then that&#8217;s fine.  But probably best not to try to allocate memory or start playing sounds from inside a thread or anything.  :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2011/03/29/more-little-updates/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>VectorStorm library update</title>
		<link>http://www.vectorstorm.org/2011/03/24/vectorstorm-library-update/</link>
		<comments>http://www.vectorstorm.org/2011/03/24/vectorstorm-library-update/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 11:51:06 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=1960</guid>
		<description><![CDATA[For the first time since getting my new job, I&#8217;ve finally sat down and written a little code on my home projects.  It&#8217;s not too much, but it felt pretty good to write it. I&#8217;ve fixed the VectorStorm engine bug which was causing problems with the middle mouse button and right mouse buttons (often swapping [...]]]></description>
			<content:encoded><![CDATA[<p>For the first time since getting my new job, I&#8217;ve finally sat down and written a little code on my home projects.  It&#8217;s not too much, but it felt pretty good to write it.</p>
<p>I&#8217;ve fixed the VectorStorm engine bug which was causing problems with the middle mouse button and right mouse buttons (often swapping the two, or causing them not to work at all).  It was an embarrassing mistake;  I had just mis-assigned labels for the controls, causing some minor swapping when loading saved control preferences.  I&#8217;ve made this bug fix both within MMORPG Tycoon 2 (where it was a major problem), and within the trunk VectorStorm library (where it was less of a problem, since no standard VectorStorm games were using mouse control).  If any of you have been looking at or using the VectorStorm library, you should go get those fixes.  If not, don&#8217;t worry about it too much, just be aware that I&#8217;m back to the compiler again.  :)</p>
<p>I&#8217;ve also begun poking with Tycoon code again.  Not a whole lot;  am just slowly easing myself back into it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2011/03/24/vectorstorm-library-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some bugfixes to VectorStorm</title>
		<link>http://www.vectorstorm.org/2011/01/04/some-bugfixes-to-vectorstorm/</link>
		<comments>http://www.vectorstorm.org/2011/01/04/some-bugfixes-to-vectorstorm/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 04:43:44 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=1889</guid>
		<description><![CDATA[I have no idea what this image is. I&#8217;ve made a bunch of little tweaks to the VectorStorm engine today.  Most notably: When doing a scene update, the camera now updates last, instead of first.  Previously, the camera would pick where to be before the game had a chance to take any actions, which usually [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2011/01/Image.jpg"><img class="alignnone size-medium wp-image-1890" title="Image" src="http://www.vectorstorm.org/wp-content/uploads/2011/01/Image-300x190.jpg" alt="" width="300" height="190" /></a>I have no idea what this image is.</p>
<p>I&#8217;ve made a bunch of little tweaks to the VectorStorm engine today.  Most notably:</p>
<p>When doing a scene update, the camera now updates <em>last</em>, instead of first.  Previously, the camera would pick where to be before the game had a chance to take any actions, which usually led to the game camera lagging one frame behind whatever it was supposed to be following.  (Of course, now you&#8217;ll have the opposite problem;  the game will no longer be able to tell where the camera is, since it won&#8217;t have moved into position until after the game finishes its update)  In practice, the real solution is for the game itself to take responsibility for updating the camera whenever is appropriate for that game.  But as a default, having the camera update last is usually less-bad than having it update first.  So I&#8217;ve changed it.</p>
<p>I noticed that vsFont wasn&#8217;t applying text colors to strings which were justified as &#8220;centered&#8221; or &#8220;right&#8221;;  they were always coming through as pure white.  This is now fixed, in current trunk.</p>
<p>I also added another &#8220;primitive&#8221; function for creating renderable textured rectangles (as vsFragments that can be attached to a vsSprite or vsModel), this time supporting tiled textures.  You can specify how big the tiles should be, and can optionally specify a rotation for the texture.  Check for <tt><strong>vsMakeTiledTexturedBox2D()</strong></tt> in VS_Primitive.h, for that.</p>
<p>I&#8217;ve also been poking with the bloom effect again;  I noticed that the trunk version looks pretty ugly at large screen sizes.  I think I have it balanced nicely again, but haven&#8217;t committed these changes to the public repository yet;  probably later tonight or tomorrow, once I&#8217;m certain that performance is still okay.</p>
<p>Finally, I&#8217;ve just finished scaling down the Asteroids testbed game.  It&#8217;s been misbehaving ever since I converted it over to Box2D, because its objects were moving too fast for Box2D to cope with.  So I&#8217;ve reduced everything by a factor of ten, and now things are moving at a reasonable speed again.  I&#8217;ll be checking that in a bit later on as well.  Oddly, I&#8217;m still occasionally having shots bounce off of asteroids, without receiving a collision callback.  Mind you, I&#8217;m using an ancient version of Box2D;  maybe I should update that someday.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2011/01/04/some-bugfixes-to-vectorstorm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multitouch</title>
		<link>http://www.vectorstorm.org/2010/11/19/multitouch/</link>
		<comments>http://www.vectorstorm.org/2010/11/19/multitouch/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 13:48:16 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[General life]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=1755</guid>
		<description><![CDATA[Today I set up Multitouch gestures for iPhone/iPad. Again, this photo is using exactly the same graphics as the past few days, just now you can use multitouch gestures to zoom and rotate the interface.  (Most of my time went into the zooming.  Surprisingly difficult to get the maths right for that, in this case.) [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2010/11/Multitouch.jpg"><img class="alignnone size-medium wp-image-1756" title="Multitouch" src="http://www.vectorstorm.org/wp-content/uploads/2010/11/Multitouch-224x300.jpg" alt="" width="224" height="300" /></a>Today I set up Multitouch gestures for iPhone/iPad.</p>
<p>Again, this photo is using exactly the same graphics as the past few days, just now you can use multitouch gestures to zoom and rotate the interface.  (Most of my time went into the zooming.  Surprisingly difficult to get the maths right for that, in this case.)</p>
<p>It feels.. surprisingly natural.  I didn&#8217;t think it&#8217;d feel this good to move an object around on the screen this way.  There&#8217;s probably a bestselling game just in that interaction, if you could figure out a way to wrap a game around it (and if somebody else hasn&#8217;t already done it.  I&#8217;m sure someone has).  I&#8217;m not sure exactly what game you could wrap around this interaction, but it does feel really, really nice.</p>
<p>Right now, VectorStorm supports only two simultaneous touch events.  But now that I have two working, it&#8217;d be really easy to add up to about ten.  But in this case, I only need two for the pinch/zoom interface.  So I&#8217;ll probably make do with what&#8217;s in there now.</p>
<p>Tomorrow, I may take a stab at sound support.  Or more likely, I&#8217;ll spend time on the game code itself, again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2010/11/19/multitouch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Further dull development</title>
		<link>http://www.vectorstorm.org/2010/09/14/further-dull-development/</link>
		<comments>http://www.vectorstorm.org/2010/09/14/further-dull-development/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 11:58:37 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=1526</guid>
		<description><![CDATA[Oddly enough, these dry bits of engine development are often the most exciting to me, since they open up all sorts of exciting new possibilities, and make development substantially easier in the future. I&#8217;ve been doing further development on the &#8220;automatic save/load&#8221; system that I&#8217;ve talked about before;  the system which automatically handles loading and [...]]]></description>
			<content:encoded><![CDATA[<p>Oddly enough, these dry bits of engine development are often the most exciting to me, since they open up all sorts of exciting new possibilities, and make development substantially easier in the future.</p>
<p>I&#8217;ve been doing further development on the &#8220;automatic save/load&#8221; system that I&#8217;ve talked about before;  the system which automatically handles loading and saving of game data, without me having to write custom code for everything the way that I did back in previous games.  For comparison, in MMORPG Tycoon 1, nearly half of my total development time went into the save/load functionality &#8212; it&#8217;s extremely complicated, and extremely bug-prone, so anything that I can do to make the saving/loading process easier and safer is going to be a huge win, overall!</p>
<p>This &#8220;how do we load and save large amounts of data&#8221; issue, incidentally, is one that professional game development teams everywhere have struggled with forever, and I&#8217;ve seen a lot of different solutions to it.  But I&#8217;ve gotta say, this solution I&#8217;ve been working on is by far the best that I&#8217;ve ever seen within the C++ language;  it imposes few restrictions on the code I write, and can just automatically figure out how to save files out based upon inspecting the saveable variables I expose within each class.</p>
<p>What I&#8217;ve done today is to make this system recursive.  That is, you can now have an object which contains other objects, which contain other objects.  Or to give a more concrete example:</p>
<p>In MMORPG Tycoon 2, there&#8217;s an object for each of a character class&#8217;s abilities.  So if he has three different types of attack, that&#8217;s three code objects which store information about how much damage those types of attack do, etc.  Those three ability objects are stored inside another object, an &#8220;Ability Set&#8221;, which lists all the abilities available to one character class.</p>
<p>With this new stuff I&#8217;ve written today, it&#8217;s now possible for me to simply call &#8220;AbilitySet-&gt;Save(&#8220;Filename&#8221;)&#8221;, and have the AbilitySet save itself out, plus all of the Abilities which are inside of it, into a single neat data file.  Similarly, &#8220;AbilitySet-&gt;Load(&#8220;Filename&#8221;)&#8221; loads that data file from disk, recreating the AbilitySet object itself and all of the abilities that it should contain.  This is all typesafe &#8212; the AbilitySet can only contain objects of &#8220;Ability&#8221; type (or derived from that type), and no typecasting is required at any point during the process.</p>
<p>Of course, the next step is going to be to have the CharacterClassPrototype have an AbilitySet inside itself, so that when I load a class prototype from disk, it automatically loads the abilityset, and the abilityset&#8217;s contents.  And then a ClassManager will be set to contain ClassPrototypes, so that when I save the ClassManager, it automatically saves out all of the class prototypes inside it, and so forth and so on.  Eventually, everything in the game should be included within this data hierarchy, so a single call to &#8220;Save()&#8221; or &#8220;Load()&#8221; at the top level will be able to automatically handle saving or loading the complete game state, all from a single line of code.</p>
<p>So I&#8217;m pleased.  :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2010/09/14/further-dull-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Major rendering restructure</title>
		<link>http://www.vectorstorm.org/2010/09/05/major-rendering-restructure/</link>
		<comments>http://www.vectorstorm.org/2010/09/05/major-rendering-restructure/#comments</comments>
		<pubDate>Sun, 05 Sep 2010 09:38:24 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=1508</guid>
		<description><![CDATA[Today I spent the whole day doing just one thing:  a major restructuring of VectorStorm&#8217;s rendering architecture.  This is, without a doubt, the biggest change to how rendering works in VectorStorm since I first wrote it. What you&#8217;re looking at in this screenshot is a not-yet-activated starting point, being rendered as a glowing outline, behind [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2010/09/RendererRevamp.jpg"><img class="alignnone size-medium wp-image-1510" title="RendererRevamp" src="http://www.vectorstorm.org/wp-content/uploads/2010/09/RendererRevamp-300x193.jpg" alt="" width="300" height="193" /></a>Today I spent the whole day doing just one thing:  a major restructuring of VectorStorm&#8217;s rendering architecture.  This is, without a doubt, the biggest change to how rendering works in VectorStorm since I first wrote it.</p>
<p>What you&#8217;re looking at in this screenshot is a not-yet-activated starting point, being rendered as a glowing outline, behind a tree.  Anyone who&#8217;s played with the MS1 build of Tycoon2 will know that one of the big rendering problems that it had was that glowing objects would often glow through opaque objects that were in front of them.  As you can see, this is no longer the case.  VectorStorm now automatically ensures that objects are drawn in the correct order, so you won&#8217;t incorrectly see obscured glowing effects.</p>
<p>To do this, I had to <em>(warning:  the rest of this post contains dangerously boring technical details)</em> change how VectorStorm renders.</p>
<p>Originally, VectorStorm was designed for rendering simple 2D vector graphic games.  As such, it was designed with a system of &#8220;layers&#8221;.  Your game could configure how many layers it wanted to use, and register sprites or other objects onto any layer you liked.  Within each layer, objects were drawn in order, with later objects (or later layers) drawn on top of previous layers.  With vector graphics, since you only had additive lines and no solid objects, the whole issue of which line was on top really didn&#8217;t matter;  the layers were really used just for putting objects under different cameras.  For example, in The Muncher&#8217;s Labyrinth, the game world was in one layer, and the HUD was in a different layer, just so the two could be rendered using different cameras and I didn&#8217;t need to worry about moving the HUD around to match the camera.  When I added solid rendering for ThunderStorm, the layers worked really well to ensure that some objects would always draw in front of other objects.</p>
<p>Each renderable object would have a &#8220;Draw()&#8221; function called on it, being given a pointer to a display list to which it could append its own rendering commands.  This was (in my own opinion) simple and elegant, and it was great for a while.</p>
<p>But now that VectorStorm is rendering in 3D, layers don&#8217;t really make sense any more.  We still have them, but in 3D we have a z buffer which automatically lets the closest object be drawn, regardless of whether it was drawn first or last, so it&#8217;s usually no longer important to manage which objects are drawn first or last, except for in special circumstances (glow effects, transparency, etc).</p>
<p>But the real problem is that we now often have objects which have different drawing styles within a single object.  For example, the cursor in MT2 (and MT1, for that matter) is made up of two parts;  a dark background, and a glowing outline.  Under the &#8220;just add your commands to this display list&#8221; approach, each object has to render all of its geometry at once.  This meant that I couldn&#8217;t (for example) draw the background portion of the cursor early, and the glowing part later on;  they&#8217;d both always render at the same time.</p>
<p>Another possible issue is that of rendering partially transparent objects.  These see-through objects are always a problem with modern 3D games, since z-buffers can&#8217;t be used to render them (z-buffers assume that everything is opaque, and so won&#8217;t allow you to draw anything behind a pane of glass, for example, if you draw the glass first).  The traditional way to handle these translucent objects is to sort them from back to front, then draw them in that order, after you&#8217;ve drawn all the non-translucent objects.  But with the simple-and-elegant way that I was handling drawing of objects, there was no way to sort the objects into any different order than they were already in.</p>
<p>Anyhow, enough of the problem statement.  :)</p>
<p>What I&#8217;ve changed is that renderable objects in VectorStorm are no longer given a pointer to the game&#8217;s vsDisplayList when it&#8217;s time for them to render.  Instead, they&#8217;re now given a vsRenderQueue object.  On that vsRenderQueue, they can provide their rendering instructions in one of several ways, and the vsRenderQueue can then reorder the drawing as required, to make sure that (for example) the glowing and transparent parts of objects are drawn last, while their opaque portions can still be drawn earlier.</p>
<p>The other change is that vsLayer is now completely gone.  Instead, we now have vsScenes, which work very much like vsLayers did;  they&#8217;re just collections of renderable objects.  Like before, your game can have any number of vsScenes, and they&#8217;re rendered in order.  Right now, they share a single z-buffer and render target between them all, but setting it up so that the different scenes can have separate renders is certainly possible in the future, if I ever need that feature.</p>
<p>You can probably tell by how I&#8217;m gushing, but I&#8217;m absolutely thrilled and relieved to have this all working at last.  Lots of stuff in MT2 (particularly the very old code) is currently working via a &#8220;compatibility&#8221; mode that I&#8217;ve put in the vsRenderQueue, and I do still need to convert those bits of code over to using the new systems instead.  But this change has illuminated a whole bunch of unreliable rendering code that was lurking in the GUI systems until now, and the stricter system should keep me from writing terrible code again in the future.</p>
<p>Right now, these changes are only in my MT2 development branch &#8212; they haven&#8217;t been propagated back into trunk, largely because I&#8217;d probably have to make a lot of big adjustments to the testbed apps to make them render under the new systems, and I&#8217;m feeling like taking a bit of a rest, after this ten-hour coding session.  But I&#8217;ll update trunk sometime in the foreseeable future, and will post about it when I do.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2010/09/05/major-rendering-restructure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

