<?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>conceptual inertia &#187; code</title>
	<atom:link href="http://www.conceptualinertia.net/aoakenfo/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.conceptualinertia.net/aoakenfo</link>
	<description>mediocrity at its finest</description>
	<lastBuildDate>Mon, 06 Jun 2011 02:53:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>couchdb reader_acl</title>
		<link>http://www.conceptualinertia.net/aoakenfo/couchdb-reader_acl</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/couchdb-reader_acl#comments</comments>
		<pubDate>Wed, 15 Sep 2010 06:39:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.conceptualinertia.net/aoakenfo/?p=604</guid>
		<description><![CDATA[I installed CouchDB 1.0.1 with MacPorts 1.9.1 and quickly ran into problems: The &#8216;attachments&#8217; test hung in Chrome 6.0.472.55. I ran the same test in Firefox 3.6.9 and it worked. The &#8216;reader_acl&#8217; failed with an exception. I couldn&#8217;t create an admin. The couchdb.log certainly had errors but I couldn&#8217;t find a solution online. I tried [...]]]></description>
			<content:encoded><![CDATA[<p>I installed CouchDB 1.0.1 with MacPorts 1.9.1 and quickly ran into problems:</p>
<ul>
<li>The &#8216;attachments&#8217; test hung in Chrome 6.0.472.55. I ran the same test in Firefox 3.6.9 and it worked.</li>
<li>The &#8216;reader_acl&#8217; failed with an exception.</li>
<li>I couldn&#8217;t create an admin.</li>
</ul>
<p>The couchdb.log certainly had errors but I couldn&#8217;t find a solution online. I tried uninstalling the port and reinstalling with no luck. Eventually I gave up and downloaded CouchDBX. Creating an admin worked but it also had problems running the Test Suite (I had to Force Quit).</p>
<p>Then I tried <a href="http://guide.couchdb.org/editions/1/en/mac.html">Homebrew</a>. After installation I ran the Test Suite with 100% success and was able to create an admin! Awesome, now I&#8217;ll just add org.apache.couchdb to launchctrl&#8230;hmm it&#8217;s not under /Library/LaunchDaemons or /opt/local/Library/LaunchDaemons. After a little digging I eventually found it under /usr/local/Cellar/couchdb/1.0.1/Library/LaunchDaemons/. Only a few steps remain:</p>
<ul>
<li>Copy org.apache.couchdb.plist into /Library/LaunchDaemons</li>
<li>Change the value under the UserName key to your user short name (hint: look under /Users)</li>
<li>sudo launchctl start org.apache.couchdb or you can test it for sure by restarting (shortcut key: Control-Command-Eject)</li>
</ul>
<p>Everything now appears to be in working order.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/couchdb-reader_acl/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>flash drawing experiments</title>
		<link>http://www.conceptualinertia.net/aoakenfo/flash-drawing</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/flash-drawing#comments</comments>
		<pubDate>Tue, 29 Jun 2010 05:54:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.conceptualinertia.net/aoakenfo/?p=541</guid>
		<description><![CDATA[I&#8217;ve been working on a drawing/filter tool in Flash and here are some preliminary test results:]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a drawing/filter tool in Flash and here are some preliminary test results:</p>

<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test1' title='test1'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test1-150x150.jpg" class="attachment-thumbnail" alt="test1" title="test1" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test3' title='test3'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test3-150x150.jpg" class="attachment-thumbnail" alt="test3" title="test3" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test4' title='test4'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test4-150x150.jpg" class="attachment-thumbnail" alt="test4" title="test4" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test6' title='test6'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test6-150x150.jpg" class="attachment-thumbnail" alt="test6" title="test6" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test7' title='test7'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test7-150x150.jpg" class="attachment-thumbnail" alt="test7" title="test7" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test10' title='test10'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test10-150x150.jpg" class="attachment-thumbnail" alt="test10" title="test10" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test11' title='test11'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test11-150x150.jpg" class="attachment-thumbnail" alt="test11" title="test11" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test12' title='test12'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test12-150x150.jpg" class="attachment-thumbnail" alt="test12" title="test12" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test13' title='test13'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test13-150x150.jpg" class="attachment-thumbnail" alt="test13" title="test13" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test14' title='test14'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test14-150x150.jpg" class="attachment-thumbnail" alt="test14" title="test14" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test15' title='test15'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test15-150x150.png" class="attachment-thumbnail" alt="test15" title="test15" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test16' title='test16'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test16-150x150.png" class="attachment-thumbnail" alt="test16" title="test16" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test17' title='test17'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test17-150x150.png" class="attachment-thumbnail" alt="test17" title="test17" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test19' title='test19'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test19-150x150.png" class="attachment-thumbnail" alt="test19" title="test19" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test20' title='test20'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test20-150x150.png" class="attachment-thumbnail" alt="test20" title="test20" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test21' title='test21'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test21-150x150.png" class="attachment-thumbnail" alt="test21" title="test21" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test22' title='test22'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test22-150x150.png" class="attachment-thumbnail" alt="test22" title="test22" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test23' title='test23'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test23-150x150.png" class="attachment-thumbnail" alt="test23" title="test23" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test24' title='test24'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test24-150x150.png" class="attachment-thumbnail" alt="test24" title="test24" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test25' title='test25'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test25-150x150.png" class="attachment-thumbnail" alt="test25" title="test25" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test26' title='test26'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test26-150x150.png" class="attachment-thumbnail" alt="test26" title="test26" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test27' title='test27'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test27-150x150.png" class="attachment-thumbnail" alt="test27" title="test27" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test28' title='test28'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test28-150x150.png" class="attachment-thumbnail" alt="test28" title="test28" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test29' title='test29'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test29-150x150.png" class="attachment-thumbnail" alt="test29" title="test29" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test30' title='test30'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test30-150x150.png" class="attachment-thumbnail" alt="test30" title="test30" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test31' title='test31'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test31-150x150.png" class="attachment-thumbnail" alt="test31" title="test31" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test32' title='test32'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test32-150x150.png" class="attachment-thumbnail" alt="test32" title="test32" /></a>
<a href='http://www.conceptualinertia.net/aoakenfo/flash-drawing/test33' title='test33'><img width="150" height="150" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2010/06/test33-150x150.png" class="attachment-thumbnail" alt="test33" title="test33" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/flash-drawing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>adding FLEX_HOME and building as3-signals on a mac</title>
		<link>http://www.conceptualinertia.net/aoakenfo/adding-flex_home-and-building-as3-signals-on-a-mac</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/adding-flex_home-and-building-as3-signals-on-a-mac#comments</comments>
		<pubDate>Wed, 02 Jun 2010 16:04:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.conceptualinertia.net/aoakenfo/?p=535</guid>
		<description><![CDATA[Fire up a terminal: cd ~/Library/SDKs git clone http://github.com/robertpenner/as3-signals.git You can find the above url on the as3-signals homepage on github. My personal pref is to put 3rd party libraries under ~/Library/SDKs If you look inside the as3-signals dir, there is a build.xml file which requires a FLEX_HOME variable to be set. So, I downloaded [...]]]></description>
			<content:encoded><![CDATA[<p>Fire up a terminal:</p>
<ul>
<li><span style="color: #993300;">cd<span style="color: #993300;"> </span></span><span style="color: #993300;">~/Library/SDKs</span></li>
<li><span style="color: #993300;">git clone http://github.com/robertpenner/as3-signals.git</span></li>
</ul>
<p>You can find the above url on the <a href="http://github.com/robertpenner/as3-signals">as3-signals homepage on github</a>. My personal pref is to put 3rd party libraries under ~/Library/SDKs</p>
<p>If you look inside the as3-signals dir, there is a build.xml file which requires a FLEX_HOME variable to be set. So, I downloaded the Flex 4 SDK and dropped it under /Developer/SDKs/flex_sdk_4. In the terminal, we need to set the env variable FLEX_HOME. First, lets check if you have an existing one defined. In the shell, type</p>
<ul>
<li><span style="color: #993300;">env</span></li>
</ul>
<p>You should see a list of defined variables. If you need to remove an existing FLEX_HOME, you can do so by typing</p>
<ul>
<li><span style="color: #993300;">export -n FLEX_HOME</span></li>
</ul>
<p>Otherwise, you can add a new FLEX_HOME by typing:</p>
<ul>
<li><span style="color: #993300;">FLEX_HOME=&#8221;/Developer/SDKs/flex_sdk_4&#8243;</span></li>
<li><span style="color: #993300;">export FLEX_HOME</span></li>
</ul>
<p>If you type <span style="color: #993300;">env</span> again FLEX_HOME is now added to the list. Now we can build as3-signals.</p>
<ul>
<li><span style="color: #993300;">cd ~/Library/SDKs/as3-signals/</span></li>
<li><span style="color: #993300;">ant</span></li>
</ul>
<p>Ant looks for a build.xml by default. Upon a successful build you&#8217;ll find a .swc in the bin folder.</p>
<p>Note: Setting FLEX_HOME this way will only last for 1 terminal session. If you&#8217;d like a more permanent solution, see: http://mactip.blogspot.com/2004/04/setting-environment-variables.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/adding-flex_home-and-building-as3-signals-on-a-mac/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# finite state machine (fsm)</title>
		<link>http://www.conceptualinertia.net/aoakenfo/simple-fsm</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/simple-fsm#comments</comments>
		<pubDate>Sun, 14 Jan 2007 01:57:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://conceptualinertia.wordpress.com/?p=212</guid>
		<description><![CDATA[Take a look at the following output: The above output was generated by an Orc entity with an associated finite state machine (FSM). Although a FSM can be used for many things, in game development it&#8217;s typically used to model character behaviour. Why? It&#8217;s simple and easy to debug. Let&#8217;s have a look at Main [...]]]></description>
			<content:encoded><![CDATA[<p>Take a look at the following output:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fsmdemo1.jpg"><img class="alignnone size-full wp-image-213" title="fsmdemo1" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fsmdemo1.jpg" alt="" width="666" height="333" /></a></p>
<p>The above output was generated by an Orc entity with an associated finite state machine (FSM). Although a FSM can be used for many things, in game development it&#8217;s typically used to model character behaviour. Why? It&#8217;s simple and easy to debug.</p>
<p>Let&#8217;s have a look at Main to get a high-level feel for using an Orc entity:</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">static void</span> Main(<span style="color: #0000ff;">string</span>[] args)
{
    <span style="color: #33cccc;">Orc </span>o = <span style="color: #0000ff;">new </span><span style="color: #33cccc;">Orc</span>();

    o.Event = <span style="color: #33cccc;">OrcEvent</span>.Wander;
    o.UpdateState();

    o.Event = <span style="color: #33cccc;">OrcEvent</span>.Eat;
    o.UpdateState();

    o.Event = <span style="color: #0000ff;">null</span>;
    o.UpdateState();

    <span style="color: #33cccc;">Console</span>.ReadLine();
}
 </code></pre>
<p>In a real game loop the UpdateState method would be called once per frame. Continuing with a top-down approach, let&#8217;s see the components that make up an Orc entity. First, we find a enum to represent simple event identifiers.</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">enum </span><span style="color: #33cccc;">OrcEvent</span>
{
    Eat,
    Wander
}
 </code></pre>
<p>Events can trigger a change in state. It&#8217;s possible to use a table to map events to associated states. For example, the OrcEvent.Eat maps to the EatState and the OrcEvent.Wander maps to the WanderState. However, states don&#8217;t always have a 1-to-1 correspondence. For example, an OrcEvent.SeeEnemy could map to an AttackState. Here we see a transition table specific to Orcs:</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">class </span><span style="color: #33cccc;">OrcTransitionTable </span>: Ai.<span style="color: #33cccc;">StateTransitionTable</span>
{
    <span style="color: #0000ff;">public </span>OrcTransitionTable()
    {
        <span style="color: #0000ff;">base</span>.table.Add(<span style="color: #33cccc;">OrcEvent</span>.Eat, <span style="color: #0000ff;">new </span><span style="color: #33cccc;">EatState</span>());
        <span style="color: #0000ff;">base</span>.table.Add(<span style="color: #33cccc;">OrcEvent</span>.Wander, <span style="color: #0000ff;">new </span><span style="color: #33cccc;">OrcWanderState</span>());
    }
}
 </code></pre>
<p>The base type StateTransitionTable handles housekeeping chores for the table:</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
</code><span style="color: #0000ff;"><span class="keyword">abstract public class</span></span> <span style="color: #33cccc;"><span class="usertype">StateTransitionTable</span></span>
{
    <span style="color: #0000ff;"><span class="keyword">protected</span> </span><span style="color: #33cccc;"><span class="usertype">Dictionary</span></span>&lt;<span style="color: #0000ff;"><span class="keyword">object</span></span>, <span style="color: #33cccc;"><span class="usertype">IState</span></span>&gt; table = <span style="color: #0000ff;">new </span><span style="color: #33cccc;">Dictionary</span>&lt;<span style="color: #0000ff;"><span class="keyword">object</span></span>, <span style="color: #33cccc;"><span class="usertype">IState</span></span>&gt;();

    <span style="color: #0000ff;"><span class="keyword">public void</span></span> SetState(<span style="color: #0000ff;"><span class="keyword">object</span> </span>evt, <span style="color: #33cccc;"><span class="usertype">IState</span> </span>state)
    {
        table.Add(evt, state);
    }

    <span style="color: #0000ff;"><span class="keyword">public</span> </span><span style="color: #33cccc;"><span class="usertype">IState</span> </span>GetState(<span style="color: #0000ff;"><span class="keyword">object</span> </span>evt)
    {
        Ai.<span style="color: #33cccc;"><span class="usertype">IState</span> </span>i = <span style="color: #0000ff;"><span class="keyword">null</span></span>;

        <span style="color: #0000ff;"><span class="keyword">try</span></span>
        {
            i = table[evt];

        }
        <span style="color: #0000ff;"><span class="keyword">catch</span> </span>(<span style="color: #33cccc;"><span class="usertype">KeyNotFoundException</span></span>)
        {
            <span class="keyword">return <span style="color: #0000ff;">null</span></span>;
        }

        <span style="color: #0000ff;"><span class="keyword">return</span> </span>i;
    }
}</pre>
<p>What exactly is IState? It&#8217;s an interface with 3 methods for state processing:</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">public interface</span> <span style="color: #33cccc;">IState</span>
{
    <span style="color: #0000ff;">void </span>Enter(<span style="color: #33cccc;">Entity </span>e);
    <span style="color: #0000ff;">void </span>Execute(<span style="color: #33cccc;">Entity </span>e);
    <span style="color: #0000ff;">void </span>Exit(<span style="color: #33cccc;">Entity </span>e);
}
 </code></pre>
<p>Each method takes an entity type as a parameter. When switching states, the Exit method is called for the current state. The new state&#8217;s Enter method is then called. The current state is then assigned the new state. Execute is called once per frame to perform state processing.</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code><span style="color: #0000ff;">
abstract public class</span> <span style="color: #33cccc;">Entity</span>
{
    <span style="color: #0000ff;">protected </span>Ai.<span style="color: #33cccc;">StateTransitionTable </span>transitionTable = <span style="color: #0000ff;">null</span>;
    <span style="color: #0000ff;">protected </span><span style="color: #33cccc;">IState </span>currentState = <span style="color: #0000ff;">null</span>;

    <span style="color: #0000ff;">public void</span> UpdateState()
    {
        <span style="color: #0000ff;">if </span>(currentState != <span style="color: #0000ff;">null</span>)
            currentState.Execute(<span style="color: #0000ff;">this</span>);
        <span style="color: #0000ff;">else</span>
            System.Diagnostics.<span style="color: #0000ff;">Trace</span>.WriteLine(<span style="color: #993300;">"zero state"</span>);
    }

    <span style="color: #0000ff;">public object</span> Event
    {
        <span style="color: #0000ff;">set</span>
        {
            <span style="color: #0000ff;">if </span>(value == <span style="color: #0000ff;">null</span>)
            {
                currentState.Exit(<span style="color: #0000ff;">this</span>);
                currentState = <span style="color: #0000ff;">null</span>;
                <span style="color: #0000ff;">return</span>;
            }

            <span style="color: #33cccc;">IState </span>i = transitionTable.GetState(<span style="color: #0000ff;">value</span>);

            <span style="color: #0000ff;">if </span>(i != <span style="color: #0000ff;">null</span>)
            {
                <span style="color: #0000ff;">if </span>(currentState != <span style="color: #0000ff;">null</span>)
                    currentState.Exit(<span style="color: #0000ff;">this</span>);

                currentState = i;
                currentState.Enter(<span style="color: #0000ff;">this</span>);
            }
        }
    }
}
 </code></pre>
<p>Implementing an Orc entity is trivial:</p>
<ul>
<li> Inherit from Ai.Entity</li>
<li>Set the transition table in the constructor</li>
<li>Start adding methods for the new character</li>
</ul>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">class </span><span style="color: #33cccc;">Orc </span>: Ai.<span style="color: #33cccc;">Entity</span>
{
    <span style="color: #0000ff;">static </span>Orc()
    {
        transitionTable = <span style="color: #0000ff;">new </span><span style="color: #33cccc;">OrcTransitionTable</span>();
    }

    <span style="color: #0000ff;">public void</span> Drool()
    {
        <span style="color: #33cccc;">Console</span>.WriteLine(<span style="color: #993300;">"drooling..."</span>);
    }
}
 </code></pre>
<p>Of course, an entity will need a variety of states to transition to. To create a new state type implement the IState interface. For example, here are a few Orc-related states:</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">class </span><span style="color: #33cccc;">EatState </span>: Ai.<span style="color: #33cccc;">IState</span>
{
    <span style="color: #0000ff;">public void</span> Enter(Ai.<span style="color: #33cccc;">Entity </span>e)
    {
        <span style="color: #33cccc;">Console</span>.WriteLine(<span style="color: #993300;">"entering eat state"</span>);
    }

    <span style="color: #0000ff;">public void</span> Execute(Ai.<span style="color: #33cccc;">Entity </span>e)
    {
        <span style="color: #33cccc;">Console</span>.WriteLine(<span style="color: #993300;">"executing eat state"</span>);
    }

    <span style="color: #0000ff;">public void</span> Exit(Ai.<span style="color: #33cccc;">Entity </span>e)
    {
        <span style="color: #33cccc;">Console</span>.WriteLine(<span style="color: #993300;">"exiting eat state"</span>);
    }
}

<span style="color: #0000ff;">class </span><span style="color: #33cccc;">OrcWanderState </span>: Ai.<span style="color: #33cccc;">IState</span>
{
    <span style="color: #0000ff;">public void</span> Enter(Ai.<span style="color: #33cccc;">Entity </span>e)
    {
        <span style="color: #33cccc;">Console</span>.WriteLine(<span style="color: #993300;">"entering wander state"</span>);
    }

    <span style="color: #0000ff;">public virtual void</span> Execute(Ai.<span style="color: #33cccc;">Entity </span>e)
    {
        <span style="color: #33cccc;">Console</span>.WriteLine(<span style="color: #993300;">"executing wander state"</span>);

        <span style="color: #33cccc;">Orc </span>o = e <span style="color: #0000ff;">as </span><span style="color: #33cccc;">Orc</span>;

        <span style="color: #0000ff;">if </span>(o != <span style="color: #33cccc;">null</span>)
            o.Drool();
    }

    <span style="color: #0000ff;">public void</span> Exit(Ai.<span style="color: #33cccc;">Entity </span>e)
    {
        <span style="color: #33cccc;">Console</span>.WriteLine(<span style="color: #993300;">"exiting wander state"</span>);
    }
}

<span style="color: #0000ff;">class </span><span style="color: #33cccc;">CustomizedOrcWanderState </span>: <span style="color: #33cccc;">OrcWanderState</span>
{
    <span style="color: #0000ff;">public override</span> <span style="color: #0000ff;">void </span>Execute(Ai.<span style="color: #33cccc;">Entity </span>e)
    {
        <span style="color: #0000ff;">base</span>.Execute(e);

        <span style="color: #33cccc;">Console</span>.WriteLine(<span style="color: #993300;">"unique orc personality here..."</span>);
    }
}
 </code></pre>
<p>Those are the basics of implementing a finite state machine for character control. You can download the source code <a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/FsmDemo1.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/simple-fsm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>game of life</title>
		<link>http://www.conceptualinertia.net/aoakenfo/game-of-life</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/game-of-life#comments</comments>
		<pubDate>Sat, 13 Jan 2007 10:47:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://conceptualinertia.wordpress.com/?p=214</guid>
		<description><![CDATA[Conway&#8217;s &#8216;Game of Life&#8217; produces some interesting patterns from a few simple rules. This demo utilizes WPF with simple styling and animation. One day I&#8217;ll have to learn how to record, edit, and post videos online. Until then, it&#8217;s nothing but a static screenshot for you: You can download the source here.]]></description>
			<content:encoded><![CDATA[<p>Conway&#8217;s &#8216;Game of Life&#8217; produces some interesting patterns from a few simple rules. This demo utilizes WPF with simple styling and animation.</p>
<p>One day I&#8217;ll have to learn how to record, edit, and post videos online. Until then, it&#8217;s nothing but a static screenshot for you:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/gameoflife1.jpg"><img class="alignnone size-full wp-image-216" title="gameoflife1" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/gameoflife1.jpg" alt="" width="638" height="476" /></a></p>
<p>You can download the source <a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/GameOfLifeDemo.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/game-of-life/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>win32 nostalgia</title>
		<link>http://www.conceptualinertia.net/aoakenfo/win32-nostalgia</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/win32-nostalgia#comments</comments>
		<pubDate>Sun, 02 Jul 2006 11:48:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://conceptualinertia.wordpress.com/?p=238</guid>
		<description><![CDATA[Remember the first time you learned Win32 programming? I thought I&#8217;d post a couple of old demos I made during my first encounter with Win32 many, many, years ago. The above image is from the demo called Elasticity. Drag the square and then let it go. The square will snap back to the origin as [...]]]></description>
			<content:encoded><![CDATA[<p>Remember the first time you learned Win32 programming? I thought I&#8217;d post a couple of old demos I made during my first encounter with Win32 many, <em>many</em>, years ago.</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/elasticity1.jpg"><img class="alignnone size-full wp-image-240" title="elasticity1" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/elasticity1.jpg" alt="" /></a></p>
<p>The above image is from the demo called Elasticity. Drag the square and then let it go. The square will snap back to the origin as if it were attached to an elastic band.</p>
<p>The next image is from the demo called Swarm. It tries to mimic a swarm of fruit flies chasing your cursor.</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/swarm.jpg"><img class="alignnone size-full wp-image-241" title="swarm" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/swarm.jpg" alt="" width="521" height="301" /></a></p>
<p>I cleaned up the source just enough so that it would run. You can download the source for Elasticity and Swarm <a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/Elasticity and Swarm.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/win32-nostalgia/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>kondo tool</title>
		<link>http://www.conceptualinertia.net/aoakenfo/kondo-tool</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/kondo-tool#comments</comments>
		<pubDate>Wed, 21 Jun 2006 19:17:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://conceptualinertia.wordpress.com/?p=209</guid>
		<description><![CDATA[Here&#8217;s a little tool I made for fun to control my Kondo KHR-1. It hasn&#8217;t been thoroughly tested, so don&#8217;t be surprised if any &#8220;features&#8221; pop up. You can download the source here.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/khr1test1.jpg"><img class="alignnone size-full wp-image-210" title="khr1test1" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/khr1test1.jpg" alt="" width="700" height="534" /></a></p>
<p>Here&#8217;s a little tool I made for fun to control my Kondo KHR-1. It hasn&#8217;t been thoroughly tested, so don&#8217;t be surprised if any &#8220;features&#8221; pop up. You can download the source <a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/Khr1Test2.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/kondo-tool/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>novo</title>
		<link>http://www.conceptualinertia.net/aoakenfo/novo</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/novo#comments</comments>
		<pubDate>Sat, 17 Jun 2006 13:44:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://conceptualinertia.wordpress.com/?p=192</guid>
		<description><![CDATA[Novo1.zip &#8211; &#8220;Lesson 101 &#8211; Box on a Plane&#8221; is the first sample in the PhysX SDK Training Programs. Here&#8217;s a screenshot of a DirectX port written in C++: The first thing to do is download the PhysX SDK. After it&#8217;s installed, you&#8217;ll need to set the directory paths in Visual Studio for the include [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/Novo1.zip">Novo1.zip</a> &#8211; &#8220;Lesson 101 &#8211; Box on a Plane&#8221; is the first sample in the PhysX SDK Training Programs. Here&#8217;s a screenshot of a DirectX port written in C++:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/novo1.jpg"><img class="alignnone size-full wp-image-193" title="novo1" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/novo1.jpg" alt="" width="638" height="477" /></a></p>
<p>The first thing to do is download the PhysX SDK. After it&#8217;s installed, you&#8217;ll need to set the directory paths in Visual Studio for the include files:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/novo2.jpg"><img class="alignnone size-full wp-image-194" title="novo2" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/novo2.jpg" alt="" width="642" height="380" /></a></p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/novo3.jpg"><img class="alignnone size-full wp-image-195" title="novo3" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/novo3.jpg" alt="" width="644" height="377" /></a></p>
<p>The demo has standard first-person camera controls. Also, be sure to check out WM_KEYDOWN in the WindowProc for a list of other controls.</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/Novo2.zip">Novo2.zip</a> &#8211; Lesson 102 &#8211; Sphere and Torque:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson102.jpg"><img class="alignnone size-full wp-image-196" title="lesson102" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson102.jpg" alt="" width="639" height="480" /></a></p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/Novo3.zip">Novo3.zip</a> &#8211; Lesson 103 &#8211; Capsule, Local Pose, and Center of Mass:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson103.jpg"><img class="alignnone size-full wp-image-197" title="lesson103" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson103.jpg" alt="" width="638" height="477" /></a></p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/Novo4.zip">Novo4.zip</a> &#8211; Lesson 104 &#8211; Convex Shapes and Anisotropic Friction:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson104.jpg"><img class="alignnone size-full wp-image-198" title="lesson104" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson104.jpg" alt="" width="639" height="476" /></a></p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/Novo5.zip">Novo5.zip</a> &#8211; Lesson 105 &#8211; The User Contact Report and the Contact Stream Iterator:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson105.jpg"><img class="alignnone size-full wp-image-199" title="lesson105" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson105.jpg" alt="" width="637" height="477" /></a></p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/Novo6.zip">Novo6.zip</a> &#8211; Lesson 106 &#8211; Static and Kinematic Actors. The screenshot doesn&#8221;t look like much, however, the user can control the middle cube (as a kinematic actor) bouncing it off the other actors.</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson106.jpg"><img class="alignnone size-full wp-image-200" title="lesson106" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/lesson106.jpg" alt="" width="636" height="477" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/novo/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>file type associations</title>
		<link>http://www.conceptualinertia.net/aoakenfo/file-type-associations</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/file-type-associations#comments</comments>
		<pubDate>Thu, 15 Jun 2006 14:41:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://conceptualinertia.wordpress.com/?p=207</guid>
		<description><![CDATA[Applications typically have some type of project file format. For example, Maya saves scenes using a binary file: This file type is associated with Maya, it has the .mb extension and a custom icon. Double-clicking the file will open it in Maya. Today, we&#8217;re going to associate TestApp with the .testapp extension: To associate a [...]]]></description>
			<content:encoded><![CDATA[<p>Applications typically have some type of project file format. For example, Maya saves scenes using a binary file:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation1.jpg"><img class="alignnone size-full wp-image-223" title="fileassociation1" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation1.jpg" alt="" width="147" height="67" /></a></p>
<p>This file type is associated with Maya, it has the .mb extension and a custom icon. Double-clicking the file will open it in Maya. Today, we&#8217;re going to associate TestApp with the .testapp extension:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation2.jpg"><img class="alignnone size-full wp-image-224" title="fileassociation2" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation2.jpg" alt="" width="147" height="60" /></a></p>
<p>To associate a file type<strong></strong>, you need to do three things:</p>
<ol>
<li>Add the file extension and associated application to the registry.</li>
<li>When double-clicking a .testapp file, determine whether an instance of the associated process is already running.</li>
<li>If the application is already running, pass th<strong></strong>e file across process boundaries.</li>
</ol>
<p>The first step is easy and makes use of the following Win32 functions to create and set entries:</p>
<ul>
<li>RegOpenKeyEx</li>
<li>RegCreateKeyEx</li>
<li>RegSetValueEx</li>
</ul>
<p>The code to create key/value pairs in the registry is straightforward. Therefore, I&#8217;m not going to list it here so please reference the source code included in today&#8217;s download.</p>
<p>After executing the registration code, you should have new keys under HKEY_CLASSES_ROOT with the following structure:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation3.jpg"><img class="alignnone size-full wp-image-225" title="fileassociation3" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation3.jpg" alt="" width="584" height="125" /></a></p>
<p>And a new TestApp key where we assoicate the file with a default icon (which is indexed at 0 as an embedded resource in the executable):</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation42.jpg"><img class="alignnone size-large wp-image-228" title="fileassociation42" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation42.jpg?w=700" alt="" width="700" height="125" /></a></p>
<p>The executable to launch is set under the Command section, with %1 being the command line param:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation51.jpg"><img class="alignnone size-large wp-image-230" title="fileassociation51" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation51.jpg?w=700" alt="" width="700" height="121" /></a></p>
<p>Use RegEdit to verify the above entries after executing today&#8217;s demo. To execute RegEdit use the Run prompt:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation6.jpg"><img class="alignnone size-full wp-image-231" title="fileassociation6" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation6.jpg" alt="" width="345" height="185" /></a></p>
<p>Once the file associations have been added to the registry, the next thing to do is determine if an instance of TestApp is running. The Process class in the System::Diagnostics namespace makes this step trivial.</p>
<p>So how does one application communicate with another across process boundaries? Under Win32 you use named pipes. A pipe connects two ends together &#8211; a client and server. Under .NET, named pipes have been wrapped up in the System::Runtime::Remoting::Channels::Ipc namespace. An IpcChannel is used when one application needs to communicate with another application in a different process on the same machine.</p>
<p>However, before we look at inter-process communication (IPC) let&#8217;s have a look at class SimpleFile which represents our .testapp file format.</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">public ref class</span> SimpleFile : <span style="color: #0000ff;">public </span>MarshalByRefObject
{
    <span style="color: #0000ff;">public</span>: <span style="color: #0000ff;">delegate void</span> LoadDelegate(SimpleFile^ simpleFile);
    <span style="color: #0000ff;">private</span>: LoadDelegate^ loadDel;

    <span style="color: #0000ff;">public</span>: <span style="color: #0000ff;">event </span>LoadDelegate^ LoadEvent
    {
        <span style="color: #0000ff;">void </span>add(LoadDelegate^ value)
        {
            loadDel += value;
        }

        <span style="color: #0000ff;">void </span>remove(LoadDelegate^ value)
        {
           loadDel -= value;
        }
    }
 </code></pre>
<p>Remoting is used for communication between app domains. An app domain is a logical container for a .NET applciation and is often refered to as a &#8220;lightweight process&#8221;.</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/appdomainlayout1.jpg"><img class="alignnone size-full wp-image-233" title="appdomainlayout1" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/appdomainlayout1.jpg" alt="" width="700" height="227" /></a></p>
<p>The same remoting mechanism is used between two app domains whether those app domains are in the same process, in different processes on the same machine, or different processes on different machines. Any type that wants to expose its availability across app domains must inherit from MarshalByRefObject or be serializable.</p>
<p>To keep things as simple as possible, the SimpleFile &#8220;format&#8221; only contains a single value, which is parsed and stored:</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">private</span>: <span style="color: #0000ff;">int </span>ultimateAnswer;
<span style="color: #0000ff;">public</span>: <span style="color: #0000ff;">property int</span> TheAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything
{
    <span style="color: #0000ff;">int </span>get() { <span style="color: #0000ff;">return this</span>-&gt;ultimateAnswer; }
}

<span style="color: #0000ff;">public</span>: <span style="color: #0000ff;">void </span>Load(String^ filePath)
{
    XmlTextReader^ xtr = <span style="color: #0000ff;">gcnew </span>XmlTextReader(filePath);

    <span style="color: #0000ff;">while</span>( xtr-&gt;Read() )
    {
        <span style="color: #0000ff;">if</span>( xtr-&gt;NodeType == XmlNodeType::Element )
        {
            <span style="color: #0000ff;">if</span>( xtr-&gt;Name == <span style="color: #993300;">"UltimateAnswer"</span> )
            {
                xtr-&gt;Read();
                <span style="color: #0000ff;">this</span>-&gt;ultimateAnswer = <span style="color: #0000ff;">int</span>::Parse(xtr-&gt;Value);
            }
       }
    }

    xtr-&gt;Close();
    <span style="color: #0000ff;">delete </span>xtr;

    <span style="color: #0000ff;">if </span>(loadDel != <span style="color: #0000ff;">nullptr</span>)
        loadDel(<span style="color: #0000ff;">this</span>);
}
 </code></pre>
<p>Here we see the value stored in the sample file foobar.testapp:</p>
<p><a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation7.jpg"><img class="alignnone size-full wp-image-234" title="fileassociation7" src="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/2008/10/fileassociation7.jpg" alt="" width="391" height="185" /></a></p>
<p>The constructor in the Form class is overloaded to accept an array of arguments:</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">public</span>: Form1(<span style="color: #0000ff;">array</span>&lt;String^&gt;^ args)
{
    InitializeComponent();

    <span style="color: #008000;">// - in this example, we register the file type associations every time
    //   the application runs (overwriting keys)
    // - however, you would normally do this only once as part of your
    //   installation process</span>
    RegisterFileAssociations();

    <span style="color: #008000;">// - cache any arguments passed from Main</span>
    <span style="color: #0000ff;">this</span>-&gt;args = args;
}
 </code></pre>
<p>If there were no arguments passed, the application is starting up for the first time.</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">private</span>: System::Void OnFormLoad(System::Object^ sender,
                                 System::EventArgs^ e)
{
    <span style="color: #008000;">// - application is loading for the first time</span>
    <span style="color: #0000ff;">if</span>( args-&gt;Length == 0 )
    {
        RegisterService();
    }
 </code></pre>
<p>The host or server has to tell .NET which object&#8217;s it&#8217;s willing to expose. These objects or well-known types are registered using the static method RegisterWellKnownServiceType of the RemotingConfiguration class.</p>
<p>The host also has to register a channel with ChannelServices. A channel will monitor a port and accept incoming calls, servicing those calls with a thread from the thread pool. The IpcChannel is a welcome addition because prior versions of .NET provided only the TcpChannel and HttpChannel for communication. Both TcpChannel and HttpChannel have associated overhead for the network stack regardless if the communication taking place is on the same machine or across a network. IPC provides a direct line, reducing overhead and increasing performance.</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">private</span>: <span style="color: #0000ff;">void </span>RegisterService()
{
    BinaryServerFormatterSinkProvider^ serverProv = <span style="color: #0000ff;">
        gcnew </span>BinaryServerFormatterSinkProvider();
    serverProv-&gt;TypeFilterLevel = TypeFilterLevel::Full;

    Hashtable^ properties = <span style="color: #0000ff;">gcnew </span>Hashtable();
    properties[<span style="color: #993300;">"portName"</span>] = <span style="color: #993300;">"SimpleFileServer"</span>;

    IpcChannel^ ipc = <span style="color: #0000ff;">gcnew </span>IpcChannel(properties, <span style="color: #0000ff;">nullptr</span>, serverProv);
    ChannelServices::RegisterChannel(ipc, <span style="color: #0000ff;">false</span>);

    RemotingConfiguration::RegisterWellKnownServiceType(
                                      SimpleFile::<span style="color: #0000ff;">typeid</span>,
                                      <span style="color: #993300;">"SimpleFile.rem"</span>,
                                      WellKnownObjectMode::Singleton);

    file = (SimpleFile^)Activator::GetObject(
                                      SimpleFile::<span style="color: #0000ff;">typeid</span>,
                                      <span style="color: #993300;">"ipc://SimpleFileServer/SimpleFile.rem"</span>);

    file-&gt;LoadEvent += <span style="color: #0000ff;">gcnew </span>SimpleFile::LoadDelegate(<span style="color: #0000ff;">this</span>,
                                                      &amp;Form1::OnProjectFileOpen);
}
 </code></pre>
<p>During server registration, a SimpleFile is activated and its LoadEvent is hooked up to the following:</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">private</span>: <span style="color: #0000ff;">delegate void</span> InvokeDelegate(SimpleFile^ simpleFile);
<span style="color: #0000ff;">private</span>: <span style="color: #0000ff;">void </span>OnProjectFileOpen(SimpleFile^ simpleFile)
{
    <span style="color: #008000;">// cross-thread op</span>
    <span style="color: #0000ff;">array</span>&lt;Object^&gt;^ arr = { simpleFile };
    <span style="color: #0000ff;">this</span>-&gt;Invoke(<span style="color: #0000ff;">gcnew </span>InvokeDelegate(<span style="color: #0000ff;">this</span>, &amp;Form1::ProcessFile), arr);
}

<span style="color: #0000ff;">public</span>: <span style="color: #0000ff;">void </span>ProcessFile(SimpleFile^ simpleFile)
{
    <span style="color: #0000ff;">this</span>-&gt;label2-&gt;Text =
        simpleFile-&gt;TheAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything.ToString();
}
 </code></pre>
<p>Invoke is used to update the Form&#8217;s user interface. Execution has to take place on the caller&#8217;s thread to avoid a cross-thread exception.</p>
<p>Back to OnFormLoad, where a list of processes is then assembled. It&#8217;s possible the process was launched with a double-click on a .testapp file. If so, services need to be registered and a SimpleFile loaded:</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">array</span>&lt;Process^&gt;^ processArray =
    Process::GetProcessesByName(Process::GetCurrentProcess()-&gt;ProcessName);

<span style="color: #008000;">// application loading for the first time from a double-click on file</span>
<span style="color: #0000ff;">if</span>( processArray-&gt;Length == 1 )
{
    RegisterService();

    SimpleFile sf;
    sf.LoadEvent += <span style="color: #0000ff;">gcnew </span>SimpleFile::LoadDelegate(<span style="color: #0000ff;">this</span>,
                                                   &amp;Form1::OnProjectFileOpen);
    sf.Load(filePath.ToString());
}
 </code></pre>
<p>Otherwise, a process is already running and SimpleFile needs to get its information across process boundaries. Here we see the client registering an IpcChannel and activating the well-known file (SimpleFile):</p>
<pre style="padding-left:30px;background-color:#f5f5f5;"><code>
<span style="color: #0000ff;">else if</span>( processArray-&gt;Length &gt; 1 )
{
    MessageBox::Show(<span style="color: #993300;">"Instance already running, passing args along"</span>);

    <span style="color: #0000ff;">for each</span>( Process^ p <span style="color: #0000ff;">in </span>processArray )
    {
        <span style="color: #0000ff;">if</span>( p-&gt;Id != Process::GetCurrentProcess()-&gt;Id )
        {
            <span style="color: #0000ff;">try</span>
            {
                IpcChannel^ ipc = <span style="color: #0000ff;">gcnew </span>IpcChannel(<span style="color: #993300;">"SimpleClient"</span>);
                ChannelServices::RegisterChannel(ipc, <span style="color: #993300;">false</span>);

                SimpleFile^ file =
                    (SimpleFile^)Activator::GetObject(
                                        SimpleFile::<span style="color: #0000ff;">typeid</span>,
                                        <span style="color: #993300;">"ipc://SimpleFileServer/SimpleFile.rem"</span>);

                if (file == <span style="color: #0000ff;">nullptr</span>)
                {
                    MessageBox::Show(<span style="color: #993300;">"Failure to connect with remote server"</span>);
                    this-&gt;Close();
                }

                file-&gt;Load(args[0]);
                <span style="color: #0000ff;">this</span>-&gt;Close();
            }
            <span style="color: #0000ff;">catch</span>(Exception^ e)
            {
                MessageBox::Show(e-&gt;Message);
            }

        } <span style="color: #008000;">// end if</span>

   } <span style="color: #008000;">// end for each</span>

} <span style="color: #008000;">// end else if</span>
 </code></pre>
<p>In summary, the application is now assoicated with a file type<strong></strong>. Double-clicking the file will launch the app. If the app is already running, IPC will be used to pass the file<strong></strong> info across process boundaries, allowing the application already running to open the file <strong></strong> as a new &#8220;project&#8221;.</p>
<p>Build and run the demo once to associate the file type in the registry. If you don&#8217;t see a blue icon for &#8220;foobar.testapp&#8221;, hit F5 in the explorer window to refresh it. Shut down the application and then try double-clicking various files with the .testapp extension.</p>
<p>You can download the source <a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/FileAssociations.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/file-type-associations/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>flash splash</title>
		<link>http://www.conceptualinertia.net/aoakenfo/flash-splash</link>
		<comments>http://www.conceptualinertia.net/aoakenfo/flash-splash#comments</comments>
		<pubDate>Tue, 06 Jun 2006 13:15:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://conceptualinertia.wordpress.com/?p=202</guid>
		<description><![CDATA[Ideally, your application should not need a splash screen because its load time should be nearly instantaneous. However, it&#8217;s not always the case. Updating the user about the progress of initialization is desirable. The ability to entertain the user at the same time is even more desirable. Most splash screens are static bitmaps. Some applications [...]]]></description>
			<content:encoded><![CDATA[<p>Ideally, your application should not need a splash screen because its load time should be nearly instantaneous. However, it&#8217;s not always the case. Updating the user about the progress of initialization is desirable. The ability to entertain the user at the same time is even more desirable. Most splash screens are static bitmaps. Some applications echo textual updates about which modules have been loaded or what systems have been initialized. This text typically flies by very quickly on-screen and may be echoed to a log file. What happens if we use Flash as the basis for a splash screen?</p>
<p>Today&#8217;s Solution consists of a C++/CLI class library containing a Flash splash screen class. A C# Windows application is used to test splash screen functionality. Please note that simply copying an existing Form  (ie. the FlashForm in today&#8217;s download) between projects is not recommended because you&#8217;ll run into a lot of errors. Ultimately, it&#8221;s faster if you create the Form in the target project and then copy &#8216;n paste portions of the code over (rebuilding along the way).</p>
<p>Instructions on how to setup a ShockwaveFlash control can be found <a href="http://www.conceptualinertia.net/aoakenfo/?p=18">here</a>.<br />
The code for using Flash as a splash screen (including the .fla) is available for download <a href="http://www.conceptualinertia.net/aoakenfo/wp-content/uploads/source/FlashSplashDemo.zip">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.conceptualinertia.net/aoakenfo/flash-splash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

