<?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>Purple Pwny Games</title>
	<atom:link href="http://www.purplepwny.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.purplepwny.com/blog</link>
	<description>Following development of the Harmony Game Engine</description>
	<lastBuildDate>Tue, 09 Feb 2010 02:47:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Component Based Entity System Design Part 2</title>
		<link>http://www.purplepwny.com/blog/?p=290</link>
		<comments>http://www.purplepwny.com/blog/?p=290#comments</comments>
		<pubDate>Mon, 18 May 2009 22:28:27 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=290</guid>
		<description><![CDATA[Finally! Part 2 has arrived. Purple Pwny is really still in a formulation state as far as development of an actual game goes, so we havn&#8217;t had a chance to extensively use the component system in anything other than a testing scenario. The only finalized portion of the ComponentManager interface thus far is the GetComponent [...]]]></description>
			<content:encoded><![CDATA[<p>Finally! Part 2 has arrived. Purple Pwny is really still in a formulation state as far as development of an actual game goes, so we havn&#8217;t had a chance to extensively use the component system in anything other than a testing scenario. The only finalized portion of the ComponentManager interface thus far is the GetComponent function.</p>
<p>GetComponent takes the name of a component family and an optional specialization parameter that applies to said family. For instance, to retrieve a component of type HealthComponent specialized for an Elephant character one would call as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">HealthComponent <span style="color: #000040;">*</span>health <span style="color: #000080;">=</span> m_ComponentManager<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetComponent<span style="color: #000080;">&lt;</span>health<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Health&quot;</span>, <span style="color: #FF0000;">&quot;Elephant&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>The ComponentManager class serves mostly to act as a factory for customized components at this time. However, I dont foresee it needing much functionality outside of that as Entities are intended to &#8220;manage&#8221; their own components.</p>
<p>Here is the relevant portion of the class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span>
T<span style="color: #000040;">*</span> ComponentManager<span style="color: #008080;">::</span><span style="color: #007788;">GetComponent</span><span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> name,std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> specialization<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
    m_xmlElement <span style="color: #000080;">=</span> doc.<span style="color: #007788;">FirstChildElement</span><span style="color: #008000;">&#40;</span>name<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    m_xmlElement<span style="color: #000080;">=</span> m_xmlElement<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>FirstChildElement<span style="color: #008000;">&#40;</span>specialization<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">map</span><span style="color: #000080;">&lt;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span>, boost<span style="color: #008080;">::</span><span style="color: #007788;">variant</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000080;">&gt;</span> <span style="color: #000080;">&gt;</span> props<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> TiXmlElement <span style="color: #000040;">*</span>m_xmlElementTemp <span style="color: #000080;">=</span> m_xmlElement<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>FirstChildElement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> m_xmlElementTemp<span style="color: #008080;">;</span> m_xmlElementTemp <span style="color: #000080;">=</span> m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>NextSiblingElement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">int</span> ival<span style="color: #008080;">;</span>
        std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> sval<span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Attribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;intval&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>QueryIntAttribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;intval&quot;</span>,<span style="color: #000040;">&amp;</span>ival<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            props<span style="color: #008000;">&#91;</span>m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>ValueStr<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> ival<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Attribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;strval&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>QueryValueAttribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;strval&quot;</span>,<span style="color: #000040;">&amp;</span>sval<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            props<span style="color: #008000;">&#91;</span>m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>ValueStr<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> sval<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    T<span style="color: #000040;">*</span> comp <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> T<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    comp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Set<span style="color: #008000;">&#40;</span>props<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> comp<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>At the moment, this actively parses the XML with 0 caching of configurations. This allows changes to occur in real-time to newly added components, which, with little modification, leads to a variety of interesting editor/game possibilities. It&#8217;s very simple to convert the current system into a cached mapping of key/value pairs. The reason we have yet to do this however, is because the plan is to permanently cache components in a SQLite database in the very near future.</p>
<p>On the horizon: Caching component configurations, and a 3 part introduction to the Harmony renderer.</p>
<p><3</p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=290</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dear Craigslist</title>
		<link>http://www.purplepwny.com/blog/?p=282</link>
		<comments>http://www.purplepwny.com/blog/?p=282#comments</comments>
		<pubDate>Mon, 18 May 2009 05:33:53 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=282</guid>
		<description><![CDATA[Purple Pwny Games was formed in 2008 by me, Tyler Bello. Originally, Purple Pwny was to serve as a platform to build my portfolio, with the eventual hope of being employed by one of the many local juggernauts. I soon came to the realization, however, that I was disgusted by the recent direction of the [...]]]></description>
			<content:encoded><![CDATA[<p>Purple Pwny Games was formed in 2008 by me, Tyler Bello. Originally, Purple Pwny was to serve as a platform to build my portfolio, with the eventual hope of being employed by one of the many local juggernauts. I soon came to the realization, however, that I was disgusted by the recent direction of the industry.  Within the last several years, games have lost their passion, their challenge, their energy &#8212; everything that made them great. This is a case of complacency in an industry that wishes to open the market to those which it once kept out. I want to make it clear that I have no problem with this. What I do have a problem with is that this complacency has spread to all games, rather than just a specific subset of them. Take Halo for instance, one the highest selling games of all time. Halo opened the door to FPS for those who had never picked up a controller. This is fine. This is great! What&#8217;s not great is that every FPS since Halo has catered to those who have never picked up a controller. With the ludicrous budgets of modern video games, this pandering appeared to be the only way to succeed on a grand scale. Only recently have incredible indie games created by teams of 2-3 seen a resurgence in popularity  as a direct result of the current state of the industry. Because of this, I decided to switch Purple Pwny&#8217;s focus from a portfolio site to a fully fledged video game company in an effort to play a part in what I believe is the next big thing in the industry.</p>
<p>The 4 foundational tenets of said company are to be as follows:</p>
<ul>
<li>Development shall be free flow. I will provide my employees with an abstract task, and they will be given full artistic freedom to make that abstract idea happen as they see fit (this concept applies to both artists and programmers, though more loosely to programmers). I acknowledge that I am not a designer or an artist; they have the vision, and I am not one to place limits on their creativity by giving detailed tasks.</li>
</ul>
<ul>
<li>Professionalism, in its bastardized modern form, is not something that we will rigorously follow. One&#8217;s clothes and hair do not determine his skillset, if we are to be judged based upon these superficial things, then it is surely the loss of those who make the judgement and not our own (and perhaps my wallet, but I&#8217;m secure enough to take that risk).</li>
</ul>
<ul>
<li>If one works hard, one cannot fail in any sense. In Purple Pwny&#8217;s worst case scenario, the company doesn&#8217;t take off, we make shitty games, the concept is a failure, one will still have received the experience of working on a team and creating something&#8230;and that means a lot in this industry.</li>
</ul>
<ul>
<li>Just do it. It sucks that it&#8217;s Nike&#8217;s slogan, but it applies heavily here. How many other people, are taking their little game development team and treating it as a true company? The difference between a &#8216;team&#8217; and a &#8216;company&#8217;, however, is quite large. A team, in this sense, carries no true connection, no penalty for leaving, and little focus on monetization (and thus little chance of it). If one just takes the plunge and &#8216;does it&#8217;, makes a charge for the top, there&#8217;s at least a possibility of true success whereas those who don&#8217;t shoot for the top for fear of failure, will never know if they can make it.</li>
</ul>
<p>In an effort to make this dream a reality, I placed ads on Craigslist looking for local people to work for no pay in an upstart game company. The response was tremendous, both negatively and positively. I receieved a steady 10-20 resumes a week while the ad was active. Admittedly, my screening process is rougher than most. I need to create a dream team, a group of people who are talented, passionate, and most importantly, share my ideals. In a large company, the ideals are fairly irrelevant. Business decisions will go on regardless of what the underlings think. In what will be such a tight knit company though, any disagreements are sure to cause turmoil throughout the team, so it is best to do all that you can to keep them to a minimum.This is no short order, and as such, finding talent that meets all criteria is quite a challenge. I&#8217;ve done a trial period with several people, none have fully worked out yet. Many on Craigslist feel compelled to bash this process stating:</p>
<ul>
<li>&#8220;You should change your ad. You sound like assholes.&#8221;</li>
<li>&#8220;Act professional and swallow it.&#8221;</li>
<li>&#8220;Why do you expect someone to show up and work their asses off for absolutely nothing?&#8221;</li>
<li>&#8220;They don&#8217;t care and won&#8217;t work with you because they will receive nothing in return.&#8221;</li>
</ul>
<p>These responses convey the attitude that has taken over not just this industry, but most. The attitude of a robotic sheeple who bow to their overlords and do whatever they are told. Little do the nay-sayers know how many responses I receive weekly&#8230;from individuals that, to be honest, are far above working for free. Purple Pwny must be attracting them for a reason. Some of them have even stated that they are looking to escape the humdrum of their 9-5 cubicle job.</p>
<p>So, this one&#8217;s for you, trolls of Craigslist. Every negative response that I receive will now be linked to this post.<br />
<strong><br />
Addendum:</p>
<p>Damn, this struck a nerve! We&#8217;ve been getting so many hits on this post, and it looks like someone posted it up on SA (I can&#8217;t find it at this moment however). The storm of negative comments to this post  shows a great misunderstanding. I don&#8217;t expect anyone to give up their day job to work here (hell, I havn&#8217;t even left MY day job!). Nor do I expect to line my pockets with gold while my employees wallow in despair. So many game companies, and tech companies in general, who do not pursue venture funding, begin in the garage with a group of unpaid friends. Unfortunately, it&#8217;s 2009 and this has grown to be a very uncommon practice. The fact remains, WE&#8217;RE NOT PROFITABLE. Who in their right mind would work here if I were rolling in money and they were getting none of it (and actually, the plan is that if we ever do become profitable&#8230;it is split evenly among all of us).  </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=282</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Lurking Around</title>
		<link>http://www.purplepwny.com/blog/?p=273</link>
		<comments>http://www.purplepwny.com/blog/?p=273#comments</comments>
		<pubDate>Mon, 27 Apr 2009 01:35:04 +0000</pubDate>
		<dc:creator>Alex Loeffler</dc:creator>
				<category><![CDATA[Art]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=273</guid>
		<description><![CDATA[
I have been away for some time, extremely busy with school. But i have not forgotten about you guys ^-^!
I will try my best to keep you all posted on new art.
]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.purplepwny.com/blog/wp-content/uploads/2009/04/sneaky_sneaky_by_death_azn.jpg" rel="lightbox[273]"><img class="aligncenter size-medium wp-image-276" title="sneaky_sneaky" src="http://www.purplepwny.com/blog/wp-content/uploads/2009/04/sneaky_sneaky_by_death_azn.jpg" alt="sneaky_sneaky" width="300" height="194" /></a></p>
<p>I have been away for some time, extremely busy with school. But i have not forgotten about you guys ^-^!</p>
<p>I will try my best to keep you all posted on new art.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=273</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Component Based Entity System Design Part 1</title>
		<link>http://www.purplepwny.com/blog/?p=215</link>
		<comments>http://www.purplepwny.com/blog/?p=215#comments</comments>
		<pubDate>Sat, 25 Apr 2009 03:10:40 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=215</guid>
		<description><![CDATA[About a week ago, I decided that if I needed to dynamic_cast my entities everywhere they were used, I was doing something wrong. It&#8217;s not that an inheritance based entity system is inherently wrong per se, but in large systems it tends to become an impossible to manage web of sloppy code. Seeing this issue, [...]]]></description>
			<content:encoded><![CDATA[<p>About a week ago, I decided that if I needed to dynamic_cast my entities everywhere they were used, I was doing something wrong. It&#8217;s not that an inheritance based entity system is inherently wrong per se, but in large systems it tends to become an impossible to manage web of sloppy code. Seeing this issue, and wanting to make Harmony the best it can be, I began to tackle the monstrous job of refactoring the entity code to a component based design.</p>
<p>I read the available literature (which is sparse, as it always is with entity systems):</p>
<p>1. <a href="http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/">Evolve Your Hierarchy : Refactoring Game Entities With Components</a><br />
2. <a href="http://www.amazon.com/Game-Programming-Gems-CD-ROM-Development/dp/1584504501/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1240439786&#038;sr=8-1">Game Programming Gems 6 , Section 4.6 : Game Object Component System</a><br />
3. <a href="http://www.drizzle.com/~scottb/gdc/game-objects_files/frame.htm">A Data-Driven Game Object System</a><br />
4. <a href="http://garage.gaspowered.com/?q=su_301">301: Introduction to Dungeon Siege Architecture</a></p>
<p>and got to work.</p>
<p>In my opinion, the implementation in Game Programming Gems 6 is too rigid and overly complex, 2 things that I&#8217;m trying to escape in Harmony. So after struggling to wrap my head around how to get it to work, since, if it&#8217;s in a book, it MUST be the best&#8230;I gave up, recognized that ingenuity is the key to success and created an original component based entity system design. </p>
<p>This is part 1 of a 2 part series, in this post I will review the Component class itself aswell as the Entities that hold them.</p>
<p>Part 2 will cover the Component Manager.</p>
<p>In most games, entities are derived from a series of concrete base classes. These base classes provide the ability to render, move, posses AI, etc. This system of inheritance quickly becomes unwieldy in practice and devolves into a mass of dynamic_casts and spaghetti code.  Also, this system does not lend itself well to data driven game design, as all possible entities and the interfaces that they implement must be specified at compile time. Optimally, in modern games, we want a system in which we can create entities dynamically on the fly at runtime. This not only makes the compile/debug cycle a non-issue for designers, but also opens up a realm of possibilities including: easy post-release patches that add new content through pure data, Spore-like creature creation, and simple user generated content.</p>
<p>An alternative to the standard architecture, which has come into the spotlight only recently, is the component based architecture. In this system, there is typically only 1 very generic Entity class that serves to hold the Components that implement its functionality. An Entity with hit-points would contain the HealthComponent, which would implement all of the methods relevant to dealing with hit points. This greatly increases the cleanliness of Entity&#8217;s direct interface and moves it all out into easy to manage and fully pluggable classes of functionality.</p>
<p>My implementation of this system is as follows:</p>
<p>Component.h</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Component <span style="color: #008000;">&#123;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
&nbsp;
    Component<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    ~Component<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
    std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> GetFamily<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> GetName<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">void</span>    SetOwner<span style="color: #008000;">&#40;</span>Entity<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    Entity<span style="color: #000040;">*</span> GetOwner<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> Set<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">map</span><span style="color: #000080;">&lt;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span>,boost<span style="color: #008080;">::</span><span style="color: #007788;">variant</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000080;">&gt;</span> <span style="color: #000080;">&gt;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> m_familyName<span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> m_name<span style="color: #008080;">;</span>
    Entity<span style="color: #000040;">*</span> m_owner<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>To create components, one must simply derive a type from this base class which implements all the base facilities that a component may need. The Set() function is used in conjunction with XML to give instance specific values to the properties of a component. For example, here is a snippet from the implementation of HealthComponent.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">HealthComponent<span style="color: #008080;">::</span><span style="color: #007788;">HealthComponent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    m_name <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;BasicHealth&quot;</span><span style="color: #008080;">;</span>
    m_familyName <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;Health&quot;</span><span style="color: #008080;">;</span>
    hp <span style="color: #000080;">=</span> <span style="color: #0000dd;">100</span><span style="color: #008080;">;</span>
    max <span style="color: #000080;">=</span> <span style="color: #0000dd;">100</span><span style="color: #008080;">;</span>
    min <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">void</span> HealthComponent<span style="color: #008080;">::</span><span style="color: #007788;">Set</span><span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">map</span><span style="color: #000080;">&lt;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span>,boost<span style="color: #008080;">::</span><span style="color: #007788;">variant</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000080;">&gt;</span> <span style="color: #000080;">&gt;</span> props<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
   <span style="color: #666666;">//a variant is used because data can only be one of 2 things</span>
    hp <span style="color: #000080;">=</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">get</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>props<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">&quot;hp&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    max <span style="color: #000080;">=</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">get</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>props<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">&quot;max&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    min <span style="color: #000080;">=</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">get</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>props<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">&quot;min&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>HealthComponent&#8217;s members are given sensible initial values in the contructor, if one wishes to use this component with different data, one can simply define a component template in XML (shown in part 2 of this article) which will override these default values. For instance, the following template would be suitable for a tank character:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;health<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tank<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name</span> <span style="color: #000066;">strval</span>=<span style="color: #ff0000;">&quot;TankHealth&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hp</span>  <span style="color: #000066;">intval</span>=<span style="color: #ff0000;">&quot;1000&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;max</span> <span style="color: #000066;">intval</span>=<span style="color: #ff0000;">&quot;1000&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;min</span> <span style="color: #000066;">intval</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tank<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/health<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Entity.h</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Entity <span style="color: #008000;">&#123;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
&nbsp;
    Entity<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    Entity<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> name<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    ~Entity<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>GetID<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">string</span>  <span style="color: #000040;">&amp;</span>GetName<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">void</span> AddComponent<span style="color: #008000;">&#40;</span>Component<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">void</span> RemoveComponent<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span>
    T <span style="color: #000040;">*</span> GetComponent<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> familyName<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">dynamic_cast</span><span style="color: #000080;">&lt;</span>t<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>m_components<span style="color: #008000;">&#91;</span>familyName<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">void</span> Do<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    SDL_Rect <span style="color: #000040;">&amp;</span>GetLocation<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> m_id<span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> m_name<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> nextID<span style="color: #008080;">;</span>
    SDL_Rect m_location<span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">map</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000080;">&gt;</span> m_keymap<span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">map</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span>,std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000080;">&gt;</span> m_mousemap<span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">map</span><span style="color: #000080;">&lt;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span>, Component<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span> m_components<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>As you can see, an entity is little more than a container of components. In addition to components, it holds a name and position. Also, all entities are inherently able to accept input, so that is the source of m_keymap, m_mousemap, and Do(std::string). Components are held in m_components and are indexed by their family name. GetComponent(std::string) is a templated function that returns a properly pre-casted component of the family name. </p>
<p>Do note that the system in its current form is very bare bones, entirely lacks error checking, and is subject to sweeping changes. Stay tuned for part 2, and as always <3.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=215</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Input, the Harmony Way</title>
		<link>http://www.purplepwny.com/blog/?p=232</link>
		<comments>http://www.purplepwny.com/blog/?p=232#comments</comments>
		<pubDate>Thu, 23 Apr 2009 02:35:38 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=232</guid>
		<description><![CDATA[Hey, Tony here.  It&#8217;s been quite a while since I joined up as a programmer at Pwny (6 weeks~), however I&#8217;ve been lurking in the shadows.  Well, I have emerged today to talk to you about (as the title suggests) the way in which the Harmony engine handles input.  The basic idea [...]]]></description>
			<content:encoded><![CDATA[<p>Hey, Tony here.  It&#8217;s been quite a while since I joined up as a programmer at Pwny (6 weeks~), however I&#8217;ve been lurking in the shadows.  Well, I have emerged today to talk to you about (as the title suggests) the way in which the Harmony engine handles input.  The basic idea for our input system is to create a logical way for people to adjust controls without actually having to edit and compile for every minor change.  In other words, avoid putting an army of if statements inside the source code.  How does one accomplish such a feat? XML.  By storing different &#8216;keymaps&#8217; (both mouse and keyboard control configurations) inside an XML document, the assignment of input to entities becomes trivial.  One line: AddInput(Entity*,std::string keymap).  Even better, the XML is formatted very simplistically, allowing for anyone to create their own keymap with ease.  I can rant about how easy it is, but in the end, code speaks much louder.</p>
<p>Keymap.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keyboard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveLeft&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;d</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveRight&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveDown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;w</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveUp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/keyboard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;l</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveLeft&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;r</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveRight&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;m</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveDown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;y</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;Vert&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity2<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keyboard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;j</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveLeft&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;l</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveRight&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;k</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveDown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;i</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveUp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/keyboard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;l</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveLeft&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;r</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveRight&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;m</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;MoveDown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;x</span> <span style="color: #000066;">act</span>=<span style="color: #ff0000;">&quot;Hor&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity2<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>InputManager.h</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> InputManager <span style="color: #008000;">&#123;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
&nbsp;
    InputManager<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    ~InputManager<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">void</span> AddInput<span style="color: #008000;">&#40;</span>Entity<span style="color: #000040;">*</span>,std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">void</span> HandleInput<span style="color: #008000;">&#40;</span>SDL_Event<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
&nbsp;
    Uint8 <span style="color: #000040;">*</span>kbarray<span style="color: #008080;">;</span>
    Uint8 MouseState<span style="color: #008080;">;</span>
    TiXmlDocument  m_doc<span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span> ControllableObjects<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>HandleInput sends messages to all objects that care about a particular event. I.e. if the event is that the &#8216;H&#8217; key was pressed, only objects with a mapped &#8216;H&#8217; key will receive word of the event. AddInput loops through the XML and fills the keymap with keys and their associated actions, as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> InputManager<span style="color: #008080;">::</span><span style="color: #007788;">AddInput</span><span style="color: #008000;">&#40;</span>Entity<span style="color: #000040;">*</span> ent,std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> keymap<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    ControllableObjects.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>ent<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> act<span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> key<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>TiXmlElement <span style="color: #000040;">*</span>m_xmlElementTemp <span style="color: #000080;">=</span> m_doc.<span style="color: #007788;">FirstChildElement</span><span style="color: #008000;">&#40;</span>keymap<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>FirstChildElement<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Keyboard&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>FirstChildElement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> m_xmlElementTemp<span style="color: #008080;">;</span> m_xmlElementTemp <span style="color: #000080;">=</span> m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>NextSiblingElement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>QueryValueAttribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;act&quot;</span>,<span style="color: #000040;">&amp;</span>act<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        key <span style="color: #000080;">=</span> m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>ValueStr<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        ent<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_keymap.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>make_pair<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>key<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span>,act<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>m_doc.<span style="color: #007788;">FirstChildElement</span><span style="color: #008000;">&#40;</span>keymap<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>FirstChildElement<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Mouse&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>TiXmlElement <span style="color: #000040;">*</span>m_xmlElementTemp <span style="color: #000080;">=</span> m_doc.<span style="color: #007788;">FirstChildElement</span><span style="color: #008000;">&#40;</span>keymap<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>FirstChildElement<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Mouse&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>FirstChildElement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> m_xmlElementTemp<span style="color: #008080;">;</span> m_xmlElementTemp <span style="color: #000080;">=</span> m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>NextSiblingElement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>QueryValueAttribute<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;act&quot;</span>,<span style="color: #000040;">&amp;</span>act<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            key <span style="color: #000080;">=</span> m_xmlElementTemp<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>ValueStr<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            ent<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_mousemap.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>make_pair<span style="color: #008000;">&#40;</span>key<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span>,act<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Scarily long arrow chains? Yes, I know.</p>
<p>I learned 2 invaluable rules in making this system, and will pass them on to you so that my mistakes are not duplicated:</p>
<p>1.)  Basic rule of life:  Know what you&#8217;re working with well.  Seriously.  Saves lives.  In other words, don&#8217;t end up writing numerous lines of code attempting to do something and then figure out that something built in does it, but better. Case in point, don&#8217;t write code that polls the current state of the keyboard if your libraries do it for you.</p>
<p>2.)  If using SDL, use GetKeyState/GetMouseState, honestly. SDL has easier to use facilities for polling events, but I have found them far inferior to SDL&#8217;s direct hardware state queries.</p>
<p>Good Day.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=232</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Teaser ;]</title>
		<link>http://www.purplepwny.com/blog/?p=206</link>
		<comments>http://www.purplepwny.com/blog/?p=206#comments</comments>
		<pubDate>Tue, 31 Mar 2009 01:19:28 +0000</pubDate>
		<dc:creator>Alex Loeffler</dc:creator>
				<category><![CDATA[Art]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=206</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.purplepwny.com/blog/wp-content/uploads/2009/03/beta-level1.jpg" rel="lightbox[206]"><img class="aligncenter size-medium wp-image-201" title="beta-level1" src="http://www.purplepwny.com/blog/wp-content/uploads/2009/03/beta-level1.jpg" alt="beta-level1" width="300" height="194" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=206</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hello World. This Is Your Captain, Alex, Speaking</title>
		<link>http://www.purplepwny.com/blog/?p=181</link>
		<comments>http://www.purplepwny.com/blog/?p=181#comments</comments>
		<pubDate>Sun, 29 Mar 2009 00:28:55 +0000</pubDate>
		<dc:creator>Alex Loeffler</dc:creator>
				<category><![CDATA[Art]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=181</guid>
		<description><![CDATA[Hello world,
My name is Alex Loeffler and I am the artist for Purple Pwny. I&#8217;m going to fill you in on what i&#8217;ll be working on for the next few weeks until the release of our first game. To start, I will be taking ideas such as genre, environment, character, and various movable objects into [...]]]></description>
			<content:encoded><![CDATA[<p>Hello world,<br />
My name is Alex Loeffler and I am the artist for Purple Pwny. I&#8217;m going to fill you in on what i&#8217;ll be working on for the next few weeks until the release of our first game. To start, I will be taking ideas such as genre, environment, character, and various movable objects into consideration and coming up with scenarios that provide interesting and fun gameplay. Some of you are thinking, what!?!? How can you combine such general ideas into one giant cluster? Well my simple answer for you is storyboarding. Heh who is this guy&#8230; Starting off with storyboarding? Yeah Yeah I know&#8230; it might seem weird to start off with a storyboard with no background ideas. But I feel if I pump out ideas and sketch the character, environment, and possible game elements into one piece, it helps the discovery of new concepts, genres, and game elements. Often I will use a sharpie or charcoal to sketch because they are permanent and hard to erase. <strong>You should never erase your artwork, there is always time to refine it later.</strong> An example of the method I use as follows: Say I draw a warrior princess in a swamp who has to escape the clutches of a dark wizard while avoiding poisonous shrubbery. Then, I draw a mech robot collecting wreckage from a destroyed ship while being attacked by alien savages. Ill then combine these to ideas by picking out the strongest elements of each. The product would be something like: A warrior princess collecting valuable plants from wreckage while avoiding savages. The more time I spend on this, the more fun and original concepts I can provide to you <img src='http://www.purplepwny.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
I just got back from GDC.</p>
<p style="text-align: left;">Made a ton of valuable contacts, and, made this to show you what I mean about combining general ideas into something worthwhile: <a href="http://www.purplepwny.com/blog/wp-content/uploads/2009/03/character1_by_death_azn.jpg" rel="lightbox[181]"><img class="aligncenter size-medium wp-image-180" title="CharacterDesign1" src="http://www.purplepwny.com/blog/wp-content/uploads/2009/03/character1_by_death_azn.jpg" alt="CharacterDesign1" width="300" height="194" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=181</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Implementing Camera Behaviors</title>
		<link>http://www.purplepwny.com/blog/?p=174</link>
		<comments>http://www.purplepwny.com/blog/?p=174#comments</comments>
		<pubDate>Sat, 28 Mar 2009 18:32:42 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=174</guid>
		<description><![CDATA[A necessary addendum to the prior post on implementing a camera in SDL is the inclusion of a set of &#8216;behaviors&#8217; for the camera to follow.
I&#8217;ve slightly reworked the interface to reflect how I would like the Camera to work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
&#160;
#include &#60;vector&#62;
#include &#34;SDL.h&#34;
&#160;
class Entity;
&#160;
class Camera&#123;
 public:
  Camera&#40;int x,int y, int width, int height&#41;;
  ~Camera&#40;&#41;;
&#160;
 [...]]]></description>
			<content:encoded><![CDATA[<p>A necessary addendum to the prior post on <a href="http://www.purplepwny.com/blog/?p=139">implementing a camera in SDL</a> is the inclusion of a set of &#8216;behaviors&#8217; for the camera to follow.</p>
<p>I&#8217;ve slightly reworked the interface to reflect how I would like the Camera to work.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #339900;">#include &lt;vector&gt;</span>
<span style="color: #339900;">#include &quot;SDL.h&quot;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Entity<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Camera<span style="color: #008000;">&#123;</span>
 <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  Camera<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x,<span style="color: #0000ff;">int</span> y, <span style="color: #0000ff;">int</span> width, <span style="color: #0000ff;">int</span> height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  ~Camera<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">void</span> MoveRelative<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x,<span style="color: #0000ff;">int</span> y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetPosition<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x, <span style="color: #0000ff;">int</span> y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetFollow<span style="color: #008000;">&#40;</span>Entity<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> UnsetFollow<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  SDL_Rect GetPosition<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  SDL_Rect<span style="color: #000040;">&amp;</span> GetViewport<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
 <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
&nbsp;
  <span style="color: #0000ff;">void</span> EdgePushBehavior<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
&nbsp;
  Entity <span style="color: #000040;">*</span> entToFollow<span style="color: #008080;">;</span>
  SDL_Rect m_viewport<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>The new bits to note are, entToFollow, Update(), SetFollow(Entity*), UnsetFollow(), and EdgePushBehavior(). entToFollow is the entity that the camera will be basing its behavior off of, such as following the entity around the screen centered, trailing the entity, etc. Update will alter the position of the camera based upon whichever behavior is chosen. At the moment, this looks like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> Camera<span style="color: #008080;">::</span><span style="color: #007788;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
  <span style="color: #666666;">//implement various behaviors that a camera can have, trail, center, bob, etc</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>entToFollow<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
  EdgePushBehavior<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>If we&#8217;ve been told to base our behavior off of an entity (entToFollow has been set with SetFollow(Entity*)), perform the active behavior. At the moment, the &#8216;active behavior&#8217; is hardcoded, but a SetActiveBehavior function is easy enough to implement. EdgePushBehavior() itself looks like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #0000ff;">void</span> Camera<span style="color: #008080;">::</span><span style="color: #007788;">EdgePushBehavior</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
  <span style="color: #666666;">//If we're hitting the right edge of the viewport</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>entToFollow<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_location.<span style="color: #007788;">x</span><span style="color: #000040;">+</span>entToFollow<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_location.<span style="color: #007788;">w</span><span style="color: #008000;">&#41;</span><span style="color: #000080;">&gt;=</span><span style="color: #008000;">&#40;</span>m_viewport.<span style="color: #007788;">x</span><span style="color: #000040;">+</span>m_viewport.<span style="color: #007788;">w</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
    m_viewport.<span style="color: #007788;">x</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> <span style="color: #666666;">//TODO: RATE LIMITER</span>
     <span style="color: #008000;">&#125;</span>
  <span style="color: #666666;">//left edge</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>entToFollow<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_location.<span style="color: #007788;">x</span><span style="color: #000080;">&lt;=</span>m_viewport.<span style="color: #007788;">x</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
    m_viewport.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #666666;">//top edge</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>entToFollow<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_location.<span style="color: #007788;">y</span><span style="color: #000080;">&lt;=</span>m_viewport.<span style="color: #007788;">y</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
    m_viewport.<span style="color: #007788;">y</span> <span style="color: #000040;">-</span><span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #666666;">//bottom edge</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>entToFollow<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_location.<span style="color: #007788;">y</span><span style="color: #000040;">+</span>entToFollow<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_location.<span style="color: #007788;">h</span><span style="color: #008000;">&#41;</span><span style="color: #000080;">&gt;=</span><span style="color: #008000;">&#40;</span>m_viewport.<span style="color: #007788;">y</span><span style="color: #000040;">+</span>m_viewport.<span style="color: #007788;">h</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
    m_viewport.<span style="color: #007788;">y</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>When we hit an edge of the screen, we move the camera in the direction of travel, think Mario games. Harmony will include the most common behaviors, but adding more will be as simple as adding a new function to a derived camera class. Also in the works, is CameraManager. This will provide one point of access to all active cameras and make the management of multiple cameras trivial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=174</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Script To Add Licenses (Or Any Text) To The Beginning Of Source Files</title>
		<link>http://www.purplepwny.com/blog/?p=153</link>
		<comments>http://www.purplepwny.com/blog/?p=153#comments</comments>
		<pubDate>Fri, 27 Mar 2009 07:38:37 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=153</guid>
		<description><![CDATA[Deciding on an open source license can be quite confusing. I chose to license Harmony with Zlib and I would say that it&#8217;s largely due to its ease of use. The documentation on open source licensing is sparse at best, and when present, overly verbose (see: GPL). Anyway, part of open source licensing is adding [...]]]></description>
			<content:encoded><![CDATA[<p>Deciding on an open source license can be quite confusing. I chose to license Harmony with Zlib and I would say that it&#8217;s largely due to its ease of use. The documentation on open source licensing is sparse at best, and when present, overly verbose (see: GPL). Anyway, part of open source licensing is adding the license inside of comment tags at the top of every source file. Doing this manually would be tedious and uninteresting, so I flexed my PHP muscle and came up with a script to do it for me!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$YEAR</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2009</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$COPYRIGHT_HOLDERS</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Tyler Bello (www.purplepwny.com)'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$license</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/*
Copyright (c) <span style="color: #006699; font-weight: bold;">$YEAR</span> <span style="color: #006699; font-weight: bold;">$COPYRIGHT_HOLDERS</span>
&nbsp;
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
&nbsp;
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
&nbsp;
    1. The origin of this software must not be misrepresented; you must not
    claim that you wrote the original software. If you use this software
    in a product, an acknowledgment in the product documentation would be
    appreciated but is not required.
&nbsp;
    2. Altered source versions must be plainly marked as such, and must not be
    misrepresented as being the original software.
&nbsp;
    3. This notice may not be removed or altered from any source
    distribution.
*/<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$directory</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Adding license to the following files : <span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/.\.[cChH](pp)?/&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;./<span style="color: #006699; font-weight: bold;">$file</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//change regex to suit your particular language, this one is C/C++</span>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$file</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$existingContent</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;./<span style="color: #006699; font-weight: bold;">$file</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$fileHandle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$file</span>&quot;</span><span style="color: #339933;">,</span>w<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileHandle</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$license</span><span style="color: #006699; font-weight: bold;">$existingContent</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileHandle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">closedir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>To use: Replace the necessary variables (Year, Copyright Holders, License) with those of your choosing. Save the file as add_license.php in the directory that contains the files you wish to license. Run it from the command line with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">php add_license.php</pre></td></tr></table></div>

<p>PHP isn&#8217;t the most practical way to accomplish this. Perhaps I, or another kind soul, will port it to an executable! It&#8217;s 3 AM and I can&#8217;t sleep. Awesome <img src='http://www.purplepwny.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  <3</p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=153</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Stall And Be Forgiven, And How To Make A  Camera In SDL</title>
		<link>http://www.purplepwny.com/blog/?p=139</link>
		<comments>http://www.purplepwny.com/blog/?p=139#comments</comments>
		<pubDate>Thu, 26 Mar 2009 00:58:11 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.purplepwny.com/blog/?p=139</guid>
		<description><![CDATA[Yeah, I said it would be out by Monday. Forgive me, we ran into some road blocks. Alex, our artist, is actually at GDC right now, handing out some of these.  He&#8217;s got a post for you about effective storyboarding, but he&#8217;s waiting to post it until he gets back. Tony has been out [...]]]></description>
			<content:encoded><![CDATA[<p>Yeah, I said it would be out by Monday. Forgive me, we ran into some road blocks. Alex, our artist, is actually at GDC right now, handing out some of these. <a href="http://74.207.231.193/blog/wp-content/uploads/2009/03/buscards.png" rel="lightbox[139]"><img src="http://74.207.231.193/blog/wp-content/uploads/2009/03/buscards.png" alt="Business Cards" title="Business Cards" width="252" height="144" class="aligncenter size-full wp-image-144" /></a> He&#8217;s got a post for you about effective storyboarding, but he&#8217;s waiting to post it until he gets back. Tony has been out of the game due to some surprise school work, so I&#8217;ve been alone. My hands have not been idle though. I worked on creating a Camera class for the engine over the past few days. It&#8217;s actually a lot simpler than I had anticipated.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #666666;">//Camera simply holds information, is not a surface that we render to.</span>
<span style="color: #666666;">//Check objects on rendering pass for falling within viewport. If they do,</span>
<span style="color: #666666;">//render them to the screen.</span>
<span style="color: #339900;">#include &lt;vector&gt;</span>
<span style="color: #339900;">#include &quot;SDL.h&quot;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Entity<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Camera<span style="color: #008000;">&#123;</span>
 <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  Camera<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x,<span style="color: #0000ff;">int</span> y, <span style="color: #0000ff;">int</span> width, <span style="color: #0000ff;">int</span> height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  ~Camera<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">void</span> MoveRelative<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x,<span style="color: #0000ff;">int</span> y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetPosition<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x, <span style="color: #0000ff;">int</span> y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  SDL_Rect GetPosition<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">//should return a Vec2D</span>
  <span style="color: #0000ff;">void</span> Follow<span style="color: #008000;">&#40;</span>Entity<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  SDL_Rect<span style="color: #000040;">&amp;</span> GetViewport<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
 <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
&nbsp;
  SDL_Rect m_viewport<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>The comment at the top is fairly self explanatory. Camera is really nothing more than a way to represent a rectangular viewport used to determine the screen locations of entities. To determine the screen location we subtract the camera location from the world location of the entity. As shown here:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">SDL_Rect<span style="color: #000040;">*</span> EntityManager<span style="color: #008080;">::</span><span style="color: #007788;">GetScreenLocation</span><span style="color: #008000;">&#40;</span>SDL_Rect<span style="color: #000040;">*</span> loc<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
&nbsp;
  SDL_Rect viewport <span style="color: #000080;">=</span> game<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_Camera<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>GetViewport<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  screenPos.<span style="color: #007788;">x</span> <span style="color: #000080;">=</span> loc<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000040;">-</span> viewport.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
  screenPos.<span style="color: #007788;">y</span> <span style="color: #000080;">=</span> loc<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>y <span style="color: #000040;">-</span> viewport.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">return</span> <span style="color: #000040;">&amp;</span>screenPos<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And once we&#8217;ve determined the screen location, we can go 1 step further and cull entities that are no longer visible.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> EntityManager<span style="color: #008080;">::</span><span style="color: #007788;">CullEntity</span><span style="color: #008000;">&#40;</span>SDL_Rect<span style="color: #000040;">&amp;</span> screenPos<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
  <span style="color: #666666;">//TODO:Check all points of an object to avoid pop in</span>
&nbsp;
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>screenPos.<span style="color: #007788;">x</span> <span style="color: #000080;">&gt;</span> SCREEN_WIDTH <span style="color: #000040;">||</span> screenPos.<span style="color: #007788;">y</span> <span style="color: #000080;">&gt;</span> SCREEN_HEIGHT<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
         <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span> <span style="color: #666666;">//do cull the entity</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The only problem with this function as it stands is that there will be pop in of entities when they are moving from left to right into screen space. This isn&#8217;t too big of a deal, but will be fixed soon. To use these functions, simply blit like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>CullEntity<span style="color: #008000;">&#40;</span>GetScreenLocation<span style="color: #008000;">&#40;</span>loc<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	SDL_BlitSurface<span style="color: #008000;">&#40;</span> srcSurface, srcRect, destSurface, screenPos <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>For the sake of clarity, these 2 functions (CullEntity and GetScreenLocation) have been left seperate, in a working environment it may be better to simply call GetScreenLocation inside of CullEntity. Coming soon, &#8220;Soft Programming vs. Hard Programming&#8221; and &#8220;Input, the Harmony Way&#8221;. Until then, <3</p>
]]></content:encoded>
			<wfw:commentRss>http://www.purplepwny.com/blog/?feed=rss2&amp;p=139</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

