<?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>jet.ro &#187; Code</title>
	<atom:link href="http://jet.ro/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://jet.ro</link>
	<description>designer/programmer tidbits</description>
	<lastBuildDate>Thu, 03 May 2012 14:41:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>LD22: LIFELONE</title>
		<link>http://jet.ro/2012/04/14/ld22-lifelone/</link>
		<comments>http://jet.ro/2012/04/14/ld22-lifelone/#comments</comments>
		<pubDate>Sat, 14 Apr 2012 10:56:43 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=1098</guid>
		<description><![CDATA[About LIFELONE, a game for 22nd Ludum Dare 48.]]></description>
			<content:encoded><![CDATA[<p><img src="http://jet.ro/wp-content/uploads/2012/04/screenshot-prev-260.png" alt="" title="LIFELONE preview image" width="261" height="147" class="alignright size-full wp-image-1092" /></p>
<p>22nd <a href="http://www.ludumdare.com/" title="Ludum Dare" target="_new">Ludum Dare</a> contest was held late last year. Now that it&#8217;s going to be held 23rd time next weekend, I thought maybe it&#8217;s finally time to add a page and posting about my entry to the last one!</p>
<p>So, for the #22 theme was &#8220;Alone&#8221;, weirdly somewhat close to theme used for 20th LD48. I made a wannabe-artsy-moody game called <em>LIFELONE</em> which tries to convey feelings of loneliness. Or something. <a href="http://jet.ro/games/prototypes/lifelone/" title="LIFELONE">Check it out</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2012/04/14/ld22-lifelone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scanline</title>
		<link>http://jet.ro/2011/12/16/scanline/</link>
		<comments>http://jet.ro/2011/12/16/scanline/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 20:24:42 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Visuals]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=1058</guid>
		<description><![CDATA[Scanline - 1D demo for AltParty 2011.]]></description>
			<content:encoded><![CDATA[<p>Back in October, we wanted to attend the forthcoming <a href="http://www.altparty.org/2011/" title="AltParty2011" target="_blank">Alternative Party</a> event. I think one could say it is a <a href="http://en.wikipedia.org/wiki/Demoscene" target="_blank">demoscene</a> event, but with a broader or different scope or goals &#8211; for example, encouraging or embracing artistic expression with niche platforms (either niche by being rare, or niche by being so old).</p>
<p>So, we thought about taking part in the alternative demo competition. The platform is mostly free choice there, but the compo name itself directs you to think about something different. I thought that maybe it could be interesting to make a demo which would consist of only a single static line with changing colors, and try to take most of that limitation. That is, to make a &#8220;1-Dimensional Demo&#8221; (at least by my definition).<br />
<span id="more-1058"></span></p>
<p>Early on I decided there is no need to try showing technical mastery with such a hard limitation, and decided that it is enough to just make a vertically big image and small amount code which shows that image one line at a time, until the image ends. I made a few effect prototypes with Photoshop, synced to music by checking music positions in milliseconds and converting those to Y-pixel coordinates in the image, after deciding on a frame rate.</p>
<p>It became clear that there should be a good piece of music to go with the effects, because good audio can add so much more to the experience. I asked my friend <a href="http://iki.fi/cube/" title="!Cube" target="_blank">!Cube</a> if he could make up a composition starting with some piano playing, since I thought it could make a nice start to show just white bars on black background, flashing with colors synced to the piano.</p>
<p>To get beyond my tests (still accompanied by my own music), I asked <a href="http://iki.fi/ase/" title="stRana" target="_blank">stRana</a> to help me with the actual production and design. That and just a few days later, most of the pieces started coming together, and we ended up finishing it nicely in time, a day or two before the event started.</p>
<p>For the tech part, I actually just expanded on my first proto tests a bit more. The production is built with <a href="http://processing.org" title="Processing" target="_blank">Processing</a>. It was mostly fine for the task, except that using the accompanying &#8220;minim&#8221; library for audio playing didn&#8217;t seem to be a perfect choice. I&#8217;m not sure of the contributing factors, but it seems the audio latency varies by computer and maybe even some times on the same computer. It didn&#8217;t seem to help much to ask for playing position from the audio system, since that seemed to be a too granular value not really telling where the actual audio play &#8220;head&#8221; is going. But, I didn&#8217;t want to rewrite the whole production just to fix this thing since it worked fine otherwise.</p>
<p>In the end we did really fine; <em>Scanline</em> by Rustbloom ended up winning the Alternative Demo competition. The weird thing is that the prizes in Alternative Party are usually strange obsolete leftover stuff donated by companies; we got two huge rack-mountable servers which were probably really good in their heyday, back in 2003. :) But we also got a bit of actual money on top of that (yay!).</p>
<p>You can download the executable version here: (.zip)<br />
<a href="http://jet.ro/files/Scanline_Demo1D.zip"><b>Download for Windows &amp; Mac OS X</b></a> (hint: source code is also there if you look for a source/ folder)</p>
<p>Or just watch it from the YouTube right here:<br />
<iframe width="640" height="360" src="http://www.youtube.com/embed/1TTxO-WEnak" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2011/12/16/scanline/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Better looking anti-aliased lines with simple trick</title>
		<link>http://jet.ro/2011/06/04/better-looking-anti-aliased-lines-with-simple-trick/</link>
		<comments>http://jet.ro/2011/06/04/better-looking-anti-aliased-lines-with-simple-trick/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 11:00:45 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Visuals]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=999</guid>
		<description><![CDATA[Low-tech and simple solution for rendering hardware accelerated gamma-correct anti-aliased lines.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s some notes about anti-aliased lines.<br />
For these tests of rendering anti-aliased lines my goals were roughly as follows:</p>
<ul>
<li>relatively high-quality anti-aliased lines (better than subsampling or postprocessing)</li>
<li>simple low-tech solution extendable to wide range of platforms (e.g. not relying on availability  of shaders)</li>
<li>visually better consistency than what you get if you just ask graphics API to anti-alias lines for you, and you might not even get any if the hardware is lacking</li>
<li>try to solve issue of anti-aliased lines showing a &#8220;roping&#8221; effect</li>
<li>concentrate on case of single lines without yet going to additional complexities such as line caps or joins between multiple lines</li>
</ul>
<p><span id="more-999"></span><br />
I set to test out stuff with <a href="http://www.processing.org" target="_new">Processing</a>, and decided first to do a comparison of what anti-aliased lines look by default in it. Here&#8217;s an animation showing my simple test pattern with P2D, P3D and JAVA2D renderers:<br />
<img src="http://jet.ro/wp-content/uploads/2011/06/AA_comparison_anim.gif" alt="" title="AA comparison anim, defaults from Processing" width="220" height="130" class="alignnone size-full wp-image-1003" /><br />
As you can see, the results vary a bit, which is no surprise since those different renderers surely have differing precision/performance goals or just a different way to render the lines. For lines close to perfectly horizontal/vertical lines they&#8217;re pretty similar, showing clearly the &#8220;roping&#8221; effect I mentioned above. For lines close to 45 degree angles the JAVA2D renderer seems to look a bit better.</p>
<p>So, to move forward, here&#8217;s a magnified illustration of the technique how I&#8217;m drawing lines using two quads having a gradient going from 100% in center to 0% towards edge. In actual rendering that gradient ramp is done in alpha channel, but for these example images I&#8217;m using green background and a ramp from white to black to show more clearly what&#8217;s being done.<br />
<img src="http://jet.ro/wp-content/uploads/2011/06/quads_illustration_1pix_fins.png" alt="" title="quads_illustration_1pix_fins" width="340" height="170" class="alignnone size-full wp-image-1001" /><br />
I&#8217;m basically just building on top of somebody else&#8217;s basic idea about how to render hardware accelerated lines by constructing polygons with gradient fins yourself instead of using a call to draw line primitives. I don&#8217;t know whose idea this is originally, having heard this a few times from different sources, but to fully research this subject you&#8217;d need to go back 30 years or so (check the short list of related links at end of this post).</p>
<p>When you use this technique to draw a line with &#8220;1 pix&#8221; thickness (although the fins cover total of 2 pixels), it yields pretty identical result with what you see in the above examples from Processing&#8217;s P2D/P3D/JAVA2D renderers. Well, not quite &#8211; for some reason, it actually depends a bit on the hardware. On low-end Intel GMA950 that statement of looking the same holds true. When I try that on my desktop PC with nVidia video card, the lines actually look much better (slightly fatter but without the roping). I found this out only later though, since I did all of my initial tests about this on a mini laptop which has the GMA950. :)</p>
<p>When the roping issue of anti-aliased lines is discussed, I have noticed that often somebody knowledgeable enough says it&#8217;s actually a gamma issue. The problem here being of course the fact that there are many ways to tackle the gamma thing, where none of them are a silver bullet solution which wouldn&#8217;t bring a host of other problems with it.</p>
<p>I got the idea that I could modify the above technique to draw two 0.5 unit wide fins per side, and apply gamma correction at the halfway. This would be still very simple and low-tech way to draw gamma corrected lines.</p>
<p>So here&#8217;s an illustration of what&#8217;s modified compared to the previous example:<br />
<img src="http://jet.ro/wp-content/uploads/2011/06/quads_illustration_halfpix_gamma.png" alt="" title="AA lines with half-way gamma corrected gradient fins" width="340" height="170" class="alignnone size-full wp-image-1005" /></p>
<p>The magic value of 0.72974 comes from 0.5^(1/2.2), assuming that your display gamma is 2.2. I also tried 0.707107 which comes from 0.5^(1/2), which is equal to sqrt(0.5), i.e. a good approximation which is &#8220;close enough&#8221; if you want to simplify the equation. Here is an animation showing the differences with no gamma correction, and then gamma correction with values of 2 and 2.2:<br />
<img src="http://jet.ro/wp-content/uploads/2011/06/AA_comparison_custom_lines_anim.gif" alt="" title="AA gamma comparison anim, half-way gamma corrected fins" width="220" height="130" class="alignnone size-full wp-image-1007" /></p>
<p>As I said above, the &#8220;no gamma&#8221; case looks very close to the gamma corrected one on different hardware, but the gamma 2.2 corrected case looks identical on the few machines I tried this on. I&#8217;m not sure what&#8217;s going on with that, hopefully somebody can explain it to me. I don&#8217;t have any explicitly enabled &#8220;gamma correction&#8221; features from drivers.</p>
<p>A few observations from the images. With the above technique even the perfectly horizontal and vertical lines get a small halo to nearby pixels. What&#8217;s good though is that the perceived brightness stays same very well regardless of line angle.</p>
<p>Perhaps one of the most annoying side effects of this technique is the fact that now the lines look fatter than normal 1 pix wide lines. I have done a few tests of reducing the fin width and/or decreasing the brightness. You can&#8217;t reduce the fin width much without the result quickly getting ugly, but decreasing just the brightness doesn&#8217;t really make the line look much thinner, it looks just darker. I don&#8217;t know what would be the optimal way, but I think maybe it involves a combination of both to some extent. Here&#8217;s one test image where I have reduced the fin width slightly as well as the brightness:<br />
<img src="http://jet.ro/wp-content/uploads/2011/06/ogl_custom_aa_lines_CUSTOM_GAMMA22_darker.png" alt="" title="example of trying to reduce line width with the gamma correction" width="220" height="130" class="alignnone size-full wp-image-1008" /><br />
I think a bit of the roping effect has crawled back in, but the perceived brightness between angles is pretty much ok.</p>
<p><a href="http://jet.ro/files/ogl_custom_aa_lines.pde">Here&#8217;s test code</a>, runnable inside <a href="http://www.processing.org" target="_new">Processing</a>. What&#8217;s additionally not visible in the example images above is the fact that the default renderers clamp coordinates to integers, while this method allows you to draw lines with perfect sub-pixel precision. The test code is modified to offset the lines by time slowly so you can see that in action. If you want to try the regular lines reference test case, replace the renderer in initial size() call to P2D/P3D/JAVA2D, and replace the call to testAALines(&#8230;) in draw() with the commented call to testLines(&#8230;).</p>
<p>Related links:</p>
<ul>
<li><a href="http://portal.acm.org/citation.cfm?id=357309" target="_new">Anti-Aliasing Through the Use of Coordinate Transformations</a> (K. Turkowski, 1982).
<li><a href="http://www.hpl.hp.com/techreports/Compaq-DEC/WRL-98-2.pdf" target="_new">Prefiltered Antialiased Lines Using Half-Plane Distance Functions</a>
<li><a href="http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter22.html">GPU Gems 2 chapter 22: Fast Prefiltered Lines</a></li>
<li><a href="http://homepage.mac.com/arekkusu/bugs/invariance/TexAA.html" target="_new">OpenGL Invariance: Texture AA</a> (with glAArg library)</li>
</ul>
<p>Additional credits/thanks: I think I learned first time about using simple gradient instead of other tricks (like textures) from <a href="http://digestingduck.blogspot.com" target="_new">Mikko Mononen</a>. <a href="http://www.harveycartel.org/raigan/" target="_new">Raigan Burns</a> noted that the line being a bit fat and &#8220;bleeding&#8221; into adjacent pixels is actually a feature, since that way the lines actually look a lot better in motion. Alex May told me that most of <a href="http://www.eufloria-game.com" target="_new">Eufloria</a> game&#8217;s drawing works like this, except for using texture for drawing the lines and having a bunch of textures with different gradients to get different visuals. The gradients are circular and lines are drawn using a cross section of the texture, with rest of the texture used to make caps for round-ended lines.</p>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2011/06/04/better-looking-anti-aliased-lines-with-simple-trick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LD20: Guinea Pig Warrior</title>
		<link>http://jet.ro/2011/06/01/ld20-guinea-pig-warrior/</link>
		<comments>http://jet.ro/2011/06/01/ld20-guinea-pig-warrior/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 18:56:50 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=994</guid>
		<description><![CDATA[20th Ludum Dare contest was held a few weeks ago. The given theme was &#8220;It’s Dangerous to go Alone! Take this!&#8221;. I created a little platformer where the player character has a temporal projection sidekick. Check out Guinea Pig Warrior.]]></description>
			<content:encoded><![CDATA[<p><img src="http://jet.ro/wp-content/uploads/2011/06/guineapigwarrior-thumb.png" alt="" title="Mini preview image" width="260" height="152" class="alignright size-full wp-image-991" /></p>
<p>20th <a href="http://www.ludumdare.com/" target="_new">Ludum Dare</a> contest was held a few weeks ago. The given theme was &#8220;It’s Dangerous to go Alone! Take this!&#8221;. I created a little platformer where the player character has a temporal projection sidekick. Check out <a href="http://jet.ro/games/prototypes/guinea-pig-warrior/" target="_top">Guinea Pig Warrior</a>.</p>
<div class="cb"></div>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2011/06/01/ld20-guinea-pig-warrior/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LD19: Drill Warrior</title>
		<link>http://jet.ro/2011/03/05/ld19-drill-warrior/</link>
		<comments>http://jet.ro/2011/03/05/ld19-drill-warrior/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 20:33:25 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=982</guid>
		<description><![CDATA[19th Ludum Dare contest was held already back in December. Since I managed to make an entry this time, I figured out I could post about it before the next one is held, which will be probably next month. The theme was &#8220;Discovery&#8221;. Description, downloadable Windows build and source code of my game Drill Warrior [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://jet.ro/wp-content/uploads/2011/03/drillwarrior-thumb.jpg" alt="" title="drillwarrior-thumb" width="260" height="152" class="alignright size-full wp-image-979" /></p>
<p>19th <a href="http://www.ludumdare.com/" target="_new">Ludum Dare</a> contest was held already back in December. Since I managed to make an entry this time, I figured out I could post about it before the next one is held, which will be probably next month.</p>
<p>The theme was &#8220;Discovery&#8221;. Description, downloadable Windows build and source code of my game <em>Drill Warrior</em> can be downloaded from the <a href="/games/prototypes/drill-warrior/">separate page about the game</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2011/03/05/ld19-drill-warrior/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Various ways to backup</title>
		<link>http://jet.ro/2010/07/04/various-ways-to-backup/</link>
		<comments>http://jet.ro/2010/07/04/various-ways-to-backup/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 12:57:54 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Misc.]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=917</guid>
		<description><![CDATA[Over the years I have been using several kinds of solutions to backup stuff. Here&#8217;s a description of the ones I can remember. Many of them focus on being low-cost, simple and straightforward, but are far from a perfect solution in many other ways. A common technique for me has been to just make zip [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years I have been using several kinds of solutions to backup stuff. Here&#8217;s a description of the ones I can remember. Many of them focus on being low-cost, simple and straightforward, but are far from a perfect solution in many other ways.</p>
<p><span id="more-917"></span></p>
<p>A common technique for me has been to just make zip files of whatever I want to backup. Simple snapshots of a project, so I end up with bunch of &#8220;projectname-YYYYMMDD.zip&#8221; files. Or altenatively a common zip of certain folder which gets updated over time. For example, before I moved to using cvs or svn for source code version control, I used a batch file like this to backup all my little coding projects:</p>
<blockquote><p><strong>backup.bat</strong><code><br />
@zip -u -r d:\backup\prog_c * -x *.ilk *.pdb *.idb *.ncb *.opt *.plg *.bsc *.sbr *.pch *.obj *.zip *.dll<br />
</code></p></blockquote>
<p>As you can see, this just updates an existing zip and excludes bunch of unnecessary files which I didn&#8217;t want to keep bloating up the backup zip. A worthy note is that I have usually made sure I have two separate hard disks in a computer and put the backups on the other one from the original data. At some point I also tried to switch to using <a href="http://dar.linux.free.fr/" target="_top">dar</a> instead of the zip files, since it would have had some advantages over the zip files. I didn&#8217;t end up using that for long though.</p>
<p>Like I hinted above, nowadays I&#8217;m using version control for source code, so I don&#8217;t make such zips that frequently anymore. Instead I have made sure that the version control repository gets backed up somehow.</p>
<p>My first solution was to make nightly snapshots of the repository using a script on the server, and then occasionally copy a snapshot file back to my main computer. I used this solution for many years. Below is copy of the backup script I used, which creates a .tar.gz backup file with given prefix from a specified file mask, adding YYYY-MM-DD timestamp to the backup file name, and also keeps only given number of snapshots around cleaning up any older ones.</p>
<blockquote><p><strong>dobackup.sh</strong><code><br />
#!/bin/sh</p>
<p>if [[ ! $1 || ! $2 || ! $3 || ! $4 || ! $5 ]]<br />
then<br />
    echo $0 destdir name execdir mask backups<br />
    echo $'\t'destdir = directory to put backups in<br />
    echo $'\t'name = file prefix name of this backup<br />
    echo $'\t'execdir = directory to run the backup tar command in<br />
    echo $'\t'mask = filemask to give for tar<br />
    echo $'\t'backups = number of backups of name to keep in destdir<br />
    exit<br />
fi</p>
<p>DESTDIR=$1<br />
NAME=$2<br />
EXECDIR=$3<br />
MASK=$4<br />
BACKUPS=$5</p>
<p>DESTFILE=$DESTDIR/$NAME-`date +%F`.tar.gz</p>
<p>cd $EXECDIR<br />
tar zcf $DESTFILE $MASK</p>
<p>EXTRAFILES=$((`ls $DESTDIR/$NAME-* | wc -l` - $BACKUPS))</p>
<p>if [[ $EXTRAFILES > 0 ]]<br />
then<br />
    rm -f `ls -t $DESTDIR/$NAME-* | tail -$EXTRAFILES`<br />
fi<br />
</code></p></blockquote>
<p>I had then another script which called the above one to create backup files from a few places in the system, and was put in a cron job to be run once per night. The backup script looked something like this:</p>
<blockquote><p><strong>allbackups.sh</strong><code><br />
#!/bin/sh<br />
# All automatic nightly backups<br />
cd /home/user/bin<br />
BACKUPDIR=/var/backups/user<br />
umask 007<br />
# /home/share (includes version control repository)<br />
./dobackup.sh $BACKUPDIR share /home share 7<br />
# misc stuff<br />
./dobackup.sh $BACKUPDIR misc /home/user "bin bookmarks.html code" 7<br />
</code>
</p></blockquote>
<p>More recently I have also moved to mirroring stuff over to another computer using rsync. This was something I needed to do to create an off-site remote backup for my workplace&#8217;s version control repository. To do this, I have simply put ssh-keys in place to allow automatic remote ssh login from a certain machine to run rsync over it, and then I have a cron job line like this to update the mirror every night:</p>
<blockquote><p><strong>nightly rsync mirror for cron job file:</strong><code><br />
30 5 * * * /usr/bin/rsync -avz -e ssh user@server:/path/* /backup/mirror/ > /backup/log/last_cron_mirror.txt 2>&#038;1<br />
</code></p></blockquote>
<p>Additionally I&#8217;m also backing up some paths of this web server every now and then using simple tar commands in a script, and the following command to back up a dump of the mysql database:</p>
<blockquote><p><strong>compressed mysql dump, must be run as root:</strong><code><br />
 /usr/bin/mysqldump --defaults-file=/etc/mysql/debian.cnf -A -Q --opt | /bin/bzip2 > ~/db-mysql-`date +%Y%m%d`.sql.bz2<br />
</code></p></blockquote>
<p>Finally, since there are multiple computers in our household, we have also been simply copying manually some files over to a share in another computer to have at least a single duplicate. These days I have also set Windows 7 backup software to maintain a backup of certain folders and system state to a share in my home Linux server. In the past I also sometimes made manually a backup of my Windows XP computer&#8217;s system state using the OS backup tool. Also recently when a brand new hard disk failed for me, I bought another one and after getting the warranty replacement I put the two into a mirrored RAID disk.</p>
<p>I have experienced so many hard disk crashes over time so I have learned to pay at least some attention to backing up the most important stuff, even if I really still tend to be a little bit lazy about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2010/07/04/various-ways-to-backup/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unwrapping Values &#8211; nearest next angle from a previous angle</title>
		<link>http://jet.ro/2010/06/29/unwrapping-values-nearest-next-angle-from-a-previous-angle/</link>
		<comments>http://jet.ro/2010/06/29/unwrapping-values-nearest-next-angle-from-a-previous-angle/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 16:30:14 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=908</guid>
		<description><![CDATA[How to unwrap angle values to find a shortest transition from one angle to another.]]></description>
			<content:encoded><![CDATA[<p>So, assuming you have angles <em>previousAngle</em> and <em>nextAngle</em>, and you want to transition from the first to the second smoothly. If it&#8217;s like from 358 to 2, a simple linear interpolation will awfully go through almost a full circle down from 358 to 2, when a simple four degree transition forward would have been enough, i.e. you should have been going to 362 degrees instead. So, how to figure out what&#8217;s the shortest transition?</p>
<p>I remember hitting against this problem numerous times, always remembering that I have solved it previously but always seem unable to find the previous solution. And I still can&#8217;t just write it out by heart.</p>
<p>Once again I had to solve this, so this time I tried to Google for it (&#8220;angle wrap delta&#8221;), and found out that somebody named Jason S had posted a <a href="http://stackoverflow.com/questions/2500430/calculating-rotation-in-360-deg-situations" target="_new">nice generalization</a> to a related question in <a href="http://stackoverflow.com" target="_new">Stackoverflow.com</a>.</p>
<p>For your convenience, I&#8217;m posting a modified C version of the code here.<br />
<span id="more-908"></span><br />
<code><br />
// Fancy generalization for wrapping below (e.g. for angles).<br />
// Original code found from:<br />
// http://stackoverflow.com/questions/2500430/calculating-rotation-in-360-deg-situations</p>
<p>// symmetric modulo:<br />
// y = smod(x,m) = x+k*m where k is an integer,<br />
// and y is always in the range [-0.5,0.5)*m<br />
static float smod(float x, float m)<br />
{<br />
&nbsp;&nbsp;return x - ((floorf(x / m + 0.5f)) * m);<br />
}</p>
<p>// Unwraps a value, used for e.g. angles.<br />
// Caveat: Doesn't handle negative input values correctly.<br />
// Workaround: Wrap original value prev to [0..range) before applying this.<br />
// &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.g.: prev = fmodf(fmodf(prev, range) + range, range);<br />
static float unwrap(float prev, float next, float range)<br />
{<br />
&nbsp;&nbsp;return prev + smod(next - prev, range);<br />
}<br />
</code></p>
<p>There&#8217;s one <strong>caveat</strong>: it doesn&#8217;t seem to work correctly for negative angles. Just now I don&#8217;t have the time now to figure that out. But an easy workaround is to wrap the original angle first with angle=fmodf(fmodf(angle,2*pi)+2*pi,2*pi) and then transition from that angle to the destination. If somebody posts a better version I&#8217;ll update the post. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2010/06/29/unwrapping-values-nearest-next-angle-from-a-previous-angle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Little framework for making prototypes or an LD48 entry</title>
		<link>http://jet.ro/2009/12/11/little-framework-for-making-prototypes-or-an-ld48-entry/</link>
		<comments>http://jet.ro/2009/12/11/little-framework-for-making-prototypes-or-an-ld48-entry/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 20:13:45 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=838</guid>
		<description><![CDATA[Little framework for making prototypes or an LD48 entry]]></description>
			<content:encoded><![CDATA[<p>If you didn&#8217;t know yet, the <a href="http://ludumdare.com" target="_new">Ludum Dare</a> 48 hour game development competition is held again this weekend. In the competition the idea is to make a game using a given theme, more or less from scratch. Basically most people use some small amount basecode to start up with as there&#8217;s not really that much point to make every boring bit (like how to open a window) again every time. Besides, a little framework still has less stuff than what fine tools such as Unity3D provides you with to start with. :)</p>
<p>
So here&#8217;s my little C++ basecode/framework for making a Ludum Dare 48 hour game development competition entry. It should be equally suitable for making some other little prototype games. You&#8217;ll need to svn checkout <a href="http://irrlicht.sourceforge.net" target="_new">Irrlicht</a> and download <a href="http://www.fmod.org" target="_new">FMOD 3</a> separately. The framework is meant to be used on Windows with Microsoft Visual C++ 2008 (Express Edition is enough).</p>
<p>
<a href="http://jet.ro/files/framework_LD48_tonic_200912.zip">framework_LD48_tonic_200912.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2009/12/11/little-framework-for-making-prototypes-or-an-ld48-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code: Tokenizer</title>
		<link>http://jet.ro/2009/11/10/code-tokenizer/</link>
		<comments>http://jet.ro/2009/11/10/code-tokenizer/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 18:30:47 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=782</guid>
		<description><![CDATA[C++ Tokenizer class for splitting C strings into tokens by given separators.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little C++ utility class for splitting C strings into tokens by given separators. It&#8217;s inspired by &#8220;tokenwad&#8221; taken from <a href="http://www.iki.fi/sol/code.html" target="_new">Sol&#8217;s CFL3</a>, which I have used quite a few times. This version has low memory overhead as it performs only 1-2 allocations (depending if the tokenization is done in-place or a separate copy is needed).</p>
<p><span id="more-782"></span></p>
<blockquote><p>
<code>Tokenizer(bool trimWhitespace = true), clear(bool trimWhitespace = true)</code><br />
Initializes / resets tokenizer, whitespace trimming from begin and end of tokens is optional.</p>
<p><code>bool tokenize(const char *str, const char *separators);</code><br />
Tokenizes string by the given separators. Creates a private copy of the data. Returns true when successful, or false if tokenization failed for some reason.</p>
<p><code>bool tokenizeInPlace(char *str, const char *separators);</code><br />
Tokenizes string in-place by the given separators, destroying the original content. Returns true when successful, or false if tokenization failed for some reason.</p>
<p><code>int count() const;</code><br />
Returns count of tokens, or 0 if tokenizer hasn&#8217;t been run yet.</p>
<p><code>char * get(int index) const;</code><br />
Returns token by index, or 0 if no token with such index exists.</p>
<p><code>int getAsInt(int index, int defaultValue = -1);</code><br />
Returns token as integer, or given default value if it can&#8217;t be converted.</p>
<p><code>bool equals(int index, const char *str);</code><br />
Returns true if token with given index equals given string, or false otherwise.</p>
<p><code>bool equalsIgnoreCase(int index, const char *str);</code><br />
Returns true if token with given index equals given string case insensitively, or false otherwise.
</p></blockquote>
<p>Download source code (Tokenizer.cpp, Tokenizer.h, tokenizer_test.cpp):<br />
<a href="http://jet.ro/files/tokenizer.zip">tokenizer.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2009/11/10/code-tokenizer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tool: Binary data to embeddable char array</title>
		<link>http://jet.ro/2009/11/09/tool-binary-data-to-embeddable-char-array/</link>
		<comments>http://jet.ro/2009/11/09/tool-binary-data-to-embeddable-char-array/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 20:22:51 +0000</pubDate>
		<dc:creator>jetro</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Misc.]]></category>

		<guid isPermaLink="false">http://jet.ro/?p=777</guid>
		<description><![CDATA[Sometimes there&#8217;s a need to embed some little bit of binary data in the executable. The reasons may vary &#8211; perhaps it is for a resource you want to exist even if data files are missing, or it could be even something you want to &#8220;hide&#8221; from some curious wannabe-hackers. In the past years my [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes there&#8217;s a need to embed some little bit of binary data in the executable. The reasons may vary &#8211; perhaps it is for a resource you want to exist even if data files are missing, or it could be even something you want to &#8220;hide&#8221; from some curious wannabe-hackers.</p>
<p>In the past years my typical use case was as follows. I used to make &#8220;64 KB intros&#8221; (such as <a href="http://www.youtube.com/watch?v=tJUX1OL0uVA" target="_new">this one</a>), and for those I needed to embed a few data files to the executable as object data, so that I could exploit compression of the executable packer without writing a proper compression tool myself (such as <a href="http://upx.sourceforge.net" target="_new">UPX</a>).</p>
<p><span id="more-777"></span><br />
First I ended up making a simple tool which just reads in a file, byte-by-byte, and outputs something like this:<br />
<code>static unsigned char data[]={13,37,74,47, ... };</code><br />
That worked just fine and easy &#8211; <code>sizeof(data)</code> can be used to get the length of the data. Writing such a tool took probably something like 5-10 minutes. I think I have actually written that same little utility multiple times in the last decade, sometimes just forgetting where the previously created version were and then just re-creating it.</p>
<p>However, at some point I ended up with a solution where music of the production was an XM module with generated samples. The actual playable module file was huge in size &#8211; several megabytes &#8211; but the trick was that all the samples were generated at initialization time of the application. My quick hack for this was to make a tool which read in the XM module, replaced the sample data with blank data and stored the tiny bits of metadata for sample generation. And then just embed the huge binary file, so that executable compressor would crunch it down a lot (because it&#8217;s mostly empty blank data anyway).</p>
<p>Everything was fine, except for the fact that the compiler&#038;linker I used didn&#8217;t like that idea at all, declaring a compile-time handled char array of several megabytes. To workaround this, I took the previously mentioned little utility and added simple RLE compression, which was just enough of a workaround and was trivial to decode as well. Problem solved. (Note that this way of adding music to an intro is now considered ancient, and more modern way is <a href="http://www.pouet.net/prod.php?which=15073" target="_new">something like this</a>).</p>
<p>Recently I found a version of these two little utilities and decided maybe I can save a few minutes of somebody&#8217;s time &#8212; or at least my own time if I ever consider writing the same thing over again and happen to remember I have added those to my web page.</p>
<p>I called the first one &#8220;binso&#8221; for reason I can&#8217;t remember anymore. The RLE-version is simply &#8220;binsorle&#8221;. There&#8217;s also testrle.c code for testing and decompressing the data made by binsorle. Note that the code has been written no later than 2001 (possibly even earlier than that), and hasn&#8217;t been really &#8220;stress tested&#8221; to be bug-free. Any bug reports are still welcome, of course.</p>
<p>Download source-code and pre-built win32 executable files:<br />
<a href="http://jet.ro/files/binso.zip">binso.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jet.ro/2009/11/09/tool-binary-data-to-embeddable-char-array/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

