<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>David Amador</title>
	
	<link>http://www.david-amador.com</link>
	<description>Developer's Blog</description>
	<lastBuildDate>Sun, 15 Apr 2012 17:02:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DavidAmador" /><feedburner:info uri="davidamador" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>DavidAmador</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Xbox 360 Controller Input in C++ via XInput</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/SPxifIscdTg/</link>
		<comments>http://www.david-amador.com/2012/04/xbox-360-controller-input-in-c-via-xinput/#comments</comments>
		<pubDate>Sun, 15 Apr 2012 10:41:27 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[directX]]></category>
		<category><![CDATA[Xbox360]]></category>
		<category><![CDATA[xInput]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1915</guid>
		<description><![CDATA[So you have that Xbox360 controller laying around and want to connect it to your game? On XNA this is an out of the box option but if you&#8217;re using C++ you have a bit more work to do first. First of all, you will need the DirecX 9.0+ sdk. The includes. #define WIN32_LEAN_AND_MEAN // [...]]]></description>
			<content:encoded><![CDATA[<p>So you have that Xbox360 controller laying around and want to connect it to your game?</p>
<p>On XNA this is an out of the box option but if you&#8217;re using C++ you have a bit more work to do first.</p>
<p>First of all, you will need the DirecX 9.0+ sdk.</p>
<p>The includes.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#define WIN32_LEAN_AND_MEAN // We don't want the extra stuff like MFC and such</span>
<span style="color: #339900;">#include &lt;windows&gt;</span>
<span style="color: #339900;">#include &lt;XInput.h&gt;     // XInput API</span>
<span style="color: #339900;">#pragma comment(lib, &quot;XInput.lib&quot;)   // Library. If your compiler doesn't support this type of lib include change to the corresponding one</span></pre></div></div>

<p>Let&#8217;s define the buttons</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">enum</span>
<span style="color: #008000;">&#123;</span>
	GamePad_Button_DPAD_UP          <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span>,
	GamePad_Button_DPAD_DOWN        <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span>,
	GamePad_Button_DPAD_LEFT        <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span>,
	GamePad_Button_DPAD_RIGHT       <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span>,
	GamePad_Button_START            <span style="color: #000080;">=</span> <span style="color: #0000dd;">4</span>,
	GamePad_Button_BACK             <span style="color: #000080;">=</span> <span style="color: #0000dd;">5</span>,
	GamePad_Button_LEFT_THUMB       <span style="color: #000080;">=</span> <span style="color: #0000dd;">6</span>,
	GamePad_Button_RIGHT_THUMB      <span style="color: #000080;">=</span> <span style="color: #0000dd;">7</span>,
	GamePad_Button_LEFT_SHOULDER    <span style="color: #000080;">=</span> <span style="color: #0000dd;">8</span>,
	GamePad_Button_RIGHT_SHOULDER   <span style="color: #000080;">=</span> <span style="color: #0000dd;">9</span>,
	GamePad_Button_A                <span style="color: #000080;">=</span> <span style="color: #0000dd;">10</span>,
	GamePad_Button_B                <span style="color: #000080;">=</span> <span style="color: #0000dd;">11</span>,
	GamePad_Button_X                <span style="color: #000080;">=</span> <span style="color: #0000dd;">12</span>,
	GamePad_Button_Y                <span style="color: #000080;">=</span> <span style="color: #0000dd;">13</span>,
	GamePadButton_Max <span style="color: #000080;">=</span>             <span style="color: #0000dd;">14</span>
<span style="color: #008000;">&#125;</span>GamePadButton<span style="color: #008080;">;</span></pre></div></div>

<p><img src="http://www.david-amador.com/wp-content/uploads/2012/04/450px-360_controller.svg_.jpg" alt="" title="450px-360_controller.svg" width="450" height="208" class="alignnone size-full wp-image-1932" /></p>
<p>After some digging I don&#8217;t think Microsoft exposes access to the Guide button, let me know if you find anything. Anyway it&#8217;s not something we need on Windows.</p>
<p>Now the GamePadIndexes</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// GamePad Indexes</span>
<span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">enum</span>
<span style="color: #008000;">&#123;</span>
	GamePadIndex_One <span style="color: #000080;">=</span>  <span style="color: #0000dd;">0</span>,
	GamePadIndex_Two <span style="color: #000080;">=</span>  <span style="color: #0000dd;">1</span>,
	GamePadIndex_Three <span style="color: #000080;">=</span><span style="color: #0000dd;">2</span>,
	GamePadIndex_Four <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span>,
<span style="color: #008000;">&#125;</span>GamePadIndex<span style="color: #008080;">;</span></pre></div></div>

<p>The GamePadIndex is to define the player position. Like on the Xbox360, this way we can control up to 4 controllers.</p>
<p>We need something to store the GamePad state</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// The GamePad State Stuct, were we store the buttons positions</span>
<span style="color: #0000ff;">struct</span> GamePadState 
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">bool</span>		_buttons<span style="color: #008000;">&#91;</span>GamePadButton_Max<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
	Vector2 	_left_thumbstick<span style="color: #008080;">;</span>               <span style="color: #666666;">// &lt;= I'm using a Vector2 (floats) class but you can replaced it with a float X and Y or whatever your Vector2 class is</span>
	Vector2	        _right_thumbstick<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">float</span>		_left_trigger<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">float</span>		_right_trigger<span style="color: #008080;">;</span>	
        <span style="color: #666666;">// Just to clear all values to default</span>
	<span style="color: #0000ff;">void</span> reset<span style="color: #008000;">&#40;</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><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>i<span style="color: #000080;">&lt;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>GamePadButton_Max<span style="color: #008080;">;</span><span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> _buttons<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		_left_thumbstick.<span style="color: #007788;">set</span><span style="color: #008000;">&#40;</span><span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		_right_thumbstick.<span style="color: #007788;">set</span><span style="color: #008000;">&#40;</span><span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		_left_trigger <span style="color: #000080;">=</span> _right_trigger <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Now a small class</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #0000ff;">class</span> GamePadXbox 
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span> 
	GamePadXbox<span style="color: #008000;">&#40;</span>GamePadIndex player<span style="color: #008000;">&#41;</span>			
	<span style="color: #008000;">&#123;</span>
                  _playerIndex <span style="color: #000080;">=</span> player<span style="color: #008080;">;</span>
                  State.<span style="color: #007788;">reset</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">virtual</span> ~GamePadXbox<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #666666;">// We don't want the controller to be vibrating accidentally when we exit the app</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>is_connected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> vibrate<span style="color: #008000;">&#40;</span><span style="color:#800080;">0.0f</span>,<span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">bool</span> is_connected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">void</span> vibrate<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> leftmotor <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span>, <span style="color: #0000ff;">float</span> rightmotor <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</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>
&nbsp;
 <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
   GamePadState	State<span style="color: #008080;">;</span>
 <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
   XINPUT_STATE _controllerState<span style="color: #008080;">;</span>
   GamePadIndex _playerIndex<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Now, onto the GamePadXbox::is_connected()</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> is_connected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
     <span style="color: #666666;">// clean the state</span>
     <span style="color: #0000dd;">memset</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>_controllerState,<span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>XINPUT_STATE<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #666666;">// Get the state</span>
     DWORD Result <span style="color: #000080;">=</span> XInputGetState<span style="color: #008000;">&#40;</span>_controllerNum, <span style="color: #000040;">&amp;</span>_controllerState<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>Result <span style="color: #000080;">==</span> ERROR_SUCCESS<span style="color: #008000;">&#41;</span>	<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
     <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Documentation for the XInputGetState is <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputgetstate%28v=vs.85%29.aspx">here</a>.</p>
<p>Onto the vibrate function. Now, the Vibration accepts values between 0 and 65535. But we don&#8217;t want to be typing that every time so the vibrate accepts from a range of 0.0f (0) to 1.0f (65535);</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> vibrate<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> leftmotor <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span>, <span style="color: #0000ff;">float</span> rightmotor <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">// Create a new Vibraton </span>
	XINPUT_VIBRATION Vibration<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">memset</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>Vibration, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>XINPUT_VIBRATION<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> leftVib <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>leftmotor<span style="color: #000040;">*</span><span style="color:#800080;">65535.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> rightVib <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>rightmotor<span style="color: #000040;">*</span><span style="color:#800080;">65535.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Set the Vibration Values</span>
	Vibration.<span style="color: #007788;">wLeftMotorSpeed</span> <span style="color: #000080;">=</span> leftVib<span style="color: #008080;">;</span>
	Vibration.<span style="color: #007788;">wRightMotorSpeed</span> <span style="color: #000080;">=</span> rightVib<span style="color: #008080;">;</span>
        <span style="color: #666666;">// Vibrate the controller</span>
	XInputSetState<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>_controllerNum, <span style="color: #000040;">&amp;</span>Vibration<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>On the destructor I&#8217;ve placed the vibrate at 0.0f otherwise the controller may be left vibrating after your game exits until the user unplugs it.</p>
<p>Finally, the update() function. Now this one is more out of convenience, since you could get the state straight out of  XINPUT_STATE but I think this is a more consistent way of doing it. You can decide how you want on yours.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	State.<span style="color: #007788;">reset</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #666666;">// The values of the Left and Right Triggers go from 0 to 255. We just convert them to 0.0f=&gt;1.0f</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bRightTrigger</span> <span style="color: #000040;">&amp;&amp;</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bRightTrigger</span> <span style="color: #000080;">&lt;</span> XINPUT_GAMEPAD_TRIGGER_THRESHOLD<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		State._right_trigger <span style="color: #000080;">=</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bRightTrigger</span><span style="color: #000040;">/</span><span style="color:#800080;">255.0f</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bLeftTrigger</span> <span style="color: #000040;">&amp;&amp;</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bLeftTrigger</span> <span style="color: #000080;">&lt;</span> XINPUT_GAMEPAD_TRIGGER_THRESHOLD<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		State._left_trigger <span style="color: #000080;">=</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bLeftTrigger</span><span style="color: #000040;">/</span><span style="color:#800080;">255.0f</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
       <span style="color: #666666;">// Get the Buttons</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_A<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_A<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_B<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_B<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_X<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_X<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_Y<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_Y<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_DPAD_DOWN<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_DPAD_DOWN<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
		<span style="color: #666666;">// The Rest is missing, you can figure out the rest :)</span>
&nbsp;
....
             <span style="color: #008000;">&#40;</span>ThumbSticks code below<span style="color: #008000;">&#41;</span>   
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>For getting all buttons here are the official flags according to msdn</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">XINPUT_GAMEPAD_DPAD_UP          <span style="color: #208080;">0x00000001</span>
XINPUT_GAMEPAD_DPAD_DOWN        <span style="color: #208080;">0x00000002</span>
XINPUT_GAMEPAD_DPAD_LEFT        <span style="color: #208080;">0x00000004</span>
XINPUT_GAMEPAD_DPAD_RIGHT       <span style="color: #208080;">0x00000008</span>
XINPUT_GAMEPAD_START            <span style="color: #208080;">0x00000010</span>
XINPUT_GAMEPAD_BACK             <span style="color: #208080;">0x00000020</span>
XINPUT_GAMEPAD_LEFT_THUMB       <span style="color: #208080;">0x00000040</span>
XINPUT_GAMEPAD_RIGHT_THUMB      <span style="color: #208080;">0x00000080</span>
XINPUT_GAMEPAD_LEFT_SHOULDER    <span style="color: #208080;">0x0100</span>
XINPUT_GAMEPAD_RIGHT_SHOULDER   <span style="color: #208080;">0x0200</span>
XINPUT_GAMEPAD_A                <span style="color: #208080;">0x1000</span>
XINPUT_GAMEPAD_B                <span style="color: #208080;">0x2000</span>
XINPUT_GAMEPAD_X                <span style="color: #208080;">0x4000</span>
XINPUT_GAMEPAD_Y                <span style="color: #208080;">0x8000</span></pre></div></div>

<p>The ThumbSticks are a bit more tricky. They return 2 axis each but you have to make sure they are not in the deadzone. The deadzone pretty much are values !=0 but that are not relevant and can lead to errors.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
  <span style="color: #666666;">// Check to make sure we are not moving during the dead zone</span>
  <span style="color: #666666;">// Let's check the Left DeadZone</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLX</span> <span style="color: #000080;">&lt;</span> XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE <span style="color: #000040;">&amp;&amp;</span>
	_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLX</span> <span style="color: #000080;">&gt;</span> <span style="color: #000040;">-</span>XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE<span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span>
	<span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLY</span> <span style="color: #000080;">&lt;</span> XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE <span style="color: #000040;">&amp;&amp;</span>
	_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLY</span> <span style="color: #000080;">&gt;</span> <span style="color: #000040;">-</span>XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>    
	_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLX</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLY</span> <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: #666666;">// Check left thumbStick</span>
&nbsp;
  <span style="color: #0000ff;">float</span> leftThumbY <span style="color: #000080;">=</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLY</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>leftThumbY<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
        State._left_thumbstick.<span style="color: #007788;">Y</span> <span style="color: #000080;">=</span> leftThumbY<span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0000ff;">float</span> leftThumbX <span style="color: #000080;">=</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLX</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>leftThumbX<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
	State._left_thumbstick.<span style="color: #007788;">X</span> <span style="color: #000080;">=</span> leftThumbX<span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>    
&nbsp;
  <span style="color: #666666;">// For the rightThumbstick it's pretty much the same.</span></pre></div></div>

<p>So how would we use this then?</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
     GamePadXbox<span style="color: #000040;">*</span> pad <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> GamePadXbox<span style="color: #008000;">&#40;</span>GamePadIndex_One<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
     <span style="color: #008000;">&#123;</span>
       <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>pad<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>is_connected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
       <span style="color: #008000;">&#123;</span>
          pad<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
          <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>pad<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_BACK<span style="color: #008000;">&#93;</span><span style="color: #000080;">==</span><span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
       <span style="color: #008000;">&#125;</span>   
     <span style="color: #008000;">&#125;</span>
     <span style="color: #0000dd;">delete</span> pad<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Anyway, most of this code is not elegant or &#8220;pretty&#8221; but it should work, the idea is for you to understand the concept, the rest is up to you.</p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/SPxifIscdTg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/04/xbox-360-controller-input-in-c-via-xinput/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2012/04/xbox-360-controller-input-in-c-via-xinput/</feedburner:origLink></item>
		<item>
		<title>Screenies time…</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/saJP3JVSo0w/</link>
		<comments>http://www.david-amador.com/2012/03/screenies-time/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 20:36:35 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[darys legend]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1903</guid>
		<description><![CDATA[We finally released some screenshots of Dary&#8217;s Legend. Lately I&#8217;ve been working on the light system and fog of war for the game, it&#8217;s visible on the images. Here&#8217;s the official post but I&#8217;ve placed the images here for convenience.]]></description>
			<content:encoded><![CDATA[<p>We finally released some screenshots of Dary&#8217;s Legend.</p>
<p>Lately I&#8217;ve been working on the light system and fog of war for the game, it&#8217;s visible on the images.</p>
<p>Here&#8217;s the <a href="http://www.differentpixel.com/2012/03/first-darys-legend-screenshots/">official post</a> but I&#8217;ve placed the images here for convenience. </p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2012/03/dary_screenshots3.png" rel="shadowbox[sbpost-1903];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/03/dary_screenshots3-300x168.png" alt="" title="dary_screenshots3" width="300" height="168" class="alignnone size-medium wp-image-1907" /></a><a href="http://www.david-amador.com/wp-content/uploads/2012/03/dary_screenshots2.png" rel="shadowbox[sbpost-1903];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/03/dary_screenshots2-300x168.png" alt="" title="dary_screenshots2" width="300" height="168" class="alignnone size-medium wp-image-1906" /></a><a href="http://www.david-amador.com/wp-content/uploads/2012/03/dary_screenshots1.png" rel="shadowbox[sbpost-1903];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/03/dary_screenshots1-300x168.png" alt="" title="dary_screenshots1" width="300" height="168" class="alignnone size-medium wp-image-1905" /></a><a href="http://www.david-amador.com/wp-content/uploads/2012/03/dary_screenshots4.png" rel="shadowbox[sbpost-1903];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/03/dary_screenshots4-300x168.png" alt="" title="dary_screenshots4" width="300" height="168" class="alignnone size-medium wp-image-1904" /></a></p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/saJP3JVSo0w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/03/screenies-time/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2012/03/screenies-time/</feedburner:origLink></item>
		<item>
		<title>New game…</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/lwOcKMaj8fE/</link>
		<comments>http://www.david-amador.com/2012/03/new-game/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 17:11:43 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[darys legend]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1895</guid>
		<description><![CDATA[&#160; New game, called Dary&#8217;s Legend, a roguelike, dungeon crawling type. This is what I&#8217;ve been working on lately, and &#8230; well not much more to say. I&#8217;ll try and do posts with relevant stuff regarding the development of the game from now on. Going back to coding now&#8230;]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.daryslegend.com"><img class="alignnone  wp-image-1896" title="dp_site_dary_header" src="http://www.david-amador.com/wp-content/uploads/2012/03/dp_site_dary_header.jpg" alt="" width="564" height="154" /></a></p>
<p>&nbsp;</p>
<p>New game, called <a href="http://www.daryslegend.com">Dary&#8217;s Legend</a>, a roguelike, dungeon crawling type.<br />
This is what I&#8217;ve been working on lately, and &#8230; well not much more to say.</p>
<p>I&#8217;ll try and do posts with relevant stuff regarding the development of the game from now on.</p>
<p>Going back to coding now&#8230;</p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/lwOcKMaj8fE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/03/new-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2012/03/new-game/</feedburner:origLink></item>
		<item>
		<title>Where do you like games to store their save data?</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/Xo0IWsyVikU/</link>
		<comments>http://www.david-amador.com/2012/03/where-do-you-like-games-to-store-their-save-data/#comments</comments>
		<pubDate>Sat, 03 Mar 2012 12:57:47 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[save files]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1874</guid>
		<description><![CDATA[Quick question. I&#8217;m trying to decide where my next game should store their save files so I decided to make a poll. Personally I think that C:/Users/$USER$/AppData/Local/ is a total idiotic thing. Starting on Windows Vista there&#8217;s a pre-created &#8220;Saved Games&#8221; folder but most people seem to miss it since it&#8217;s not on the &#8220;My [...]]]></description>
			<content:encoded><![CDATA[<p>Quick question.</p>
<p>I&#8217;m trying to decide where my next game should store their save files so I decided to make a poll.</p>
<p>Personally I think that</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">C<span style="color: #008080;">:</span><span style="color: #000040;">/</span>Users<span style="color: #000040;">/</span>$USER$<span style="color: #000040;">/</span>AppData<span style="color: #000040;">/</span>Local<span style="color: #000040;">/</span></pre></div></div>

<p> is a total idiotic thing.</p>
<p>Starting on Windows Vista there&#8217;s a pre-created &#8220;Saved Games&#8221; folder but most people seem to miss it since it&#8217;s not on the &#8220;My Documents&#8221; folder.</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2012/03/saved-games_folder.jpg" rel="shadowbox[sbpost-1874];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/03/saved-games_folder-150x300.jpg" alt="" title="saved games_folder" width="150" height="300" class="alignnone size-medium wp-image-1875" /></a></p>
<p>There&#8217;s also other possibilities which many games I own use like</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">My Documents\My Games\Game\</pre></div></div>

<p>Others just create a folder directly on &#8220;My Documents&#8221; which some users find a bit obstructive.</p>
<p>I&#8217;ve been considering giving a read at Dropbox API (if any) too, It would be a nice touch to allow direct integration. But that&#8217;s just an idea that&#8217;s probably tricky to integrate.</p>
<p>So tell me what you think or suggest another one.</p>
<p><script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/6001864.js"></script><br />
<noscript><a href="http://polldaddy.com/poll/6001864/">Where do you like that games store their save files?</a></noscript></p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/Xo0IWsyVikU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/03/where-do-you-like-games-to-store-their-save-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2012/03/where-do-you-like-games-to-store-their-save-data/</feedburner:origLink></item>
		<item>
		<title>Some thoughts about indie dev</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/k1bEdziNdIE/</link>
		<comments>http://www.david-amador.com/2012/02/some-thoughts-about-indie-dev/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 23:10:19 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>
		<category><![CDATA[indie]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1853</guid>
		<description><![CDATA[1 &#8211; You either are, or you aren&#8217;t. People can go and , &#8220;I&#8217;m an aspiring indie game developer&#8221;. You are either doing games or not, period. If you are starting in development with your own money then you are one. People tend to think they are indie developers when money starts rolling in, well [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.david-amador.com/wp-content/uploads/2012/02/sad_developer.jpg" rel="shadowbox[sbpost-1853];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/02/sad_developer-300x251.jpg" alt="" title="sad_developer" width="300" height="251" class="alignnone size-medium wp-image-1862" /></a></p>
<p><strong>1 &#8211; You either are, or you aren&#8217;t.</strong><br />
People can go and , &#8220;I&#8217;m an aspiring indie game developer&#8221;. You are either doing games or not, period. If you are starting in development with your own money then you are one. People tend to think they are indie developers when money starts rolling in, well think again, cause money may never come.</p>
<p><strong>2 &#8211; It&#8217;s a jungle out there</strong><br />
There&#8217;s not a safe path on becoming a successful indie developer. It&#8217;s not like following another&#8217;s path will get you there. That&#8217;s why giving advices is just that, it might work or not.</p>
<p><strong>3 &#8211; There&#8217;s a minefield being left behind </strong><br />
We see it everywhere, indie bundles, pay what you want, fremium games, games at $1, the ones who made money with those models are leaving behind a bad legacy and an audience that doesn&#8217;t want to pay much.</p>
<p><strong>4 &#8211; Finish you stuff</strong><br />
You should actually be working instead of reading this.</p>
<p><strong>5 &#8211; You need to learn the rules</strong><br />
&#8230; to know when they must be broken</p>
<p><strong>6 &#8211; You need to break the rules</strong><br />
&#8230; to know why they matter.</p>
<p><strong>7 &#8211; Playing games does NOT make you a developer</strong><br />
Yet many think it&#8217;s all it takes, I&#8217;m good at playing thus I must be good at making them. You should however play critically, that is the key.</p>
<p><strong>8 &#8211; Working alone</strong><br />
..can be like rowing a boat with just one paddle.</p>
<p><strong>9 &#8211; Working with a team</strong><br />
&#8230;can be like two people on a bike, one steering and another one pedaling.</p>
<p><strong>10 &#8211; Overnight success</strong><br />
Out of nothing this indie developer! Overnight success! Million-dollar!<br />
And you think, &#8220;I can do that&#8221;. Yeah, except, those who are “overnight successes,” rarely appear out of nowhere. Minecraft? That dude&#8217;s been working in games for years. Super Meat Boy? I bet Edmund made over 30 games till now. They just stayed in obscurity for years. Work matters.</p>
<p><strong>11 &#8211; Learn to fall</strong><br />
This one&#8217;s hard especially if you think your game is great and the first comment is &#8220;This is sh**&#8221;. Learn from mistakes and do it again, but better.</p>
<p><strong>12 &#8211; Making games is hard work</strong><br />
&#8230;and you will shoot fire from your eyes to whoever says otherwise.</p>
<p><strong>13 &#8211; People who tell you to keep trying</strong><br />
&#8230;are mostly lying, they think you&#8217;re lazy and can&#8217;t get a real job.</p>
<p><strong>14 &#8211; Your parents will keep the hope</strong><br />
&#8230;that you get your act together and apply for IBM or Microsoft, cause that&#8217;s where the money is.</p>
<p><strong>15 &#8211; You will think twice</strong><br />
&#8230;when someone asks you what you do for a living. It would be the first thing said if you were a Doctor.</p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/k1bEdziNdIE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/02/some-thoughts-about-indie-dev/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2012/02/some-thoughts-about-indie-dev/</feedburner:origLink></item>
		<item>
		<title>Engine, video player and tools, tools tools!</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/tv4npHw1_bE/</link>
		<comments>http://www.david-amador.com/2012/01/engine-video-player-and-tools-tools-tools/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 19:56:20 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[anim banks]]></category>
		<category><![CDATA[Basalt]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[game tools]]></category>
		<category><![CDATA[openal]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[sprite sheet]]></category>
		<category><![CDATA[theora]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1819</guid>
		<description><![CDATA[So these past 2 weeks I&#8217;ve been adding some &#8220;bits and bytes&#8221; to the engine. Taking a rest between some more complex game mechanisms I decided to start doing a video player. After a bit research I decided to choose theora, but a bit skeptic, I&#8217;ve used it before on a game company I worked [...]]]></description>
			<content:encoded><![CDATA[<p>So these past 2 weeks I&#8217;ve been adding some &#8220;bits and bytes&#8221; to the engine. </p>
<p>Taking a rest between some more complex game mechanisms I decided to start doing a video player.</p>
<p>After a bit research I decided to choose <a href="http://theora.org/">theora</a>, but a bit skeptic, I&#8217;ve used it before on a game company I worked at and I remember being a tiny nightmare, specially because of YUV->RGB(A) conversion and because of video/audio sync. </p>
<p>If I remember correctly we couldn&#8217;t play audio, we where using separated tracks and paying the audio via a normal music play and big resolution videos (>500??) where a killer.</p>
<p>Anyway, since I&#8217;m already using OpenAL for audio I decided to give it a try. Unfortunately I didn&#8217;t had that code we where using back then so I had to do some digging on the internet. </p>
<p>So after a few days I had it working but bumped into the same problem, a bit slow. Not as slow as before cause computers have evolved. But after some reading I discovered that you can actually cache some YUV->RBG values and speed went up by like 10 fold.</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2012/01/theora_player.png" rel="shadowbox[sbpost-1819];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/01/theora_player-300x175.png" alt="" title="theora_player" width="300" height="175" class="alignnone size-medium wp-image-1833" /></a></p>
<p>I can decode 1080p videos with audio on my Core2Duo @ 2 GHz. And I mention the core since I have the decoding from the file on a separated thread so on a single core it&#8217;s probably a bit slower.<br />
But we probably will be placing videos around 512px width so there&#8217;s no problem there. I wonder if we could do the YUV->RGBA on the GPU side via a shader?</p>
<p>It&#8217;s also worth mentioning that I&#8217;m using OpenGL and &#8220;glTexSubImage2D&#8221; for updating the texture. I found out that it&#8217;s much faster than &#8220;glTexImage2D&#8221; because it respecifies the entire texture, changing its size, deleting the previous data, and so forth. &#8220;glTexSubImage2D&#8221; only modifies pixel data within the texture.</p>
<p><strong>Tools</strong></p>
<p>On the tools realm there was a need for a better Particle System Editor, the one we had has many things but adding stuff was turning into a nightmare, the old editor was build on XNA 3.1 which isn&#8217;t supported by VS2010.<br />
Since the engine is already in C++ I started from scratch and built this handy tool in 3 days or so:</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2012/01/screenshots2.png" rel="shadowbox[sbpost-1819];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/01/screenshots2-300x175.png" alt="" title="screenshots2" width="300" height="175" class="alignnone size-medium wp-image-1829" /></a><a href="http://www.david-amador.com/wp-content/uploads/2012/01/Screenshot1.png" rel="shadowbox[sbpost-1819];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/01/Screenshot1-300x175.png" alt="" title="Screenshot1" width="300" height="175" class="alignnone size-medium wp-image-1830" /></a></p>
<p>Not vary fancy but it gets the job done. </p>
<p>My next step was to fix most of the Sprite Sheet Editor bugs and issues my designer had been complaining about. </p>
<p>I already have an offline tool that grabs a bunch of tiny images and place them in an Atlas but most of the time the designer has the pieces together already on Photoshop so I incorporated a snippet of code that on double clicking an area tries to automatically detect the region around it. Anything that fails can be manually defined, the old fashioned way.</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2012/01/sprite_editor.png" rel="shadowbox[sbpost-1819];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/01/sprite_editor-300x175.png" alt="" title="sprite_editor" width="300" height="175" class="alignnone size-medium wp-image-1834" /></a></p>
<p>So in the next few days I&#8217;m working on the Animation Editor so the artist can quickly create and preview the animations from the sprite sheets without the need for me to place them in the game before hand.</p>
<p>I had most of these tools but they where awful. They did the trick for Vizati but now I&#8217;m trying to do things a bit better.</p>
<p>See you soon&#8230;</p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/tv4npHw1_bE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/01/engine-video-player-and-tools-tools-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2012/01/engine-video-player-and-tools-tools-tools/</feedburner:origLink></item>
		<item>
		<title>How to Restore the Windows 7 MBR (Master Boot Record)</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/TheVfPl9pYo/</link>
		<comments>http://www.david-amador.com/2012/01/how-to-restore-the-windows-7-mbr-master-boot-record/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 10:43:50 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Application & Software]]></category>
		<category><![CDATA[mbr]]></category>
		<category><![CDATA[windows 7]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1820</guid>
		<description><![CDATA[So I had this crisis where the MBR got broken and Windows would not boot. This can happens for many reasons, maybe you tried to dual boot your PC and something went wrong. Anyway where&#8217;s a quick tip on how to fix it (You need a Windows 7 DVD of course)! 1 &#8211; Boot your [...]]]></description>
			<content:encoded><![CDATA[<p>So I had this crisis where the MBR got broken and Windows would not boot. This can happens for many reasons, maybe you tried to dual boot your PC and something went wrong.</p>
<p>Anyway where&#8217;s a quick tip on how to fix it (You need a Windows 7 DVD of course)!</p>
<p>1 &#8211; Boot your computer to the Windows 7 DVD<br />
2 &#8211; Select your language and click next.<br />
3 &#8211; Click the button for &#8220;Use recovery tools&#8221;.<br />
4 &#8211; Then select &#8220;Command Prompt&#8221;.</p>
<p>Do this:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&nbsp;
Type: diskpart
and press Enter
&nbsp;
Type: select disk 0
and press Enter
&nbsp;
type: list volume
and press Enter</pre></div></div>

<p><img src="http://www.david-amador.com/wp-content/uploads/2012/01/53599d1251414836-mbr-restore-windows-7-master-boot-record-mbr_17a.png" alt="" title="53599d1251414836-mbr-restore-windows-7-master-boot-record-mbr_17a" width="550" height="266" class="alignnone size-full wp-image-1821" /></p>
<p>6 &#8211; Use your DVD drive letter so we can access the DVD</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">Type: exit
and press Enter
&nbsp;
to close Diskpart
&nbsp;
Type: G: (DVD drive)
and press Enter
&nbsp;
Type: cd boot
and press Enter
&nbsp;
Type: dir
and press Enter</pre></div></div>

<p><img src="http://www.david-amador.com/wp-content/uploads/2012/01/53600d1251414836-mbr-restore-windows-7-master-boot-record-mbr_18a.png" alt="" title="53600d1251414836-mbr-restore-windows-7-master-boot-record-mbr_18a" width="550" height="320" class="alignnone size-full wp-image-1822" /></p>
<p>7 &#8211; To restore the &#8220;bootsector code&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&nbsp;
TYPE: bootsect /nt60 SYS /mbr
and press Enter</pre></div></div>

<p>You should be able to restart and boot you Windows now, if it fails, well, I&#8217;m out of ideas</p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/TheVfPl9pYo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/01/how-to-restore-the-windows-7-mbr-master-boot-record/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2012/01/how-to-restore-the-windows-7-mbr-master-boot-record/</feedburner:origLink></item>
		<item>
		<title>Find/Replace in Visual Studio using regular expressions</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/P7pGbUCQd7c/</link>
		<comments>http://www.david-amador.com/2012/01/findreplace-in-visual-studio-using-regular-expressions/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 21:27:55 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1808</guid>
		<description><![CDATA[Usually Find/Replace gets the job done for what I need, although sometimes using &#8220;Replace All&#8221; can break more stuff that it fixes. But today I had this function I wanted to get rid of and simple change it with a public variable. So I had something like this. object-&#62;setLayer&#40;/*BLABAL BLA CODE, */&#41;; I want to [...]]]></description>
			<content:encoded><![CDATA[<p>Usually Find/Replace gets the job done for what I need, although sometimes using &#8220;Replace All&#8221; can break more stuff that it fixes.</p>
<p>But today I had this function I wanted to get rid of and simple change it with a public variable.</p>
<p>So I had something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">object<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setLayer<span style="color: #008000;">&#40;</span><span style="color: #ff0000; font-style: italic;">/*BLABAL BLA CODE, */</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>I want to replace it with something more simple</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">object<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>Z <span style="color: #000080;">=</span> <span style="color: #ff0000; font-style: italic;">/*BLABAL BLA CODE, */</span><span style="color: #008080;">;</span></pre></div></div>

<p>So using Visual Studio Find/Replace in regular expressions mode I used this as a search string</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">setLayer\<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#123;</span>.<span style="color: #000040;">+</span><span style="color: #008000;">&#125;</span>\<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>And this as a Replace with string</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">Z<span style="color: #000080;">=</span>\<span style="color: #0000dd;">1</span><span style="color: #008080;">;</span></pre></div></div>

<p><img class="alignnone size-full wp-image-1809" title="regular expression" src="http://www.david-amador.com/wp-content/uploads/2012/01/regular-expression.jpg" alt="" width="474" height="421" /></p>
<p>Now, notice the first one, it&#8217;s actually simple, you have &#8220;setLayer&#8221;, followed by &#8220;\(&#8221; to tell the expression we really need to be that character, after than we have &#8220;.+&#8221;, which means match any single character except a line break and at least one occurrence. Followed by &#8220;\);&#8221;</p>
<p>Now if you notice we have curly brackets around the inside of what the function receives as parameter, that&#8217;s because we are tagging that string to use it later.</p>
<p>This way on the replace we simply need &#8220;Z=&#8221; followed by the first tagged string we have &#8220;\1&#8243;. if we have more curly brackets it would be &#8220;\2&#8243;, &#8220;\3&#8243; etc.</p>
<p>Check the full list for more options: <a href="http://msdn.microsoft.com/en-us/library/2k3te2cs%28v=vs.80%29.aspx">http://msdn.microsoft.com/en-us/library/2k3te2cs%28v=vs.80%29.aspx</a></p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/P7pGbUCQd7c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/01/findreplace-in-visual-studio-using-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2012/01/findreplace-in-visual-studio-using-regular-expressions/</feedburner:origLink></item>
		<item>
		<title>post mortem of another year</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/ehlzkJZN9vY/</link>
		<comments>http://www.david-amador.com/2012/01/post-mortem-of-another-year/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 21:43:43 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1782</guid>
		<description><![CDATA[Another year has gone by, not quite what I was expecting developing wise, like putting another game out there, but things never turned out as planned. Still over the last year I&#8217;ve gradually saw out little Different Pixel brand reaching more and more places which can be very helpful in the future and sure hell [...]]]></description>
			<content:encoded><![CDATA[<p>Another year has gone by, not quite what I was expecting developing wise, like putting another game out there, but things never turned out as planned.</p>
<p>Still over the last year I&#8217;ve gradually saw out little Different Pixel brand reaching more and more places which can be very helpful in the future and sure hell is nice to see work recognized.</p>
<p>From the top of my head I recall <a href="http://kotaku.com/5820508/our-newest-xbox-live-indie-favorites-are-full-of-rainbows-and-death/gallery/5">Kotaku article on the Xbox360 release</a>, we finally managed to release the Xbox360 version, which was the first one we made. Being a <a href="http://www.dreambuildplay.com/Main/SemiFinalists.aspx">semi-finalist on Dream.Build.Play</a> 2011 and the <a href="http://www.destructoid.com/destructoid-show-mgs-menswear-gow-fitness-and-vizati-198288.phtml">coverage on Destructoid</a>.</p>
<p>More and more I get to know developers from around the world and it&#8217;s been awesome, exchanging ideas, cultural stuff, helping solve trivial stuff that we sometimes miss, the indie dev community is really neat.</p>
<p>I worked most of this year on web development which is good and sucks at both time, on one hand it keeps me closer and updated on where technology/trend is headed and that&#8217;s always good, on the other hand I never really liked it that much and further more, all stuff now circles around Facebook, which I think is pathetic, get your own website, don&#8217;t host your company page on Facebook, it should be an alternative not the real thing.</p>
<p>I got accepted to the 2011 <a href="https://codebits.eu/">Codebits</a> which was a blast, seriously, I&#8217;m definitely trying to go this the 2012 edition as well.</p>
<p>Rant: One note to the people closer to me, asking me every now and then how many copies we sold it&#8217;s annoying, I don&#8217;t ask you how much you earn on your job do I?</p>
<p><strong>Favorite games:</strong><br />
Portal 2<br />
Rage<br />
Bastion<br />
Terraria<br />
Frozen Synapse<br />
(a couple more probably which I don&#8217;t recall)</p>
<p><strong>Favorite movies:</strong><br />
Real Steel<br />
Super 8<br />
Rise of the Planet of the Apes<br />
Source Code<br />
Mission Impossible 4<br />
Fast and Furious 5</p>
<p><strong>Favorite shows:</strong><br />
Breaking Bad<br />
Castle<br />
The Walking Dead<br />
Chuck</p>
<p>So my hopes for the next year are to be able to release the current game in the oven, I&#8217;m really glad Rita accepted once again to make another one. Not only because of her art but because the way she see games, bringing a new perspective to things, also because, most artists/coders I know just want to do 3D games which I personally think can ruin things sometimes just by adding a third dimension. Just watch what happened to Sonic once it went 3d.</p>
<p>Happy new Year!!</p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/ehlzkJZN9vY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/01/post-mortem-of-another-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2012/01/post-mortem-of-another-year/</feedburner:origLink></item>
		<item>
		<title>Basalt code swarm</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/9FkYLJvZ_ao/</link>
		<comments>http://www.david-amador.com/2011/12/basalt-code-swarm/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 16:48:01 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[Basalt]]></category>
		<category><![CDATA[codeswarm]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1776</guid>
		<description><![CDATA[I discovered code swarm a while ago and decided to test on my own repositories. This is a test on Basalt, and although I&#8217;ve been working on the engine since January 2010, only in 2011 did I placed in on a repository so a bunch of stuff is added right on the beginning. This is [...]]]></description>
			<content:encoded><![CDATA[<p>I discovered <a href="http://code.google.com/p/codeswarm/">code swarm</a> a while ago and decided to test on my own repositories.</p>
<p>This is a test on Basalt, and although I&#8217;ve been working on the engine since January 2010, only in 2011 did I placed in on a repository so a bunch of stuff is added right on the beginning.</p>
<p>This is the result.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/sOpYY2PhIb4" frameborder="0" allowfullscreen></iframe></p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/9FkYLJvZ_ao" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2011/12/basalt-code-swarm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2011/12/basalt-code-swarm/</feedburner:origLink></item>
		<item>
		<title>Revert To The Old Tweetdeck</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/eAJCiBL72WI/</link>
		<comments>http://www.david-amador.com/2011/12/revert-to-the-old-tweetdeck/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 12:34:21 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Application & Software]]></category>
		<category><![CDATA[tweetdeck]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1768</guid>
		<description><![CDATA[If you use Tweetdeck you probably already know they screwed the new version (1.0) and you want to revert back. Unfortunately since they are now part of Twitter I had a hard time finding the older build and decided to share it. And that&#8217;s why you are here too probably, here it is: Tweetdeck 0.38.2, [...]]]></description>
			<content:encoded><![CDATA[<p>If you use Tweetdeck you probably already know they screwed the new version (1.0) and you want to revert back.</p>
<p>Unfortunately since they are now part of Twitter I had a hard time finding the older build and decided to share it.</p>
<p>And that&#8217;s why you are here too probably, here it is: <a href="http://www.oldversion.com/download-TweetDeck-0.38.2.html">Tweetdeck 0.38.2</a>, along with all other <a href="http://www.oldversion.com/TweetDeck.html">versions</a> are available at oldversion.com. Don&#8217;t forget you need <a href="http://www.adobe.com/products/air.html">Adobe Air</a> installed.</p>
<p><span style="color: #ff0000;">Edit 29-12-2011</span><br />
Some user have experienced a</p>
<blockquote><p>“This application cannot be installed because this installer has been mis-configured. Please contact the application author for assistance.”</p></blockquote>
<p>They solved it by uninstalling all previous versions of tweetdeck. Make sure you don&#8217;t have another one already installed.</p>
<p>&nbsp;</p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/eAJCiBL72WI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2011/12/revert-to-the-old-tweetdeck/feed/</wfw:commentRss>
		<slash:comments>152</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2011/12/revert-to-the-old-tweetdeck/</feedburner:origLink></item>
		<item>
		<title>november progress</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/vspsI_KT0sc/</link>
		<comments>http://www.david-amador.com/2011/12/november-progress/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 17:16:26 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1755</guid>
		<description><![CDATA[So as I mentioned a few weeks back, since November 1st I quit my job and I&#8217;ve been mainly focusing on our next game for Different Pixel. After a month, I think so far progress has been good. I&#8217;ve been able to work almost entirely on the game itself instead of the engine because most [...]]]></description>
			<content:encoded><![CDATA[<p>So as I mentioned a few weeks back, since November 1st I quit my job and I&#8217;ve been mainly focusing on our next game for Different Pixel.</p>
<p>After a month, I think so far progress has been good. I&#8217;ve been able to work almost entirely on the game itself instead of the engine because most of the stuff is stable enough since Vizati. </p>
<p>It&#8217;s kind of rewarding now and instead of reading tons of docs of other engines each time something doesn&#8217;t work right I usually know where the problem may be and can fix it, as good as I can at least.<br />
A few glitches here and there but so far so good. </p>
<p>I&#8217;ve managed to integrate GLSL to the engine after struggling a bit on the whole OpenGL extensions concept. Querying for extensions on the hardware/driver is a bit of obscure science, but it&#8217;s just a matter looking for them before using it.</p>
<p>Since GLSL isn&#8217;t part of OpenGL core before GL 2 if I end up placing any shaders, on older hardware (less than GL 2) I guess I&#8217;ll fallback to just fixed function. I&#8217;m still unsure about going &#8220;OpenGL 2 hardware required&#8221;, mainly because of integrated Intel cards. From what I could gather ATI supports it since the Radeon 9500 (2002), same time as DX9, so all ATI dx9 compatible should allow GL2 too. Nvidia since GeForce 6 Series (2004) I think,  Intel is a bit of a mystery to me.</p>
<p>I&#8217;ve also added a DirectX9 layer to the Render but it&#8217;s not finished, It&#8217;s just successfully creating the device in a window, still ignores everything the engine asks to draw. It might be a good idea in the future finishing it, if the target ends up being Windows it&#8217;s probably a better choice to use DX or maybe having an option in the game. </p>
<p>Oh, Git has been a life saver, seriously. Every dev should use it.</p>
<p>My artist has also been hard at work and so far I&#8217;m loving what&#8217;s done.</p>
<p>Until the next update.</p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/vspsI_KT0sc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2011/12/november-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2011/12/november-progress/</feedburner:origLink></item>
		<item>
		<title>Rage</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/xo-G06Aqpa0/</link>
		<comments>http://www.david-amador.com/2011/12/rage/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 16:47:43 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>
		<category><![CDATA[rage]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1718</guid>
		<description><![CDATA[So being a big fan of Quake, Quake 3 Arena and Doom I was eager to get my hands on id Software latest game, Rage. Like most developers out there I&#8217;ve been impressed by John Carmack&#8217;s work and breakthroughs in gaming and computer graphics for years. When I first heard Rage was targeting 60FPS I [...]]]></description>
			<content:encoded><![CDATA[<p>So being a big fan of Quake, Quake 3 Arena and Doom I was eager to get my hands on id Software latest game, Rage.</p>
<p>Like most developers out there I&#8217;ve been impressed by John Carmack&#8217;s work and breakthroughs in gaming and computer graphics for years. When I first heard Rage was targeting 60FPS I got intrigued.<br />
Almost every game targets 30FPS and targeting twice as that leaves <a href="http://www.david-amador.com/2011/08/hurry-you-only-have-16-ms-to-render-everything/" title="Hurry you only have 16 ms to render everything">less time to render each frame</a>, even more since they were promising vast wastelands, detailed characters, top notch animations and AI.</p>
<p>But enough of that. I got the PC version since I&#8217;m old fashioned and I think shooters are best played with Mouse/Kb. Besides that shooters are always a tad slower on consoles to compensate the lack of Mouse for aiming.</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2011/10/WP_000105.jpg" rel="shadowbox[sbpost-1718];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2011/10/WP_000105-300x225.jpg" alt="" title="WP_000105" width="300" height="225" class="alignnone size-medium wp-image-1731" /></a></p>
<p>The game comes packed on 3 DVD summing a 23GB install. </p>
<p>The story takes place after a meteor crashing into the earth, several arks where placed underground with people in order for mankind to survive. You are one of those survivors.<br />
There isn&#8217;t much more into, after you wake up you discovered most of the planet is a wasteland ruled by bandits, mutants and others.</p>
<p>From there you jump from mission to mission against the several factions. </p>
<p>Apart from some technical issues I first encountered, after updating the drivers I managed to play it smoothly on my laptop, my desktop rig is quite old now (6+ years) so it doesn&#8217;t quite handle it at 1080p.</p>
<p>I&#8217;m very impressed with the game&#8217;s smooth animations and enemy AI. The story itself is crap but the whole fun in this game is just playing it, the battles always feel fresh, holding the shotgun feels like an id gun indeed. You keep encountering new enemies with new tricks, near the end you are still trying to get the hang of that new enemy tactics.</p>
<p>If you have the chance try it.</p>

<a href='http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00001.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='2011-10-22_00001'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00001-150x150.jpg" class="attachment-thumbnail" alt="2011-10-22_00001" title="2011-10-22_00001" /></a>
<a href='http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00007.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='2011-10-22_00007'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00007-150x150.jpg" class="attachment-thumbnail" alt="2011-10-22_00007" title="2011-10-22_00007" /></a>
<a href='http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00010.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='2011-10-22_00010'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00010-150x150.jpg" class="attachment-thumbnail" alt="2011-10-22_00010" title="2011-10-22_00010" /></a>
<a href='http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00012.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='2011-10-22_00012'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00012-150x150.jpg" class="attachment-thumbnail" alt="2011-10-22_00012" title="2011-10-22_00012" /></a>
<a href='http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-23_00005.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='2011-10-23_00005'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-23_00005-150x150.jpg" class="attachment-thumbnail" alt="2011-10-23_00005" title="2011-10-23_00005" /></a>
<a href='http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-23_00008.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='2011-10-23_00008'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-23_00008-150x150.jpg" class="attachment-thumbnail" alt="2011-10-23_00008" title="2011-10-23_00008" /></a>
<a href='http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-23_00009.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='2011-10-23_00009'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-23_00009-150x150.jpg" class="attachment-thumbnail" alt="2011-10-23_00009" title="2011-10-23_00009" /></a>
<a href='http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-23_00010.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='2011-10-23_00010'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-23_00010-150x150.jpg" class="attachment-thumbnail" alt="2011-10-23_00010" title="2011-10-23_00010" /></a>
<a href='http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00015.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='2011-10-22_00015'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/2011-10-22_00015-150x150.jpg" class="attachment-thumbnail" alt="2011-10-22_00015" title="2011-10-22_00015" /></a>
<a href='http://www.david-amador.com/wp-content/uploads/2011/10/WP_000105.jpg' rel='shadowbox[sbalbum-1718];player=img;' title='WP_000105'><img width="150" height="150" src="http://www.david-amador.com/wp-content/uploads/2011/10/WP_000105-150x150.jpg" class="attachment-thumbnail" alt="WP_000105" title="WP_000105" /></a>

<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/xo-G06Aqpa0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2011/12/rage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2011/12/rage/</feedburner:origLink></item>
		<item>
		<title>something new in the horizon…</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/Ue63YB4oXUU/</link>
		<comments>http://www.david-amador.com/2011/10/something-new-in-the-horizon/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 09:06:14 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>
		<category><![CDATA[Game Development]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1713</guid>
		<description><![CDATA[So I&#8217;ve been out for quite some time, and this is just a quick update. First, I have tones of unread, thus answered emails on my inbox. I haven&#8217;t managed to go through that lately. I usually scroll to see if there&#8217;s a really urgent one, I will eventually read them all. I decided to [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been out for quite some time, and this is just a quick update.</p>
<p>First, I have tones of unread, thus answered emails on my inbox. I haven&#8217;t managed to go through that lately. I usually scroll to see if there&#8217;s a really urgent one,  I will eventually read them all.</p>
<p>I decided to quit my current job, my last day is October 31st. I couldn&#8217;t glimpse a very promising carrier there and I practically staggered learning-wise for the past months due to the type of work we develop so yeah, that&#8217;s it.</p>
<p>That also means that I&#8217;m taking some time to finish the current game in hands, yeahh.</p>
<p>I can&#8217;t talk about it but I&#8217;m quite excited with this. I expect to have some news about the game soon but mostly likely I won&#8217;t update the blog till then. I&#8217;ll probably keep ranting on <a href="http://www.twitter.com/DJ_Link">twitter</a> though =)</p>
<p>So starting November 1st I&#8217;ll be on my code cave @ Different Pixel.</p>
<p>Wish me luck&#8230;</p>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/Ue63YB4oXUU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2011/10/something-new-in-the-horizon/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2011/10/something-new-in-the-horizon/</feedburner:origLink></item>
		<item>
		<title>Hurry you only have 16 ms to render everything</title>
		<link>http://feedproxy.google.com/~r/DavidAmador/~3/AYmSgP6CwFY/</link>
		<comments>http://www.david-amador.com/2011/08/hurry-you-only-have-16-ms-to-render-everything/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 20:45:24 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[fps]]></category>
		<category><![CDATA[frametime]]></category>
		<category><![CDATA[optimizations]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1695</guid>
		<description><![CDATA[So I&#8217;ve been working on my new game and I&#8217;m doing some tweaks here and there on the engine. Mainly with the rendering section, trying to squeeze as much as possible, thus maintaining an acceptable framerate. It&#8217;s not like I&#8217;m doing a heavily graphic game but I like to know that It can be used [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been working on my new game and I&#8217;m doing some tweaks here and there on the engine. </p>
<p>Mainly with the rendering section, trying to squeeze as much as possible, thus maintaining an acceptable framerate. It&#8217;s not like I&#8217;m doing a heavily graphic game but I like to know that It can be used even on slower pcs and that I&#8217;m not using more cycles than necessary.</p>
<p>This past week and after reading a bunch of stuff and keynotes from John Carmack about Rage (60FPS ftw) I decided to measure my own stuff.</p>
<p>So let&#8217;s break this down, your framerate or FPS is the number of images you draw per second, not just that, you have to animate stuff, play sound, collisions, etc. </p>
<p>Most 3D games nowadays target 30 FPS, it&#8217;s the minimum acceptable before you start noticing slowdowns or not so smooth animations, for 2D games it&#8217;s a pretty realistic objective to target 60FPS.</p>
<p>Let say you want to target 30 FPS,</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">  <span style="color: #0000dd;">1</span> second <span style="color: #000080;">=</span> <span style="color: #0000dd;">1000</span> milliseconds
  <span style="color: #0000dd;">1000</span><span style="color: #000040;">/</span><span style="color: #0000dd;">30</span> <span style="color: #000080;">=</span> ~<span style="color:#800080;">33.3</span> milliseconds</pre></div></div>

<p>That means that for 30 FPS you have to calculate, animate, do collision and draw the scene in under 33.3 milliseconds. And do it again 30 more times.<br />
Sounds hard doesn&#8217;t it? </p>
<p>At 60 FPS it&#8217;s even worse</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">  <span style="color: #0000dd;">1000</span><span style="color: #000040;">/</span><span style="color: #0000dd;">60</span> <span style="color: #000080;">=</span> ~<span style="color:#800080;">16.6</span> milliseconds</pre></div></div>

<p><img style="border:none;" src="http://www.david-amador.com/wp-content/uploads/2011/08/SonicRunMediumAni.gif" alt="" title="SonicRunMediumAni" width="66" height="80" class="alignnone size-full wp-image-1703" /></p>
<p>16.6 milliseconds to do a full loop on your engine. Actually with modern technology it&#8217;s not an impressive accomplishment depending on what you are doing but it&#8217;s a good practice to<br />
look at these numbers, consider them while you code.</p>
<p>Now I&#8217;ve been making some tests on my own engine and I placed  2000 sprites each with a sprite animation and an A* pathfinding (2000 paths can be cached at a time) rendering at 100 FPS.<br />
It runs well and each loops takes 9ms.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">   <span style="color: #0000dd;">1000</span><span style="color: #000040;">/</span><span style="color: #0000dd;">100</span> <span style="color: #000080;">=</span> 10ms</pre></div></div>

<p>Each loop could take up to 10ms, so I&#8217;m wasting 1ms for each loop, bringing the sum up to 100ms per second.<br />
When I say waste it doesn&#8217;t mean you could be doing something else but you could make you game a bit more CPU friendly make making it sleep that extra millisecond each cycle.<br />
This will actually make you game use less of a processor and you can even check it on the Windows Task Manager.</p>
<p>At just 60 FPS, let&#8217;s say I&#8217;m drawing everything at 9ms too, but I could take up to 16.6</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">   <span style="color: #0000dd;">16</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">9</span> <span style="color: #000080;">=</span> 7ms
   <span style="color: #0000dd;">7</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">60</span> <span style="color: #008000;">&#40;</span>FPS<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> 420ms</pre></div></div>

<p>You can make your application sleep for almost half of a second and the game would run exactly the same<br />
Isn&#8217;t that something? </p>
<p>I&#8217;ve made a change on my pump to accommodate this and tested on Vizati, now most of the time it uses 12% of the CPU with bursts of 32%.<br />
Of course by measuring this you can also do cooler stuff like, let&#8217;s say you walk by a heavy area, or need to do some calculations, by lowering the intended FPS and drawing less times in that second you can get the other calculations done faster and return to a normal FPS much faster. </p>
<p>Well I hope this wasn&#8217;t too boring =)</p>
<blockquote><p>EDIT:<br />
After talking to some other devs there are mixed feelings about the benefits of putting your application to sleep those extra milliseconds. One thing that&#8217;s worth mentioning is that when you put your application to sleep you only guarantee that it will be idle for a minimum of let&#8217;s say 5ms, you may only regain control after 7ms, that&#8217;s really up to the OS.<br />
So my suggestion is, leave it as an option in the game, CPU throttling or something. Each user may test and see if it benefits, and in a couple of years it may in fact make some difference with to futuristic 30 core cpu where you don&#8217;t need to be using 100% of it. Starcraft 1 got a patch to do just that some time ago.
</p></blockquote>
<img src="http://feeds.feedburner.com/~r/DavidAmador/~4/AYmSgP6CwFY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2011/08/hurry-you-only-have-16-ms-to-render-everything/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.david-amador.com/2011/08/hurry-you-only-have-16-ms-to-render-everything/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.540 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-05-18 14:43:19 -->

