
<rss version="2.0">
  <channel>
    <title>Vahid Kazemi's Blog</title>
    <link>http://www.gameprogrammer.org/main.php?page=blog</link>
    <description>Read about my programming experiences and more!</description>
    <language>en-us</language>
    <pubDate>Sat, 12 May 2007 00:00:00 GMT</pubDate>
    <lastBuildDate>Thu, 15 May 2008 09:45:24 GMT</lastBuildDate>
    <managingEditor>vkazemi[@]gmail.com</managingEditor>
    <webMaster>vkazemi[@]gmail.com</webMaster>	  	
    <item>
		<title>QoP Team</title>
		<link>http://www.gameprogrammer.org/main.php?page=blog</link>
		<description>Here's a photo of &quot;Quest of Persia: Lotfali Khan Zand&quot; development team standing near Lotfali Khan's grave. From left to right Hamid Abdollahi(Animator), me Vahid Kazemi (Programmer), Roozbeh Edjbari (Level Designer), Puya Dadgar (Project Manager).

&lt;p&gt;&lt;img class='x3dimg' src=&quot;images/qopdev.jpg&quot;&gt;</description>
		<pubDate>Mon, 05 May 2008 00:00:00</pubDate>
		<guid>http://www.gameprogrammer.org/comments.php?msg=94</guid>
    </item>

		
    <item>
		<title>Twitter</title>
		<link>http://www.gameprogrammer.org/main.php?page=blog</link>
		<description>Join me on twitter!
&lt;p&gt;
&lt;div id=&quot;twitter_div&quot;&gt;
&lt;h2 class=&quot;twitter-title&quot;&gt;Twitter Updates&lt;/h2&gt;
&lt;ul id=&quot;twitter_update_list&quot;&gt;&lt;/ul&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://twitter.com/javascripts/blogger.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://twitter.com/statuses/user_timeline/vkazemi.json?callback=twitterCallback2&amp;count=3&quot;&gt;&lt;/script&gt;
</description>
		<pubDate>Fri, 02 May 2008 00:00:00</pubDate>
		<guid>http://www.gameprogrammer.org/comments.php?msg=93</guid>
    </item>

		
    <item>
		<title>Flash Tetris</title>
		<link>http://www.gameprogrammer.org/main.php?page=blog</link>
		<description>Recently I started to learn a little bit of flash programming! Actually it's really fun, for the start I've created a 3D Tetris game but may be soon I create a flash section in GameProgrammer.org to put some more of my flash works.

&lt;p&gt;Use [Arrow Keys] and [Space] to play!

&lt;p&gt;
&lt;INPUT type=&quot;button&quot; value=&quot;Play!&quot; onClick=&quot;window.open('flash/Tetrix.html','mywindow','width=440,height=440,left=0,top=100,screenX=0,screenY=100')&quot;&gt; 
</description>
		<pubDate>Sat, 09 Feb 2008 00:00:00</pubDate>
		<guid>http://www.gameprogrammer.org/comments.php?msg=91</guid>
    </item>

		
    <item>
		<title>Quest of Persia</title>
		<link>http://www.gameprogrammer.org/main.php?page=blog</link>
		<description>&lt;p&gt;Here's an screen shot of Quest of Persia: Lotfali Khan Zand, which I'm currently working on as the Lead Programmer. Checkout &lt;a class='x3dmainlink' href=&quot;http://www.questofpersia.com/lotfali/index.html&quot;&gt;Quest of Persia's website&lt;/a&gt; for more!

&lt;p align=&quot;center&quot;&gt;&lt;img class='x3dimg' src=&quot;images/qop4.jpg&quot;&gt;&lt;/p&gt;
</description>
		<pubDate>Fri, 06 Jul 2007 00:00:00</pubDate>
		<guid>http://www.gameprogrammer.org/comments.php?msg=88</guid>
    </item>

		
    <item>
		<title>It's all about performance!</title>
		<link>http://www.gameprogrammer.org/main.php?page=blog</link>
		<description>&lt;p&gt;Writing an effective code is one of the most important and challenging responsibilities of a game programmer.

&lt;p&gt;High-level programming languages like C++ hide a lot of things from a programmer
that you can hardly guess what exactly will be your compiled code. A simple call to a function in C++
could be dozens of lines of machine code, but you don't need to care because your computer can process
billions of lines of machine code in a second, but when it comes to video game programming everything
change, and that's because you have limited time and a lot of obejcts to process.

&lt;p&gt;A simple optimization technique that I wanna talk about here is about memory allocation and deallocation of 
fixed multi-dimensional arrays. Here is a simple code to allocate and free a two dimensional array:

&lt;p&gt;&lt;table class='x3dcode'&gt;&lt;tr&gt;&lt;td&gt;// allocate&lt;BR&gt;T **data = new T*[sizeX];&lt;BR&gt;for(int i=0;i&amp;lt;sizeX;i++){&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data[i]=new T[sizeY]&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;// free&lt;BR&gt;for(int i=0;i&amp;lt;sizeX;i++){&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete [] data[i]&lt;BR&gt;}&lt;BR&gt;delete [] data;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;

&lt;p&gt;But if your array is fixed and you don't plan to change it's size then it's not the most efficient way to do it.
consider you want to allocate a 100*10 array, to allocate and free this amount of memory you should call new and 
delete operators 101 times and that takes a lot of cpu time, but with a little change to your code you can optimize
it so that one call to new and delete does all the job. Here is my implementation:

&lt;p&gt;&lt;table class='x3dcode'&gt;&lt;tr&gt;&lt;td&gt;class FixedArray&lt;BR&gt;{&lt;BR&gt;public:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;template&amp;lt;class T&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;static T **New(int sizeX, int sizeY)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int sizeAddress = sizeof(T*)*sizeX;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int sizeData = sizeof(T)*sizeX*sizeY;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;char *data = new char[sizeAddress+sizeData];&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(int i=0;i&amp;lt;sizeX;i++){&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;((T**)data)[i] = &amp;((T*)(data+sizeAddress))[i*sizeY];&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;memset(data+sizeAddress, 0, sizeData);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return (T **)data;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;static void Delete(void *p)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete [] p;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;};&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;</description>
		<pubDate>Fri, 27 Apr 2007 00:00:00</pubDate>
		<guid>http://www.gameprogrammer.org/comments.php?msg=85</guid>
    </item>

		
    <item>
		<title>Unsized array</title>
		<link>http://www.gameprogrammer.org/main.php?page=blog</link>
		<description>&lt;p&gt;Last night when I was coding some parts of my current game project I found out about a Visual C++ extension which allows you to define an unsized array in the end of an structure.

&lt;p&gt;
&lt;p&gt;&lt;table class='x3dcode'&gt;&lt;tr&gt;&lt;td&gt;struct KT&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int Keyframes;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Matrix4f Transform[];&lt;BR&gt;};&lt;BR&gt;&lt;BR&gt;KT *data = static_cast&amp;lt;KT *&amp;gt;(file-&amp;gt;GetData());&lt;BR&gt;&lt;BR&gt;for(int i=0;i&amp;lt;data-&amp;gt;Keyframes;i++)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Matrix4f &amp;m = data-&amp;gt;Transform[i];&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;BR&gt;}&lt;BR&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;

&lt;p&gt;It's nice but in my case something like Matrix4f Transform[1] could work as well, and may be It doesn't worth the portability issues, but I found some interesting uses of the extension in MSDN, like:

&lt;p&gt;&lt;table class='x3dcode'&gt;&lt;tr&gt;&lt;td&gt;struct PERSON {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;unsigned number;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;char name[];   // Unsized array&lt;BR&gt;};&lt;BR&gt;&lt;BR&gt;struct PERSON me  = { 6, &quot;Me&quot; };        // Legal&lt;BR&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/p&gt;

But you must be careful when using an unsized array, because the size of such an array won't be counted on the size of the container structure.</description>
		<pubDate>Sun, 22 Apr 2007 00:00:00</pubDate>
		<guid>http://www.gameprogrammer.org/comments.php?msg=83</guid>
    </item>

		
    <item>
		<title>Welcome!</title>
		<link>http://www.gameprogrammer.org/main.php?page=blog</link>
		<description>&lt;img class='x3dimg' align=right src=&quot;images/vahid.brm.jpg&quot;&gt;

&lt;p&gt;Welcome to my blog!

&lt;p&gt;Finally I decided to start my blog here, I try to write a little bit about what I'm doing, and may be you can find some beta versions of my codes and articles in here.

&lt;p&gt;I didn't have enough time to code the blog so if you want to post a comment you need to wait until I code the comment system. Actually I was in the middle of playing God of War II, and I managed to beat it last night! It was hell of a game, my brain just blew off specially at the ending. You won't find such a different and amazing gameplays on any other game, I can undoubtedly tell you that It is the best game ever on PS2 or may be just ever! If they just keep up the good work then may be God of War 3 become the best game of PS3 however we can't expect it in near future considering how long it took them to create previous episodes.

&lt;p&gt;By the way if you have any question, suggestion or comment or may be a virus you want to share with me, send it by email to vkazemi [at] gmail [dot] com.

&lt;p&gt;

&lt;a class='x3dmainlink' href=&quot;http://www.linkedin.com/in/vahidkazemi&quot; &gt;&lt;img class='x3dimg' src=&quot;http://www.linkedin.com/img/webpromo/btn_liprofile_blue_80x15.gif&quot; width=&quot;80&quot; height=&quot;15&quot; border=&quot;0&quot; alt=&quot;View Vahid Kazemi's profile on LinkedIn&quot;&gt;&lt;/a&gt;</description>
		<pubDate>Sat, 21 Apr 2007 00:00:00</pubDate>
		<guid>http://www.gameprogrammer.org/comments.php?msg=81</guid>
    </item>

	
</rss>


