<?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>Rui Figueira's Blog</title>
	<atom:link href="http://www.crazygaze.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.crazygaze.com/blog</link>
	<description>Knowing is not enough; we must apply. Willing is not enough; we must do.</description>
	<lastBuildDate>Fri, 24 Sep 2010 16:22:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Cutscene using squirrel scripting</title>
		<link>http://www.crazygaze.com/blog/2010/09/24/cutscene-using-squirrel-scripting/</link>
		<comments>http://www.crazygaze.com/blog/2010/09/24/cutscene-using-squirrel-scripting/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 16:20:19 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[squirrel]]></category>
		<category><![CDATA[Weston Westie]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/?p=181</guid>
		<description><![CDATA[The last 2 weeks or so, I’ve been working on an update for Weston Westie, and one of the things coming out with the update is cutscenes. I’ve been integrating Squirrel Scripting into the engine, as I thought would make things easier if I used a scripting language. After the initial painful process of making [...]]]></description>
			<content:encoded><![CDATA[<p>The last 2 weeks or so, I’ve been working on an update for Weston Westie, and one of the things coming out with the update is cutscenes.     <br />I’ve been integrating Squirrel Scripting into the engine, as I thought would make things easier if I used a scripting language.     <br />After the initial painful process of making it work on Samsung Wave, creating some bindings between C++ and Squirrel, things started to pick up.     <br />In Weston Westie, cutscenes are mostly a series of still images, playing some sounds, some fading out/in, the occasional moving background, etc.     <br />Using coroutines, the cutscene scripting is done in a serial way, unaware of the game loop.     </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:dd24aca2-9b4b-4fb9-a7ef-b869a90fef87" class="wlWriterEditableSmartContent">
<div><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/zVnSWbLgtIA&amp;hl=en"></param><embed src="http://www.youtube.com/v/zVnSWbLgtIA&amp;hl=en" type="application/x-shockwave-flash" width="425" height="355"></embed></object></div>
<div style="width:425px;clear:both;font-size:.8em">One of the simple cutscenes I’ve done so far.</div>
</div>
<p>The scripting for this particular scene goes kind of like this (simplified version)…</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:bf2e1757-0f6c-4107-8c69-2e46e3c7e0f6" class="wlWriterEditableSmartContent">
<pre>
<pre class="brush: cpp; pad-line-numbers: true;">
function SailAway()
{
	// Load needed resources...
	local imgDash = resourcemanager.Get(ResourceType.IMAGE, &quot;Sequences_Debut_Dash&quot;);
	local imgWestonOnFire = resourcemanager.Get(ResourceType.IMAGE, &quot;Sequences_Debut_WestonOnFire&quot;);
	local imgEnd1Shore = resourcemanager.Get(ResourceType.IMAGE, &quot;Sequences_End1Shore&quot;);
	local sngDetermination = resourcemanager.Get(ResourceType.SOUND, &quot;Determination&quot;);
	// ...

	// Create a UI Scene to use
	local scene = CUIScene.Create();
	scene.Activate();

	// Create two widgets to display a background, and a front image
	local back = CWidget.Create(scene.GetRootWidget());
	local front = CWidget.Create(scene.GetRootWidget());

	// Setup the images
	back.SetBackgroundImage(imgWestonOnFire, CColour4.WHITE);
	front.SetBackgroundImage(imgDash, CColour4.WHITE);

	// Setup background and foreground images movement using some helper classes
	// ...

	//
	// First part - Weston appearing, with the &quot;fire&quot; background
	//

	// play introduction song as weston appears
	local sngH = soundmanager.Play(sngDetermination, false);
	TickFor(2.0); // animate everything for 2 seconds
	// starts a fade out on the song, that takes 4 seconds
	soundmanager.SetFade(sngH, 0, 4.0);
	TickFor(1.0); // animate for 1.0

	//
	// Second part - weston surprised
	//

	// Show weston surprised at shore
	front.SetBackgroundImage(imgEnd1Shore, CColour4.WHITE);
	// Play &quot;surprised&quot; sound
	soundmanager.Play(sndWhat, false);
	TickFor(1.0);

	// .. and the list goes on, serially showing images,
	// playing sounds, fading, etc

}
</pre>
</pre>
</div>
<p>My engine doesn’t have any specific support for cutscenes, or fancy editors, so each cutscene is basically handcoded.<br />
  <br />I do have some utility code to automate a fade in/ou, or move an image around for example. </p>
<p>I use mostly C++, so I’m used to strongly typed languages. Using a scripting language like squirrel is a bit painful at start, as the compiler isn’t much of a help catching mistakes. On the other hand, it does force you to pay more attention on what you’re doing. </p>
<p>Overall, I’m happy with squirrel. The library is relatively small, and with a bit of effort you can find your way around. </p>
<p>In the future I’ll probably try some other scripting languages, particularly Lua, since it’s so widespread in the games industry, or AngelScript, which is not that widespread, but has a nice feature set and it’s closer to C++. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2010/09/24/cutscene-using-squirrel-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Music Disk</title>
		<link>http://www.crazygaze.com/blog/2010/09/18/music-disk/</link>
		<comments>http://www.crazygaze.com/blog/2010/09/18/music-disk/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 21:21:54 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[demoscene]]></category>
		<category><![CDATA[Music Disk]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/?p=149</guid>
		<description><![CDATA[Some time ago (2007 I think), I mentioned that czPlayer has origins in an old sound system I coded for a Music Disk, back in 1998. I managed to find a zip file with that same Music Disk, and wrap it with DOSBox, so that anyone can take a look, as it wouldn’t run in [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago (2007 I think), I mentioned that <a href="http://www.crazygaze.com/blog/czplayer/">czPlayer</a> has origins in an old sound system I coded for a Music Disk, back in 1998.    <br />I managed to find a zip file with that same Music Disk, and wrap it with <a href="http://www.dosbox.com/" target="_blank">DOSBox</a>, so that anyone can take a look, as it wouldn’t run in modern PCs.</p>
<p>You can <strong><a href="http://www.crazygaze.com/downloads/misc/PH5_5.zip">download it here</a></strong>.    <br />Just unpack to a folder, and run the “<strong>LaunchPH5_5</strong>” batch script. It will automatically launch PH5.5 running inside DOSBox.    </p>
<p>I coded pretty much everything apart from a really nice graphics library I got from a book, and most of the work was done during 1998 Summer holidays. Some of the awesome features (in 1997-1998 at least):</p>
<ul>
<li>Runs in VGA VESA mode, 800&#215;600, with support for Linear Frame Buffer. (Sounds like Chinese to you? If not, then you’re getting old)</li>
<li>Optimized 256 colour palette.</li>
<li>Coded in good old Watcom C++ for DOS, and runs in protected mode (uses PMODE/W)</li>
<li>The sound system itself was quite nice, support a couple of things not commonly found:</li>
<ul>
<li>Critical mixing functions coded in hand optimized assembly</li>
<li>Support from SB Mono to SB 16.</li>
<li>Support for Gravis Ultrasound, both hardware mixing, or software mixing, to work around the hardware voices limitation.</li>
<li>Mono, Stereo, 8 and 16 bits support</li>
<li>Fixed point mixing</li>
<li>Quite decent Impulse Tracker format support</li>
</ul>
</ul>
<p>The art was done by a friend of mine.   <br />Music was done by that same friend, and a friend of his, whom I never met, using Impulse Tracker.    <br />Two of the songs were mine, but not as good as the other ones, since after all I was the coder!</p>
<p>Just look at these awesome screen shots!   <br />Keep in mind that’s from 1998, using a <strong>800&#215;600 8bits</strong> display mode</p>
<h3>Sound Setup Screen</h3>
<p>Coded in ASCII mode. Look at those amazing shadows <img style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/wlEmoticonsmile.png" /></p>
<p><a href="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_002.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="ph5_5_002" border="0" alt="ph5_5_002" src="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_002_thumb.png" width="800" height="500" /></a></p>
<p>&#160;</p>
<h3>Start-up screen</h3>
<p>The awesome start-up screen, calculating some really useful lookup tables.   <br />Also, note the <strong>800&#215;600</strong> video mode, at <strong>8 bits</strong>. Live wasn’t easy.</p>
<p><a href="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_003.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="ph5_5_003" border="0" alt="ph5_5_003" src="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_003_thumb.png" width="804" height="504" /></a></p>
<h3>
<p>User Interface (Trance Zone)</h3>
<p>The UI was divided in two zones   <br />The background art was indeed nice. The way everything fits on top is a bit crude without antialiasing, because with just 256 colours, it was a limited palette to choose from.    <br />The spheres with the song names were faded in and out in a cycle.    </p>
<p>     <a href="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_004.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="ph5_5_004" border="0" alt="ph5_5_004" src="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_004_thumb.png" width="804" height="604" /></a><br />
<h3><font style="font-weight: normal"></font></h3>
<h3>Trip-Hop Zone</h3>
<p>And the other zone, which we could scroll to. It had a complete different set of colours, which didn’t help. Both zone colours came from the same 256 colour palette.</p>
<p><a href="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_011.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="ph5_5_011" border="0" alt="ph5_5_011" src="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_011_thumb.png" width="804" height="604" /></a></p>
<h3>Some options</h3>
<p>I had some options for sound and the graphics. Turning off interpolation would only have an effect if using software mixing of course.</p>
<p><a href="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_018.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="ph5_5_018" border="0" alt="ph5_5_018" src="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_018_thumb.png" width="804" height="604" /></a></p>
<h3>Credits</h3>
<p>Notice the transparency of the dialog box. As all the other screenshots, still using the same colour palette.</p>
<p><a href="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_020.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="ph5_5_020" border="0" alt="ph5_5_020" src="http://www.crazygaze.com/blog/wp-content/uploads/2010/09/ph5_5_020_thumb.png" width="804" height="604" /></a></p>
<p>&#160;</p>
<h3>Conclusion</h3>
<p>That was the first project I started, finished, and released.    <br />Also, the first project using the original czPlayer. The current version still has a bit of that code, but most of it has been refactored.    <br />It’s an interesting experience to look at code I wrote &gt;12 years ago, with a complete coding style.    <br />Was an interesting thing to work on. I remember sitting down with my friend to discuss details and take a look at each other’s work.    <br />Also, I remember a particular day I was brainstorming about display modes, and If I could go for 16bits/24bits mode, which would look a lot nicer, but would require a lot more CPU at that time.    </p>
<p>These were the specs of the computer I used for coding:</p>
<ul>
<li>Pentium 233 MMX</li>
<li>32 MB</li>
<li>About 20 MB of Hard Drive space, for code and assets</li>
<li>SB16 clone, and a GUS sound cards</li>
<li>Cirrus Logic Laguna 5464 PCI graphics card     </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2010/09/18/music-disk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Going freelance again</title>
		<link>http://www.crazygaze.com/blog/2010/08/31/going-freelance-again/</link>
		<comments>http://www.crazygaze.com/blog/2010/08/31/going-freelance-again/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 20:13:20 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Freelance]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/?p=123</guid>
		<description><![CDATA[After all that&#8217;s been happening at Realtime Worlds, I&#8217;ve decided to give another stab at going freelance for a while. I&#8217;ve been pondering it for a while, but faced with the recent events (APB&#8217;s lackluster sales, Realtime Worlds going into administration), I&#8217;ve pretty much decided that&#8217;s the way to go, at least for a while. [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">After all that&#8217;s been happening at <a title="Realtime Worlds" href="http://www.realtimeworlds.com" target="_blank">Realtime Worlds</a>, I&#8217;ve decided to give another stab at going freelance for a while.</div>
<div>
<div>I&#8217;ve been pondering it for a while, but faced with the recent events (APB&#8217;s lackluster sales, Realtime Worlds going into administration), I&#8217;ve pretty much decided that&#8217;s the way to go, at least for a while.</div>
<div>Main reason is that I&#8217;m pretty much done with APB. I do love the game, and at this moment I have &gt;200hours, but on a job perspective it doesn&#8217;t offer me the satisfaction it used to, like when I was designing and implementing the Music Studio sound system, or designing and implementing the sound prioritization we have on top of Wwise.</div>
<div>Also, I want to gain more experience in other areas (other than Audio).</div>
<div>With the hiring spree that happened here in Dundee after the news about Realtime Worlds, I did had to turn down a few interviews with some interesting Studios, but I feel it was the right thing to do.</div>
<div>I want to step back a little and decide where to go from here, instead of rushing to another job.</div>
<div>Like for example, I did enjoyed working on my lastest hobby project <a title="Weston Westie" href="http://www.samsungapps.com/topApps/topAppsDetail.as?productId=G00000066270" target="_blank">Weston Westie</a>, developed with my friend and CEO at <a title="BitRabbit" href="http://www.bitrabbit.net/" target="_blank">BitRabbit</a>, for the brand new Samsung Wave, which is the first device with the Bada OS.</div>
<div>I did all the coding myself, except for the thin framework BitRabbit provided ( <a title="RabbitFactory" href="http://www.bitrabbit.net/article.php?news=48&amp;cat=29" target="_blank">RabbitFactory</a> ) which abstracts all the platform details, and was a nice way to play around with things I normally don&#8217;t, like OpenGL ES, basic AI, UI, Gameplay, etc.</div>
<div>Although Weston Westie was launched in July, we&#8217;ve done basically no marketing, as we want to polish it for the first update (improve textures, put some eye candy, experiment with a different control method).</div>
<div>At this moment, I have some work lined up with Jenkins Software, whom I&#8217;ve worked with in the past.</div>
<div>I get to work from home (like I did before), which is nice bonus. <img src='http://www.crazygaze.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
<div>The job itself is to revise,update and improve RakNet&#8217;s documentation.</div>
<div>This particular contract doesn&#8217;t actually involve much coding, and some programmers at heart might find it dead boring, but personally I see it as great opportunity to get paid to learn something valuable.</div>
<div>Positive things I see coming out of this:</div>
<div>
<ul>
<li>With the high demand for multiplayer games, knowing RakNet library inside out will surely stand out on my CV. I can always say&#8230; &#8220;After all I wrote the documentation. <img src='http://www.crazygaze.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> &#8221;</li>
<li>I get to practice actual writting, since English is not my native language. I think it&#8217;s ok, but there&#8217;s always room for improvement.</li>
<li>Working from home does have some benefits. I can work any time I want, as long as the job gets done. That helps when I need to so something within typical business hours.</li>
<li>With the knowledge I&#8217;ll get from RakNet, I can write some Raknet code samples, and post them here, generating traffic.</li>
</ul>
</div>
</div>
<div>
<p>On top of all this, since I&#8217;ve decided to go freelance, some funny synchronicities happened recently.</p>
<ul>
<li>Bitrabbit might have some more freelance coming up my way</li>
<li> Today went to a workshop for videogames startups, and some interesting things happened:
<ul>
<li>Lots of good tips on running a business, PR, Marketing, etc</li>
<li>Some old friend from Realtime Worls is planning a startup, and since we&#8217;re both planning on staying in Dundee, some work might come my way.</li>
<li>One other friend was there, and reminded me to join him and a few other developers for an apparently weekly Wednesday talk (in a local pub), which I knew about, but never actually attended.</li>
</ul>
</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2010/08/31/going-freelance-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plans for the next version of czPlayer</title>
		<link>http://www.crazygaze.com/blog/2009/11/29/plans-for-the-next-version-of-czplayer/</link>
		<comments>http://www.crazygaze.com/blog/2009/11/29/plans-for-the-next-version-of-czplayer/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 23:15:42 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[czPlayer]]></category>
		<category><![CDATA[sound system]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/2009/11/29/plans-for-the-next-version-of-czplayer/</guid>
		<description><![CDATA[Been in Scotland for near 2 years already, working at RealtimeWorlds, more specifically in a game called APB. Times does fly when we&#8217;re having fun! Meanwhile, I did work a bit in czPlayer, but nothing really new. Mostly bugfixes or small features for a client. So despite not having any updates here in the blog, [...]]]></description>
			<content:encoded><![CDATA[<div>Been in Scotland for near 2 years already, working at RealtimeWorlds, more specifically in a game called <strong>APB</strong>.</div>
<div>Times does fly when we&#8217;re having fun!</div>
<div>Meanwhile, I did work a bit in czPlayer, but nothing really new. Mostly bugfixes or small features for a client.</div>
<div>So despite not having any updates here in the blog, the following things happened to czPlayer</div>
<div>- Some games using czPlayer were release</div>
<div>- A client added iPhone support. Was as simple as creating a single class with about 160 lines of code.</div>
<div>- Implemented volume ramping, which helps a great deal in removing clicks, especially for chiptunes</div>
<div>- Added some other small features, again with minor effort. <img src='http://www.crazygaze.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
<div>- Fixed some bugs, especially related to Symbian.</div>
<div>Also, apart from czPlayer, I managed to squeeze in some other small freelance work.</div>
<div>The last few months I&#8217;ve been thinking where to go next with czPlayer, and I&#8217;ve decided to go with a new design.</div>
<div>Personally, I think the current design is really good performance-wise, minimizing copying memory around unnecessary or other unnecessary overhead.</div>
<div>For example, internally a <em>Mixer</em> object contains <em>MixerInputGroup</em> objects, and each <em>MixerInputGroup</em> contains individual <em>MixerInput </em>objects. Each of those classes have a <em>SetVolume</em> method, which allows me to have several levels of volume (aka as Global volume and channel volume) which get multiplied to calculate a final volume to apply in a single mixing pass, avoiding the need to mix at the <em>MixerInputGroup</em> level, and then again at the <em>Mixer</em> level.</div>
<div>Although the current design has proven successful, it does have severe limitations in flexibility, has for example not being able to apply an <span style="color: #000000;">hypothetically</span> effect to a single sound or sound group. It&#8217;s only possible to apply an effect to the final mix.</div>
<div>So I decided to go with a new design which should be more flexible, but I&#8217;ll still use the old codebase as reference, especially because of the small fixes/features I&#8217;ve implemented meanwhile.</div>
<div>Some of the new features I&#8217;m planning:</div>
<div>- DSP plugins. Will probably provide just 1 or two as an example.</div>
<div>- Configurable DSP network. This will make it possible to create a custom DSP network and play sounds in specific point in the network.</div>
<div>- Streaming support. Only Ogg Vorgis planned so far, but should pave the way for other formats</div>
<div>- Maybe virtual voices (ala FMOD style), if I get the time.</div>
<div></div>
<div>Again, those features shouldn&#8217;t add significant overhead until used, of course.</div>
<div></div>
<div>If the user  sticks with the default settings, performance should hopefully be comparable to the current version.</div>
<div>I&#8217;ll be dropping support for old Symbian editions (&lt; 3rd edition), which should make some things easier.</div>
<div>I wish I could drop Palm OS, which is a real pain to develop for, but a particular client still requires it.</div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2009/11/29/plans-for-the-next-version-of-czplayer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>czPlayer 0.2.1 Released</title>
		<link>http://www.crazygaze.com/blog/2008/03/01/czplayer-021-released/</link>
		<comments>http://www.crazygaze.com/blog/2008/03/01/czplayer-021-released/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 02:00:39 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[czPlayer]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/archives/44</guid>
		<description><![CDATA[Here I am again. Almost 2 months and here it is a new version. No new fancy features or big changes. Basically, I&#8217;ve just added support for loading WAV files encoded with ADPCM (IMA and Microsoft ADPCM supported). I&#8217;ve been so quiet for a reason&#8230; Last 2 months I&#8217;ve been looking for a new position [...]]]></description>
			<content:encoded><![CDATA[<p>Here I am again.<br />
Almost 2 months and here it is a new version.<br />
No new fancy features or big changes. Basically, I&#8217;ve just  added support for loading WAV files encoded with ADPCM (IMA and Microsoft ADPCM  supported).</p>
<p>I&#8217;ve been so quiet for a reason&#8230;<br />
Last 2 months I&#8217;ve been  looking for a new position in the games industry, and finally got one in  Scotland-Dundee.</p>
<p>You can download the new version here :<br />
<a href="http://www.crazygaze.com/blog/czplayer"> Download lastest czPlayer demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2008/03/01/czplayer-021-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Highly customizable C++ template String class</title>
		<link>http://www.crazygaze.com/blog/2008/01/30/highly-customizable-c-template-string-class/</link>
		<comments>http://www.crazygaze.com/blog/2008/01/30/highly-customizable-c-template-string-class/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 03:39:48 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[string class]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/archives/43</guid>
		<description><![CDATA[In my last contract, we used CEGUI for the User Interface. The String class provided and used by CEGUI uses an internal array as quick buffer for small strings, and reverts to the heap when the data doesn&#8217;t fit that quick buffer. That approach increases performance if the quick buffer is big enough to hold [...]]]></description>
			<content:encoded><![CDATA[<p> In my last contract, we used CEGUI for the User Interface. The String class provided and used by CEGUI uses an internal array as quick buffer for small strings, and reverts to the heap when the data doesn&#8217;t fit that quick buffer.<br />
That approach increases performance if the quick buffer is big enough to hold most of your string operations.</p>
<p>However it lacks some features:</p>
<ul>
<li>The quick buffer size is hard-coded in the class, instead of template-based.</li>
<li>When reverting to heap based, it doesn&#8217;t use any mechanisms to minimize allocations/ deallocations, like for example (Reference counting and Copy-On-Write)</li>
</ul>
<p>Since I&#8217;m starting a new hobby project (my own small game engine), to test ideas and learn some new things, the first thing I&#8217;m coding is my own String class, which I&#8217;m also using as an exercise to test some more advanced templates stuff, instead of the classical <em>&#8220;container of values of type T&#8221;</em>.</p>
<p>So&#8230; about my String class.</p>
<p>Features:</p>
<ul>
<li>Completely template based, using policies like described in the book <em>Modern C++</em>. This allows for a great deal of customization.</li>
<li>Using policies, it supports multiple types of string storage. Currently it support 2 storage types:
<ul>
<li>Heap based with reference counting and Copy-On-Write, to delay memory allocations/deallocations as much as possible.</li>
<li>Quick buffer based (like CEGUI), but with fallback to Heap based  like described above when the data doesn&#8217;t fit the quick buffer. Also, the quick buffer size itself is a template parameter, so we set the size based on the use we have in mind.</li>
</ul>
</li>
<li>We can mix strings declared with different policies (the ones provided), and internally it will still try to minimize memory allocations/deallocations, by using reference counting and Copy-On-Write when possible.</li>
<li>We can specify our own Allocator for heap based strings</li>
<li>Basic methods for manipulations. I need to implement a lot more.</li>
</ul>
<p>Missing/Todo:</p>
<ul>
<li>More methods for manipulations (make it more compatible with the std::string)</li>
<li>Unicode support. I&#8217;ve laid down the bases for that, but currently only works with <em>char</em> type</li>
</ul>
<p>When coding it, I&#8217;ve used <em>CppUnite2</em> for the tests. See this link for more information (<a href="http://www.gamesfromwithin.com/articles/0512/000103.html">Games from Within: CppUnitLite2 1.1</a>).</p>
<p>I haven&#8217;t used this String class in a complex product yet, only in the tests during development, so I can&#8217;t talk about performance or bugs yet.</p>
<p>If you want to check it out, download it below:</p>
<p>NOTE: I&#8217;ve only tested it with Visual Studio 2005 (with sp1), so the provided project files are for that same compiler.</p>
<p><a href="http://www.crazygaze.com/downloads/misc/czstring.zip">czString Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2008/01/30/highly-customizable-c-template-string-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Possible downtime of the site</title>
		<link>http://www.crazygaze.com/blog/2008/01/25/possible-downtime-of-the-site/</link>
		<comments>http://www.crazygaze.com/blog/2008/01/25/possible-downtime-of-the-site/#comments</comments>
		<pubDate>Fri, 25 Jan 2008 16:41:20 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/archives/42</guid>
		<description><![CDATA[My Web Hosting provider is upgrading their servers sometime during the next days (between 25-28 January), so this website will probably be down for ~1hour! That is, if everything goes right. If you&#8217;re one of the employers I had/will have interviews with, and you&#8217;re reading this, I really hope the site won&#8217;t offline for too [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">My Web Hosting provider is upgrading their servers sometime during the next days (between 25-28 January), so this website will probably be down for ~1hour! That is, if everything goes right.</p>
<p class="MsoNormal">If you&#8217;re one of the employers I had/will have interviews with, and you&#8217;re reading this, I really hope the site won&#8217;t offline for too long.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2008/01/25/possible-downtime-of-the-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>czPlayer 0.2.0 released</title>
		<link>http://www.crazygaze.com/blog/2008/01/07/czplayer-020-released/</link>
		<comments>http://www.crazygaze.com/blog/2008/01/07/czplayer-020-released/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 09:49:25 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[czPlayer]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/archives/41</guid>
		<description><![CDATA[I&#8217;ve been working hard on czPlayer, and here is the result. Version 0.2.0 released. The API is mostly incompatible with the previous 0.1.1 version. I&#8217;ve made a lot of changes to this version and added some new features, so I decided to jump the version number to 0.2.0. All the internal refactoring I&#8217;ve made will [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working hard on <a href="http://www.crazygaze.com/blog/czplayer">czPlayer</a>, and here is the result. Version 0.2.0 released.<br />
The API is mostly incompatible with the previous 0.1.1 version.<br />
I&#8217;ve made a lot of changes to this version and added some new features, so I decided to jump the version number to 0.2.0.<br />
All the internal refactoring I&#8217;ve made will hopefully allow me to add some new features I have in mind, like DSP effects (both internal and user provided) .<br />
Needless to say, I&#8217;m not particularly confident about the stability of this version, with all the changes I&#8217;ve made. Some functions were not even tested yet. But like I said in earlier posts, there is always something to fix or improve, so I better release and work from there, than to keep fixing/improving stuff and never release.<br />
I have so many crazy ideas for features! But most of them will not be implemented, because of the targeted platforms.<br />
Codesize and performance have priority, not features&#8230; well&#8230; at least for czPlayer.<br />
That leads me to another thing I&#8217;ve been thinking about!<br />
Maybe I&#8217;ll eventually fork czPlayer into Mobile and Non-Mobile versions, so that I can go wild on all the things I want to implement. Hehe<br />
Most of what I dislike in czPlayer (both internal, and in the external API), are a direct consequence  of the compromises I had to make to support the targeted platforms, and have the same API for all of them.<br />
Nuff said! You&#8217;ve got to ask yourself one question: Do you feel lucky? Well, do you, punk ?</p>
<p>If so, go ahead, download the new version and give it a try:<br />
<a href="http://www.crazygaze.com/blog/czplayer"> Download lastest czPlayer demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2008/01/07/czplayer-020-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplifying code using states</title>
		<link>http://www.crazygaze.com/blog/2007/12/19/simplifying-code-using-states/</link>
		<comments>http://www.crazygaze.com/blog/2007/12/19/simplifying-code-using-states/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 16:46:23 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[code design]]></category>
		<category><![CDATA[State Diagrams]]></category>
		<category><![CDATA[UML]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/archives/39</guid>
		<description><![CDATA[Lately I have been refactoring czPlayer to add more features and make future maintenance easier. Some parts of the code are almost 10 years old, when I first started playing with sound coding. Needless to say, my code style and quality has improved a lot in 10 years, and it&#8217;s a funny thing to look [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I have been refactoring <a href="http://www.crazygaze.com/blog/czplayer">czPlayer</a> to add more features and make future maintenance easier.<br />
Some parts of the code are almost 10 years old, when I first started playing with sound coding.<br />
Needless to say, my code style and quality has improved a lot in 10 years, and it&#8217;s a funny thing to look at code this old. <img src='http://www.crazygaze.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
As I was refactoring the code, I found a lot of ambiguities and redundancies caused by member variables added over time.<br />
Let me explain&#8230;.<br />
I had a class responsible for MOD processing, and some of the member variables were:</p>
<pre class="brush: cpp;">
class MODModule
{
	// ...
	bool m_loaded;
	bool m_playing;
	bool m_paused;
	bool m_reachedEnd;
};
</pre>
<p>What&#8217;s the problem with this approach ?<br />
Let&#8217;s see&#8230;<br />
Suppose I want to call methods on the MOD object (e.g: Pause(), Resume(), etc)<br />
I need to make some checks in each method.</p>
<p>To pause&#8230;</p>
<pre class="brush: cpp;">
if (!m_loaded || m_playing || m_paused)
	return SOME_ERROR;
m_pause = true;
// ... do pause stuff
</pre>
<p>Then to resume&#8230;</p>
<pre class="brush: cpp;">
if (!m_loaded || !m_paused)
	return SOME_ERROR;
m_paused = false;
// ... do resume stuff
</pre>
<p>When the MOD finishes playing, I needed something like this&#8230;</p>
<pre class="brush: cpp;">
// ... some code that checks for end
m_reachedEnd = true;
//ups... How about m_playing, m_paused?
//We need to change their values, so we don't break code elsewhere
m_playing = false;
m_pause = false;
</pre>
<p>And similar things when playing, stopping, etc.<br />
See the problems?</p>
<ul>
<li>We need checks for multiples variables</li>
<li>We need to make sure the variables have valid values in relation to each other</li>
<li>What if we want to add an extra state? For example, &#8220;bool m_fading&#8221;. We would need to examine a lot of code to check how the other variables are used, and hardwire this new one somewhere. Every time you need to add an extra variable, you&#8217;ll need to check more and more code to make sure everything is ok.</li>
</ul>
<p>Now look at the meaning of the variables. They are mostly mutually exclusive.</p>
<ul>
<li>If it&#8217;s playing, it can&#8217;t be paused and hasn&#8217;t reached the end.</li>
<li>If it&#8217;s paused, it&#8217;s not playing, and hasn&#8217;t reached the end yet.</li>
<li>&#8230; and so on&#8230;.</li>
</ul>
<p>The more data members a class has, the harder it gets to keep the object in a valid state, so, the less data to manage, the better. Less maintenance and less bugs.</p>
<p>One technique I use a lot when trying to simplify code is to look at it with state diagrams whenever possible.<br />
Here it is what happens (kind of) with instances of the MODModule class:</p>
<p><a title="mod_states.png" href="http://www.crazygaze.com/blog/wp-content/uploads/2007/12/mod_states.png"><img src="http://www.crazygaze.com/blog/wp-content/uploads/2007/12/mod_states.png" alt="mod_states.png" /></a></p>
<p>I can easily translate it to code with enums.</p>
<pre class="brush: cpp;">
enum MODState
{
    MOD_STATE_NOT_LOADED,
    MOD_STATE_STOPPED,
    MOD_STATE_PLAYING,
    MOD_STATE_PAUSED,
    MOD_STATE_REACHED_END
};

class MODModule
{
    // ...
    MODState m_state; // Now we have only one variable
};
</pre>
<p>This approach is a lot easier to maintain, and less error prone.<br />
Now the code in most functions become something like this:</p>
<p>To play&#8230;</p>
<pre class="brush: cpp;">
if (m_state!=MOD_STATE_STOPPED)
    return SOME_ERROR;
m_state = MOD_STATE_PLAYING;
// ... do play stuff
</pre>
<p>To pause&#8230;</p>
<pre class="brush: cpp;">
if (m_state!=MOD_STATE_PLAYING)
    return SOME_ERROR;
m_state = MOD_STATE_PAUSED;
// ... do pause stuff
</pre>
<p>To resume&#8230;</p>
<pre class="brush: cpp;">
if (m_state!=MOD_STATE_PAUSED)
    return SOME_ERROR;
m_state = MOD_STATE_PLAYING;
// ... do resume stuff
</pre>
<p>To stop&#8230;</p>
<pre class="brush: cpp;">
// We cannot stop if it's not even loaded yet, or it's already stopped
if (m_state==MOD_STATE_NOT_LOADED || m_state==MOD_STATE_STOPPED)
    return SOME_ERROR;
m_state = MOD_STATE_STOPPED;
// ... do stop stuff
</pre>
<p>The code may look similar, but it&#8217;s a lot less error prone, easier to follow and maintain.<br />
Looking at the State Diagram, I could easily squeeze in a &#8220;Fading&#8221; state and understand the conditions to enter or leave that state.</p>
<p>As a bonus, using enums will enforce more rules and help you out with errors the compiler might catch. Always prefer compile-time errors over run-time errors. <img src='http://www.crazygaze.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2007/12/19/simplifying-code-using-states/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>czPlayer 0.1.1 released</title>
		<link>http://www.crazygaze.com/blog/2007/12/16/czplayer-011-released/</link>
		<comments>http://www.crazygaze.com/blog/2007/12/16/czplayer-011-released/#comments</comments>
		<pubDate>Sun, 16 Dec 2007 22:13:51 +0000</pubDate>
		<dc:creator>ruifig</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[czPlayer]]></category>

		<guid isPermaLink="false">http://www.crazygaze.com/blog/archives/38</guid>
		<description><![CDATA[New release of czPlayer. Just a few bug fixes in the internal mixer, and minor changes in the documentation. Those bugs were particular hard to find and fix. They appeared mostly for short looped sounds, like those commonly used in chiptunes, causing some distortion or high pitch. I was making some wrong calculations for looped [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span lang="EN-GB">New release of czPlayer.<br />
Just a few bug fixes in the internal mixer, and minor changes in the documentation.<br />
Those bugs were particular hard to find and fix. They appeared mostly for short looped sounds, like those commonly used in chiptunes, causing some distortion or high pitch. I was making some wrong calculations for looped sounds, which caused 1 or 2 sound frames to be skipped for each sound. For big samples, you can&#8217;t hear the difference, but for very short samples, especially looped, just 1 or 2 wrong frames can mess up the final mix, since they represent a significant part of the affected samples.<br />
I have a lot of changes planned, but  I&#8217;m waiting for a client to  finish  his game before I go wild on the code! hehe<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><a href="http://www.crazygaze.com/blog/czplayer">Download lastest czPlayer demo.</a><o:p></o:p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazygaze.com/blog/2007/12/16/czplayer-011-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

