<?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>// Indie Shift</title>
	<atom:link href="http://shift.net.nz/feed/" rel="self" type="application/rss+xml" />
	<link>http://shift.net.nz</link>
	<description>Indie iOS Development</description>
	<lastBuildDate>Thu, 07 Feb 2013 02:00:22 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.7.3</generator>
	<item>
		<title>Memory Mapped files on iOS &#8211; worth checking out</title>
		<link>http://shift.net.nz/2011/04/memory-mapped-files-on-ios-worth-checking-out/</link>
		<comments>http://shift.net.nz/2011/04/memory-mapped-files-on-ios-worth-checking-out/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 17:07:58 +0000</pubDate>
		<dc:creator><![CDATA[Lloyd]]></dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://shift.net.nz/?p=168</guid>
		<description><![CDATA[Overview I&#8217;ve been following Carmack&#8217;s tweets on porting RAGE to iOS and was intrigued by his and other mentions that memory mapped files work so well on the platform. Mapped files have the advantage of being cached by the OS (in kernel memory space) and paged in and out of memory as necessary. On a [&#8230;]]]></description>
				<content:encoded><![CDATA[<h2>Overview</h2>
<p>I&#8217;ve been following <a href="http://twitter.com/id_aa_carmack" target="_blank">Carmack&#8217;s</a> tweets on porting RAGE to iOS and was intrigued by his and other <a href="http://twitter.com/__ReJ__/status/45498139641249792" target="_blank">mentions</a> that memory mapped files work so well on the platform.</p>
<p>Mapped files have the advantage of being cached by the OS (in kernel memory space) and paged in and out of memory as necessary. On a desktop platform or console, the unpredictable seek time of the disk makes this less feasible, but with the gauranteed solid state disk of apple products it becomes an interesting proposition.</p>
<p>Since the mapping is in kernel space it can actually remain cached across application launches which is a nice performance win.</p>
<h2>The Test</h2>
<p><a href="http://strayrobotgames.com/">Wooords</a> has a 1MB resident english dictionary for checking word submissions against. The dictionary is a array of sorted 64bit ints, to look up a word a simple binary search is performed.</p>
<p>The dictionary is an ideal candidate for moving to a memory mapped file as the OS can cache the commonly hit parts of the data file and leave the rest on disk (although I&#8217;m not sure how smart the caching algorithm is? Is it page based?)</p>
<p>To test these theories out I implemented the required calls and timed the binary search for a variety of words.</p>
<div style="text-align: center;">
<table style="border-collapse: collapse; width: 50%; margin: 0px auto;" border="1&quot;">
<tbody>
<tr>
<td></td>
<td>Malloc</td>
<td>Mapped</td>
</tr>
<tr>
<td>Lookup 1</td>
<td>0.009ms</td>
<td>0.111ms</td>
</tr>
<tr>
<td>Lookup 2</td>
<td>0.009ms</td>
<td>0.010ms</td>
</tr>
<tr>
<td>Lookup 3</td>
<td>0.008ms</td>
<td>0.008ms</td>
</tr>
<tr>
<td>Lookup 4</td>
<td>0.011ms</td>
<td>0.011ms</td>
</tr>
<tr>
<td>Lookup 5</td>
<td>0.008ms</td>
<td>0.072ms</td>
</tr>
</tbody>
</table>
</div>
<p>As we can see the mmap array has similar performance but there&#8217;s an initial spike as the data is loaded by the kernel and a couple smaller spikes during usage.</p>
<p>For dictionary lookup the extra latency now and again is not a problem and therefore the choice to use mapped files easy.</p>
<h2>Technical Implementation</h2>
<p>To use a memory mapped file, simply open the file as usual and then call the mmap function. Once you&#8217;re done with the data munmap it and close the file.</p>
<p>Map</p>
<pre class="brush: cpp; title: ; notranslate">
FILE* fp = fopen(&quot;file.dat&quot;, &quot;rb&quot;);
fseek(fp, 0, SEEK_END);
size_t length = ftell(fp);fseek(fp, 0, SEEK_SET);
int fd = fileno(fp);
off_t offset = 0;
void* data = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, offset);
fclose(fp);
</pre>
<p>Arguments</p>
<div>
<table style="border-collapse: collapse; width: 90%; margin: 0px auto;" border="1&quot;">
<tbody>
<tr>
<td>NULL</td>
<td>Base address to use for mapping, this doesn&#8217;t matter for us, let the OS choose one</td>
</tr>
<tr>
<td>length</td>
<td>Number of bytes to map into memory, in our case the whole file</td>
</tr>
<tr>
<td>PROT_READ</td>
<td>We&#8217;re only interested in readying the file</td>
</tr>
<tr>
<td>MAP_SHARED</td>
<td>Share this file with other processes on the system, if its written to we get the updates. This should be the most performant, otherwise the OS has to do a copy on write.</td>
</tr>
<tr>
<td>fd</td>
<td>The file descriptor</td>
</tr>
<tr>
<td>offset</td>
<td>The start of the mapping on the file</td>
</tr>
</tbody>
</table>
<p>For a detailed explation of the parameters see <a href="http://linux.die.net/man/2/mmap" target="_blank">man mmap</a>.</p>
</div>
<p>Unmap</p>
<pre class="brush: cpp; title: ; notranslate">
munmap(data, length);
</pre>
<h2>Conclusion</h2>
<p>Using memory mapped files can reduce your process memory footprint with minor modifications to your code. It can however cause small load stalls, so the best thing to do is to benchmark it in your application.</p>
<p>Overall its another great tool in the iOS developers toolbox.</p>
]]></content:encoded>
			<wfw:commentRss>http://shift.net.nz/2011/04/memory-mapped-files-on-ios-worth-checking-out/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Custom leaderboards with GoogleAppEngine</title>
		<link>http://shift.net.nz/2011/03/custom-leaderboards-with-googleappengine/</link>
		<comments>http://shift.net.nz/2011/03/custom-leaderboards-with-googleappengine/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 20:20:33 +0000</pubDate>
		<dc:creator><![CDATA[Lloyd]]></dc:creator>
				<category><![CDATA[Game Services]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://shift.net.nz/?p=145</guid>
		<description><![CDATA[Custom? Why custom I hear you say &#8211; GameCenter provides all the leaderboard APIs anybody could ever need, or does it? Unfortunately Wooords requires a lot more than 25 (the current GameCenter limit) leaderboards as the  game is going to ship with a lot more puzzles. This has led me to consider a number of other options. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-151" title="appengine_lowres" src="http://shift.net.nz/wp-content/uploads/appengine_lowres.gif" alt="Google App Engine" width="142" height="109" />Custom? Why custom I hear you say &#8211; GameCenter provides all the leaderboard APIs anybody could ever need, or does it?</p>
<p>Unfortunately <a href="http://strayrobotgames.com" target="_blank">Wooords</a> requires a lot more than 25 (the current GameCenter limit) leaderboards as the  game is going to ship with a lot more puzzles. This has led me to consider a number of other options. After <a href="http://gamesfromwithin.com/google-app-engine-as-back-end-for-iphone-apps" target="_blank">reading</a> a number of <a href="http://gamesfromwithin.com/life-in-the-top-100-and-the-google-app-engine" target="_blank">great posts</a> on GAE, I decided to it was the best fit for my needs and I like Python. <a href="http://heroku.com" target="_blank">Heroku</a> could be another good alternative if you prefer Ruby on Rails.</p>
<h2>Implementation</h2>
<p>For a basic leaderboard implementation all we need to be able to do is submit and query scores. More complex features like querying friends scores can easily be built on top of this.</p>
<h4>Message Format</h4>
<p>I chose json as my message format as I already had support for it built into my engine. Unfortunately GAE runs python 2.5, which doesn&#8217;t support json natively, however I downloaded simplejson (which works identically to the 2.6 version) and it just worked. All communication is done via HTTP post requests to the google cluster.</p>
<h4>Names and UserIds</h4>
<p>Each user requires a unique id in the system, rather than forcing to users to create an account I decided to use the existing GameCenter information to store the UserId and their name. When the game starts up it &#8216;registers&#8217; the user with the server, this simply records their id and name and gives me the option to send back a Message of the Day. If the user is running an older version of iOS or a device that does not support GameCenter, the system fallsback to using the device id and allows the user to pick a name.</p>
<h4>Security</h4>
<p>With a simple json message format it won&#8217;t take long before somebody starts sniffing your network packets and then attempts to submit a fake score. To counter this all messages that require security checking contain an additional <em>auth</em> token. This token is based on a number of things, the most important being a server key that changes regularly.</p>
<p>The system consists of two tokens, a client key and a rolling server token.</p>
<p>When the client wishes to send a secure message it first requests an authentication token from the server, this token is only valid for a short period of time to reduce the chance of somebody sniffing and then using the token. This server token is then combined with the client token and used to sign the contents of the message.</p>
<p>When the server receives the request, it checks the signature against the contents of the message, if it matches the message is processed, otherwise it is ignored.</p>
<p>It is important to obfuscate the client token in the executable so that the key cannot be obtained with a hex editor.</p>
<h2>Other Advantages</h2>
<p>The custom leaderboards can now store a lot more than just score. I track time, word count and a bunch of other statistics as well.</p>
<p>After implementing the leaderboards a bunch of other things became a lot easier, for example I could now store user profiles in GAE and have cross device syncing. When the game starts, it simply requests the profile from the server, if the profile received has more points than the profile on the device it replaces the local profile, otherwise we send out profile to back to the server.</p>
<p>All in all working with AppEngine has been a very easy process, things will get a bit more interesting when the app goes live.</p>
]]></content:encoded>
			<wfw:commentRss>http://shift.net.nz/2011/03/custom-leaderboards-with-googleappengine/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using OpenAL on iOS</title>
		<link>http://shift.net.nz/2010/12/using-openal-on-ios/</link>
		<comments>http://shift.net.nz/2010/12/using-openal-on-ios/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 06:19:33 +0000</pubDate>
		<dc:creator><![CDATA[Lloyd]]></dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://shift.net.nz/?p=121</guid>
		<description><![CDATA[There are a number of articles around on implementing CoreAudio on iOS, but not so much information on OpenAL on this platform. In this article I&#8217;m going to give a brief overview of how and why I chose to use OpenAL. Why OpenAL? OpenAL provides a simple cross platform API for playing audio. Developing directly [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>There are a number of articles around on implementing CoreAudio on iOS, but not so much information on OpenAL on this platform.</p>
<p>In this article I&#8217;m going to give a brief overview of how and why I chose to use OpenAL.</p>
<h2>Why OpenAL?</h2>
<p>OpenAL provides a simple cross platform API for playing audio. Developing directly for OpenAL ensures compatibility across all Mac, Windows and Linux desktop machines too, which is extremely useful for development as audio and art assets can be tested directly on desktop hardware without the need for the ios simulators.</p>
<p>OpenAL also automatically handles the device mute button, which is a handy side affect.</p>
<h2>Which file format?</h2>
<p>On desktop systems, ogg-vorbis would probably be the best choice for audio encoding as is completely free and has great compression ratios. However on mobile platforms using too mich CPU time for audio decompression reduces framerate and adds unnecessary battery drain.</p>
<p>The Quicktime IMA4 format reduces audio file size to a quater of its PCM equivalent while only requiring a small amount of code<sup><a href="#footer1">1</a></sup> in your application which makes it very attractive for this platform. Apple provide a number of functions for working with audio files which makes implementation a lot easier, however because of my requirements for application to run on non Apple systems I had to implement all the low level functions. I found the older AIFF file format a lot easier to work with than the more modern CAF format.</p>
<p>It should also be noted there are open source libraries to help with loading audio like <a href="http://www.mega-nerd.com/libsndfile/">libsndfile</a>, however their license (LGPL in the case of libsndfile) make them too restrictive for static linking in an closed source iOS application.</p>
<h2>Implementation</h2>
<p>I chose to implement all sound playback as streaming sounds, since iOS devices use solidstate disks, seek time is negligible. No samples are ever loaded completely into memory.</p>
<p>A single OpenAL audio source supports multiple buffers, load any number of buffers into the source and OpenAL will play through the buffers in order. When a buffer has been been played, detach the buffer, fill it with new data and queue it for the source. 3 buffers of 48k each works quite well.</p>
<p>When a sample is played, load and decode enough data to fill all the buffers (with IMA4 simply multiply the compressed size by 4 to get the uncompressed size) and start the playback.</p>
<p>To handle the recycling of the buffers set up a second thread in the audio engine that runs every quater of a second looking for buffers that have been used on all playing sound sources and fills them.</p>
<p>Its a good idea to implement the system without IMA4 support first (hint: WAV files), get that working and then add decompression as a second step. For convenience leave the support for playing uncompressed files in, your content developers will probably get annoyed having to compress files simply for testing.</p>
<h2>Converting files</h2>
<p>The easiest way to compress your audio files to IMA4 is to the command line afconvert tool provided with every Mac. The converter takes just about any input format (including MP3) and writes a multitude of different codecs and file formats. In this case we use AIFC and IMA4.</p>
<p><code><br />
afconvert -f AIFC -d ima4 input.wav output.ima4<br />
</code></p>
<h2>Conclusion</h2>
<p>Implementing OpenAL is straight forward and provides a great cross platform alternative to CoreAudio. Using IMA4 will greatly reduce the size of your application without using too much CPU for decompression.</p>
<p><a name="footer1"></a> Source code to the IMA decompression can be found <a href="/source-code/ima4-codec/">here</a>.</p>
<p><strong>UPDATE</strong>: I&#8217;ve since discovered that this IMA decoder doesn&#8217;t work exactly like the apple implementation which means it causes a small amount of noise that is only audible when playing very quiet tracks. I suggest looking at the Apple sample <a href="http://developer.apple.com/library/mac/#samplecode/AudioCodecSDK/Introduction/Intro.html" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://shift.net.nz/2010/12/using-openal-on-ios/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Building a MVC UI with libRocket</title>
		<link>http://shift.net.nz/2010/10/building-a-mvc-ui-with-librocket/</link>
		<comments>http://shift.net.nz/2010/10/building-a-mvc-ui-with-librocket/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 20:46:44 +0000</pubDate>
		<dc:creator><![CDATA[Lloyd]]></dc:creator>
				<category><![CDATA[libRocket]]></category>

		<guid isPermaLink="false">http://shift.net.nz/?p=72</guid>
		<description><![CDATA[The Model-View-Controller pattern is used extensively in modern web APIs. (Rails, Django, ZendFramework, &#8230;) so I thought I&#8217;d give it a try with the interface I&#8217;m building for my latest project. It worked out pretty well. Motivation I&#8217;m using libRocket to render the UI for Wooords on iOS. libRocket comes with great Python integration, that [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><!--start_raw--><br />
<a href="http://shift.net.nz/wp-content/uploads/rocketlogo.gif"><img src="http://shift.net.nz/wp-content/uploads/rocketlogo.gif" alt="libRocket" title="rocketlogo" width="64" height="64" class="alignright size-full wp-image-189" /></a><br />
The <a href="http://en.wikipedia.org/wiki/Model%E2%80%93View%E2%80%93Controller" target="_blank">Model-View-Controller</a> pattern is used extensively in modern web APIs. (Rails, Django, ZendFramework, &#8230;) so I thought I&#8217;d give it a try with the interface I&#8217;m building for my latest project. It worked out pretty well.</p>
<h2>Motivation</h2>
<p>I&#8217;m using <a href="http://librocket.com" target="_blank">libRocket</a> to render the UI for <a href="http://strayrobotgames.com/wooords">Wooords</a> on iOS. libRocket comes with great Python integration, that allows the programmer to do just about anything with it from script, however Python is a bit heavyweight for my needs on mobile devices, it&#8217;s more suited to the desktop or console usage.</p>
<p>I need to build a simple system where by menu flow and events can be triggered from RML (libRocket&#8217;s markup language, think HTML with extensions) so interfaces can be prototyped and mocked up without touching the c++ code &#8211; think live reload, fast iteration.</p>
<p><strong>The Model-View-Controller pattern&#8230;</strong></p>
<p><em>“ The pattern isolates &#8220;domain logic&#8221; (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing and maintenance of each (separation of concerns).”</em> &#8211; Wikipedia</p>
<p>The two parts I&#8217;m going to describe below are the Controller and the View, the Model is the internal data structures specific to your game.</p>
<h2>Views and Controllers</h2>
<p>In my case libRocket is managing the view, as defined in RML files and the c++ programmer is implementing the controller.</p>
<p>The libRocket document will send events to its attached controller, which will update your model (drink a potion, disable sounds, etc) and then update the view accordingly.</p>
<p>The engine should support a way of registering a named controller with a c++ class, that will be invoked at runtime. You could do this with an instancer, or have all your controllers permanently resident. When a screen is required the engine looks up the controller by name, instances it if necessary and requests libRocket to load the corresponding view (RML file). I recommend keeping the file name of the RML file the same as the controller name.</p>
<p>A number of screens do not require any special behaviour (think <em>Main Menu</em>, P<em>ause Menu</em>), you should consider providing a generic controller implementation that implements basic common functionality that the more complex menus could derive from.</p>
<h2>Hooking into the event system</h2>
<p>By default libRocket does not handle inline RML events. Adding the Python plugin allows you to use Python events, however we want to implement our own event handling. We need to register a custom event listener and its corresponding instancer. This instancer is invoked whenever libRocket parses an event in RML (<em>onclick</em>, <em>onload</em>, <em>onkeydown</em>, etc<a href="#librocketevents"><sup>1</sup></a>). You should pass in a pointer to your engines UI manager class (in my case <em>UIContext</em>), so that it can be notified when an event fires.</p>
<div class="code">class EventListener : public Rocket::Core::EventListener<br />
{<br />
public:<br />
	EventListener(UIContext* context, const Rocket::Core::String&amp; value) : mContext(context), mValue(value)<br />
	{<br />
	}<br />
	virtual ~EventListener() {}</p>
<p>	/// Sends the event value through to Invader&#8217;s event processing system.<br />
	virtual void ProcessEvent(Rocket::Core::Event&amp; event)<br />
	{<br />
		mContext-&gt;processEvent(event, mValue.CString());<br />
	}</p>
<p>	/// Destroys the event.<br />
	virtual void OnDetach(Rocket::Core::Element* element)<br />
	{<br />
		delete this;<br />
	}</p>
<p>private:<br />
	UIContext* mContext;<br />
	Rocket::Core::String mValue;<br />
};</p>
<p>class EventListenerInstancer : public Rocket::Core::EventListenerInstancer<br />
{<br />
public:<br />
	EventListenerInstancer(UIContext* context) : mContext(context) {}<br />
	virtual ~EventListenerInstancer() {}</p>
<p>	/// Instances a new event handle for Invaders.<br />
	virtual Rocket::Core::EventListener* InstanceEventListener(const Rocket::Core::String&amp; value)<br />
	{<br />
		return new EventListener(mContext, value);<br />
	}</p>
<p>	// Destroys the instancer.<br />
	virtual void Release()<br />
	{<br />
		delete this;<br />
	}<br />
private:<br />
	UIContext* mContext;<br />
};
</p></div>
<p>Then somewhere in your initialisation code you&#8217;ll need to tell libRocket about your EventListenerInstancer</p>
<div class="code">
Rocket::Core::Factory::RegisterEventListenerInstancer(new EventListenerInstancer(this));
</div>
<p>After implementing the above code you should be able to define a <em>onclick</em> event on a button in RML as follows:</p>
<pre>&lt;button onclick=”hello”&gt;My Button&lt;/button&gt;</pre>
<p>If you load this view and click the button, processEvent on your UIContext will get called with the text “hello”. In this way, you can generically send events to your UI system from RML files.</p>
<h2>Basic control script</h2>
<p>Sending text strings through to your UIContext is all very well, but you probably want to be able to have some basic control from RML.</p>
<p>The text strings coming through from RML can be any format you like, I chose to implement a simple parser that understands C like function syntax. This way I can separate commands with semicolons and pass as my arguments as necessary.</p>
<p>I&#8217;ve implemented 3 basic commands</p>
<ul>
<li>open(&lt;menu name&gt;): This opens a menu, by looking up the controller and associated view</li>
<li>close([menu name]): Closes the named menu, if no menu is specified, it closes the menu this RML is associated with</li>
<li>sendevent(&lt;event name&gt;, [menu_name]): Sends the event to the named menu, or the current menu if no name is specified.</li>
</ul>
<p>The <em>open</em> and <em>close</em> functions are pretty self explanatory. The <em>sendevent</em> function simply calls the virtual method <em>processEvent</em> on the specified controller with a string. Its up to that controller to interpret the string as it sees fit. For example my pause menu calls <em>sendevent(pause, game)</em> in its onload event, which sends the <em>pause</em> event to the <em>game</em> controller whenever the pause menu is opened.</p>
<h2>Conclusion</h2>
<p>Hooking into the libRocket event system and providing a very simple scripting interface allows you to prototype and build your whole menu flow without touching c++ code. Once the menus are defined you can then go back and define custom controllers for each screen and add the required events for triggering more complex behaviours from the views.</p>
<div style="font-size: 12px">
<a name="librocketevents"></a>1 &#8211; For a full list of supported rocket events see: <a href="http://librocket.com/wiki/documentation/RML/Events" target="_blank">http://librocket.com/wiki/documentation/RML/Events</a>
</div>
<p><!--end_raw--></p>
]]></content:encoded>
			<wfw:commentRss>http://shift.net.nz/2010/10/building-a-mvc-ui-with-librocket/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building Universal i386/arm6/arm7 freetype library</title>
		<link>http://shift.net.nz/2010/09/compiling-freetype-for-iphoneios/</link>
		<comments>http://shift.net.nz/2010/09/compiling-freetype-for-iphoneios/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 21:44:55 +0000</pubDate>
		<dc:creator><![CDATA[Lloyd]]></dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://shift.net.nz/?p=43</guid>
		<description><![CDATA[Over the last couple of weeks I&#8217;ve been preparing for the libRocket open source release. One of the things that confused me for awhile was how to go about building FreeType for iPhone/iOS. After a fair bit of trial and error I came up with something that allowed me to be a universal i386/i686/arm6/arm7 binary, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><!--start_raw--></p>
<p>Over the last couple of weeks I&#8217;ve been preparing for the <a href="http://librocket.com">libRocket</a> open source release. One of the things that confused me for awhile was how to go about building FreeType for iPhone/iOS. After a fair bit of trial and error I came up with something that allowed me to be a universal i386/i686/arm6/arm7 binary, so thought I&#8217;d document it here.</p>
<h2>Compiling the library</h2>
<p>We have to compile the library four times, once for each architecture.</p>
<h4>i386</h4>
<p><code>$ ./configure CFLAGS="-arch i386"<br />
$ make</code></p>
<p>This forces configure to use the i386 architecture and build the library. The built library is located at objs/.libs/libfreetype.a. We copy this to our top level folder and build the next architecture.</p>
<p><code>$ cp objs/.libs/libfreetype.a libfreetype-i386.a</code></p>
<h4>x86_64</h4>
<p>Similar build setup for x86_64, notice the addition of &#8221;make clean&#8221;, we want to completely remove the i386 code.</p>
<p><code>$ ./configure CFLAGS="-arch x86_64";make clean;make<br />
$ cp objs/.libs/libfreetype.a libfreetype-x86_64.a</code></p>
<h4>arm6</h4>
<p>Arm6 is used on iPhone 3G and earlier. There are quite a few arguments that need to be passed to configure to make it build for arm6. I&#8217;m going under the assumption that you&#8217;re targeting iOS 3.2 using gcc-4.2 as your compiler. If this is not what you want, please update the arguments below accordingly.</p>
<p><code>$ ./configure --prefix=/usr/local/iphone --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2  CFLAGS="-arch armv6 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=3.2 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/usr/include/libxml2 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar LDFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -miphoneos-version-min=3.2"<br />
$ make clean;make<br />
$ cp objs/.libs/libfreetype.a libfreetype-arm6.a</code></p>
<h4>arm7</h4>
<p>Arm7 is used on iPhone 3GS and newer. We do the exact same options as above, but pass arm7 as the architecture (remember to update the CFLAGS and the LDFLAGS)</p>
<p><code>$ ./configure --prefix=/usr/local/iphone --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2  CFLAGS="-arch armv7 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=3.2 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/usr/include/libxml2 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar LDFLAGS="-arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -miphoneos-version-min=3.2"<br />
$ make clean;make<br />
$ cp objs/.libs/libfreetype.a libfreetype-arm7.a</code></p>
<h2>Bringing it all together as a universal library</h2>
<p>We now have 4 individual libraries. To combine them into a single universal library use the &#8221;lipo&#8221; tool.</p>
<p><code>$ lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64 libfreetype-arm6.a libfreetype-arm7.a</code></p>
<p>And thats it,  you can check which architectures are in a library with the -info argument.</p>
<p><code>$ lipo -info libfreetype.a<br />
Architectures in the fat file: libfreetype.a are: armv6 armv7 i386 x86_64</code><br />
<!--end_raw--></p>
]]></content:encoded>
			<wfw:commentRss>http://shift.net.nz/2010/09/compiling-freetype-for-iphoneios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reducing executable size on iPhone</title>
		<link>http://shift.net.nz/2010/03/reducing-executable-size-on-iphone/</link>
		<comments>http://shift.net.nz/2010/03/reducing-executable-size-on-iphone/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 12:03:03 +0000</pubDate>
		<dc:creator><![CDATA[Lloyd]]></dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Ogre3d]]></category>

		<guid isPermaLink="false">http://www.shift.net.nz/?p=37</guid>
		<description><![CDATA[The biggest thing I noticed when after switching to Ogre3d on the iPhone was the large jump in executable size. With my old engine the release executable for the iPhone was just over 1MB, after the switch my executable was around 8MB! This doesn&#8217;t leave much room for content as ideally we want to stay [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>The biggest thing I noticed when after switching to Ogre3d on the iPhone was the large jump in executable size. With my old engine the release executable for the iPhone was just over 1MB, after the switch my executable was around 8MB! This doesn&#8217;t leave much room for content as ideally we want to stay under the 10MB mark to allow our application to be downloaded over 3G.</p>
<p>So where was all this space going? I&#8217;d already disabled any static plugins that I didn&#8217;t need, leaving OgreMain, RenderSystemGLES, Plugin_ParticleFX, FreeType, OIS and FreeImage.</p>
<p>Taking a look at the iPhone dependencies folder, there were 2 libraries that jumped out at me, FreeImage (1.3MB) and FreeType (500kb).</p>
<p>I decided the quickest way to get my executable size down was to remove these two dependencies. Unfortunately my current code base relies on FreeType for fonts, so I set that aside as a second phase, however removing FreeImage should be trivial as all I needed to do was disable it in Ogre, rebuild and then provide a custom ImageCodec for the image types I used (only TGA).</p>
<p>I rebuilt Ogre and my application, disabling ZIP archives at the same time and I&#8217;m pleased to say it reduced the size of my executable by 1.5MB!</p>
<p>I&#8217;ve placed my custom <a href="http://www.shift.net.nz/source-code/ogre3d-tga-codec">TGA Codec</a> in the <a href="http://www.shift.net.nz/source-code/">Source Code</a> section of this site, you may find it useful.</p>
<p>In the coming weeks I plan to remove FreeType and switch completely to Bitmap based fonts.</p>
]]></content:encoded>
			<wfw:commentRss>http://shift.net.nz/2010/03/reducing-executable-size-on-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ogre3d for iPhone</title>
		<link>http://shift.net.nz/2010/01/ogre3d-for-iphone/</link>
		<comments>http://shift.net.nz/2010/01/ogre3d-for-iphone/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 07:08:50 +0000</pubDate>
		<dc:creator><![CDATA[Lloyd]]></dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Ogre3d]]></category>

		<guid isPermaLink="false">http://www.shift.net.nz/?p=4</guid>
		<description><![CDATA[For awhile now I&#8217;ve been prototyping iPhone applications and games. A fair amount of my time was dedicated to maintaining an engine, providing artists with tools for testing on the iPhone and debugging pipeline issues (I had been using the POD file format, as used in oolong and developed by Imagination Technologies &#8211; the developer [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>For awhile now I&#8217;ve been prototyping iPhone applications and games. A fair amount of my time was dedicated to maintaining an engine, providing artists with tools for testing on the iPhone and debugging pipeline issues (I had been using the POD file format, as used in oolong and developed by Imagination Technologies &#8211; the developer of the iPhone graphics chip).</p>
<p>Recently I stumbled across the announcement of Ogre3d 1.7 and there were two features that were of great interest to me.</p>
<ul>
<li> MIT License</li>
<li> iPhone support (OpenGL ES Renderer)</li>
</ul>
<p>Switching to the MIT license means Ogre3d can be statically linked to an application without requiring your code to be open source, previously it was LGPL, which as far as I understand it that you didn&#8217;t have to release any code that linked with Ogre3d dynamically (not possible on the iPhone)</p>
<p>Adding a native OpenGL ES Renderer to means any code written for Ogre would run with little modification on the iPhone.</p>
<p>The Ogre3d engine technology is a lot more advanced than my own tech and the content pipeline is so much more mature. Ogre3d has a very large active community who have developed many plugins and addons and been used in a couple of high profile PC titles. The Ogre Team is also currently working on an OpenGL ES 2.0 implementation (used by the iPhone 3GS), with full shader support. Being able to run the game on iPhone, Mac and PC is a great advantage.</p>
<p>Being a more advanced engine means it probably wont be quite as quick as a custom built solution, however I should be able to spend a lot more time in game code, rather than engine code.</p>
<p>For me, its a no brainer and I&#8217;m sure my artists are going to enjoy the more streamlined pipeline.</p>
]]></content:encoded>
			<wfw:commentRss>http://shift.net.nz/2010/01/ogre3d-for-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
