<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>Minalien.com</title>
	<atom:link href="http://www.minalien.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.minalien.com</link>
	<description>The Internet is Watching You.</description>
	<lastBuildDate>Sat, 20 Feb 2010 20:41:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/us/</creativeCommons:license>		<item>
		<title>Torque Game Builder/Box2D Integration</title>
		<link>http://www.minalien.com/index.php/2010/02/20/torque-game-builderbox2d-integration/</link>
		<comments>http://www.minalien.com/index.php/2010/02/20/torque-game-builderbox2d-integration/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 20:41:39 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.minalien.com/?p=132</guid>
		<description><![CDATA[I&#8217;ve been looking at Box2D a lot recently, mostly because Torque 2D (Torque Game Builder&#8217;s replacement) is going to be using it. It&#8217;s a damn good, and powerful, two-dimensional physics engine -- it&#8217;s what powered Crayon Physics, and several similar physics-oriented games. Box2D is a pretty beautiful thing, from what I&#8217;ve looked at, and it&#8217;s <a href="http://www.minalien.com/index.php/2010/02/20/torque-game-builderbox2d-integration/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_133" class="wp-caption alignright" style="width: 310px"><a href="http://www.minalien.com/index.php/2010/02/20/torque-game-builderbox2d-integration/box2d-editor/" rel="attachment wp-att-133"><img src="http://www.minalien.com/wp-content/uploads/2010/02/box2d-editor-300x174.png" alt="Box2D TGB" title="Box2D scene setup in the Torque Game Builder GUI" width="300" height="174" class="size-medium wp-image-133" /></a><p class="wp-caption-text">This Box2D implementation is perfectly integrated into the Torque Game Builder GUI.</p></div>I&#8217;ve been looking at Box2D a lot recently, mostly because Torque 2D (Torque Game Builder&#8217;s replacement) is going to be using it. It&#8217;s a damn good, and powerful, two-dimensional physics engine -- it&#8217;s what powered Crayon Physics, and several similar physics-oriented games. Box2D is a pretty beautiful thing, from what I&#8217;ve looked at, and it&#8217;s been ported to a lot of systems. Recently, I found a Torque Game Builder integration for it, and figured I&#8217;d look into it. Currently, it&#8217;s integrated into the Torque Game Builder editor, and still allows for the use of the standard TGB physics (you cannot have both Box2D and TGB physics on the same object, however). The system comes in the form of a class that needs to be set on the Scene itself, and behaviors that you add to objects. The system uses the object&#8217;s convex collision polygon, as well.</p>
<p><strong>Video</strong><br />
<!-- Smart Youtube --><span class="youtube"><object type="application/x-shockwave-flash" width="480" height="360" data="http://www.youtube.com/v/pgPT93m8yDg&amp;rel=1&amp;color1=3a3a3a&amp;color2=999999&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0&amp;ap=%2526fmt%3D22"><param name="movie" value="http://www.youtube.com/v/pgPT93m8yDg&amp;rel=1&amp;color1=3a3a3a&amp;color2=999999&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0&amp;ap=%2526fmt%3D22" /><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent" /></object></span></p>
<p><strong>Screenshots of the Pyramid Test</strong><br />
<a href="http://www.minalien.com/index.php/2010/02/20/torque-game-builderbox2d-integration/box2d-test1/" rel="attachment wp-att-134">Stacked Pyramid</a><br />
<a href="http://www.minalien.com/index.php/2010/02/20/torque-game-builderbox2d-integration/box2d-test2/" rel="attachment wp-att-135">Tumbling Pyramid</a></p>
<p><strong>TGB/Box2D Integration Links</strong><br />
<a href="http://www.torquepowered.com/products/torque-2d" target="_blank">Torque Game Builder 1.7.4</a><br />
<a href="http://code.google.com/p/tgb-box2d-integration/" target="_blank">Box2D implementation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minalien.com/index.php/2010/02/20/torque-game-builderbox2d-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aliens vs Predator</title>
		<link>http://www.minalien.com/index.php/2010/02/18/aliens-vs-predator/</link>
		<comments>http://www.minalien.com/index.php/2010/02/18/aliens-vs-predator/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 17:34:44 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.minalien.com/?p=96</guid>
		<description><![CDATA[Well, Aliens vs Predator was finally released two days ago, and I hadn&#8217;t noticed. Started downloading it the night it was released, rather than the day. Anyway, started playing it last night, and this morning, and I&#8217;m loving the game. The demo wasn&#8217;t all that great, I&#8217;ll admit, but that&#8217;s mostly because Free-For-All in the <a href="http://www.minalien.com/index.php/2010/02/18/aliens-vs-predator/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_97" class="wp-caption alignright" style="width: 310px"><a href="http://www.minalien.com/index.php/2010/02/18/aliens-vs-predator/aliens-vs-predator-ps3-xbox-360-screenshot/" rel="attachment wp-att-97"><img src="http://www.minalien.com/wp-content/uploads/2010/02/aliens-vs-predator-ps3-xbox-360-screenshot-300x166.jpg" alt="Humans are so totally fucked in this game." title="AvP Console Screenshot" width="300" height="166" class="size-medium wp-image-97" /></a><p class="wp-caption-text">Humans are so totally fucked in this game.</p></div>Well, Aliens vs Predator was finally released two days ago, and I hadn&#8217;t noticed. Started downloading it the <strong>night</strong> it was released, rather than the day. Anyway, started playing it last night, and this morning, and I&#8217;m loving the game. The demo wasn&#8217;t all that great, I&#8217;ll admit, but that&#8217;s mostly because Free-For-All in the AVP setting is pointless. To really enjoy the game, you need a Team Free-For-All, with each team being one of the three races in-game (Xenomorph, Predator, or Human). Although I have to say, playing as a Human/Marine in the multi-player game modes is very masochistic. Think about it &#8211; as a human, you lack the badassery of the Predators, which includes vision modes specifically designed to help hunt humans and Xenomorphs (believe me, in the dark multi-player levels, Xenomorphs are hard as fuck to spot, harder yet to kill, and don&#8217;t even think about catching one if they decide to sprint away), you lack the cloaking, so you&#8217;re easy as hell to spot, no matter where you are (again, the Predators can spot all humans with one visor mode, and the Xenomorphs (aliens, for anybody who hasn&#8217;t figured that out yet) can track you by &#8220;scent&#8221; &#8211; which, in gameplay terms, is an outline showing where you are. Unlike the Predator&#8217;s visors, though, Xenomorphs can see you even through walls), and if you aren&#8217;t with a group of friends &#8211; well, count yourself among the dead. Because that&#8217;s really the only opportune time to kill either of the opposing races &#8211; if they start to take out one of your buddies.</p>
<p>Playing as the Xenomorphs, in multi-player especially, but single-player as well, can get disorienting fast. You see, Xenomorphs can run on walls, and can jump from one wall to another. And they&#8217;re fucking <strong>fast</strong>. If I, as a Xenomorph, get injured and need a quick escape, I hold my sprint key and just fucking <strong>run.</strong> There&#8217;s no way that either a Predator or a Human will be able to catch up to me &#8211; especially if I&#8217;m switching between walls, ceilings, and floor, and jumping from surface to surface. But, as I said, this has the disadvantage of being severely disorienting, however incredibly bad-ass it may be.</p>
<p>Playing as the Predators is amazingly fun, especially in the multi-player games. While you <strong>can</strong> be seen by humans when your cloak is engaged, they&#8217;re usually twitchy as hell and won&#8217;t spot you well in the shadows. Xenomorphs still have their scent-tracking thing, and will spot you just as well as they&#8217;d spot a human, but you&#8217;ve got auto-tracking, shoulder-mounted badassery in the form of a laser gun that is fast enough to track them, provided they don&#8217;t jump behind a wall or into a vent. You&#8217;ve also got proximity mines, and a few other useful tools, and no player will be too happy when, out of nowhere, in spite of their vigilance, they&#8217;re blasted from behind by a laser cannon from a creature they can barely play. But hey, if they&#8217;re masochistic enough to play as humans in multi-player, that&#8217;s their own damn fault. Who wants to play a pathetic human when you can play incredibly-advanced alien hunters (I guess that human&#8217;s <strong>aren&#8217;t</strong> the toughest prey anymore) or incredibly-deadly alien beasts, anyway?</p>
<p>In short, if you have the chance to buy it, whether it&#8217;s for PC (where I play), XBOX 360, or some other platform, I highly recommend it. If you do get it on PC, don&#8217;t be a puss &#8211; buy it over Steam, not at a store, and hit me up for a game.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.minalien.com/index.php/2010/02/18/aliens-vs-predator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Need to stop being lazy.</title>
		<link>http://www.minalien.com/index.php/2010/02/16/need-to-stop-being-lazy/</link>
		<comments>http://www.minalien.com/index.php/2010/02/16/need-to-stop-being-lazy/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 21:18:49 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.minalien.com/?p=94</guid>
		<description><![CDATA[Well, I&#8217;ve come to the conclusion that I need to stop being lazy and get some work done on the OS X port of Waxy&#8217;s Sushi Party. So, for the next couple of nights, I am going to start working my ass off to get an early prototype ready.
This means a lot of playing the <a href="http://www.minalien.com/index.php/2010/02/16/need-to-stop-being-lazy/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Well, I&#8217;ve come to the conclusion that I need to stop being lazy and get some work done on the OS X port of Waxy&#8217;s Sushi Party. So, for the next couple of nights, I am going to start working my ass off to get an early prototype ready.</p>
<p>This means a lot of playing the game, taking notes, and fucking around with Torque Game Builder for me, and nightly development blog entries for the whole.. two or three of you who read my blog. Yeah, so, enjoy. >.></p>
]]></content:encoded>
			<wfw:commentRss>http://www.minalien.com/index.php/2010/02/16/need-to-stop-being-lazy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++/D3D Pong Tutorial 02: Setting up Direct3D and our Engine Framework</title>
		<link>http://www.minalien.com/index.php/2010/02/15/pong-series-02/</link>
		<comments>http://www.minalien.com/index.php/2010/02/15/pong-series-02/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 20:16:28 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Pong (C++/DirectX)]]></category>
		<category><![CDATA[Series]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.minalien.com/?p=68</guid>
		<description><![CDATA[Tutorial Description
In the last tutorial, we set up the basics required for the Windows API to open our window. While basic, the task was also essential, though many people who are familiar with Win32 Programming will likely have gained nothing from it. Here, we are going to do several tasks. In no particular order, they <a href="http://www.minalien.com/index.php/2010/02/15/pong-series-02/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p><strong>Tutorial Description</strong><br />
In the last tutorial, we set up the basics required for the Windows API to open our window. While basic, the task was also essential, though many people who are familiar with Win32 Programming will likely have gained nothing from it. Here, we are going to do several tasks. In no particular order, they are as follows:<br />
1) Set up Direct3D rendering<br />
2) Set up the framework for our game engine<br />
3) Implementing game timing</p>
<p><strong>Downloads</strong><br />
<a href="http://files.minalien.com/D3DPong/02/D3DPong-Bin.rar">Binary Only (10.4KB)</a><br />
<a href="http://files.minalien.com/D3DPong/02/D3DPong.rar">Full VS2010 Project Dir (13.1MB)</a></p>
<p><strong>Starting Words</strong><br />
<em>Notice: This tutorial continues from where the &#8220;<a href="http://www.minalien.com/index.php/2010/01/24/pong-series-01/">C++/D3D Pong Tutorial 01</a>&#8221; article left off. Please read it if you have not already.</em></p>
<p><span id="more-68"></span></p>
<p><strong>Libraries</strong><br />
You will need to add the following three libraries to your project:<br />
d3d9.lib<br />
d3dx9.lib<br />
dxguid.lib</p>
<p><strong>Code Listing 1: CGameTimer.h</strong></p>
<pre class="brush: cpp;">#pragma once

// Global Headers
#include &lt;time.h&gt;
#include &lt;Windows.h&gt;

namespace D3DPong
{
	class CGameTimer
	{
	private:
		// Marks the starting point of the timer
		DWORD _start;

	public:
		/** Constructor &amp; Destructor **/
		CGameTimer(void);

		/** Function Declarations **/
		DWORD GetTime(void);		// Retrieve the current time (in milliseconds)
		DWORD GetStartTime(void);	// Get the Timer's start time (in milliseconds)
		DWORD GetRunTime(void);		// Get the Timer's running time (in millseconds)
		void Reset(void);			// Reset the timer.
	};
};</pre>
<p>This small bit of code will mark the base of our game timing system. This system will make it possible to use delta timing, so that we do not have to cap the frame limit by using unnecessary processing. You will see how this works when we start setting up the rendering engine, but for now, allow me to give you an explanation of the class.</p>
<pre class="brush: cpp;">	private:
		// Marks the starting point of the timer
		DWORD _start;</pre>
<p>The game timer&#8217;s only variable, this DWORD value will store the start time, in milliseconds, for when the timer started (its creation or a call to reset()).</p>
<pre class="brush: cpp;">		/** Function Declarations **/
		DWORD GetTime(void);		// Retrieve the current time (in milliseconds)
		DWORD GetStartTime(void);	// Get the Timer's start time (in milliseconds)
		DWORD GetRunTime(void);		// Get the Timer's running time (in millseconds)
		void Reset(void);			// Reset the timer.</pre>
<p>Constructor declarations aren&#8217;t anything special, so I won&#8217;t bother going into detail about that. These four functions, however, are very important to the engine.</p>
<p><strong>GetTime()</strong> will give us an easier method of getting the system time, in milliseconds. It takes away some of our reliance on the Windows API.<br />
<strong>GetStartTime()</strong> will allow us to retrieve the time that the Timer was last started or reset.<br />
<strong>GetRunTime()</strong> will give us the running time of our timer object. This will be vital when we implement Delta timing.<br />
<strong>Reset()</strong> will reset the timer&#8217;s &#8220;start time.&#8221; This will allow us to more easily handle timed events, if a timer doesn&#8217;t need to continually run.</p>
<p><strong>Code Listing 2: CGameTimer.cpp</strong></p>
<pre class="brush: cpp;">#include &quot;CGameTimer.h&quot;

namespace D3DPong
{
	CGameTimer::CGameTimer(void)
	{
		this-&gt;_start = timeGetTime();
	}

	DWORD CGameTimer::GetTime(void)
	{
		return timeGetTime();
	}

	DWORD CGameTimer::GetStartTime(void)
	{
		return this-&gt;_start;
	}

	DWORD CGameTimer::GetRunTime(void)
	{
		return (timeGetTime() - this-&gt;_start);
	}

	void CGameTimer::Reset(void)
	{
		this-&gt;_start = this-&gt;GetTime();
	}
};</pre>
<p>And here we are, the flesh and bones of the game timer class. All of these are single-line functions, but this will make a large portion of our engine&#8217;s logic. Most of it should be pretty obvious, if you read the descriptions above.</p>
<p><b>Creating our Entry Point</b><br />
Before we get into the nitty-gritty portions of creating our engine framework and setting up Direct3D, I&#8217;m going to do two things. First, I&#8217;m going to show you where we are going to set up and handle our game logic, which will be separate from our Engine code. After that, I am going to give you a brief roadmap before jumping into the large bits of code that will make up our game engine.</p>
<p><b>Code Listing 3: Game.h</b></p>
<pre class="brush: cpp;">#pragma once

#include &lt;windows.h&gt;

extern bool GamePreLoad(void);
extern bool GameInit(void);
extern void GameUpdate(float);
extern void GameRender(float);
extern void GameEnd(void);</pre>
<p>These functions, when fleshed out, will contain all of our game&#8217;s logic.<br />
<i>GamePreLoad()</i> &#8211; Within this method, we will do some initial setup (such as setting up the game window dimensions)<br />
<i>GameInit()</i> &#8211; And here, we will load our initial game resources and set up initial logic settings.<br />
<i>GameUpdate(delta)</i> &#8211; This function will be called every frame, and will contain our game logic. The floating-point value that it is passed is the timing delta (the time between the last frame and this one). We will use this timing delta<br />
<i>GameRender(delta)</i> &#8211; This function will also be called every frame, and will always be called <em>after</em> GameUpdate. Our rendering logic will be executed here.<br />
<i>GameEnd()</i> &#8211; This will be called to execute last-minute cleanup for the game.</p>
<p><strong>Code Listing 4: Game.cpp</strong></p>
<pre class="brush: cpp;">#include &quot;Game.h&quot;

bool GamePreLoad(void)
{
	return true;
}

bool GameInit(void)
{
	return true;
}

void GameUpdate(float delta)
{
}

void GameRender(float delta)
{
}

void GameEnd(void)
{
}</pre>
<p>This is just the empty framework for now. All of our game logic, when we begin work on it in future tutorials, will go here. We&#8217;ll modify this at the end of this tutorial to do some basic setup in the PreLoad function.</p>
<p><strong>What Lies Ahead</strong><br />
Alright, we&#8217;ve got some fun work ahead of us. First, we are going to be setting up the game engine&#8217;s code. That will be a pretty decent-sized trek through the woods, but I&#8217;m going to try to cover it as thoroughly as I can without stepping into a discussion about the various pieces of clockwork that aren&#8217;t entirely necessary.</p>
<p><strong>Code Listing 5: CGameEngine.h</strong></p>
<pre class="brush: cpp;">#pragma once

// Global Header Files
#include &lt;Windows.h&gt;
#include &lt;d3d9.h&gt;
#include &lt;d3dx9.h&gt;

// Local Header Files
#include &quot;CGameTimer.h&quot;
#include &quot;Game.h&quot;

namespace D3DPong
{
	class CGameEngine
	{
	private:
		CGameEngine(void);						// ctor
		CGameEngine(CGameEngine const&amp;) { };	// copy ctor
		virtual ~CGameEngine(void);				// dtor

		static CGameEngine* _instance;

		HWND	_windowHandle;

		LPDIRECT3D9			_d3d;
		LPDIRECT3DDEVICE9	_device;
		LPD3DXSPRITE 		_spriteHandler;

		LPCWSTR	_windowTitle;
		int		_screenWidth, _screenHeight, _colorDepth;

		const static D3DCOLOR _ambientColor;

		CGameTimer*	_gameTimer;
		bool		_gameRunning;

	public:
		static CGameEngine* Instance(void) { return _instance; }

		bool Init(int, int, int);
		void End(void);
		void Update(void);
		void BeginRender(void);
		void EndRender(void);

		LPDIRECT3DDEVICE9 GetDevice(void) { return this-&gt;_device; }
		LPD3DXSPRITE GetSpriteHandler(void) { return this-&gt;_spriteHandler; }
		HWND GetWindowHandle(void) { return this-&gt;_windowHandle; }
		LPCWSTR GetWindowTitle(void) { return this-&gt;_windowTitle; }
		int GetScreenWidth(void) { return this-&gt;_screenWidth; }
		int GetScreenHeight(void) { return this-&gt;_screenHeight; }
		int GetColorDepth(void) { return this-&gt;_colorDepth; }
		bool GetGameRunning(void) { return this-&gt;_gameRunning; }
		CGameTimer* GetGameTimer(void) { return this-&gt;_gameTimer; }

		void SetWindowHandle(HWND val) { this-&gt;_windowHandle = val; }
		void SetWindowTitle(LPCWSTR);
		void SetScreenWidth(int val) { this-&gt;_screenWidth = val; }
		void SetScreenHeight(int val) { this-&gt;_screenHeight = val; }
		void SetColorDepth(int val) { this-&gt;_colorDepth = val; }
	};
};</pre>
<p>Aaaannnd here we go. Time for the explanations. I&#8217;ll leave out the accessor &#038; mutators, as those should be second nature to anybody who has been able to follow along thus far.</p>
<pre class="brush: cpp;">		CGameEngine(void);						// ctor
		CGameEngine(CGameEngine const&amp;) { };	// copy ctor
		virtual ~CGameEngine(void);				// dtor

		static CGameEngine* _instance;</pre>
<p>Here, we have the constructor, copy constructor, and destructor. These are all defined in the private section because we only want to allow them to be initialized when the engine instance (which is a <a href="http://en.wikipedia.org/wiki/Singleton_pattern" target="_blank">singleton</a>) is first defined (in CGameEngine.cpp). The copy constructor is left empty (it wont be used at all), and the destructor is made virtual in case we decide to create a class that inherits from it at a later point (which is unlikely, but the option will still be available). Lastly, we create a static pointer that will serve as the singleton. We will be able to access the game engine at any time by calling CGameEngine::Instance().</p>
<pre class="brush: cpp;">		HWND	_windowHandle;

		LPDIRECT3D9			_d3d;
		LPDIRECT3DDEVICE9	_device;
		LPD3DXSPRITE 		_spriteHandler;

		LPCWSTR	_windowTitle;
		int		_screenWidth, _screenHeight, _colorDepth;

		const static D3DCOLOR _ambientColor;

		CGameTimer*	_gameTimer;
		bool		_gameRunning;</pre>
<p>Most of the member variables are self-explanatory. The engine will need an instance of the game window&#8217;s handle for some of the Direct3D setup, as well as for other tasks, such as changing the window&#8217;s title. The three Direct3D variables are the Direct3D instance, which gives us access to a lot of the device creation features, the Direct3D device itself, which will handle our game&#8217;s rendering backbone, and then the D3DX sprite handler, which will allow us to do 2D rendering without going through the trouble of creating and texturing 3D quads, which anybody with experience doing that method of 2D will tell you is a royal pain in the ass. Finally, we create variables to store our window&#8217;s attributes (title, screen size, color depth), a static variable to store our ambient color (which will not change throughout the game), a boolean to keep track of whether or not the game is running (which will be important when we start modifying our game loop), and a game timer, which we will use to track the time between frames in the game.</p>
<pre class="brush: cpp; toolbar: false;">		CGameEngine* Instance(void) { return _instance; }</pre>
<p>Again, back to our Singleton implementation. Although this is simply an accessor, I wanted to point it out because of its importance to our singleton implementaiton.</p>
<pre class="brush: cpp;">		bool Init(int, int, int);
		void End(void);
		void Update(void);
		void BeginRender(void);
		void EndRender(void);</pre>
<p>And these methods make up the meat of our game engine.<br />
<em>Init(width, height, depth)</em> &#8211; This method will initialize the Direct3D systems, and will configure our render settings.<br />
<em>End()</em> &#8211; This is called to end the game.<br />
<em>Update()</em> &#8211; This method is called every frame, will calculate the timing delta and call our GameUpdate() and GameRender() methods.<br />
<em>BeginRender()</em> &#8211; Basic rendering setup (starting the D3D device, starting the sprite handler, etc)<br />
<em>EndRender()</em> &#8211; The inverse of our BeginRender function &#8211; this method ends the rendering systems started in BeginRender, then presents the scene (swaps the render buffers)</p>
<pre class="brush: cpp; toolbar: false;">void SetWindowTitle(LPCWSTR);</pre>
<p>You may have noticed this lonely mutator sitting here, undefined. Fight your urge to follow the other mutators on this one &#8211; we&#8217;re going to be defining this one in CGameEngine.cpp, so that if we would decide to change our window title in-game, we can, and doing so requires a touch more than changing the value of _windowTitle.</p>
<p>And here we go, the meat of our game engine.</p>
<p><strong>Code Listing 6: CGameEngine.cpp</strong></p>
<pre class="brush: cpp;">#include &quot;CGameEngine.h&quot;
#include &quot;WinMain.h&quot;

namespace D3DPong
{
	const D3DCOLOR CGameEngine::_ambientColor = D3DCOLOR_RGBA(255, 255, 255, 0);
	CGameEngine* CGameEngine::_instance = new CGameEngine();

	CGameEngine::CGameEngine(void)
		: _windowHandle(NULL), _windowTitle(L&quot;D3DPong&quot;),
		_screenWidth(640), _screenHeight(480), _colorDepth(32),
		_gameRunning(false),
	{
	}

	CGameEngine::~CGameEngine(void)
	{
		if(this-&gt;_gameRunning)
			this-&gt;_gameRunning = false;

		if(this-&gt;_spriteHandler)
			this-&gt;_spriteHandler-&gt;Release();

		if(this-&gt;_device)
			this-&gt;_device-&gt;Release();

		if(this-&gt;_d3d)
			this-&gt;_d3d-&gt;Release();

		delete this-&gt;_spriteHandler;
		delete this-&gt;_device;
		delete this-&gt;_d3d;
	}

	bool CGameEngine::Init(int width, int height, int depth)
	{
		// Set up Engine Vars
		this-&gt;_screenWidth = width;
		this-&gt;_screenHeight = height;
		this-&gt;_colorDepth = depth;
		// Initialize Direct3D
		this-&gt;_d3d = Direct3DCreate9(D3D_SDK_VERSION);
		if(!this-&gt;_d3d)
			return false;

		// Get the Display Mode (to ensure maximum compatibility)
		D3DDISPLAYMODE disp;
		this-&gt;_d3d-&gt;GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &amp;disp);

		// Presentation Parameters
		D3DPRESENT_PARAMETERS d3dpp;
		ZeroMemory(&amp;d3dpp, sizeof(D3DPRESENT_PARAMETERS));
		d3dpp.Windowed = true;
		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		d3dpp.EnableAutoDepthStencil = true;
		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
		d3dpp.BackBufferFormat = disp.Format;
		d3dpp.BackBufferWidth = this-&gt;_screenWidth;
		d3dpp.BackBufferHeight = this-&gt;_screenHeight;
		d3dpp.hDeviceWindow = this-&gt;_windowHandle;

		// Create the Direct3D Device
		this-&gt;_d3d-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, this-&gt;_windowHandle, D3DCREATE_HARDWARE_VERTEXPROCESSING, &amp;d3dpp, &amp;this-&gt;_device);

		if(!this-&gt;_device)
			return false;

		// Enable Z-buffering, set the fill mode, and set the ambient color (white)
		this-&gt;_device-&gt;SetRenderState(D3DRS_ZENABLE, true);
		this-&gt;_device-&gt;SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
		this-&gt;_device-&gt;SetRenderState(D3DRS_AMBIENT, this-&gt;_ambientColor);

		// Initialize the Sprite handler
		if(FAILED(D3DXCreateSprite(this-&gt;_device, &amp;this-&gt;_spriteHandler)))
			return false;

		// Game Initialization
		if(!GameInit())
			return false;

		return true;
	}

	void CGameEngine::End(void)
	{
		this-&gt;_gameRunning = false;
		GameEnd();
	}

	void CGameEngine::Update(void)
	{
		static float lastFrame = 0.0f;

		float delta = ((float)((int)this-&gt;_gameTimer-&gt;GetTime())) - lastFrame;
		lastFrame = ((float)((int)this-&gt;_gameTimer-&gt;GetTime()));

		GameUpdate(delta);

		this-&gt;BeginRender();

		GameRender(delta);

		this-&gt;EndRender();
	}

	void CGameEngine::BeginRender(void)
	{
		if(!this-&gt;_device)
			return;

		if(FAILED(this-&gt;_device-&gt;BeginScene()))
			return;

		if(FAILED(this-&gt;_spriteHandler-&gt;Begin(D3DXSPRITE_ALPHABLEND)))
			return;
	}

	void CGameEngine::EndRender(void)
	{
		if(!this-&gt;_device)
			return;

		this-&gt;_spriteHandler-&gt;End();

		if(FAILED(this-&gt;_device-&gt;EndScene()))
			return;

		if(FAILED(this-&gt;_device-&gt;Present(NULL, NULL, NULL, NULL)))
			return;
	}

	void CGameEngine::SetWindowTitle(LPCWSTR val)
	{
		this-&gt;_windowTitle = val;

		if(this-&gt;_windowHandle)
			SetWindowText(this-&gt;_windowHandle, this-&gt;_windowTitle);
	}
};</pre>
<p>Ready? Here we go.</p>
<pre class="brush: cpp;">	const D3DCOLOR CGameEngine::_ambientColor = D3DCOLOR_RGBA(255, 255, 255, 0);
	CGameEngine* CGameEngine::_instance = new CGameEngine();</pre>
<p>Here, we are creating and defining the singleton instance, and setting up the ambient color constant. Pretty simple.</p>
<pre class="brush: cpp;">	CGameEngine::CGameEngine(void)
		: _windowHandle(NULL), _windowTitle(L&quot;D3DPong&quot;),
		_screenWidth(640), _screenHeight(480), _colorDepth(32)
		_gameRunning(false),
	{
	}</pre>
<p>Technically, this is an empty constructor, but we&#8217;re using a shorthand method of setting default values for some of our class&#8217;s member variables.</p>
<pre class="brush: cpp;">	CGameEngine::~CGameEngine(void)
	{
		if(this-&gt;_gameRunning)
			this-&gt;_gameRunning = false;

		if(this-&gt;_spriteHandler)
			this-&gt;_spriteHandler-&gt;Release();

		if(this-&gt;_device)
			this-&gt;_device-&gt;Release();

		if(this-&gt;_d3d)
			this-&gt;_d3d-&gt;Release();

		delete this-&gt;_spriteHandler;
		delete this-&gt;_device;
		delete this-&gt;_d3d;
	}</pre>
<p>A standard cleanup within the Game Engine&#8217;s destructor. First, we have to release all of the DirectX devices, to ensure that none of them are currently being used, and so that they can do their internal cleanup. Finally, we delete the pointers, as a final cleanup. Because this will mark the end of the application, this wouldn&#8217;t cause any sort of memory leak, but I&#8217;d prefer not to rely on the operating system to clean up our leftovers.</p>
<pre class="brush: cpp;">	bool CGameEngine::Init(int width, int height, int depth)
	{
		// Set up Engine Vars
		this-&gt;_screenWidth = width;
		this-&gt;_screenHeight = height;
		this-&gt;_colorDepth = depth;
		// Initialize Direct3D
		this-&gt;_d3d = Direct3DCreate9(D3D_SDK_VERSION);
		if(!this-&gt;_d3d)
			return false;

		// Get the Display Mode (to ensure maximum compatibility)
		D3DDISPLAYMODE disp;
		this-&gt;_d3d-&gt;GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &amp;disp);</pre>
<p>Onto the Initialization. This one&#8217;s a big one. First, we&#8217;re just setting our member variables, so that we can keep track of our size and depth changes. Initializing Direct3D itself is easy and straightforward &#8211; you just call Direct3DCreate9 to create a Direct3D 9 manager, and pass the SDK version (Always pass it as D3D_SDK_VERSION, to ensure that the engine is compatible with future Direct3D releases).</p>
<p>Finally, we get the display mode of the desktop. This will be used when we are setting the Direct3D Presentation Parameters, which define hour our rendering is handled with the graphics card. While we could stick with a generic D3DFMT_R5G6B5, which will work almost universally, this will ensure that the display format used is compatible with the current video card and monitor.</p>
<pre class="brush: cpp;">		// Presentation Parameters
		D3DPRESENT_PARAMETERS d3dpp;
		ZeroMemory(&amp;d3dpp, sizeof(D3DPRESENT_PARAMETERS));
		d3dpp.Windowed = true;
		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		d3dpp.EnableAutoDepthStencil = true;
		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
		d3dpp.BackBufferFormat = disp.Format;
		d3dpp.BackBufferWidth = this-&gt;_screenWidth;
		d3dpp.BackBufferHeight = this-&gt;_screenHeight;
		d3dpp.hDeviceWindow = this-&gt;_windowHandle;</pre>
<p>The presentation parameters are incredibly important to Direct3D. It tells the system how large to make the back buffer (we&#8217;re using our screen dimensions), what to do when it swaps the buffers (discards the currently-rendering, then displays the new buffer), and sets the window handle that is used.</p>
<pre class="brush: cpp;">		// Create the Direct3D Device
		this-&gt;_d3d-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, this-&gt;_windowHandle, D3DCREATE_HARDWARE_VERTEXPROCESSING, &amp;d3dpp, &amp;this-&gt;_device);

		if(!this-&gt;_device)
			return false;

		// Enable Z-buffering, set the fill mode, and set the ambient color (white)
		this-&gt;_device-&gt;SetRenderState(D3DRS_ZENABLE, true);
		this-&gt;_device-&gt;SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
		this-&gt;_device-&gt;SetRenderState(D3DRS_AMBIENT, this-&gt;_ambientColor);</pre>
<p>Now we&#8217;re creating the Direct3D rendering device. We are configuring it as follows:<br />
1) It will use the default adapter (the primary monitor/video card), everything will be handled on the hardware level (graphics card) for rendering, rather than software rendering (basically, use the GPU instead of the CPU), and we pass the presentation parameters and the address to map the newly created device to. Finally, we set three render states: Z-buffering, Solid fill mode, and ambient color. These settings will enhance our graphics quality, and give us some fun tools to use in later games. (Have you noticed, yet, that the engine is something that can easily be re-used in later projects?)</p>
<pre class="brush: cpp;">		// Initialize the Sprite handler
		if(FAILED(D3DXCreateSprite(this-&gt;_device, &amp;this-&gt;_spriteHandler)))
			return false;

		// Game Initialization
		if(!GameInit())
			return false;</pre>
<p>Getting back to more simple-to-comprehend steps. Here, we&#8217;re ensuring that we are able to create our sprite handler (which will make our two-dimensional rendering a lot easier to implement), and calling the game&#8217;s initialization method, so that it can handle game setup. And we&#8217;re done.</p>
<pre class="brush: cpp;">	void CGameEngine::End(void)
	{
		this-&gt;_gameRunning = false;
		GameEnd();
	}</pre>
<p>This method will allow us to end the game. First, it changes the &#8220;running&#8221; flag, which will tell our engine to jump out of the loop, and then it calls the GameEnd method, allowing us to do some last-minute cleanup before the engine itself closes out.</p>
<pre class="brush: cpp;">	void CGameEngine::Update(void)
	{
		static float lastFrame = 0.0f;

		float delta = ((float)((int)this-&gt;_gameTimer-&gt;GetTime())) - lastFrame;
		lastFrame = ((float)((int)this-&gt;_gameTimer-&gt;GetTime()));

		GameUpdate(delta);

		this-&gt;BeginRender();

		GameRender(delta);

		this-&gt;EndRender();
	}</pre>
<p>Another important one. The first thing we do is declare a static floating-point value, to store the time (in millseconds) of our last frame. We then calculate the delta (the time between calls to the Update() method) by subtracting the time the last frame started from the current game time. After calculating the delta, it changes frameTime to reflect the start of <em>this</em> frame. After that, we give a call to our GameUpdate method, passing the timing delta, start rendering, call GameRender, and then end rendering. In case you were wondering, the delta passed to GameRender is for animation purposes &#8211; the rendering method is the best place to put frame calculations for animations, in my opinion.</p>
<pre class="brush: cpp;">	void CGameEngine::BeginRender(void)
	{
		if(!this-&gt;_device)
			return;

		if(FAILED(this-&gt;_device-&gt;BeginScene()))
			return;

		if(FAILED(this-&gt;_spriteHandler-&gt;Begin(D3DXSPRITE_ALPHABLEND)))
			return;
	}</pre>
<p>Here, we start rendering. First of all, if our device isn&#8217;t active, we&#8217;re going to crash if we try to call any methods on it, so we do a check to make sure it exists. Then, we begin the Direct3D scene, and begin 2D rendering within the sprite handler. By passing the D3DXSPRITE_ALPHABLEND parameter to the sprite handler, we ensure that alpha values will be honored by the rendering system, making transparency an easy task to deal with &#8211; it&#8217;s the artist&#8217;s problem now. Transparent PNGs are the best thing to use for two-dimensional game art, at the moment (excluding, of course, custom, optimized file formats created for an engine).</p>
<pre class="brush: cpp;">	void CGameEngine::EndRender(void)
	{
		if(!this-&gt;_device)
			return;

		this-&gt;_spriteHandler-&gt;End();

		if(FAILED(this-&gt;_device-&gt;EndScene()))
			return;

		if(FAILED(this-&gt;_device-&gt;Present(NULL, NULL, NULL, NULL)))
			return;
	}</pre>
<p>Now, we&#8217;re doing the opposite. We still need to make sure our device exists before we stop rendering, but beyond that, we stop the systems in the order they were presented. The last method, Present, swaps the display buffers, and is required if we want our rendering to actually appear.</p>
<pre class="brush: cpp;">	void CGameEngine::SetWindowTitle(LPCWSTR val)
	{
		this-&gt;_windowTitle = val;

		if(this-&gt;_windowHandle)
			SetWindowText(this-&gt;_windowHandle, this-&gt;_windowTitle);
	}</pre>
<p>Do you remember how I said our SetWindowTitle was a special mutator? Here it is. We could just stick with setting our _windowTitle member variable, but that would make this function useful only in the GamePreLoad method, which is called before the game window is created. This method, however, allows us to find out if the window has been created already. If it has, it updates the title there, as well, allowing for us to, for example, display the game score in the window&#8217;s title (not recommended, and I will not be showing you how to do so.)</p>
<p><strong>Moving on</strong><br />
Well, we&#8217;ve got our engine laid out, and it&#8217;s something that we&#8217;ll be able to use in future projects as well as this one &#8211; we&#8217;ll just need to change the contents of our game functions (GamePreLoad, GameInit, etc), though we might want to replace the namespace (D3DPong) with another at a later date. Now that we&#8217;ve got the hard part out of the way, we are going to make changes to the WinMain.cpp file that we created in the last tutorial, so that we can call our GamePreLoad function and actually make use of the game engine. You just got done with a lot of code, so I won&#8217;t hold it against you if you go take a breather, get some soda, or play a game for a while.</p>
<p><strong>Code Change Set 1: WinMain.cpp</strong><br />
All of these changes will be to the WinMain.cpp file.</p>
<p>For starters, scroll to the top of the file, and include CGameEngine.cpp after including WinMain.h</p>
<pre class="brush: cpp; toolbar: false;">#include &quot;WinMain.h&quot;
#include &quot;CGameEngine.h&quot;</pre>
<p>Remove g_bGameOver variable declaration. We&#8217;re going to be using our game engine&#8217;s GetGameRunning accessor in its place. Don&#8217;t worry about replacing it anywhere in code yet, we&#8217;ll do that on our way through.</p>
<p>We&#8217;re going to add a preprocessor directive to create an alias for CGameEngine::Instance(), to make it easier to access our game engine. Add the following after the two include directives:</p>
<pre class="brush: cpp; toolbar: false;">#define GEInstance D3DPong::CGameEngine::Instance()

using namespace D3DPong;</pre>
<p>This will allow us an easier method of getting our game engine&#8217;s instance (make sure you don&#8217;t add a semicolon to that preprocessor macro &#8211; if you do, we can&#8217;t use GEInstance->method. We are then telling our engine that this source file will be using the D3DPong namespace, so that we don&#8217;t have to prefix all of our engine features with <i>D3DPong::</i>.</p>
<p>Now, search for:</p>
<pre class="brush: cpp;">	case WM_QUIT:
	case WM_CLOSE:
	case WM_DESTROY:{
		g_bGameOver = true;
					} break;</pre>
<p>and replace it with:</p>
<pre class="brush: cpp;">	case WM_QUIT:
	case WM_CLOSE:
	case WM_DESTROY:{
		GEInstance-&gt;End();
					} break;</pre>
<p>Makes things easier, doesn&#8217;t it? It also ensures that our GameEnd function is called when we end the game.</p>
<p>Remove the initialization of g_bGameOver from our WinMain function.</p>
<pre class="brush: cpp; toolbar: false;">	// Setup Globals
	g_bGameOver = false;</pre>
<p>We want to allow our game the chance to set up the window and do some other system initialization before we set everything up, so add a call to GamePreLoad() where the g_bGameOver global used to be defined.</p>
<pre class="brush: cpp;">	WNDCLASSEX wc;	// Window Class Structure

	if(!GamePreLoad())
		return 0;

	// Fill the structure</pre>
<p>Now, we want to update our CreateWindowEx call to use the engine&#8217;s width and height, which will be set in GamePreLoad() (or left to their default 640&#215;480 values, if not set):<br />
Replace the entire call with:</p>
<pre class="brush: cpp;">	// Create the Program Window
	hWnd = CreateWindowEx(NULL,										// dwExStyle
		L&quot;GameWindow&quot;,												// Class Name - must match the lpszClassname of a registered window class
		GEInstance-&gt;GetWindowTitle(),								// Window Title
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,	// dwStyle
		0, 0,														// Screen Coordinates (X, Y)
		GEInstance-&gt;GetScreenWidth(), GEInstance-&gt;GetScreenHeight(),// Screen Size (Width, Height)
		NULL,														// Parent Window
		NULL,														// Menu
		hInstance,													// Instance Handle
		NULL);														// Extra Parameters</pre>
<p>Below that, after we Show and Update the window, we wil make a call to the game engine&#8217;s Init function:</p>
<pre class="brush: cpp;">	// Initialize the Game Engine
	GEInstance-&gt;SetWindowHandle(hWnd);
	if(!GEInstance-&gt;Init(GEInstance-&gt;GetScreenWidth(), GEInstance-&gt;GetScreenHeight(), GEInstance-&gt;GetColorDepth()))
		return 0;</pre>
<p>We pass the width, height, and color depth to the init function. It was designed this way, again, to allow later classes to inherit from the current engine. A note, for anybody who would do that: you&#8217;ll need to go into CGameEngine.cpp and change <i>CGameEngine* CGameEngine::_instance = new CGameEngine();</i> to <i>CGameEngine* CGameEngine::_instance = new NewClassName();</i>. The singleton method that I used for this project is somewhat rough, and certainly isn&#8217;t the best method, but it&#8217;s one of the easiest to understand for new developers.</p>
<p>Finally, we update our application&#8217;s loop:</p>
<pre class="brush: cpp;">// Message Loop
	while(GEInstance-&gt;GetGameRunning())
	{
		while(PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&amp;msg);
			DispatchMessage(&amp;msg);
		}

		GEInstance-&gt;Update();
	}</pre>
<p>Build, run, and see if it comes up with a black screen for you.</p>
<p><strong>Game Setup Test</strong><br />
Now we&#8217;re going to do a quick, easy test to make sure we can properly configure our game at startup (in GamePreLoad). Open Game.cpp, and change GamePreLoad to the following:</p>
<pre class="brush: cpp;">bool GamePreLoad(void)
{
	D3DPong::CGameEngine::Instance()-&gt;SetScreenWidth(800);
	D3DPong::CGameEngine::Instance()-&gt;SetScreenHeight(600);
	D3DPong::CGameEngine::Instance()-&gt;SetWindowTitle(L&quot;Direct3D Pong Tutorial 02&quot;);

	return true;
}</pre>
<p><em>Note: I recommend creating the same Macro we defined in WinMain.cpp, so that you can shorten calls as GEInstance.</em></p>
<p>Run it, and you should have an 800&#215;600 window, titled &#8220;Direct3D Pong Tutorial 02&#8243;.</p>
<p><strong>Conclusion</strong><br />
That concludes the second tutorial in the D3D Pong series. Stay tuned for the next tutorial series, where we create a class to handle and render game sprites and scene objects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.minalien.com/index.php/2010/02/15/pong-series-02/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What did I just do?</title>
		<link>http://www.minalien.com/index.php/2010/02/04/what-did-i-just-do/</link>
		<comments>http://www.minalien.com/index.php/2010/02/04/what-did-i-just-do/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 20:24:26 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.minalien.com/?p=66</guid>
		<description><![CDATA[Well, I&#8217;m not entirely sure why, but for some reason I seem to have thought that it would be an okay idea to buy a Mac. What is wrong with me, I honestly don&#8217;t know, but I can say that it&#8217;s a pretty solid system. And I like the fact that the iMac only has <a href="http://www.minalien.com/index.php/2010/02/04/what-did-i-just-do/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_109" class="wp-caption alignleft" style="width: 310px"><a href="http://www.minalien.com/?attachment_id=109"><img src="http://www.minalien.com/wp-content/uploads/2010/02/Mac_SS1-300x168.png" alt="Screenshot of my iMac" title="iMac Screenshot" width="300" height="168" class="size-medium wp-image-109" /></a><p class="wp-caption-text">Making my terminal insult Justin.</p></div>Well, I&#8217;m not entirely sure why, but for some reason I seem to have thought that it would be an okay idea to buy a Mac. What is wrong with me, I honestly don&#8217;t know, but I can say that it&#8217;s a pretty solid system. And I like the fact that the iMac only has a single cable &#8211; the power cable &#8211; while everything else (system, monitor, etc) is either built-in or (in the case of the keyboard &#038; mouse) running through Bluetooth.</p>
<p>At least now I can start working on the native builds of my Mac-based projects (Waxy&#8217;s Sushi Party among them).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.minalien.com/index.php/2010/02/04/what-did-i-just-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++/D3D Pong Tutorial 01: Setting up the Project</title>
		<link>http://www.minalien.com/index.php/2010/01/24/pong-series-01/</link>
		<comments>http://www.minalien.com/index.php/2010/01/24/pong-series-01/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 01:51:19 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Pong (C++/DirectX)]]></category>
		<category><![CDATA[Series]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.minalien.com/?p=55</guid>
		<description><![CDATA[Alright, the time has come for me to start up my tutorials again. Suppose I&#8217;ll start off with creating a Pong clone using C++ and Direct3D 9 (the game will be in two dimensions, though, for this product. Perhaps a 3D Pong tutorial can come later.)
Welcome to the D3D Pong Tutorial Series
Throughout this tutorial series, <a href="http://www.minalien.com/index.php/2010/01/24/pong-series-01/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Alright, the time has come for me to start up my tutorials again. Suppose I&#8217;ll start off with creating a Pong clone using C++ and Direct3D 9 (the game will be in two dimensions, though, for this product. Perhaps a 3D Pong tutorial can come later.)</p>
<p><strong>Welcome to the D3D Pong Tutorial Series</strong><br />
Throughout this tutorial series, we will be developing a two-dimensional Pong clone using C++ and Direct3D 9. The tutorial assumes basic knowledge of the C++ language, as well as basic familiarity with namespaces, pointers, and the Microsoft Visual Studio IDE.</p>
<p><strong>System Requirements</strong><br />
This tutorial series assumes that the following are true:<br />
1) You have the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=B66E14B8-8505-4B17-BF80-EDB2DF5ABAD4&#038;displaylang=en">DirectX SDK</a> installed and configured on your system.<br />
2) You know how to configure your IDE to use the header files and libraries included within the DirectX SDK<br />
3) You know how to set up a new Win32 project (vice the use of a console project) in your IDE<br />
4) You know how to add static libraries to a project within your IDE</p>
<p><strong>Tutorial Description</strong><br />
This tutorial covers the first part of the D3D Pong project. We will create a Windows Application project, add the appropriate libraries, and will create the game/application window. In the next tutorial, we will cover setting up Direct3D, and will lay out the framework for the game engine.</p>
<p><span id="more-55"></span></p>
<p><strong>Starting Words</strong><br />
In this tutorial series, I&#8217;m not going to give instructions to any particular IDE. I personally use Visual Studio 2010 B2 right now, and will at least be assuming the use of Visual Studio as far as some code samples go. If your particular compiler toolchain doesn&#8217;t support the </p>
<pre class="brush: cpp; toolbar: false;">#pragma once</pre>
<p>directive, simply replace any instances of that with the following:</p>
<pre class="brush: cpp; toolbar: false;">#ifndef _FILENAME_H_
#define _FILENAME_H_</pre>
<p>and put a</p>
<pre class="brush: cpp; toolbar: false;">#endif</pre>
<p>at the end of your file. This should be habit for most C++ developers, but I&#8217;m including this notice for the people who aren&#8217;t as familiar as the rest of us.</p>
<p><strong>Project Setup</strong><br />
Go ahead and create a new Win32 Project within your IDE. Make sure that you are creating an empty Windows Application project, without MFC or any other fancy ties.</p>
<p>At this point in the project, we&#8217;re only going to add a single library to the project: winmm.lib.</p>
<p><strong>Code Listing 1: WinMain.h</strong></p>
<pre class="brush: cpp;">#pragma once

// Trim the size of Windows.h
#define WIN32_LEAN_AND_MEAN

// Global Header Files
#include &lt;Windows.h&gt;

// Function Declarations
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);</pre>
<p>This header should look standard to anybody with any Win32 API experience. Defining WIN32_LEAN_AND_MEAN strips a lot of the contents of Windows.h that we&#8217;ll never need, which will shorten the build time for the project. After bringing in the Windows header, we declare the two primary functions of any Windows application: WinMain and WinProc. Onto the big one..</p>
<p><strong>Code Listing 2: WinMain.cpp</strong></p>
<pre class="brush: cpp;">#include &quot;WinMain.h&quot;

// Global Variables
bool g_bGameOver;</pre>
<p>We start by including the WinMain.h header file that we created from the first code block, then define a global boolean variable called g_bGameOver. This variable will actually later be <em>declared</em> in our engine&#8217;s main header as an external variable, so that the rest of the game code can access it, but we are going to have the declaration done within WinMain.cpp.</p>
<pre class="brush: cpp;">// Window Callback
LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
		// Called when the game window is closed
	case WM_QUIT:
	case WM_CLOSE:
	case WM_DESTROY:{
		g_bGameOver = true;
					} break;
	}

	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}</pre>
<p>This is our Window procedure, which handles all events on the game window. We are only worried about three events, which all relate to the same thing: the user exited the game. Through this method, we can perform any last-minute computations before we actually exit the application.</p>
<pre class="brush: cpp;">// Application Entry Point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
	// Local Variables
	MSG msg;		// Message Structure
	HWND hWnd;		// Window Handle
	WNDCLASSEX wc;	// Window Class Structure

	// Setup Globals
	g_bGameOver = false;</pre>
<p>Moving onto the Application&#8217;s entry point, we declare three variables in the local scope to hold our messages, our window handle, and the window structure itself, then assign a value of <em>false</em> to the g_bGameOver global.</p>
<pre class="brush: cpp;">
	// Fill the structure
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WinProc;
	wc.cbClsExtra = NULL;
	wc.cbWndExtra = NULL;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = NULL;
	wc.lpszMenuName = NULL;
	wc.lpszClassName = L&quot;GameWindow&quot;;
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	// Register the structure
	RegisterClassEx(&amp;wc);</pre>
<p>Standard Win32 structure filling. The things of note here are the assigning of a window icon, a cursor, a Small Icon, and most importantly, the window&#8217;s class name. The class name is important because it is what we will use to tell CreateWindowEx what it will use as window class when creating the application window.</p>
<pre class="brush: cpp;">
	// Create the Program Window
	hWnd = CreateWindowEx(NULL,										// dwExStyle
		L&quot;GameWindow&quot;,												// Class Name - must match the lpszClassname of a registered window class
		L&quot;D3D Pong Tutorial&quot;,										// Window Title
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,	// dwStyle
		0, 0,														// Screen Coordinates (X, Y)
		640, 480,													// Screen Size (Width, Height)
		NULL,														// Parent Window
		NULL,														// Menu
		hInstance,													// Instance Handle
		NULL);														// Extra Parameters

	// Ensure that there were no creation errors
	if(!hWnd)
	{
		MessageBox(NULL, L&quot;Error Creating Application Window&quot;, L&quot;Fatal Error&quot;, MB_OK | MB_ICONERROR);
		return 0;
	}</pre>
<p>Standard window creation code. Always make sure that you test pivotal objects and ensure that they were actually created before attempting to use them. If our window isn&#8217;t created, we can&#8217;t do anything at all. Note that, like in the class definition, we are putting an L in front of the strings &#8211; this casts native strings into the LPCWSTR type, which will ensure that it is formatted as intended for the window.</p>
<pre class="brush: cpp;">
	// Display the window
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);

	// Message Loop
	while(!g_bGameOver)
	{
		while(PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&amp;msg);
			DispatchMessage(&amp;msg);
		}
	}

	// Exit
	return 0;
}</pre>
<p>Finally, we show the window, do an initial Update call, and begin listening for messages. While this tutorial wasn&#8217;t much, especially for anybody experienced with the Win32 API, it provides us a firm ground on which we can start the rest of the tutorials in the series.</p>
<p><strong>Code Listing 3: WinMain.cpp (Full Listing)</strong><br />
Just for reference, here is the complete WinMain.cpp file:</p>
<pre class="brush: cpp;">#include &quot;WinMain.h&quot;

// Global Variables
bool g_bGameOver;

// Window Callback
LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
		// Called when the game window is closed
	case WM_QUIT:
	case WM_CLOSE:
	case WM_DESTROY:{
		g_bGameOver = true;
					} break;
	}

	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

// Application Entry Point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
	// Local Variables
	MSG msg;		// Message Structure
	HWND hWnd;		// Window Handle
	WNDCLASSEX wc;	// Window Class Structure

	// Setup Globals
	g_bGameOver = false;

	// Fill the structure
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WinProc;
	wc.cbClsExtra = NULL;
	wc.cbWndExtra = NULL;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = NULL;
	wc.lpszMenuName = NULL;
	wc.lpszClassName = L&quot;GameWindow&quot;;
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	// Register the structure
	RegisterClassEx(&amp;wc);

	// Create the Program Window
	hWnd = CreateWindowEx(NULL,										// dwExStyle
		L&quot;GameWindow&quot;,												// Class Name - must match the lpszClassname of a registered window class
		L&quot;D3D Pong Tutorial&quot;,										// Window Title
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,	// dwStyle
		0, 0,														// Screen Coordinates (X, Y)
		640, 480,													// Screen Size (Width, Height)
		NULL,														// Parent Window
		NULL,														// Menu
		hInstance,													// Instance Handle
		NULL);														// Extra Parameters

	// Ensure that there were no creation errors
	if(!hWnd)
	{
		MessageBox(NULL, L&quot;Error Creating Application Window&quot;, L&quot;Fatal Error&quot;, MB_OK | MB_ICONERROR);
		return 0;
	}

	// Display the window
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);

	// Message Loop
	while(!g_bGameOver)
	{
		while(PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&amp;msg);
			DispatchMessage(&amp;msg);
		}
	}

	// Exit
	return 0;
}</pre>
<p>The remaining tutorials in this series will be set up as a series of code blocks, vice this single, full-listing, except under certain circumstances. I included the full code listing for this because it doesn&#8217;t require a lot of explanation for people who are at least passingly familiar with the Win32 API.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.minalien.com/index.php/2010/01/24/pong-series-01/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Update</title>
		<link>http://www.minalien.com/index.php/2010/01/23/an-update/</link>
		<comments>http://www.minalien.com/index.php/2010/01/23/an-update/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 21:55:00 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Waxy's Sushi Party]]></category>
		<category><![CDATA[Drama]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.minalien.com/?p=53</guid>
		<description><![CDATA[So, I know nobody reads my blog, but whatever. Yeah, I&#8217;m posting in defiance. Take that, everybody who doesn&#8217;t read this! That will show you. Yeah.
Anyway, a lot of drama going on with the management of Simple Machines Forums, which is a shame because it&#8217;s such a great piece of software. You can read about <a href="http://www.minalien.com/index.php/2010/01/23/an-update/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>So, I know nobody reads my blog, but whatever. Yeah, I&#8217;m posting in defiance. Take that, everybody who doesn&#8217;t read this! That will show you. Yeah.</p>
<p>Anyway, a lot of drama going on with the management of Simple Machines Forums, which is a shame because it&#8217;s such a great piece of software. <a href="http://www.smf-friends.org/index.php?topic=267.0">You can read about it here</a>. I won&#8217;t be surprised when things just go to hell and the people who want to stick with SMF&#8217;s original values end up creating a new branch of SMF that does follow their visions. But I guess this is a good enough reason to start looking at other bulletin board systems. Seems to be a lot of this type of drama going on in the internet world these days &#8211; once-strong communities that lose favor of their long-standing members and being taken over by a single entity that was once thought to be a valuable member of the community. Here&#8217;s looking at you, ZFGC &#8211; you know who I&#8217;m talking about.</p>
<p>Still have a lot to do recently, between picking up the work on SevenIRC (which hasn&#8217;t progressed at all since the last post, to be honest), upping the work on PkGame (I&#8217;ve been doing a lot of design work here), and now the port for Waxy&#8217;s Sushi Party. Anybody who wants to see the game can go <a href="http://www.wearehive.com/index.php?&#038;page_id=sushi_index">here</a> and check it out. I&#8217;m currently building the Mac OS X port for the game, and doing some prototyping and working with HiVE to come up with design considerations for the XBOX 360 port (planned to be published through XBOX Live! Indie Games, so keep your eyes peeled if you&#8217;re interested). Unfortunately, I only have a Windows computer, so anybody with a Mac computer that is willing to do some beta testing at a later date, don&#8217;t hesitate to get hold of me. The engine I&#8217;m using (Torque Game Builder) for the Mac prot is cross-platform, so there may (pending discussions with HiVE) possibly be a new Windows build, as well.</p>
<p>Still doing some planning for several game development tutorials, hopefully I&#8217;ll get around to starting them soon. Played the demo for Brutal Legend, and I&#8217;m sold. I&#8217;m buying it next weekend, after I get paid, along with Mass Effect 2 PC.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.minalien.com/index.php/2010/01/23/an-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>All Set</title>
		<link>http://www.minalien.com/index.php/2009/12/29/all-set/</link>
		<comments>http://www.minalien.com/index.php/2009/12/29/all-set/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 03:44:55 +0000</pubDate>
		<dc:creator>Ken</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.minalien.com/?p=12</guid>
		<description><![CDATA[Alright, so, got WordPress set up (again), got my GeSHi and OpenID plugins installed, got things set up to try to block spammy comments, and, most importantly, I found a pretty interesting theme for the blog. Now I just need to work on the TorqueScript language file for the GeSHi plugin (CodeColorer, specifically) and make <a href="http://www.minalien.com/index.php/2009/12/29/all-set/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Alright, so, got WordPress set up (again), got my GeSHi and OpenID plugins installed, got things set up to try to block spammy comments, and, most importantly, I found a pretty interesting theme for the blog. Now I just need to work on the TorqueScript language file for the GeSHi plugin (CodeColorer, specifically) and make sure my Gravatar is working properly, and everything should be green for me to start writing up some development tutorials.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.minalien.com/index.php/2009/12/29/all-set/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
