<?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>South Winds Games :: Blog &#187; Juan Pablo</title>
	<atom:link href="http://www.southwindsgames.com/blog/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.southwindsgames.com/blog</link>
	<description>Casual Games Development</description>
	<lastBuildDate>Sat, 05 Mar 2011 17:32:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Some of our bits &#8230;</title>
		<link>http://www.southwindsgames.com/blog/2011/02/28/some-of-our-bits/</link>
		<comments>http://www.southwindsgames.com/blog/2011/02/28/some-of-our-bits/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 18:54:44 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[C++ Template]]></category>
		<category><![CDATA[Euler Integrator]]></category>
		<category><![CDATA[Simple Integrator Template]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=230</guid>
		<description><![CDATA[Hi!
Today I did some minors changes to our main site (please tell us if there is something wrong  ) and I thought it would be good to add another entry to the blog.
Well, since some time I was thinking about sharing this beautiful piece of code. It is beautiful because of the use we [...]]]></description>
			<content:encoded><![CDATA[<p>Hi!</p>
<p>Today I did some minors changes to our <a href="http://www.southwindsgames.com">main site</a> (<a href="http://southwindsgames.com/contact.php">please tell us if there is something wrong</a> <img src='http://www.southwindsgames.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) and I thought it would be good to add another entry to the blog.<br />
Well, since some time I was thinking about sharing this beautiful piece of code. It is beautiful because of the use we have given to it, we used this tool for almost everything.<br />
<span id="more-230"></span></p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> T, <span style="color: #0000ff;">int</span> N<span style="color: #000080;">&gt;</span> <span style="color: #0000ff;">class</span> IntegratorBase <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T mV<span style="color: #008000;">&#91;</span>N<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T<span style="color: #000040;">&amp;</span> operator<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span>i<span style="color: #000080;">&gt;=</span><span style="color: #0000dd;">0</span> <span style="color: #000040;">&amp;&amp;</span> i<span style="color: #000080;">&lt;</span>N<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #0000ff;">return</span> mV<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> operator<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> i<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> <span style="color: #008000;">&#123;</span> <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span>i<span style="color: #000080;">&gt;=</span><span style="color: #0000dd;">0</span> <span style="color: #000040;">&amp;&amp;</span> i<span style="color: #000080;">&lt;</span>N<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #0000ff;">return</span> mV<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> T<span style="color: #000080;">&gt;</span> <span style="color: #0000ff;">class</span> FirstOrderIntegrator <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> IntegratorBase<span style="color: #000080;">&lt;</span>T,<span style="color: #0000dd;">2</span><span style="color: #000080;">&gt;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FirstOrderIntegrator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FirstOrderIntegrator<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> x, <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> v<span style="color: #008000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> x<span style="color: #008080;">;</span> &nbsp;this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> v<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> t<span style="color: #008000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> t<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> T<span style="color: #000080;">&gt;</span> <span style="color: #0000ff;">class</span> SecondOrderIntegrator <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> IntegratorBase<span style="color: #000080;">&lt;</span>T,<span style="color: #0000dd;">3</span><span style="color: #000080;">&gt;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SecondOrderIntegrator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SecondOrderIntegrator<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> x, <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> v, <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> a<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> x<span style="color: #008080;">;</span> &nbsp;this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> v<span style="color: #008080;">;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> a<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> t<span style="color: #008000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T vt <span style="color: #000080;">=</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> t<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> vt <span style="color: #000040;">*</span> <span style="color:#800080;">0.5f</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> t<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> vt<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666;">// This is a fat one.</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> T<span style="color: #000080;">&gt;</span> <span style="color: #0000ff;">class</span> ThirdOrderIntegrator <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> IntegratorBase<span style="color: #000080;">&lt;</span>T,<span style="color: #0000dd;">4</span><span style="color: #000080;">&gt;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ThirdOrderIntegrator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ThirdOrderIntegrator<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> x, <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> v, <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> a, <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span> w<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> x<span style="color: #008080;">;</span> &nbsp;this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> v<span style="color: #008080;">;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> a<span style="color: #008080;">;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> w<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> t<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T mv3t <span style="color: #000080;">=</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span> t<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T mv2t <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> mv3t <span style="color: #000040;">*</span> <span style="color:#800080;">0.5f</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> t<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> mv3t<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> mv2t <span style="color: #000040;">*</span> <span style="color:#800080;">0.5f</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> t<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>mV<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> mv2t<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></div></div>
<p>It is a template structure for elements that can be integrated over time.<br />
It is Game development related and actually it is not as precise since it uses Euler integration. However, you can modify it to use the integration you want &#8230; and actually, it wouldn&#8217;t be as hard to create a RK4 version of the mechanic.</p>
<p>With this mechanic you will be able to access the derivatives with the index operator []:</p>
<p>X[0] -> The thing you are integrating<br />
X[1] -> First derivative over time<br />
X[2] -> Second derivative over time</p>
<p>Which is really really handy (you won&#8217;t believe me how much).</p>
<p>A tipical usage:</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">struct</span> Particle <span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; FirstOrderIntegrator<span style="color: #000080;">&lt;</span>Vector2f<span style="color: #000080;">&gt;</span> mPosition<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; FirstOrderIntegrator<span style="color: #000080;">&lt;</span>Color4f<span style="color: #000080;">&gt;</span> mColor<span style="color: #008080;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> t<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mPosition.<span style="color: #007788;">Update</span><span style="color: #008000;">&#40;</span>t<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mColor.<span style="color: #007788;">Update</span><span style="color: #008000;">&#40;</span>t<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">void</span> Draw<span style="color: #008000;">&#40;</span> GraphicThing<span style="color: #000040;">&amp;</span> gt <span style="color: #008000;">&#41;</span> &nbsp;<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; gt.<span style="color: #007788;">Draw</span><span style="color: #008000;">&#40;</span> mPosition<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span>, mColor<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">void</span> InvertDirection<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mPosition<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">*</span><span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color:#800080;">1.0f</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></div></div>
<p>You probably know about templates and integrators but haven&#8217;t thought about using them that way &#8230; yeah, there are many situations where this structure cannot help you, but in many cases it will save you to write a lot of code <img src='http://www.southwindsgames.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>See you later!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2011/02/28/some-of-our-bits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Airport Mania 2: Wild Trips</title>
		<link>http://www.southwindsgames.com/blog/2010/12/22/airport-mania-2-wild-trips/</link>
		<comments>http://www.southwindsgames.com/blog/2010/12/22/airport-mania-2-wild-trips/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 16:55:47 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Airport Mania 2]]></category>
		<category><![CDATA[Game Release]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=224</guid>
		<description><![CDATA[Hey!
It&#8217;s finally out  

If you are in the US you can get it at Amazon.
If you are in Canada (or in the US as well) you can get it at Game House.
We are all really happy 
- Juan Pablo
]]></description>
			<content:encoded><![CDATA[<p>Hey!<br />
It&#8217;s finally out <img src='http://www.southwindsgames.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img src="http://www.southwindsgames.com/archives/images/am2_little_box.jpg" alt="Airport Mania 2: Wild Trips" /></p>
<p>If you are in the US you can get it at <a href="http://www.amazon.com/Airport-Mania-Trips-Premium-Download/dp/B004FGN94E">Amazon</a>.</p>
<p>If you are in Canada (or in the US as well) you can get it at <a href="http://www.gamehouse.com/download-games/airport-mania-2-wild-trips-premium-edition">Game House</a>.</p>
<p>We are all really happy <img src='http://www.southwindsgames.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
- Juan Pablo</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2010/12/22/airport-mania-2-wild-trips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inner Quest, our 4th game</title>
		<link>http://www.southwindsgames.com/blog/2010/05/19/inner-quest-our-4th-game/</link>
		<comments>http://www.southwindsgames.com/blog/2010/05/19/inner-quest-our-4th-game/#comments</comments>
		<pubDate>Thu, 20 May 2010 00:34:16 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[South Winds Games]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=210</guid>
		<description><![CDATA[Hi all!
Yeah! our fourth game is here. It is called &#8220;Inner Quest&#8220;, a match-3 game which was created having in mind the best user experience possible. We focused on make it smoother and soft, relaxing and pleasant

A video says more than a 1000 screen shots:


We are getting older, actually getting older is good for a [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all!</p>
<p>Yeah! our fourth game is here. It is called &#8220;<strong>Inner Quest</strong>&#8220;, a match-3 game which was created having in mind the best user experience possible. We focused on make it smoother and soft, relaxing and pleasant</p>
<p><span id="more-210"></span></p>
<p>A video says more than a 1000 screen shots:</p>
<div style="margin:10px; text-align:center; ">
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/CDg8vBJdRns&#038;hl=es&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/CDg8vBJdRns&#038;hl=es&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></div>
<p>We are getting older, actually getting older is good for a company but anyway when I look back I feel some nostalgy (drop a tear).</p>
<p>The road until here was hard, and it seems that the upcoming road is harder, but as long as we can make games and eat every day we will be more than fine!</p>
<p>Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2010/05/19/inner-quest-our-4th-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>We finally changed our look :)</title>
		<link>http://www.southwindsgames.com/blog/2010/04/23/we-finally-changed-our-look/</link>
		<comments>http://www.southwindsgames.com/blog/2010/04/23/we-finally-changed-our-look/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 02:37:16 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[South Winds Games]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=201</guid>
		<description><![CDATA[As we promissed after 2009 new year we finally changed our look  
The work was:

Redesign the logo
Update the graphics in all our games (Dylo&#8217;s Adventure is the only one with the old logo)
Redesign our site (which was the biggest challenger)
Customize the order pages at Plimus (not as easy as it sounds)
Re-skin this blog
Buy new [...]]]></description>
			<content:encoded><![CDATA[<p>As we <a href="http://www.southwindsgames.com/blog/2009/01/01/hello-world/">promissed</a> after 2009 new year we finally changed our look <img src='http://www.southwindsgames.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <span id="more-201"></span><br />
The work was:</p>
<ul>
<li>Redesign the logo</li>
<li>Update the graphics in all our games (Dylo&#8217;s Adventure is the only one with the old logo)</li>
<li>Redesign our <a href="http://www.southwindsgames.com">site</a> (which was the biggest challenger)</li>
<li>Customize the <a href="http://southwindsgames.plimus.com/jsp/buynow.jsp?contractId=1661382">order pages at Plimus</a> (not as easy as it sounds)</li>
<li>Re-skin this blog</li>
<li>Buy new t-shirts with the new logo <img src='http://www.southwindsgames.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<p>Actually this has low priority over many things so it was a challenger to keep working on it with the time passing by.<br />
I&#8217;m really proud of the result <img src='http://www.southwindsgames.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
- Juan Pablo</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2010/04/23/we-finally-changed-our-look/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplz Zoo on Steam!</title>
		<link>http://www.southwindsgames.com/blog/2010/04/05/simplz-zoo-on-steam/</link>
		<comments>http://www.southwindsgames.com/blog/2010/04/05/simplz-zoo-on-steam/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 23:57:34 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=188</guid>
		<description><![CDATA[If you have an account on Steam you can now get Simplz Zoo with some of the Steam features like Achievements and Cloud file system.
Whatch out the free demo and full description here.

]]></description>
			<content:encoded><![CDATA[<p>If you have an account on Steam you can now get Simplz Zoo with some of the Steam features like Achievements and Cloud file system.<br />
Whatch out the free demo and full description <a href="http://store.steampowered.com/app/7470/">here</a>.<br />
<a href="http://store.steampowered.com/app/7470/"><img class="size-full wp-image-192 alignnone" style="border: 0pt none; margin: 5px;" title="Simplz Zoo on Steam" src="http://www.southwindsgames.com/blog/wp-content/uploads/2010/04/simplz_zoo_steam.png" alt="Simplz Zoo on Steam" width="188" height="145" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2010/04/05/simplz-zoo-on-steam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Airport Mania &#8211; Retail</title>
		<link>http://www.southwindsgames.com/blog/2009/12/13/airport-mania-retail/</link>
		<comments>http://www.southwindsgames.com/blog/2009/12/13/airport-mania-retail/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 15:37:09 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[South Winds Games]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=182</guid>
		<description><![CDATA[Hi!
We were (are and will be) very busy because we are working on a new pretty ambitious project: www.simplzzoo.com. We expect it to be here really soon, will talk about it later.
Airport Mania hit Retail!
Just a little picture:

See you!
- Juan Pablo
]]></description>
			<content:encoded><![CDATA[<p>Hi!<br />
We were (are and will be) very busy because we are working on a new pretty ambitious project: www.simplzzoo.com. We expect it to be here really soon, will talk about it later.<br />
Airport Mania hit Retail!<span id="more-182"></span><br />
Just a little picture:<br />
<img src="http://www.southwindsgames.com/archives/Image63.jpg" alt="Airport Mania Retail Version" /></p>
<p>See you!<br />
- Juan Pablo</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2009/12/13/airport-mania-retail/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Traversing an array in random order / Non repetitive Random Number Generator</title>
		<link>http://www.southwindsgames.com/blog/2009/07/20/traversing-an-array-in-random-order-non-repetitive-random-number-generator/</link>
		<comments>http://www.southwindsgames.com/blog/2009/07/20/traversing-an-array-in-random-order-non-repetitive-random-number-generator/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 17:30:38 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[LCG]]></category>
		<category><![CDATA[Linear Congruence Generator]]></category>
		<category><![CDATA[Traversing an array in random order]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=143</guid>
		<description><![CDATA[The problem is simple. You have an array and you want to traverse it in random order. 
There is a trivial solution, to sort the array:
for&#40;int i=N; i&#62;1; --i&#41; 
&#160; &#160; &#160; swap&#40; array&#91; rand&#40;&#41;%i &#93;, array&#91; i-1 &#93; &#41;;
&#8230; but what if you can&#8217;t modify the array and having an array of indexes is [...]]]></description>
			<content:encoded><![CDATA[<p>The problem is simple. You have an array and you want to traverse it in random order. <span id="more-143"></span></p>
<p>There is a trivial solution, to sort the array:</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span>N<span style="color: #008080;">;</span> i<span style="color: #000080;">&gt;</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> <span style="color: #000040;">--</span>i<span style="color: #008000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; swap<span style="color: #008000;">&#40;</span> array<span style="color: #008000;">&#91;</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span>i <span style="color: #008000;">&#93;</span>, array<span style="color: #008000;">&#91;</span> i<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span> <span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></div>
<p>&#8230; but what if you can&#8217;t modify the array and having an array of indexes is too expensive, let&#8217;s say for example that you want to traverse all the pixels of the screen. What you actually need is a non repetitive random number generator which works in linear time. </p>
<p>There is a handy one around, it is called <a href="http://en.wikipedia.org/wiki/Linear_congruence_generator">Linear Congruential Generator</a> (LCG). This is the one most programming languages implement as their default random number generator.</p>
<p>The LCG equation is simple:<br />
<strong>X&#8217; = ( a * X + c) % m</strong><br />
Where <strong>X</strong> is the last generated number, <strong>X&#8217;</strong> is the new one, <strong>a</strong> is an arbitrary constant multiplier, <strong>c</strong> an arbitrary constant increment and <strong>m</strong> is the modulus.<br />
So this function jumps from number to number in a non sequential way, but to have a full period of <strong>m</strong> (to always fall in a different number without repeating it until <strong>m</strong> jumps) some conditions should be met:</p>
<dt>0</dt>
<dd><strong>a</strong> and <strong>c</strong> can be any finite number, positive or negative but it will be the same if they are <strong>0 <= c < m, 0 <= a < m </strong>because of the modulus operation. For <strong>c</strong> it is easy to see it, but let see it for <strong>a</strong>:<br />
Suppose we take a constant <strong>a&#8217;</strong> which is any integer number, and represent it as <strong>a&#8217; = a+m*i</strong> being <strong>a&#8217; = a%m</strong> and <strong>i = a/m</strong> (all in integer arithmetic)<br />
Then <strong>( (a&#8217;+m*i)*X + c ) % m = ( a&#8217;*X + m*i*X + c ) % m</strong><br />
since <strong>(m*i*X) % m = 0</strong> we end up with <strong>( a&#8217; * X + c ) % m</strong><br />
The next conditions are described thinking on <strong>a</strong> and <strong>c</strong> in ranges <strong>[0,m)</strong>.</dd>
<dt>1</dt>
<dd><strong>c</strong> and <strong>m</strong> should be relatively prime (coprime).  This means that they don&#8217;t have any common divisor. Example: 22 = 11*2 and 25 = 5*5. </dd>
<dt>2</dt>
<dd><strong>a-1</strong> should be divisible by all prime factors of <strong>m</strong>. Suppose <strong>m</strong> is 1176 = 2*2*2*3*7*7, <strong>a-1</strong> must be divisible by 2*3*7=42.</dd>
<dt>3</dt>
<dd><strong>a-1</strong> should be multiple of 4 if <strong>m</strong> is multiple of 4 (According to Donald E. Knuth).</dd>
</dl>
<p>The first <strong>X</strong> value can be any number, it will be the <em>seed</em>, after <strong>m</strong> iterations you will end in the same number(mod <strong>m</strong>).</p>
<p>When the LCG reach the initial value it will cycle in the same order it did the first time for ever (from a number X and the same constants you will always jump to the same number).</p>
<p>The quality of the randomness of the LCG is questionable for some critical computations, there are better random number generators, but for most requirements it is more than enough. The most important thing actually is to know what you are doing.<br />
With different constants and seeds we will have different permutations of the numbers in the range <strong>[0,m)</strong>.<br />
Now the next problem is how to pick good constants.</p>
<p>If the size of the array is known in compilation time and only one way of traversing is needed you can simply chose the numbers doing some tests.<br />
Now, if you don&#8217;t have the size of the array in compilation time and/or you need different ways of traversing the array it gets a bit more complicated.</p>
<p>Take into account that you can have an <strong>m</strong> bigger than <strong>N</strong> (the array size), when <strong>X >= N</strong> you can just discard this value in a way similar to:</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">do</span> <span style="color: #008000;">&#123;</span> X <span style="color: #000080;">=</span> LCG<span style="color: #008000;">&#40;</span>X,a,c,m<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span> X <span style="color: #000080;">&gt;=</span> N <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></div>
<p>We can have a table of prime numbers, but figuring out which numbers to pick to either satisfy the coprime property with <strong>c</strong> and to get close to <strong>N</strong> will be a challenge as well &#8230; </p>
<p>Other approach would be to pick <strong>m</strong> to be a power of two:<br />
 &#8211; We can be sure to satisfy the coprime condition just making <strong>c</strong> odd.<br />
 &#8211; We can reduce the modulus operation to a bit mask operation gaining constant speed.<br />
 &#8211; <strong>a</strong> can be calculated with <strong>a = ( ( s*4 )+1) &#038; (m-1)</strong> where <strong>s</strong> is just a random number bigger than 0 and <strong>a-1</strong> is multiple of 4 and divisible by all prime factors of <strong>m</strong> (which is only the number two).</p>
<p>There are two disadvantages about using a power of two as <strong>m</strong> .<br />
 &#8211; First, we can end up with up to the double less one iterations to calculate all the <strong>X</strong>; <strong>N</strong> can be far away from <strong>m</strong><br />
 &#8211; The quality of the random numbers generated is less because of the power of two modulus, the low bits of <strong>X</strong> will vary in a smaller cycle than <strong>m</strong> (this can be compensated with the discard behavior).</p>
<p>With this in mind you can create a templated <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">forward iterator</a> to just traverse any container which accepts <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">random access iterators</a>.</p>
<p>See you,<br />
- Juan Pablo</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2009/07/20/traversing-an-array-in-random-order-non-repetitive-random-number-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful Open Source Libraries</title>
		<link>http://www.southwindsgames.com/blog/2009/03/29/useful-open-source-libraries/</link>
		<comments>http://www.southwindsgames.com/blog/2009/03/29/useful-open-source-libraries/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 20:32:39 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[Legal]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[irrxml]]></category>
		<category><![CDATA[jpeglib]]></category>
		<category><![CDATA[libjpeg]]></category>
		<category><![CDATA[libpng]]></category>
		<category><![CDATA[license]]></category>
		<category><![CDATA[ogg vorvis]]></category>
		<category><![CDATA[open source libraries]]></category>
		<category><![CDATA[theora]]></category>
		<category><![CDATA[zlib]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=104</guid>
		<description><![CDATA[Of course you won&#8217;t program everything from scratch, but there are situations where you can hesitate to create your own libraries or not.
In many cases the work involved and the results you can achieve with your own libraries is enough to satisfy your requirement but in other situations it isn&#8217;t even close.
One of the best [...]]]></description>
			<content:encoded><![CDATA[<p>Of course you won&#8217;t program everything from scratch, but there are situations where you can hesitate to create your own libraries or not.<br />
In many cases the work involved and the results you can achieve with your own libraries is enough to satisfy your requirement but in other situations it isn&#8217;t even close.<br />
One of the best things of programming in C/C++ is that there is plenty of resources of any kind to satisfy a wide variety of needs, usually there is more than one solution for one requirement.<span id="more-104"></span><br />
There are Open Source and Closed Source libraries, and they can be free or paid, maybe free for non commercial projects or under a specific license.<br />
Not all Open Source libraries are free, and even not all the free ones can be used in commercial projects, even more, there are some of them that allows you to dynamically link to your code for commercial use but not to statically link. Some licenses requires you to make the source of your project public. Many licenses as well require you to make public the changes you made to the library so you share any possible improvement.</p>
<p>Here at South Winds Games we use many 3rd party libraries.</p>
<p><a href="http://zlib.net/"><img alt="ZLIB" src="http://zlib.net/images/zlib3d-b1.png" title="ZLIB" width="92" height="51" class="alignleft"  /></a><br />
For compressing and decompressing data we use the <a href="http://zlib.net/ "><strong>ZLIB</strong></a><br />
Zlib is very handy and easy to integrate and it has a <a href="http://zlib.net/zlib_license.html">very permissive license</a>, you can statically link it to your code and you don&#8217;t need to even name them (we prefer to do it). ZLib is fast and well documented, it has been written in C so it has bindings to many languages, it is completely multi-platform. I don&#8217;t thing there is a replacement for it.</p>
<p><a href="http://www.ambiera.com/irrxml/"><img alt="" src="http://www.ambiera.com/irrxml/images/irrxml_titleright.png" title="IrrXML" class="alignright" width="196" height="64" /></a><br />
For reading XML we use <a href="http://www.ambiera.com/irrxml/"><strong>irrXML</strong></a>, we tried many other like <a href="http://www.grinninglizard.com/tinyxml/"><strong>TinyXML</strong></a> and <a href="http://www.xmlsoft.org/"><strong>libxml</strong></a>  bur IrrXML situed best for our requirements.<br />
IrrXML uses the same license of ZLIB. One problem IrrXML has is that it doesn&#8217;t support UTF-8 despite it says it does, but it works perfectly with all the other encodings.<br />
IrrXML doesn&#8217;t provides a tool to write xml files, so we coded our own. If you were looking for a tool to write XML in UTF8 format (the only format it supports) here you can grab ours: <a href='http://www.southwindsgames.com/blog/wp-content/uploads/2009/03/xmlwriter.zip'>xmlwriter</a> (it has a zlib license as well). IrrXML is a C++ library and I guess it is only supported in C++, it works on Mac OS X on Intel and PowerPC computers as well as Windows, it should work on Linux as well.</p>
<p><a href="http://www.libpng.org/pub/png/libpng.html"><img alt="libpng" class="alignleft" src="http://www.libpng.org/pub/png/img_png/libpng.png" title="libpng" width="91" height="41" /></a><br />
To read PNG graphic files we use <a href="http://www.libpng.org/pub/png/libpng.html"><strong>libpng</strong></a>. The libpng library internally uses the zlib so you should take this into account to only have one instance of the zlib in your linking process. The libpng is distributed with the the zlib license and there are plenty of bindings for many languages as it has been written in C. It is updated regularly.</p>
<p><a href="http://www.ijg.org/"><img alt="" src="http://fmorg.sourceforge.net/pics/jpeglib.jpg" title="jpeglib" class="alignright" width="88" height="31" /></a><br />
We also use the <a href="http://www.ijg.org/">jpeglib</a> which allow us to read JPEG graphic files. This library was last updated in 1998 but it seems that it isn&#8217;t a problem.<br />
This library has a different license which require you to add this line in a part of your software documentation (the readme would be the best place).</p>
<blockquote><p>&#8220;this software is based in part on the work of the Independent JPEG Group&#8221;.</p></blockquote>
<p>Also the lib has been written in C and it shouldn&#8217;t take too much work to bind it to other languages.</p>
<p><a href="http://www.xiph.org/"><img alt="" src="http://www.xiph.org/images/logos/fish_xiph_org.png" title="xiph" class="alignleft" width="245" height="61" /></a><br />
From the xiph open source community we use two very important libraries and archive formats, both related to media, one for sound and other for video.</p>
<p><a href="http://www.xiph.org/downloads"><img src="http://www.southwindsgames.com/blog/wp-content/uploads/2009/03/images.jpg" alt="ogg vorbis" title="ogg vorbis" width="131" height="87" class="alignright size-full wp-image-122" /></a><br />
For sound we use the <a href="http://www.vorbis.com/">Ogg-Vorbis</a> royalty free format. The quality obtained with the ogg format is head to head with the mp3&#8217;s one and if you use the famous <strong>mp3</strong> format you <strong>must pay royalties</strong>, both are very similar one is free, the decision is easy.</p>
<p><a href="http://www.xiph.org/downloads"><img src="http://www.southwindsgames.com/blog/wp-content/uploads/2009/03/images2.jpg" alt="Theora" title="Theora" width="129" height="86" class="alignleft size-full wp-image-126" /></a><br />
For video playback we had the non reliable CODEC problem: You can use the operative system services to stream video, you have directshow on windows or the Windows Video Api and QuickTime on MacOs X but unfortunately Windows only had very bad codecs installed by default. Other option is to include the codecs on the download, but as well many of them require royalties, so we opted for the multi-platform royalty free way of doing the things. Theora is not hardware accelerated so it uses the CPU to decode the video which is not a fast process, but it is well optimized to run smoothly on a Pentium III 750 mhz (our low-end testing machine).</p>
<p>Both libraries are written in C and well <a href="http://www.xiph.org/doc/">documented</a>, there are bindings to many languages for them.<br />
Both libraries use the BSD license which is a variation of the MIT license. This allow you to close the code and use it on commercial projects, but you must include somewhere in your software documentation the copyright license included in the library.</p>
<p>We recommend you to <strong>read all the licenses of all the libraries you are using</strong>, some libraries aren&#8217;t as permissive and some others may require you to mention them or show in your software the copyright message attached to the library.</p>
<p>- Juan Pablo</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2009/03/29/useful-open-source-libraries/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Best of Casual Gameplay 2008 &#8211; Airport Mania</title>
		<link>http://www.southwindsgames.com/blog/2009/01/29/best-of-casual-gameplay-2008-airport-mania/</link>
		<comments>http://www.southwindsgames.com/blog/2009/01/29/best-of-casual-gameplay-2008-airport-mania/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 03:06:14 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[South Winds Games]]></category>
		<category><![CDATA[Airport Mania]]></category>
		<category><![CDATA[Best of casual gameplay 2008 - time managment]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=65</guid>
		<description><![CDATA[
Jayisgames.com (a very important game news and reviews site) has just published the results of its annual Best of the year, and it was a really nice surprise to find Airport Mania as the winner in the Time Management category.

The article describes why it was chosen capturing the essence of the game in a very [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="Airport Mania - Best of 2008" src="http://jayisgames.com/images/bestof2008-award.png" title="Airport Mania - Best of 2008" width="65" height="70" class="alignright" /><br />
<em>Jayisgames.com</em> (a very important game news and reviews site) has just published the results of its annual <em>Best of the year</em>, and it was a really nice surprise to find <strong>Airport Mania</strong> as the <strong>winner</strong> in the Time Management category.<br />
<span id="more-65"></span><br />
The article describes why it was chosen capturing the essence of the game in a very faithful way.</p>
<p>You may want to read the full article:<br />
<a href="http://jayisgames.com/best-of/2008/download/time-management-or-simulation/">Nominations</a><br />
<a href="http://jayisgames.com/best-of/2008/download/time-management-or-simulation-results/">And the winner is &#8230;</a></p>
<p>Have a happy day as me <img src='http://www.southwindsgames.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
- Juan Pablo</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2009/01/29/best-of-casual-gameplay-2008-airport-mania/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fast Integer Log2 function in C/C++</title>
		<link>http://www.southwindsgames.com/blog/2009/01/19/fast-integer-log2-function-in-cc/</link>
		<comments>http://www.southwindsgames.com/blog/2009/01/19/fast-integer-log2-function-in-cc/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 03:14:14 +0000</pubDate>
		<dc:creator>Juan Pablo</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[log2]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[optimized]]></category>

		<guid isPermaLink="false">http://www.southwindsgames.com/blog/?p=48</guid>
		<description><![CDATA[Some times, it happens that you need to have a high performance function that you usually use in a not optimized way. And since you never needed to optimize it you hesitated before realising it can be severly improved. Probably, this is what you would think of the integer log2 function, in general this function [...]]]></description>
			<content:encoded><![CDATA[<p>Some times, it happens that you need to have a high performance function that you usually use in a not optimized way. And since you never needed to optimize it you hesitated before realising it can be severly improved. Probably, this is what you would think of the integer log2 function, in general this function is used on not critic code so it can be &#8220;slow&#8221; without creating any problem (often used to calculate the size of a power of 2 texture to hold an image)<span id="more-48"></span></p>
<p>The usual way of calculating this log2 function is testing until the base elevated to the log is bigger than the value. This is easy with the << operator.<br />
This function returns the <strong>truncated to the integer unit log2 of value</strong>:</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">inline</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> iLog2<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> value<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> l <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span>value <span style="color: #000080;">&gt;&gt;</span> l<span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">++</span>l<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> l<span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Easy, isn&#8217;t it? And it is quite fast! you will do 8 comparations to return the log2 of 256.<br />
But what if we do a binary search instead of this linear search &#8230;</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">inline</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> Log2<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> value<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> f<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span>, s<span style="color: #000080;">=</span><span style="color: #0000dd;">32</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span>s<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; s<span style="color: #000080;">&gt;&gt;=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> value <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">1</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #008000;">&#40;</span>f<span style="color: #000040;">+</span>s<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> f<span style="color: #000040;">+</span><span style="color: #000080;">=</span>s<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> f<span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Even faster since we will be doing a fixed number of comparations.<br />
And so, if they are fixed &#8230;</p>
<div class="codecolorer-container cpp mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">inline</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> ilog2<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">register</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> x<span style="color: #008000;">&#41;</span> <br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">register</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> l<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>x <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">1</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #0000dd;">16</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> x<span style="color: #000080;">&gt;&gt;=</span><span style="color: #0000dd;">16</span><span style="color: #008080;">;</span> l<span style="color: #000040;">|</span><span style="color: #000080;">=</span><span style="color: #0000dd;">16</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>x <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">1</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #0000dd;">8</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> x<span style="color: #000080;">&gt;&gt;=</span><span style="color: #0000dd;">8</span><span style="color: #008080;">;</span> l<span style="color: #000040;">|</span><span style="color: #000080;">=</span><span style="color: #0000dd;">8</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>x <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">1</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> x<span style="color: #000080;">&gt;&gt;=</span><span style="color: #0000dd;">4</span><span style="color: #008080;">;</span> l<span style="color: #000040;">|</span><span style="color: #000080;">=</span><span style="color: #0000dd;">4</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>x <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">1</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> x<span style="color: #000080;">&gt;&gt;=</span><span style="color: #0000dd;">2</span><span style="color: #008080;">;</span> l<span style="color: #000040;">|</span><span style="color: #000080;">=</span><span style="color: #0000dd;">2</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>x <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">1</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> l<span style="color: #000040;">|</span><span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> l<span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>You can hardcode the answers and the bit settings, and this one compiles really well!<br />
If you want to go further you can expand the <em>if</em>s to 32 branches with 32 results, and so you will collapse the search time to the minimal (I cannot think on something better), but it is up to you if you want to go further. As well this function can be bounded with template arguments, but I don&#8217;t think this will ever pay off.</p>
<p>Probably you won&#8217;t find this function useful (except if you are here because you were looking for it), but in any case I liked this function so much and I wanted to share it because it shows us that even the most every day used things can be improved, refined, and can be prepared for different contexts. <strong>It isn&#8217;t all invented, you can keep discovering and creating</strong> <img src='http://www.southwindsgames.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>- Juan Pablo</p>
]]></content:encoded>
			<wfw:commentRss>http://www.southwindsgames.com/blog/2009/01/19/fast-integer-log2-function-in-cc/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

