<?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>OOgtech.org</title>
	<atom:link href="http://www.oogtech.org/content/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oogtech.org/content</link>
	<description>Tea&#039;s blog</description>
	<lastBuildDate>Mon, 07 May 2012 12:42:43 +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>Abusing inheritance and protocols</title>
		<link>http://www.oogtech.org/content/2012/04/23/abusing-inheritance-and-protocols/</link>
		<comments>http://www.oogtech.org/content/2012/04/23/abusing-inheritance-and-protocols/#comments</comments>
		<pubDate>Sun, 22 Apr 2012 17:26:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS/Cocoa]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[antipattern]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[inheritance]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=4251</guid>
		<description><![CDATA[Recently I experimented with various ways of configuring data programmatically. Okay, I&#8217;ll say loud what some will be thinking when reading this. Why not use an XML file? Well&#8230; no. Not unless you need to store this data, share it&#8230; load it over a network&#8230; (then, yes). In many other cases, using hard, compile safe [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I experimented with various ways of configuring data <em>programmatically</em>.</p>
<p>Okay, I&#8217;ll say loud what some will be thinking when reading this. Why not use an XML file?</p>
<p>Well&#8230; no. Not unless you need to store this data, share it&#8230; load it over a network&#8230; (then, yes). In many other cases, using hard, compile safe code to assign values and configure objects, has advantages.</p>
<ul>
<li>XML data without a validator (including build system integration) is no better than interpreted code.</li>
<li>Without a template (and a convenient editor driving the &#8216;form filling process&#8217;) XML data is tedious to write and tedious to maintain.</li>
<li>Hard-wired configs break at compile time. Data loaded from XML files or CSV rarely breaks before runtime.</li>
<li>There&#8217;s no point in writing data formats and validators for data that changes often &#8211; for example when a codebase / paradigm is relatively &#8216;fresh&#8217;.</li>
</ul>
<p>So I&#8217;ll go with hard-wiring and try to figure a decent pattern for it. I&#8217;ll use macros if I have to, and avoid them if I can. I was, then, looking for a patterned way of configuring my data, and I came up with <em>this</em>:</p>
<ol>
<li>Have a class <em>Foo</em>, need to configure instances of <em>Foo</em>.</li>
<li>Created an interface <em>IFooSetup</em>, specifying getter methods for configuration data: <em>getA(), getB(), getC()</em>&#8230; etc&#8230; etc&#8230;</li>
<li>Created a class <em>FooDefaultSetup &lt;IFooSetup&gt;</em> providing a default configuration.</li>
<li>Created multiple subclasses of <em>FooDefaultSetup</em> &#8211; <em>BlueFooSetup</em>, <em>YellowFooSetup</em>, <em>GreenFooSetup</em> etc etc&#8230;</li>
</ol>
<p>Not just <span style="text-decoration: underline;">I won&#8217;t do it again</span> (at least, not in ObjC). <span style="text-decoration: underline;">I will also refactor my code</span>.</p>
<p>Why is this approach troublesome &#8211; why did I come up with this idea in the first place?</p>
<p><strong>Setup interface/protocol</strong></p>
<p><em>IFooSetup</em> is a protocol dedicated to helping programmers configure instances of <em>Foo</em>. Sometimes it can work. One advantage of using an interface is that (inside an IDE) it works much like a form (a piece of paper with blanks that one needs to write into). The compiler helps the programmer ensure (often, in realtime) that all required config parameters are set.</p>
<p>So good so far (and I don&#8217;t care whether anybody&#8217;s bothered writing a class just to configure another object).</p>
<p>Maybe it is a pattern, then. <em>A fortiori</em>, however, it does take a couple of useful language features for this to actually work.</p>
<p><strong>Default config class</strong></p>
<p>Sooner or later, the idea of creating a class named <em>FooDefaultSetup</em> will arise. Why, because several objects shared common parameters. It is logical.</p>
<p>Unfortunately, although some languages allow abstract classes, ObjC does not. As a result, once we go with <em>FooDefaultSetup</em>, we have to implement all the methods declared by <em>IFooSetup</em>, including getters for which <em>FooDefaultSetup</em> can supply no meaningful default &#8211; and as a result we have just short-circuited the usability of IFooSetup &#8211; it no longer works &#8216;more or less like a form&#8217; &#8211; to determine what methods we&#8217;d like to override, we have to check the source code for <em>IFooSetup</em>.</p>
<p><strong>Breakable code.</strong></p>
<p>No real mess will start until we change the signature of a method in <em>IFooSetup</em>. At this point, it would be <em>neat</em> if the compiler could help us make sure that the many, many implementers of IFooSetup (BlueFooSetup, YellowFooSetup, &#8230; ) are updated accordingly, alas&#8230;</p>
<ul>
<li>Some languages (quizzically, the defunct Javascript 4) will have you tag every method intended to override a method up the inheritance chain. This means that you can&#8217;t accidentally override methods. It also means that you get an error when the method <em>no longer overrides another method. </em>Not so in ObjC</li>
<li>Other languages won&#8217;t let you implement a method that hasn&#8217;t been declared. Not so in ObjC.</li>
</ul>
<p>What happens, then?</p>
<p><em>FooDefaultSetup</em> is somewhat maintainable since it must implement all methods in IFooSetup.</p>
<p>Sadly, none of the subclasses of <em>FooDefaultSetup</em> are maintainable. Forgetting to update/correct the method signature for any of these subclasses is now the easiest thing in the world, resulting in code never being called. Not just any code, but sound, simple, honestly good looking trivial code that mainly consists in getters.</p>
<p>A little down the line we&#8217;ll be looking at bugs and wondering why an object doesn&#8217;t behave as expected, the trivial reason being: configuration code is out of date, and the compiler knows nothing about it.</p>
<p><strong>K.I.S.S</strong></p>
<p>So, yea&#8230; never again. Instead of configuring objects in this way, I&#8217;ll sooner do the following and be better for it:</p>
<ul>
<li>Keep it simple, stupid. Configure an object by calling accessors on this object.</li>
<li>If you need a &#8216;checklist&#8217; of what needs to be configured&#8230; consider copy-pasting the config block from another, similar object. Or write a checklist. Or write a validator.</li>
<li>At least when an accessor&#8217;s signature changes, the compiler will warn against all and every deprecated use of the modified method.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/04/23/abusing-inheritance-and-protocols/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a simple Governor</title>
		<link>http://www.oogtech.org/content/2012/04/19/writing-a-simple-governor/</link>
		<comments>http://www.oogtech.org/content/2012/04/19/writing-a-simple-governor/#comments</comments>
		<pubDate>Thu, 19 Apr 2012 10:52:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game Programming]]></category>
		<category><![CDATA[Actor]]></category>
		<category><![CDATA[Character]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[governor]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[servo]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=4216</guid>
		<description><![CDATA[When the motion of game actors is driven by a physics engine, we need a reliable method to control their motion. A governor uses negative feedback to adjust forces given a target velocity. Principle When a body of mass M is at rest, applying a force F will result in a speed S = F [...]]]></description>
			<content:encoded><![CDATA[<p><em>When the motion of game actors is driven by a physics engine, we need a reliable method to control their motion. A governor uses negative feedback to adjust forces given a target velocity.</em></p>
<p><strong>Principle</strong></p>
<p>When a body of mass <em>M</em> is at rest, applying a force <em>F</em> will result in a speed <em>S = F / m</em>.</p>
<p>This formula can be used to write a simple governor &#8211; given the current velocity V0 and a target velocity V1, we have:</p>
<p style="text-align: center;"><strong>F = ( V1 &#8211; V0 ) * M</strong></p>
<p style="text-align: left;">Units:</p>
<ul>
<li>F &#8211; force applied (Newtons)</li>
<li>V1, V0 &#8211; velocity (meters per second)</li>
<li>M &#8211; mass (kilograms)</li>
</ul>
<p>Given the above we can write a very simple function that will calculate the force F required to update the velocity of an actor at every frame.</p>
<p>It may be working better than you&#8217;d expect &#8211; notably, given motion conservation, even a trivial governor (based on the above principle) will quickly achieve target velocity.</p>
<p><strong>Scaling the output</strong></p>
<p>The above formula can be modified by introducing a scale parameter:</p>
<p style="text-align: center;"><strong>F = ( V1 &#8211; V0 ) * M * S</strong></p>
<p style="text-align: left;">The scale parameter may have uses &#8211; for example you can use it to increase the governor&#8217;s output when friction/air resistance become significant.</p>
<p style="text-align: left;">Note that <span style="text-decoration: underline;">scaling the output in this way may break time invariance</span> &#8211; the simulation will behave somewhat differently depending on the size of time steps.</p>
<p><strong>Implementation notes</strong></p>
<p><span style="text-decoration: underline;">Impulses vs continuous forces</span></p>
<p>A simple way to implement the above consists in delivering the governor&#8217;s output as <em>impulses</em>. An impulse is a discrete force applied to a physical body. <em>A</em> <em>priori </em>it may appear that continuous forces would be a better choice. However, depending on the way continuous forces are implemented by the physics engine, an impulse governor may be preferable:</p>
<ul>
<li>When applying a continuous force, the force is usually given in <em>newtons per second</em>. Therefore additional calculations are needed to precisely determine the total force delivered by the governor.</li>
<li>With impulses applied at every frame, the &#8216;stop and start&#8217; effect that one should expect is not visible.</li>
</ul>
<div>Beware that using impulses doesn&#8217;t mean that we can fully ignore the size of time steps (see &#8216;scaling the output&#8217;, above).</div>
<div></div>
<div><span style="text-decoration: underline;">Ground units</span></div>
<div></div>
<div>When driving the motion of ground units, there are many situations where the slope of the terrain isn&#8217;t known <em>a priori. </em>So the primary input to the governor is a velocity vector parallel to the horizontal plane.</div>
<div>However, applying horizontal forces to a ground unit may cause artifacts.</div>
<div></div>
<div>Why should we expect artifacts? The governor adjusts velocity towards a specified target &#8211; so if the terrain has a slope, velocity includes a vertical component. Unless this vertical component is included into the target velocity, the governor will &#8216;resist&#8217; climbing and falling.</div>
<div></div>
<div>For a ground unit, it is meaningful to disable the governor&#8217;s output when a ground unit is airborne.</div>
<p><strong>Issues</strong></p>
<p><span style="text-decoration: underline;">Sharp changes in orientation</span></p>
<p>In some games, sharp changes in orientation are not a problem, especially when the actor need to be responsive (e.g. controlled by the player). For large actors and some other games however, sharp changes in orientation look ugly. A low value for S ( ~0.1 or less ) will reduce artifacts but this solution is not ideal.</p>
<p>A simple way to solve this problem is to interpolate between the current orientation and the target velocity <em>before </em>passing the target velocity to the governor.</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Note</span>: <em>I removed the &#8216;motion aliasing&#8217; section referred here previously; the artifacts I observed in my simulations were not related to the governor itself.</em></p>
<p><strong>Going further: adaptive governors</strong></p>
<p>Compared to the solution described above an adaptive governor can handle various situations by automatically correcting the scale factor S. This is done by measuring the bias between the expected output (target velocity at frame t0) and the actual output (real velocity at frame t1 = t0+1).</p>
<p>It is wiser to start with a simple governor - whether adaptive or not, the governor needs to be initialized with a base value for S; additionally when encountering obstructions, adaptive governors tend to &#8216;overheat&#8217; &#8211; increasing S to a very high value. While it is possible to clamp the scale factor to a specific range, this is probably just the first in a series of adjustments &#8211; adaptive governors are smarter, they are also harder to design.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/04/19/writing-a-simple-governor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>F* in Objective C</title>
		<link>http://www.oogtech.org/content/2012/04/16/f-in-objective-c/</link>
		<comments>http://www.oogtech.org/content/2012/04/16/f-in-objective-c/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 12:22:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile Teams]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[Application Design]]></category>
		<category><![CDATA[F*]]></category>
		<category><![CDATA[F-Star]]></category>
		<category><![CDATA[separation]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=4181</guid>
		<description><![CDATA[This is quick tutorial showing how to get started with F* in Objective-C. F* is a proposed meta-pattern for application development (see here for related documents) You can check out the sample project from SVN: http://xp-dev.com/svn/harmony-framework/trunk/f-star/iOS/tutorial/FStarExample/ Setting up your project Open XCode. Go to File &#62; New Project Select &#8216;Empty Application&#8217;. In Product Name, I [...]]]></description>
			<content:encoded><![CDATA[<p>This is quick tutorial showing how to get started with F* in Objective-C. F* is a proposed meta-pattern for application development (see <strong><a href="http://www.oogtech.org/content/f/">here</a></strong> for related documents)</p>
<p>You can check out the sample project from SVN:</p>
<p><a href="http://xp-dev.com/svn/harmony-framework/trunk/f-star/iOS/tutorial/FStarExample/">http://xp-dev.com/svn/harmony-framework/trunk/f-star/iOS/tutorial/FStarExample/</a></p>
<p><strong>Setting up your project</strong></p>
<ol>
<li>Open XCode.</li>
<li>Go to File &gt; New Project</li>
<li>Select &#8216;Empty Application&#8217;.</li>
<li>In Product Name, I input FStarExample.</li>
<li>I put my projects under my experiments/ folder. XCode will create a folder for our project.</li>
</ol>
<p><strong>Arranging the sample project</strong></p>
<p>I like to have &#8216;headroom&#8217; in my projects. The initial project structure looks like this:</p>
<ul>
<li>FStarExample (project node)</li>
<ul>
<li>FStarExample (source location)</li>
<li>FStarExampleTests (for unit testing)</li>
<li>Frameworks (libraries required by the iOS SDK)</li>
<li>Products (build output)</li>
</ul>
</ul>
<p>I regroup all items, so that it looks like this:</p>
<ul>
<li>FStarExample (project node)</li>
<ul>
<li><strong>source</strong> (custom group)</li>
<li><strong>tests</strong> (previously, &#8216;FStarExampleTests&#8217;)</li>
<li>[implied]</li>
<ul>
<li>FStarExample-Prefix.pch (digged up from &#8216;Supporting Files&#8217; I just like to keep this one &#8216;visible&#8217;)</li>
<li>FStarExample (still the app delegate)</li>
<li>Products</li>
<li>Frameworks</li>
</ul>
</ul>
</ul>
<p>Keep in mind that XCode groups are just a convenient way to&#8230; group files. For better and for worse, grouping is irrelevant to the underlying file structure.</p>
<p><strong>Setting up an F* instance</strong></p>
<p>Under <em>source</em> I create the following structure:</p>
<ul>
<li>source</li>
<ul>
<li>[m]</li>
<li>Facade.h</li>
<li>Dispatcher.h</li>
<li>Feature.h</li>
</ul>
</ul>
<p>The <strong>Facade</strong> will be used to instantiate all the features we use in our application. The <strong>Dispatcher</strong> provides the basis for gluing features together. <strong>Feature</strong> is the base class for all application features.</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Note</span>: <em>XCode doesn&#8217;t encourage physical groupings (putting source files in separate folders &#8211; it is needless to say possible but doesn&#8217;t flow smoothly) so I&#8217;ll be content with XCode groups.</em></p>
<p><strong>Creating a feature</strong></p>
<p>To create a feature named foo, follow the steps:</p>
<ol>
<li>create a group named <em>foo</em></li>
<li>create a subclass of <em>Feature</em>, <em>Foo</em> inside group foo.</li>
<li>foo overrides <em>setup</em> in Feature.</li>
<li>import the feature class from Facade and add an entry to <em>initFeatures</em>.</li>
</ol>
<p>The sample project illustrates the above steps.</p>
<p><strong>Event handling</strong></p>
<p>The dispatcher mediates communication between features via events. In the provided example:</p>
<ul>
<li>Foo registers with the dispatcher to receive an event x. registration happens within the setup method. (While <em>setup</em> is running, nothing warrants that all features are already initialized so while it&#8217;s okay to register for events, it is not okay to dispatch.</li>
<li>After all features are setup, the start method is called on each feature, at which point Bar dispatches the event.</li>
</ul>
<div>If you <em>test</em> the sample project (hold run button in top left until options appear), you can check the output in the log window.</div>
<p><div><strong>Implementation notes</strong></div>
<p><div></div>
<div><span style="text-decoration: underline;">About event handling and the dispatcher</span></div>
<div></div>
<div>In my sample project, the dispatcher is not very scalable &#8211; as we go on and define more and more notifications, it will quickly become bloated. I will probably update the sample project a bit later to show how this can be fixed.</div>
<div></div>
<div>In practice this needs to be done with some care &#8211; when using F* defining new notifications is common enough that a templated approach quickly becomes desirable.</div>
<div></div>
<div><span style="text-decoration: underline;">About the facade</span></div>
<div></div>
<div>In the facade each feature is bound to the applications in two ways:</div>
<div>
<ul>
<li>We need to import the feature class</li>
<li>The feature class needs to be instantiated and added to the feature list.</li>
</ul>
<div>Classes can be instantiated dynamically, which practically allows turning a feature <em>off </em>without having to change any code. Needless to say this comes at the cost of compile time safety.</div>
<div></div>
<div>The facade should be connected with FStarExampleAppDelegate. As the last call in <em>application:didFinishLaunchingWithOptions</em>: I instantiate the facade. A real application would need to provide access to UI resources (here, the window provided by the app delegate).</div>
</div>
<p><div><strong>In Practice</strong></div>
<p>When I use F*, I tend two follow a 3 step cycle.</p>
<p style="padding-left: 30px;"><strong>1. induction</strong></p>
<p style="padding-left: 30px;">During the &#8216;inductive phase&#8217;, I try to focus exclusively on the problem I am solving. If I feel my feature requires external input (or a signal), I design notifications without worrying about the source of such notifications.</p>
<p style="padding-left: 30px;">This approach becomes important over time because it allows solving the problem at hand without  burdening ourselves with the growing &#8216;mass of code&#8217; that the project generates. For me this inductive phase is similar to &#8216;starting a new project&#8217;. Surely most programmers have noticed that they feel dynamic and fresh at the beginning of a new project?</p>
<p style="padding-left: 30px;"><strong>2. testing</strong></p>
<p style="padding-left: 30px;">During the testing phase, notifications can be used to write acceptance tests &#8211; test the feature in isolation.</p>
<p style="padding-left: 30px;"><strong>3. integration</strong></p>
<p style="padding-left: 30px;">During the integration phase, I make sure that the notifications the feature relies on are actually satisfied.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/04/16/f-in-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Library, Pop Tart, Static</title>
		<link>http://www.oogtech.org/content/2012/04/11/library-pop-tart-static/</link>
		<comments>http://www.oogtech.org/content/2012/04/11/library-pop-tart-static/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 07:19:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS/Cocoa]]></category>
		<category><![CDATA[*.a]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Build Phases]]></category>
		<category><![CDATA[Copy]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Nyan Cat]]></category>
		<category><![CDATA[Pop Tart]]></category>
		<category><![CDATA[static library]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=4142</guid>
		<description><![CDATA[In case you&#8217;re not getting it from the title, I may not have learned anything substantial while writing this article. I just created yet another static library, tried linking it against another, and there goes XCode (build 4C104) NYAAAAN. Since I used to write my own coding tools, I bloody well knew how to compile a java [...]]]></description>
			<content:encoded><![CDATA[<p><em>In case you&#8217;re not getting it from the title, I may not have learned anything substantial while writing this article. I just created yet another static library, tried linking it against another, and there goes XCode (build 4C104) </em>NYAAAAN.<em></em></p>
<p><em>Since I used to write my own coding tools, I bloody well</em> knew<em> how to compile a java (sigh) program on the command line. I also wrote tools in such a way that they found jars in </em>myland <em>(comforting it was, however restrictive).</em></p>
<p>XCode workspaces are meant to improve the (sodding) developer experience when dealing with complex projects. Don&#8217;t get me wrong, I&#8217;m all for wizardry &#8211; Clearly, however an <em>ignoramus ex machina</em> is usually at work when I try stringing libraries together.</p>
<p><strong>Useful notes?</strong></p>
<p>Check <a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#adding_the_static_librarys_headers">this article from the Carbon Five blog</a> for useful notes about linking static libraries. I&#8217;ll provide a new article on this topic at some point. I just wasted a couple of hours clear because this stuff is having its way. Here&#8217;s a lame summary of what I found:</p>
<ul>
<li>Like pixies, build issues appear when you least expect it. Sadly they also disappear mysteriously as soon as you try getting to the root of the problem.</li>
<li>You can fix build issues by <em>fiddling:</em></li>
<ul>
<li>If at first you don&#8217;t succeed&#8230;</li>
<li>Don&#8217;t assume a library won&#8217;t get found because it appears &#8216;marked red&#8217;</li>
<li>Don&#8217;t assume a library will get found because it doesn&#8217;t appear &#8216;marked red&#8217;</li>
<li>Assume duplicate items can easily arise when adding libraries to a project.</li>
<li>Remove duplicate items whenever you stumble on them.</li>
<li>Play with the &#8216;Location&#8217; combo (relative to group, relative to project etc&#8230;).</li>
</ul>
<li>Don&#8217;t be afraid to check build logs. The paths often look infuriatingly convoluted, but while you&#8217;re poking around to find what&#8217;s really gone wrong, the problem is getting itself fixed (and at least you&#8217;re kidding yourself that you have something to do with it).</li>
</ul>
<div>Need I say this is only the beginning of an idiotic battle? I <em>will</em> get to the bottom of this (if there is one).</div>
<p><strong>The case</strong></p>
<p>Okay, let&#8217;s say I made a library called &#8216;foobar&#8217; (I actually did)</p>
<p>Initially, under &#8216;products&#8217;, <em>libfoobar.a</em> is red. In my file inspector the location is relative to build products (and cannot be changed)</p>
<p>For sake, build (don&#8217;t add any source file) and check what happens: nothing. Well that&#8217;s good, innit? No source files, no library.</p>
<p>Now, add a source file and rebuild. Check the messages window. We now have 3 items: Precompile&#8230;, Compile&#8230; and Libtool.</p>
<p>Under Libtool, we can see the intended location of the output:</p>
<pre>-o /Users/johndoe/Library/Developer/Xcode/DerivedData/workspace-fdpyddpbphekphdqtzzutyjcagva/Build/Products/Debug-iphonesimulator/libfoobar.a</pre>
<p>Feeling paranoid (would Libtool ever <em>lie</em>?) we can verify that the library has been created by browsing to this path (Finder is gracefully setup to overlook whatever path this stuff goes under).</p>
<p>But the item still appears &#8216;marked red&#8217; under &#8216;Products&#8217;. Suspicious?</p>
<p><strong>Can&#8217;t copy libfoobar.a?</strong></p>
<p>Now let&#8217;s try linking foobar against a target inside another project (same workspace, right?). Open project settings (yea click on the project in the navigator), go to <em>Build Phases &gt; Link Binary With Libraries,</em> hit the [+] button. A cute browser now appears with libfoobar.a under Workspace (or whatever your workspace is named). Select libfoobar.a, press return and&#8230; *build*.</p>
<p>Mind, this operation adds an item to your project, now also visible in the navigator (libfoobar.a, still marked red).</p>
<p><em>If</em> there is an error, it may look like this:</p>
<pre>error: /Users/<span style="text-decoration: underline;">johndoe</span>/Library/Developer/Xcode/DerivedData/workspace-fdpyddpbphekphdqtzzutyjcagva/Build/Products/Debug-iphonesimulator<span style="text-decoration: underline;">/../../../../../../../../svn/components/base/</span>build/Release-iphoneos<span style="text-decoration: underline;">/libfoobar.a</span>: No such file or directory</pre>
<pre>Command builtin-copy failed with exit code 1</pre>
<p>What&#8217;s going on here? Let&#8217;s go and check the added library item inside our project (select the item and make check sure the inspector is open). I see this:</p>
<p style="padding-left: 30px;"><em>Location: relative to group</em></p>
<p style="padding-left: 30px;"><em>Path:<span style="text-decoration: underline;"> ../../../components/base/build/Release-iphoneos/libfoobar.a</span></em></p>
<p>Clearly not right (yet, consistent with the failed copy operation)</p>
<p>Fancy patching the path manually?</p>
<p style="padding-left: 30px;"><em>Location: relative to build products</em></p>
<p style="padding-left: 30px;"><em>Path: ../Debug-iphonesimulator/libfoobar.a</em></p>
<p>Worked for me, but not right away. Digging around I found yet another duplicate of the same library reference (marked red!). Removed it, cleared (what appears to be) the same item under &#8216;build phases&#8217; and re-re-re-added it all over again (this time by checking the box I wanted in &#8216;target memberships&#8217;).</p>
<p><strong>Not happy</strong></p>
<p>I felt somewhat unconvinced (notably, I&#8217;m not happy with the <em>Debug-iphonesimulator</em> part of the relative-to-build-products-path &#8211; how&#8217;s that supposed to backfire?).</p>
<p>So I removed the library altogether and started over. Just repeated the initial steps going by the book&#8230; sadly it&#8230; worked.</p>
<p>Until next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/04/11/library-pop-tart-static/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing Using XCode 4.2</title>
		<link>http://www.oogtech.org/content/2012/03/30/testing-using-xcode-4-2/</link>
		<comments>http://www.oogtech.org/content/2012/03/30/testing-using-xcode-4-2/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 10:21:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile Teams]]></category>
		<category><![CDATA[iOS/Cocoa]]></category>
		<category><![CDATA[4.2]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Test Suite]]></category>
		<category><![CDATA[test target]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[unit tests]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=4081</guid>
		<description><![CDATA[This article is a revision of a previous article I wrote about unit testing with XCode. I describe the steps carried to setup a test target long after a project has been created, so initially the test target will lack most of what&#8217;s needed to operate correctly (e.g frameworks, libraries and source files) Setting up [...]]]></description>
			<content:encoded><![CDATA[<p><em>This article is a revision of a previous article I wrote about unit testing with XCode.</em></p>
<p><em>I describe the steps carried to setup a test target <span style="text-decoration: underline;">long after a project has been created</span>, so initially the test target will lack most of what&#8217;s needed to operate correctly (e.g frameworks, libraries and source files)</em></p>
<p><em>Setting up may take up to a few hours.</em></p>
<p>Creating a test target isn&#8217;t a big deal (just go to the project panel, add a new target and follow the steps).</p>
<p>I expect tests to run <em>every time</em> I try to build/run the main target. If the tests won&#8217;t pass I&#8217;d rather not fire up the simulator.</p>
<p>By default, the test target is not setup to work this way. Maybe it makes sense (after all, how does it know which target to depend <em>on</em>).</p>
<ol>
<li>Go to <em>project panel =&gt; build phases</em> ; add the test target under <em>target dependencies</em>.</li>
<li>In the project panel, open &#8216;build settings&#8217; for the test target, search for and tick &#8216;Test After Build&#8217;.</li>
</ol>
<div><span style="text-decoration: underline;">Note</span>:<em> You can also edit the scheme for the main target; under &#8216;testing&#8217;, add the test target. However doing it this way won&#8217;t action tests every time you run the application; you&#8217;d have to select the test action instead of run (top-left of xcode window, press and hold the &#8216;run&#8217; button).</em></div>
<div></div>
<div>Up to &#8216;housekeeping&#8217;, the steps described below are likely necessary. Try to build before/after every step and check build messages to help you move on.</div>
<p><strong>1. Adding source files</strong></p>
<p>Maybe the fastest way to add your .m files: go to Build Phases and scroll to &#8216;source files&#8217;, then press add. type *.m as search filter. If you have many groups you may need to do this a few times to include all the required files.</p>
<p><strong>2. Disable/Enable Automated reference counting.</strong></p>
<p>In your test target, under build settings, search for &#8216;Reference counting&#8217; and tick/untick &#8220;Objective-C Automatic Reference Counting&#8221;</p>
<p><strong>3. Replace/Edit precompiled headers</strong></p>
<p>In build settings, search for &#8216;pch&#8217;. If possible I just copy the *.pch from my main target settings to the test target settings.</p>
<p><strong>4. Add the required frameworks &amp; libraries</strong></p>
<p>Most of this should be copied from your main target. Opening the assistant editor so you can compare/check both targets at once is useful (see <em>build phases &gt; link binary with libraries</em>).</p>
<p>If you miss a library it will result in countless unresolved dependencies so it&#8217;s easy to figure.</p>
<p><strong>5. List additional headers</strong></p>
<p>If you&#8217;re pointing at additional headers in build settings, ideally you can share definitions by declaring them in the project&#8217;s (not the target&#8217;s) build settings &#8211; target-specific entries can be overwritten using<em> $(inherited).</em></p>
<p><strong>Housekeeping</strong></p>
<p><span style="text-decoration: underline;">Keep your framework/library references tidy:</span> Checking the list of frameworks/libraries included in your project (there may be some in several places) may be a good idea as (harmless) duplicates may arise.</p>
<p>With frameworks/libraries, getting &#8216;red files&#8217; is not rare. In many cases this doesn&#8217;t mean anything is actually broken (sigh&#8230;)</p>
<p><span style="text-decoration: underline;">Remove unused files:</span> remove files created by the wizard, if unused (e.g. precompiled headers)</p>
<p><span style="text-decoration: underline;">Rename/Regroup:</span> Renaming/Regrouping may cause references to break and need further editing. It&#8217;s a bit fidgety so you&#8217;ve been warned.</p>
<p>I like using generic names for my source folders (e.g. not <em>MyApp Tests/</em> , just <em>test/</em> ) and certain files (<em>info.plis</em>t instead of<em> MyAppTests-Info.plist</em>). Renaming the info.plist will require editing in build settings etc&#8230; so maybe it&#8217;s easier to leave things as they are (XCode can help you rename project items).</p>
<p><strong>Caveats</strong></p>
<p>Beware that some classes in related libraries may rebuild after setting up the test suite; if old files were lingering in the system this may cause errors and confusion. Clean the build if things start looking weird.</p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/03/30/testing-using-xcode-4-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC: extracting a user agent?</title>
		<link>http://www.oogtech.org/content/2012/03/28/extracting-a-user-agent/</link>
		<comments>http://www.oogtech.org/content/2012/03/28/extracting-a-user-agent/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 06:35:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game Design]]></category>
		<category><![CDATA[acceptance tests]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[QA]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=4058</guid>
		<description><![CDATA[Starting with a naive MVC application my goal was to provide automated testing over headless graphics (e.g. using a standard test suite). How can we modify an application so that it can be used either by a real world user or by a robot? I started with a concept (&#8216;the user agent&#8217;). This is somewhat useful [...]]]></description>
			<content:encoded><![CDATA[<p><em>Starting with a naive MVC application my goal was to provide automated testing over headless graphics (e.g. using a standard test suite). How can we modify an application so that it can be used either by a real world user or by a robot?</em></p>
<p><em>I started with a concept (&#8216;the user agent&#8217;). This is somewhat useful and helped clarify the application structure. However, it seems a better way to get this to work is may be to just write a couple of tests &#8216;assuming the underlying system&#8217; is already compatible with our new requirements &#8211; in other words, design the solution outside-in.</em></p>
<p><em>Additionally, I&#8217;m looking into existing automations for iOS; I will shortly review a couple of attractive solutions.</em></p>
<p><strong>The user agent</strong></p>
<p>A so called user agent (I may be abusing the term) is an interface bridging the view and the controller. Why would it be useful to complicate our design in this way?</p>
<p>Initially, an MVC application works like this:</p>
<p style="text-align: center;">USER<em> &lt;=&gt; {View} &lt;=&gt; {Controller} &lt;=&gt; { Model } (2)</em></p>
<p style="text-align: left;">With a testing automation, it may look like this:</p>
<p style="text-align: center;"><em>{ Robot } &lt;=&gt; {View} &lt;=&gt; {Controller} &lt;=&gt; { Model }</em></p>
<p style="text-align: left;">Indeed certain automations work this way (great); what about testing over headless graphics?</p>
<ul>
<li>The<em> view</em> component <span style="text-decoration: underline;">must not</span> be instantiated.</li>
<li>We cannot instantiate the <em>controller</em> unless we hide/factor out view dependencies.</li>
</ul>
<p style="text-align: left;">We could write tests that only exercise the model; not bad, maybe too far removed from our goal.</p>
<p style="text-align: left;">So the idea is to introduce an interface (&#8216;user agent&#8217;) bridging the view and controller; then we could setup the application in either of two ways:</p>
<p style="text-align: center;">USER<em> &lt;=&gt; View &lt;=&gt; { UA } &lt;=&gt; {Controller} &lt;=&gt; { Model }</em></p>
<p style="text-align: center;"><em>{ Robot } &lt;=&gt; { UA } &lt;=&gt; {Controller} &lt;=&gt; { Model }</em></p>
<p style="text-align: left;"><strong>A quick refactoring</strong></p>
<p style="text-align: left;">Clearly dependencies between the view and controller need to be factored out in order to realize the above. Initially the controller owns a reference to the view and may processes UI events.</p>
<p style="text-align: left;">One way to proceed:</p>
<ol>
<li>Migrate event handling code to the UI; inside event handling code we invoke controller methods.</li>
<li>Provide interfaces (e.g. IUser or IUserInput, IUserOutput) that the controller uses to output to, or configure input from, the UI. The UI implements these interfaces.</li>
</ol>
<div>Then the situation is like this:</div>
<div></div>
<div style="text-align: center;"><em>View (Event Handlers) =&gt; Controller</em></div>
<div style="text-align: center;"><em>Controller =&gt; View &lt;IUser&gt;</em></div>
<div style="text-align: center;"></div>
<div style="text-align: left;">I have done exactly that with our application code. This refactoring is not overly time consuming.</div>
<div style="text-align: center;"></div>
<div style="text-align: left;">Formally, the approach does not seem incorrect. We can write a<em> Robot</em> class implementing <em>&lt;IUser&gt;</em> and <em>Robot</em> can directly invoke controller methods. This approach, however, should be validated by answering the following questions:</div>
<div style="text-align: left;"></div>
<div style="text-align: left;">Can we easily write acceptance tests?</div>
<div style="text-align: left;">Can we generate tests by recording sessions?</div>
<div style="text-align: left;"></div>
<div style="text-align: left;"><span style="text-decoration: underline;">Session recording/playback</span></div>
<div style="text-align: left;"></div>
<div style="text-align: left;">It appears that recording messages issued by the UI may not be very easy with the above solution. The <em>idea</em> is simple. In practice, however, the controller is often defined as an aggregation (a hierarchy of controllers):</div>
<div style="text-align: left;">
<ul>
<li><em>RootController</em></li>
<ul>
<li><em>ControllerA</em></li>
<li><em>ControllerB</em></li>
</ul>
</ul>
</div>
<div style="text-align: left;">Now, we can pass a <em>Recorder</em> to all controllers down the hierarchy and <em>certain methods </em>in each controller would generate messages sent to the recorder. Having to record from (and playback to) a graph instead of a single object is a complication that should be avoided. Further (contingent to the above refactoring) it is not clear which invocations should be recorded (cf. &#8220;certain methods&#8221;).</div>
<div style="text-align: left;"></div>
<div style="text-align: left;">In short, it would be reasonable to introduce an interface that captures messages from the view to the controller:</div>
<div style="text-align: left;"></div>
<div style="text-align: left;">
<div style="text-align: center;"><em>View (Event Handlers) =&gt; Controller &lt;IApplication&gt;</em></div>
<div style="text-align: center;"><em>Controller =&gt; View &lt;IUser&gt;</em></div>
</div>
<div style="text-align: left;"></div>
<div style="text-align: left;"><span style="text-decoration: underline;">Writing acceptance tests</span></div>
<div style="text-align: left;"></div>
<div style="text-align: left;">For the programmer writing acceptance tests, the controller hierarchy appears untidy. Although controller classes look &#8216;higher level&#8217; once event handling code has been factored out, the methods are still designed to be called by the UI in response to user events. This may involve continuous input as well as fairly idiosyncratic sequences. As a result, introducing <em>&lt;IApplication&gt;</em> as suggested above may not be sufficient. Compared to interaction records, manually written tests should be fairly &#8216;stylized&#8217;.</div>
<div style="text-align: left;">One solution may be to write a <em>Robot</em> class used to capture requirements for writing acceptance tests.</div>
<div style="text-align: left;"></div>
<div style="text-align: left;"><span style="text-decoration: underline;">Where is the UA?</span></div>
<div style="text-align: left;"></div>
<div style="text-align: left;">A quick refactoring is insufficient. We need more kit to get this to work. The UA would then be realized by several interfaces:</div>
<div style="text-align: left;">
<ul>
<li><em>&lt;IUser&gt;</em> specifies methods invoked by the controller in order to display output or configure user input</li>
<li><em>&lt;IApplication&gt;</em> specifies methods normally invoked by the UI in order to operate the application. Invocations of <em>IApplication</em> may be recorded for later playback.</li>
<li>A <em>Robot</em> class may define high level methods used to manually write tests.</li>
</ul>
<p><strong>To be continued&#8230;</strong></p>
<p>My impression at this point is that I may have jumped in <em>too quickly &#8211; </em>starting to design based on a &#8216;good idea&#8217; instead of formalizing use cases.</p>
<p>The UA idea is &#8216;kind of good&#8217;. But it took time to move from the idea to an understanding of what the UA might actually be.</p>
<p>Actually, the most productive step was not thinking about the UI but defining a new initializer for the session, like thus:</p>
<p style="text-align: center;"><em>Session initWithContext:(id&lt;SessionContext&gt;)context</em></p>
<p>Where:</p>
<ol>
<li><em>Session </em>represents a user session; roughly matches the model/controller.</li>
<li><em>SessionContext </em>is intended to capture anything that a user session may require to boot and run, with or without headless graphics.</li>
<ul>
<li>A live session context would provide a UI.</li>
<li>A testing context would not provide a UI.</li>
</ul>
<li><em>Session</em> can be instantiated in a headless graphics environment.</li>
</ol>
<p>If a session can be defined in this way, we have done half of the work.</p>
<p><em>(tbc)</em></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/03/28/extracting-a-user-agent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blender/XCode integration using Build Rules</title>
		<link>http://www.oogtech.org/content/2012/03/20/4000/</link>
		<comments>http://www.oogtech.org/content/2012/03/20/4000/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 08:42:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile Teams]]></category>
		<category><![CDATA[Blender Scripting]]></category>
		<category><![CDATA[iOS/Cocoa]]></category>
		<category><![CDATA[.blend]]></category>
		<category><![CDATA[Blender]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[build process]]></category>
		<category><![CDATA[build rule]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[resource management]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=4000</guid>
		<description><![CDATA[We use blender to create game assets; we also use blender as level editor. Blend files are exported to our proprietary format using py scripts. Exporting files manually is okay&#8230; to a point. Soon we find out not only that exporting files manually is a chore, it contributes to creating a beautiful mess. How to automate [...]]]></description>
			<content:encoded><![CDATA[<p><em>We use blender to create game assets; we also use blender as level editor. Blend files are exported to our proprietary format using py scripts.</em></p>
<p><em>Exporting files manually</em> is <em>okay&#8230;</em> to a point<em>. Soon we find out not only that exporting files manually is a chore, it contributes to creating a beautiful mess.</em></p>
<p>How to automate the conversion? With XCode, it can be done using build rules. I&#8217;m covering the following points:</p>
<ul>
<li>Build integration &#8211; add files to your build, automatically translate them using utilities and include the products in your app bundle.</li>
<li>Defining useful build rules.</li>
<li>Invoking blender from the command line.</li>
<li>Modifying blender scripts so that they won&#8217;t crash in a windowless environment.</li>
<li>Signaling export errors (notably, errors generated by a script running inside blender) using XCode.</li>
</ul>
<p>While we have a mixed workflow (Blender 2.49 / Blender 2.61), we&#8217;re dominantly using 2.49b, so I started with the older version. I&#8217;ll be covering 2.61&#8230; later.</p>
<p>I used the following articles as a starting point:</p>
<ul>
<li><a href="http://monkeystylegames.com/?p=45">How to add a custom build step to your project</a> (from<em> Monkey Style Games</em>)</li>
<li><a href="http://wiki.blender.org/index.php/Doc:2.4/Reference/Command_Line">Running Blender from the Command line</a> (2.4x)</li>
</ul>
<div>
<p><em>This article is not concise; I&#8217;ll summarize my findings in a coming article.</em></p>
</div>
<p><strong>The experiment</strong></p>
<p>The first step is to configure build rules to process *.blend files I guess, so in a first approximation I used this:</p>
<ul>
<li>Source files with names matching *.blend</li>
<li>Custom Script: <em>/Applications/blender/blender.app/Contents/MacOS/blender ${INPUT_FILE_PATH} </em><strong>(bad)</strong></li>
<li>Output Files:<br />
<em>${TARGET_BUILD_DIR}/../../${INPUT_FILE_BASE}.scg </em><strong>(bad)</strong></li>
</ul>
<div>I just thought it would be interesting to try this way although it&#8217;s obviously not complete. And indeed, it was.</div>
<div>First surprise, Blender opens in a window. Good for testing (notably because it&#8217;s displaying errors already; for a nice smooth build I&#8217;ll want to disable this).</div>
<div>Both Blender &amp; XCode are displaying messages in the XCode errors &amp; warnings panel, which is nice.</div>
<div></div>
<div>The initial problem is path related. The file won&#8217;t open because spaces in the path are incorrectly interpreted. So the correct form to open the blend is like this:</div>
<div>
<ul>
<li>/Applications/blender/blender.app/Contents/MacOS/blender &#8220;${INPUT_FILE_PATH}&#8221; <strong>(good)</strong></li>
</ul>
<div>Running the script is the next obvious step. For now blender just opens and idles happily until I quit. So I modify my command, like this:</div>
<div>
<ul>
<li>/Applications/blender/blender.app/Contents/MacOS/blender -b &#8220;${INPUT_FILE_PATH}&#8221; -P qwagga.py <strong>(bad)</strong></li>
</ul>
<p><strong>-b</strong> to tell blender to &#8216;render in background&#8217;. <strong>-P qwagga.py</strong> is the wishful step to run my script hoping that scripts are being run from the blender scripts folder. <strong>qwagga.py</strong> is my export script. There will be a problem with that but let&#8217;s try anyway.</p>
<p>Indeed, <strong>-b</strong> prevents the blender window from opening. Blender is reporting (via XCode) that qwagga.py wasn&#8217;t found. Interestingly it would appear that -P could also refer a script included inside the blend file (text node). For now, however, I&#8217;ll just provide the full path.</p>
<ul>
<li>/Applications/blender/blender.app/Contents/MacOS/blender -b &#8220;${INPUT_FILE_PATH}&#8221; -P /Applications/blender/blender.app/Contents/MacOS/.blender/scripts/qwagga.py <strong>(good)</strong></li>
</ul>
<p>Yea this works. As you&#8217;d expect since the exporter is trying to pop a file selection panel the script crashes with a fairly explicit message:</p>
<p><em>File &#8220;/Applications/blender/blender.app/Contents/MacOS/.blender/scripts/qwagga.py&#8221;, line 213, in &lt;module&gt;   Blender.Window.FileSelector(exportAssets,&#8217;Export to File&#8217;,PATH)</em><br />
<em>RuntimeError: the file/image selector is not available in background mode</em></p>
<p>This error can be patched easily:</p>
<p><em>    try:</em><br />
<em>            Blender.Window.FileSelector(exportAssets,&#8217;Export to File&#8217;,PATH)</em><br />
<em>    except RuntimeError:</em><br />
<em>            OUTPUT=Blender.sys.makename(ext=&#8217;.scg&#8217;)</em><br />
<em>    exportAssets(OUTPUT)</em></p>
<p>Telling XCode where the ouptut is located turned out to be a nag. The docs aren&#8217;t overly explicit about what environment variables can be used. As it turn out, however, whenever running a custom shell script (like, what we are doing now) the messages window displays a whole batch of <em>setenv</em> commands. That is all we need to know. I adjusted my entry in <em>output files</em> accordingly:</p>
<ul>
<li>${INPUT_FILE_DIR}/${INPUT_FILE_BASE}.scg</li>
</ul>
<p>Immediately after I got this work, it seemed there was &#8216;a bit of weirdness&#8217; in XCode (an error I couldn&#8217;t make sense of). For whatever reason this cleared after cleaning the build and re-saving my blend file.</p>
<p>It appears that each file is getting processed/converted whenever building (even if the input file hasn&#8217;t changed). I&#8217;m a bit worried about how this will turn when I have 200 blend files linked in this way &#8211; since blender loads almost instantly I&#8217;ll just wait and see.</p>
<p><strong>Single input =&gt; multiple output</strong></p>
<p>Now, the above looks quite useful but there are issues:</p>
<ul>
<li>My py scripts don&#8217;t output just one file.</li>
<li>In fact I have two py scripts used in blender. One outputs a single file, the other outputs a whole lot of files. The names of the files match object names in blender</li>
</ul>
</div>
<div>I would hope that both Blender and XCode can handle this situation gracefully.</div>
<div>For proof of concept, I just hacked a different output file path and created a file hierarchy looking like this :</div>
<div>
<ul>
<li>blends</li>
<ul>
<li>car_park.blend</li>
<li>build</li>
<ul>
<li>car_park.blz</li>
<ul>
<li>foo.rtf</li>
<li>bar.rtf</li>
</ul>
</ul>
</ul>
</ul>
</div>
<div>I added a &#8216;build&#8217; folder under blends because we don&#8217;t want to have output files sprawling around. Then the question is to know whether car_park.blz will be exported along with all its content (for sake, foo.rtf, bar.rtf). The answer is YES.</div>
<div></div>
<div style="padding-left: 30px;"><em><span style="text-decoration: underline;">Not perfect</span></em></div>
<div></div>
<div style="padding-left: 30px;"><em>Using this method I don&#8217;t know how to modify the location of the output in the resulting package. Before I would link a &#8216;blue folder&#8217;, so all my media 3D assets would go under [package]/3D/. Controlling the structure of this package is useful in various ways. </em></div>
<div style="padding-left: 30px;"><em></em><em>We just demonstrated that we can link a whole folder given a single input file; this means we could input a config file describing which blend files we want to translate and how; then we&#8217;d run blender </em><span style="text-decoration: underline;">once</span><em> , translate all the files and producing the correct output.</em></div>
<div style="padding-left: 30px;"><em>In the end I think this will turn out to be a better solution, notably because it will avoid translating the same files other and other even if they weren&#8217;t modified. Scene files process fast; not the case with files containing large meshes and animations.</em></div>
</div>
<p>For whatever reason, the next steps turned out to be troublesome.<br />
My second py script was symlinked. I didn&#8217;t think it would matter (strictly speaking, still don&#8217;t think it does) but I found it hard to get the script to refresh (meaning, I would edit the py script and run the build again, find the same error as previously. And again. And again.</p>
<p>An error in the scene export script caused the wrong path to be used.</p>
<p>Passing several scripts on blender command line (-P foo.py -P bar.py) doesn&#8217;t work so I ended calling blender twice which is a lesser evil. Maybe.</p>
<p><strong>Complications</strong></p>
<ol>
<li>I have a mixed workflow using both Blender 2.4x and Blender 2.5x. In theory this means that I would have to go through the motions again, finding out how I can run 2.5x from the command line (likely as not, it won&#8217;t work in the same way).</li>
<li>Scene files contain level edits and assets. Asset files do not contain level edits. Both blender 2.4x and 2.5x files are just annotated as *.blend. How do I know which version of blender to run and which scripts to call?</li>
</ol>
<p>The answer to (1) will be simple for now. <em>Don&#8217;t do that</em>. I mainly use 2.4x; the only 2.5x file that really matters so far is the one containing the PC mesh and animations. So I&#8217;ll just pass and use the manual workflow for that.</p>
<p>The answer two question (2) will be equally simple. Use a convention. For starters:</p>
<ul>
<li>level file: level<strong>.s</strong>.blend</li>
<li>asset file: asset<strong>.a</strong>.blend</li>
</ul>
<p>( and likewise when I get 2.5x scripts working, different conventions may be used )</p>
<p>This is a bit lame. Maybe a better convention might be something like:</p>
<ul>
<li>*2.4x/scenes*.blend</li>
<li>*2.5x/assets*.blend</li>
</ul>
<p>Works &#8211; although the build rule does say something like &#8220;files with name matching&#8221;, the matching rule actually uses the path.</p>
<p>A nag here is that I don&#8217;t want to have 2 or 4 &#8216;build&#8217; folders for my assets. Just one folder (that I can trash as a quick and dirty way to make sure no out of data lingers in the system) would be best. This should be straightforward, matching the output like so:</p>
<ul>
<li>${INPUT_FILE_DIR}/../../build/${INPUT_FILE_BASE}.blz</li>
</ul>
<p>Conflating the output from various files (e.g. 2.4x/assets/foo.blend and 2.4x/scenes/foo.blend ) is possible. Collisions are unlikely, however, so I&#8217;ll keep it this way.</p>
<p><strong>Polish?</strong></p>
<p><span style="text-decoration: underline;">Silencing the output?</span></p>
<p>When running blender directly from the desktop, getting console output to show up can be tricky. XCode surely doesn&#8217;t have this problem. All debug output appears in the messages window. Too much of it, in fact. Worse, something forces the item matching the translation script to expand.</p>
<p><em>No luck</em>. I was assuming (maybe wrongly) that blender output is displayed because it is sent to stderr. Either way standing messages to stderr or stdout will yield the same result. Until further notice if I want to avoid script messages blotching the output, I need to disable debug output manually.</p>
<p><span style="text-decoration: underline;">Displaying errors during the export process</span></p>
<p>An issue serious enough that putting it under &#8216;polish&#8217; may be foolish : how to ensure that XCode will alert us when export errors occur? And by the way, what is an export error?</p>
<p>I tried my luck again, this time by looking at the unit test framework output. I thought XCode may be detecting a simple pattern to identify errors, and it is. The pattern is something like this:</p>
<ul>
<li>error: <em>description of error</em></li>
</ul>
<p>The space after the colon in <em>error :</em> is required. In python (~2.7<em>)</em>, use:</p>
<p style="padding-left: 30px;"><em>print (&#8220;error: something went wrong&#8221;)</em></p>
<p>And XCode will detect the error and display a flamboyant exclamation mark. Neat.</p>
<p>This won&#8217;t stop the build from completing but a red exclamation mark is difficult to ignore so it will be enough.</p>
<p><em>What is an error, then?</em></p>
<p>A py script failing while running inside blender does NOT cause an error to appear in XCode. This is because blender returns with exit code &#8216;OK&#8217; regardless. Now that we know how to signal errors to XCode, we can insert validation related errors. But we also want to report an error when our script fails unexpectedly:</p>
<p><em>    try:</em><br />
<em>        exportAssets(PATH)</em><br />
<em>    except:</em><br />
<em>        print &#8220;error: in blender script: &#8220;, sys.exc_info()[0], &#8220;(see messages window)&#8221;</em><br />
<em>        raise</em></p>
<p><em>raise</em> causes the error to propagate, allowing detailed information to appear in the log.</p>
<p><strong>caveat:</strong> If the script contains a syntax error, it won&#8217;t run. In this case blender will report the error and exit, however we cannot alert XCode since the script didn&#8217;t even start running.</p>
<p><strong>(how to cope with) limitations</strong></p>
<p>Limitations with the approach I described derive from the atomicity of the conversion. It has to be done like this:</p>
<p style="text-align: center;"><em>input file =&gt; output file or directory</em></p>
<p style="text-align: left;">For level edits, it is fine.</p>
<p style="text-align: left;">I see a problem when several files want to output to the same deployment directory. For example, it often makes sense to define actors as shared assets (same creatures used in different levels). Although it is a bit messy, it is often convenient to keep several actors in the same blend file. But then what we&#8217;ll end up doing is this:</p>
<ul>
<li><em>myCreatures1 =&gt; targetFolderA</em></li>
<li><em>myCreatures2 =&gt; targetFolderA</em></li>
</ul>
<p>This is bad in at least two ways:</p>
<ul>
<li>We should cleanup <em>targetFolderA</em> before exporting (to avoid outdated files lingering in the build)</li>
<li>When exporting <em>myCreatures2</em>, we&#8217;ll end up copying over again data output by <em>myCreatures1.</em></li>
</ul>
<div>If we export to separate folders (<em>myCreatures1Out/, myCreatures2Out/</em>) the deployment structure becomes inconvenient. We may end up manually adding every output folder to the path used by a loader, and if we do so retrieving assets will take more time.</div>
<div></div>
<div>For shared assets, we have to choose. Either we start from a file listing all shared asset files and this becomes the input &#8211; processed by a special script &#8211; or we agree that each file will contain one actor / item. While the first solution is somewhat constraining it does help keeping things neat and requires less work.</div>
<div></div>
<div><span style="text-decoration: underline;">So, do what?</span></div>
<div></div>
<div>Although not ideal, a solution is to modify the way the loader retrieves data blocks. I want to do this conservatively.</div>
<div></div>
<div>Before, a data block would be retrieved by creating a file name against the resource paths (e.g: rabbit =&gt; retrieve the mesh called rabbit.dbk)</div>
<div></div>
<div>After, a data block can also be retrieved by matching a file name against a path in a designated shared resource folder (this would have to be the bundle&#8217;s root I&#8217;m afraid) : rabbit =&gt; rabbit.blz/rabbit.dbk</div>
<div>
<p>Additionally, the name of the blend file for a shared resource should match the name of the data it contains.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/03/20/4000/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Editing XCode Templates</title>
		<link>http://www.oogtech.org/content/2012/03/05/editing-xcode-templates/</link>
		<comments>http://www.oogtech.org/content/2012/03/05/editing-xcode-templates/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 09:56:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS/Cocoa]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wizard]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=3967</guid>
		<description><![CDATA[Much easier than editing/adding project wizards, making simple changes to file templates to suit your needs is a breeze. All you have to do is search for FILEBASENAME under your XCode install path; the filepath for each __FILEBASENAME__ .h / .m file clearly indicates what the template is used for; additionally, templates can be opened [...]]]></description>
			<content:encoded><![CDATA[<p>Much easier than editing/adding project wizards, making simple changes to file templates to suit your needs is a breeze.</p>
<p>All you have to do is search for <em>FILEBASENAME</em> under your XCode install path; the filepath for each <em>__FILEBASENAME__</em> <em>.h </em>/<em> .m</em> file clearly indicates what the template is used for; additionally, templates can be opened directly in XCode.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/03/05/editing-xcode-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apps vs Zombie: the Genius user experience</title>
		<link>http://www.oogtech.org/content/2012/03/02/genius-ux/</link>
		<comments>http://www.oogtech.org/content/2012/03/02/genius-ux/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 08:00:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone/iPad market]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=3954</guid>
		<description><![CDATA[Providing a great user experience is key to building a successful digital shopfront and I argued before that this may be a significant factor in driving customers to purchase and download from the App Store. The acquisition of Chomp by Apple sounds like great news for app developers; in the meantime I would like to [...]]]></description>
			<content:encoded><![CDATA[<p><em>Providing a great user experience is key to building a successful digital shopfront and <a href="http://www.oogtech.org/content/2011/12/16/android-devices-a-first-look-at-the-ux/">I argued before</a> that this may be a significant factor in driving customers to purchase and download from the App Store.</em></p>
<p><em>The acquisition of </em>Chomp<em> by </em>Apple<em> sounds like great news for app developers; in the meantime I would like to highlight some of the factors undermining the </em>Genius <em>user experience, hoping as usual that the big guns in California will actually take notice.</em></p>
<p><em>While personalized recommendations are a no-brainer nowadays, it would appear that </em>Genius<em> hasn&#8217;t been blessed by anything but evil faeries since it&#8217;s inception; consumers hoping to dig up great apps beyond the top 200s may be entering murky waters.</em></p>
<p><strong>Beyond the top 200s?</strong></p>
<p>I own something like 500 apps, most of which are paid games. While I play/test countless titles, I am rather candid in doing so &#8211; prioritizing the type of games I like; getting mainstream stuff for the sake of it isn&#8217;t my cup of tea.</p>
<p>Last week I checked my favorite top 200s &#8211; but I got most of what I wanted from there already; given a kind of stratification process, it so happens that the top 200s aren&#8217;t moving very fast. While this isn&#8217;t good news for app developers shipping new stuff, it doesn&#8217;t constitute in and of itself a reason for Apple to tweak their algorithms and I&#8217;m here to talk about something else.</p>
<p>In passing I also note that the top grossing, which used to be handy when looking out for premium games ($3 and above) is now well choked with <em>freemium</em> games. I am, however digressing.</p>
<p><strong>Cold Genius</strong></p>
<p>So I decided to have another look at <em>Genius</em>.</p>
<p>Around 50% of <em>Genius</em>  recommendations are immediately irrelevant to what I like (mind, 500 downloads and counting should be a good start to evaluate recommendations).</p>
<p>Digging up gems using <em>Genius</em> is a convoluted process:</p>
<ol>
<li>There are no more than 4-5 pages to browse.</li>
<li>The selection will include any previously downloaded app not currently installed on-device (which is weird, and counter-productive too since one may end up messing recommendations by rejecting apps that are liked, but no longer needed).</li>
<li>In order to get additional recommendations, one has to depress &#8220;not interested&#8221; under each and every unwanted app. However rejected apps do not disappear right away. Instead the only way to make them go away is to reload the page.</li>
<li>Rejecting a game from the main category doesn&#8217;t tell <em>Genius</em> to remove the same game from &#8216;games&#8217;. This is something I learned the stupid way as I was out for a mix of games and other interesting apps and tended to switch between categories.</li>
</ol>
<p>After playing the reject-and-reload game for 60 minutes or so, I had finally narrowed my selection down to a dozen of interesting apps. Downloaded 2 or 3 right away , postponed buying a few of the more interesting (and more expensive) games I&#8217;d found.</p>
<p>Unlike most sections of the app store, <em>Genius</em> doesn&#8217;t support scrolling by swiping. If you want to see the next page, you need to press rather tiny arrow buttons. On iPad, you can scroll by swiping &#8211; pointlessly revealing the bottom of pages with a viewable area <em>5% taller than the screen</em> in landscape mode. Awkward and somewhat disappointing coming from the master of Ux design.</p>
<p>At this point I&#8217;m guessing many shoppers give up. They head over to Appolicious or whatever app they use to discover other apps.</p>
<p><strong>25 billion downloads (no services?)</strong></p>
<p>The<em><strong> bummer</strong></em>, however, was a time bomb that didn&#8217;t explode for another week, at which point I decided to purchase one of the more expensive titles I had discovered.</p>
<p>I open my iPad, head back to <em>Genius,</em> then&#8230;</p>
<p>You guessed. <em>Genius</em> had been hard at work while I left it alone. After a week my recommendations had returned to primal chaos, sending to heavenly hell whatever app I had patiently selected. Gone, nothing, <em>nada</em>.</p>
<p>With more than a hundred games coming out everyday, logic would have it that every player can find games that will suit their taste &#8211; even after taking out the <em>krapps</em>.</p>
<p>In the meantime, the one feature that should delight app gourmets turns out to be the fifth wheel of my shopping cart.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/03/02/genius-ux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protected: Realtime Game Behavior &#8211; Cornerstone?</title>
		<link>http://www.oogtech.org/content/2012/02/13/realtime-game-behavior-yet-another-article/</link>
		<comments>http://www.oogtech.org/content/2012/02/13/realtime-game-behavior-yet-another-article/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 14:31:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game Programming]]></category>
		<category><![CDATA[game behavior]]></category>
		<category><![CDATA[realtime]]></category>

		<guid isPermaLink="false">http://www.oogtech.org/content/?p=3825</guid>
		<description><![CDATA[There is no excerpt because this is a protected post.]]></description>
			<content:encoded><![CDATA[<form action="http://www.oogtech.org/content/wp-pass.php" method="post">
<p>This post is password protected. To view it please enter your password below:</p>
<p><label for="pwbox-3825">Password:<br />
<input name="post_password" id="pwbox-3825" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="Submit" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://www.oogtech.org/content/2012/02/13/realtime-game-behavior-yet-another-article/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

