<?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>Slyfox &#187; Development</title>
	<atom:link href="http://slyfox.za.net/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://slyfox.za.net</link>
	<description>Concentrated awesome</description>
	<lastBuildDate>Sun, 30 Aug 2009 18:29:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ugly Code And Why It&#8217;s Good</title>
		<link>http://slyfox.za.net/2009/02/ugly-code-and-why-its-good/</link>
		<comments>http://slyfox.za.net/2009/02/ugly-code-and-why-its-good/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 18:49:50 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=78</guid>
		<description><![CDATA[While helping a colleague with a defect regarding things that should not happen but were and caused the whole tower of sticks to come tumbling down, I noticed a block of code that follows more or less the gist of the pseudo-sample below:
if(lots of conditions)
{
&#160;&#160;&#160;&#160;doSomeStringCopies();
&#160;&#160;&#160;&#160;if(a certain condition)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;doSomething();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;doSomethingElse();
&#160;&#160;&#160;&#160;doFinalStringCopies();
}
Bear in mind that the consistency of indentation of [...]]]></description>
			<content:encoded><![CDATA[<p>While helping a colleague with a defect regarding things that should not happen but were and caused the whole tower of sticks to come tumbling down, I noticed a block of code that follows more or less the gist of the pseudo-sample below:</p>
<p><code>if(lots of conditions)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;doSomeStringCopies();<br />
&nbsp;&nbsp;&nbsp;&nbsp;if(a certain condition)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomething();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomethingElse();<br />
&nbsp;&nbsp;&nbsp;&nbsp;doFinalStringCopies();<br />
}</code></p>
<p>Bear in mind that the consistency of indentation of the actual code was nowhere as nice as above.</p>
<p>Notice the problem? <kbd>doSomethingElse()</kbd> will be called irrespective of the secondary condition, resulting in bad things happening because a certain field does not contain a valid value for the doing of something else, but is entirely valid in terms of the business rule.</p>
<p>This is why you <em>always</em> surround your compound code structures with braces: because you never know when someone&#8217;s going to slide a &#8220;fix&#8221; into your code and neglects to add the braces. Several people (who have obviously never been burnt by this problem, and if they have, they should have their keyboard license removed from them) might think that bracing a compound structure which contains only one statement makes the code look uglier or more unreadable, but it definitely makes it a lot more maintainable.</p>
<p>(As an aside, I have a feeling that this is one of my more poorly written entries. Shame on me, I know.)</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2009/02/ugly-code-and-why-its-good/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MegaTrader I: The Premise</title>
		<link>http://slyfox.za.net/2009/01/megatrader-i-the-premise/</link>
		<comments>http://slyfox.za.net/2009/01/megatrader-i-the-premise/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 20:28:43 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=67</guid>
		<description><![CDATA[A few months ago, I started working on a J2ME game called MegaTrader, which eventually fell by the wayside as I finished up on my honours work and settled into my new work. Lately, though, I&#8217;ve been spending some time again drafting ideas and notes on the game; notes I thought I&#8217;d write up here [...]]]></description>
			<content:encoded><![CDATA[<p>A <a href="/2008/10/megatrader/">few months ago</a>, I started working on a J2ME game called MegaTrader, which eventually fell by the wayside as I finished up on my honours work and settled into my new work. Lately, though, I&#8217;ve been spending some time again drafting ideas and notes on the game; notes I thought I&#8217;d write up here for the sake of commentary and the sake of getting it down in written form.</p>
<p><span id="more-67"></span></p>
<p>So, let&#8217;s start at the most basic iteration of the game itself, ignoring any details such as interface and representation. As I stated in the original article, the game can be summed up as <a href="http://en.wikipedia.org/wiki/Dope_Wars">Dope Wars</a> in space. Thus, the mechanics of the game may be summed up as follows:</p>
<ol>
<li><strong>Sell</strong> any inventory so as to make a profit.</li>
<li><strong>Buy</strong> more inventory at a low enough price to ensure a profit in the future (the nearer in the future and the higher the profit, the better).</li>
<li><strong>Travel</strong> to a different location, repeating the process from step 1.</li>
</ol>
<p>This process is repeated until a pre-set time limit is reached, with travelling using one time unit, and inventory actions being &#8220;free&#8221; actions. The end goal of the game is to amass as much wealth as possible within the time limit, in effect competing with yourself to better a personal best high score.</p>
<p>Each turn, the inventory prices are randomised according to a item&#8217;s base value and some measure of variance. The skill involved in the game then relies on the player&#8217;s ability to recognise the base values and variances of inventory items, such that they know when a certain item is at a &#8220;low&#8221; or a &#8220;high&#8221; price, corresponding to a &#8220;buy&#8221; or a &#8220;sell&#8221; on the part of the player.</p>
<p>To add an additional level of randomisation to the game, random events may be introduced that alter the player&#8217;s stock or money levels, or drastically alter the variation in prices. This may be implemented using non-uniform random number generation, such that smaller variations are more common than extremely large variations, which may well count for a mere fraction of the random number space, but may potentially yield vast gains for the player.</p>
<p>At this basic level, the game does not invite many opportunities for strategic play, since the game may effectively be &#8220;broken&#8221; if a player collects enough data about inventory prices, disregarding any random fluctuations/events. The next article in this series will outline some of the ideas I&#8217;ve had to expand the gameplay to make the game more interesting and challenging to a player.</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2009/01/megatrader-i-the-premise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HP-UX, shared memory, and you</title>
		<link>http://slyfox.za.net/2008/12/hp-ux-shared-memory-and-you/</link>
		<comments>http://slyfox.za.net/2008/12/hp-ux-shared-memory-and-you/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 17:21:07 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[hp-ux]]></category>
		<category><![CDATA[shm]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=37</guid>
		<description><![CDATA[My current project at work involves doing some investigation into creating a daemon to allocate memory to processes using a pool of shared memory (SHM).
The reason for this is that the implementation of the C runtime (CRT) library&#8217;s memory management routines on HP-UX does not shrink the heap of a process. This effectively means that [...]]]></description>
			<content:encoded><![CDATA[<p>My current project at work involves doing some investigation into creating a <a href="http://en.wikipedia.org/wiki/Daemon_(computer_software)">daemon</a> to allocate memory to processes using a pool of <a href="http://en.wikipedia.org/wiki/Shared_memory">shared memory</a> (SHM).</p>
<p>The reason for this is that the implementation of the C runtime (CRT) library&#8217;s memory management routines on <a href="http://en.wikipedia.org/wiki/HP-UX">HP-UX</a> does not shrink the heap of a process. This effectively means that if you were to allocate a 512MB block of memory and then release that memory again, the operating system would still report your process as using 512MB of memory. Because of this, long-lived processes (such as services) that may use large amounts of memory to do processing at some point eventually dominate the memory usage of the system, even though they are actually using only a small part of this expanded heap on average. More specifically, the OS is basically reporting that there are 20 instances of a single service each using 1GB of RAM! Shared memory, on the other hand, obviously uses memory on the system, but since SHM isn&#8217;t tied to any specific process, it won&#8217;t cause the participating processes to display a huge amount of memory usage.</p>
<p>The other alternative is of course to change the way the service does processing, but this involves code changes in both the front and back-end parts of the software, so a shared memory allocator would be the path of least resistance in this case.</p>
<p>&#8220;But wait!&#8221;, you say, &#8220;Wouldn&#8217;t that involve changing the back-end code to make use of the new allocator anyway?&#8221; The answer to this is that, yes, it could, but there&#8217;s an easier option. The dynamic loader on UNIX uses a neat little environment variable called <code>LD_PRELOAD</code> which causes the shared libraries specified in it to be loaded before any other shared libraries. This allows you to easily override the CRT&#8217;s memory management routines, since yours get loaded first. This means that the amount of code that needs to be changed go from every memory allocation call to, effectively, none at all.</p>
<p>So we can have the manager allocate a big block of shared memory, and have the services communicate their requests for memory to the manager using <a href="http://en.wikipedia.org/wiki/Unix_domain_socket"></a>UNIX domain sockets</a>. The manager then attempts to service the request by reserving a block of shared memory for that process and passing the address back to the requesting process. The service can then map the shared memory segment into it&#8217;s own address space, use the memory for whatever it needs it for, and then tells the manager to release the memory again. Easy off bang!</p>
<p>Not quite, though.</p>
<p>HP-UX has support for both 32-bit and 64-bit operation. In 32-bit mode, the maximum size of a shared memory segment is 1GB, while in 64-bit mode, a shared memory segment may be up to 4TB in size. The systems we&#8217;re working on run a 64-bit kernel, so the maximum size of a segment isn&#8217;t the problem. The problem is that the processes themselves are 32-bit executables, and to understand why, I&#8217;ll need to talk about how HP-UX defines the memory space for a 32-bit executable.</p>
<p>32-bit mode implies a maximum addressable range of 2<sup>32</sup> bits, or 4GB of memory. In HP-UX, this 4GB <a href="http://en.wikipedia.org/wiki/Virtual_address_space">virtual address space</a> is divided into four quadrants of 1GB each. The first two quadrants are used for the process&#8217; <a href="http://en.wikipedia.org/wiki/Code_segment">text</a> and <a href="http://en.wikipedia.org/wiki/Data_segment">data</a> segments. The third and fourth quadrants are used as a global shared memory space, with the final 250MB of the fourth quadrant being reserved for system I/O (my guess is that this is used for buffers when doing I/O operations). The global adjective means that any shared memory in the system will be (potentially) visible in any other process. Since shared memory does utilise access control when a process requests to map a segment into its address space, there aren&#8217;t any security concerns regarding that, though. What this does mean, though, is that the total amount of shared memory available in 32-bit processes is limited to 1.75GB. And by &#8220;32-bit processes&#8221; I mean <em>all</em> 32-bit processes currently running in the system.</p>
<p>Luckily, HP-UX has a feature known as <strong>memory windows</strong>. To use memory windows, the process to be executed is run using a wrapper called <code>setmemwindow</code>, which will execute the given command in a given memory window. The effect of this is that instead of the process having the normal 1GB global Quadrant 3, it receives a separate 1GB Quadrant 3 which is then shared by all processes belonging to the same memory window.</p>
<p>The idea I had is to use this feature by partitioning the services that require the shared memory pool into groups, and having them and their respective shared memory manager all belong to the same memory window. This frees up the global Q3 for other processes running on the system that might also use SHM, and allows multiple shared memory managers to execute in parallel with their own set of managed services.</p>
<p>The current status of my investigation, barring finding out about the above technical details, is that I&#8217;ve completed a basic manager process capable of reserving and releasing blocks of the shared memory segment to requesting processes, as well as a small test program that communicates requests to the manager. The next step is to write two programs that will perform random memory allocations, one using the SHM manager and another using the standard CRT, to get an idea of what the performance impact of the additional management layer will be.</p>
<p>Hopefully someone will find this useful, since I had to do quite a bit of Google-trawling to find out about all of this. If anyone wants a few of the references I used, feel free to leave a comment, and I&#8217;ll see if I can set you up.</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2008/12/hp-ux-shared-memory-and-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Megatrader</title>
		<link>http://slyfox.za.net/2008/10/megatrader/</link>
		<comments>http://slyfox.za.net/2008/10/megatrader/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 21:25:49 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[megatrader]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=21</guid>
		<description><![CDATA[For the past week, when I haven&#8217;t been working, I&#8217;ve been spending a good deal of my free time developing a J2ME mobile game. The basic premise is Dope Wars in space, albeit with less drugs and more futuristic trade goods. The inset image is the main menu screen running in the WTK emulator. Right [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_22" class="wp-caption alignleft" style="width: 160px"><a href="http://slyfox.za.net/wp-content/uploads/2008/10/mtemu1.jpg" rel="shadowbox[post-21];player=img;"><img src="http://slyfox.za.net/wp-content/uploads/2008/10/mtemu1-150x150.jpg" alt="Megatrader Main Menu" title="Megatrader Main Menu" width="150" height="150" class="size-thumbnail wp-image-22" /></a><p class="wp-caption-text">Megatrader Main Menu</p></div>
<p>For the past week, when I haven&#8217;t been working, I&#8217;ve been spending a good deal of my free time developing a <a href="http://java.sun.com/javame/index.jsp">J2ME</a> mobile game. The basic premise is Dope Wars in space, albeit with less drugs and more futuristic trade goods. The inset image is the main menu screen running in the <acronym title="Wireless ToolKit">WTK</acronym> emulator. Right now, I&#8217;m more or less at the point where I can actually start on getting the game up and running, having spent the time thus far on getting all the support functionality down (such as drawing text using my custom fonts and being able to easily support different resolutions, since I&#8217;ll be targeting at least <a href="http://en.wikipedia.org/wiki/Quarter_VGA">QVGA</a> and <a href="http://en.wikipedia.org/wiki/Common_Intermediate_Format">QCIF+</a> displays).</p>
<p>Initially, the game will be fairly simple, featuring only simple trading: buy at planet A, travel to planet B and sell, rinse and repeat until the time limit is hit, with random price fluctuations as per the drug busts in Dope Wars. In the future, there are a couple of distinguishing features I want to add to the game, such as competing against computer-controlled traders and being able to buy different ships which affect their cargo space and travel speed, amongst other things.</p>
<p><span id="more-21"></span></p>
<div id="attachment_23" class="wp-caption alignright" style="width: 160px"><a href="http://slyfox.za.net/wp-content/uploads/2008/10/mtemu2.jpg" rel="shadowbox[post-21];player=img;"><img src="http://slyfox.za.net/wp-content/uploads/2008/10/mtemu2-150x150.jpg" alt="Megatrader: Planet Screen WIP" title="Megatrader: Planet Screen WIP" width="150" height="150" class="size-thumbnail wp-image-23" /></a><p class="wp-caption-text">Megatrader: Planet Screen WIP</p></div>
<p>For the ship travel speed to be meaningful, a distance matrix of the distances between the planets will be calculated at game initialisation, with the distance and travel speed affecting the number of days that elapse when travelling from one planet to the other. To make this an attractive option to the player, distant planets will have to have a higher bias for delivering higher yields (meaning prices are inflated or reduced more than normal), making trips to distant planets a potentially lucrative expedition, but on the other hand, may end up causing the player to lose precious time; and in this game, time is indeed money.</p>
<p>Another idea I toyed with was that of having a simple economy built in, especially if other traders are taken into account as well. If a trader reaches a planet before you and sells an enormous amount of one cargo, the demand will experience a sharp drop, causing the price to plummet. On the other hand, if you get to a planet and fill your ship&#8217;s cargo hold with a cargo type, supply decreases, and the price will increase to the next trader&#8217;s detriment.</p>
<p>An old favourite I&#8217;d thought about when designing an earlier trading game is that of black market goods. These goods perform a function similar to the distant planet idea, in that they are a potential source of a higher than normal income. Whereas distant planets are not guaranteed to have a higher price, black market goods will <em>always</em> fetch a higher price. The risk involved with black market goods is that the player stands a random chance of being caught by the authorities, resulting in the cargo being seized and the player receiving a hefty fine for their transgression.</p>
<p>There are a couple of other ideas on the whiteboard, so to speak, but for now I&#8217;ll be concentrating on getting the basics done and working, and figuring out the One And True game balance for the basic trade goods (i.e. pricing, fluctuation biases, etc.). Another thing that will limit the implementation of all these ideas is the possible limitations on code/data size on the mobile phone platforms: at the moment the QVGA version of Megatrader already weighs in 357KB. Most of the JAR&#8217;s size is caused by the background screens, which are rather varied in terms of their colour content. Since J2ME applications use PNG as image format, images that are not uniformly coloured and that do not feature consecutive strings of the same colour tend not to compress that well. Depending on how many screens I still have to add, this may or may not become an issue. If it does, I&#8217;ll have to drop a fair amount of the detail present in the screens, something I am loathe to do, since it&#8217;s about damn time we have a mobile Java game that looks <em>good</em>, for fuck&#8217;s sake.</p>
<p>Hopefully I&#8217;ll have a playable version of the game by the end of next week. And after that&#8230; well, maybe I&#8217;ll have a gander at that iPhone SDK. Or, considering I might be looking at getting a Windows Mobile phone soon, I&#8217;ll see what that old beast we call the .NET Compact Framework can do for the world. But that&#8217;s getting ahead of myself. I have to finish one version of the game first!</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2008/10/megatrader/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Acceptance Testing With Selenium I</title>
		<link>http://slyfox.za.net/2008/10/acceptance-testing-with-selenium-i/</link>
		<comments>http://slyfox.za.net/2008/10/acceptance-testing-with-selenium-i/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 19:38:30 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=12</guid>
		<description><![CDATA[The freelance work I&#8217;m currently doing called for some testing after I significantly changed the underlying framework&#8217;s internals. Considering I&#8217;d been spoilt with the idea of automating any and all testing when I was going through my Ruby on Rails phase, I started looking around for something similar in the PHP camp. The most important [...]]]></description>
			<content:encoded><![CDATA[<p>The freelance work I&#8217;m currently doing called for some testing after I significantly changed the <a href="http://edcms.net/">underlying framework</a>&#8217;s internals. Considering I&#8217;d been spoilt with the idea of automating any and all testing when I was going through my <a href="http://rubyonrails.org/">Ruby on Rails</a> phase, I started looking around for something similar in the <a href="http://php.net/">PHP camp</a>. The most important thing I had to keep in mind was that it needed to be something that was JavaScript aware, since the website utilises a <em>lot</em> of JavaScript fanciness.</p>
<p>Enter <a href="http://selenium.openqa.org/">Selenium</a>. More specifically, the combination of <a href="http://selenium-rc.openqa.org/">Selenium Remote Control</a> (RC) and <a href="http://www.phpunit.de/">PHPUnit</a>.</p>
<p>Selenium RC is a Java server application which launches instances of the browser(s) you specify, and then puts them through the paces of the tests that you define using plain old PHP and PHPUnit, checking the assertions you define. In other words, you get the effect of a real user using a real browser, without having to do all the grunt work yourself. Win-win.</p>
<p>The current version of Selenium RC (henceforth referred to as SRC) I&#8217;m using (version 0.9.2) works like a charm, but requires a small tweak to work with Firefox 3. When SRC instantiates a new instance of Firefox, it creates a temporary profile and installs a Selenium extension into the profile. This extension&#8217;s maximum Firefox version is still set to the Firefox 2 versions, so it will silently fail under Firefox 3, leaving you to gnash your teeth in frustration while you sift through Google to find out why the damn thing isn&#8217;t working.</p>
<p>Fortunately, the fix is simple. It involves unpacking the <kbd>selenium-server.jar</kbd> file, and changing the <kbd>install.rdf</kbd> located under the <kbd>customProfileDirCUSTFF</kbd> directory, so that the <kbd>maxVersion</kbd> element contains the value <kbd>3.0.*</kbd> to work with Firefox 3.0.</p>
<p>From there on, you can either pack everything up again into a new JAR (which I didn&#8217;t bother with), or simply run the server in its unpacked form.</p>
<p>Next time, I&#8217;ll dish up a small sample of how to actually go about doing that funky thing we call testing with Selenium RC and PHPUnit.</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2008/10/acceptance-testing-with-selenium-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
