<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title> &#187; The code of VGS</title>
	<atom:link href="http://blog.vortixgames.com/category/the-code-of-vgs/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.vortixgames.com</link>
	<description></description>
	<lastBuildDate>Sun, 05 Feb 2012 00:55:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Performance vs Error Checking</title>
		<link>http://blog.vortixgames.com/performance-vs-error-checking</link>
		<comments>http://blog.vortixgames.com/performance-vs-error-checking#comments</comments>
		<pubDate>Sun, 05 Feb 2012 00:55:11 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[Dev Journal: Danger Zone]]></category>
		<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Danger Zone]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=1104</guid>
		<description><![CDATA[Hi everyone, Vlad here! Seems like on a thing versus some other thing rampage with Application Design vs Game Design shortly followed by this post. I guess that&#8217;s a good thing, it means there are challenges and doubts and that we need to research. This post is also inspired by some books I&#8217;ve been reading lately and [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone, Vlad here!</p>
<p>Seems like on a thing versus some other thing rampage with <a href="http://blog.vortixgames.com/application-design-vs-game-design-round-1">Application Design vs Game Design</a> shortly followed by this post. I guess that&#8217;s a good thing, it means there are challenges and doubts and that we need to research.</p>
<p>This post is also inspired by some books I&#8217;ve been reading lately and that I highly recommend: <a href="http://shop.oreilly.com/product/9780596519544.do">The Productive Programmer</a> that was influenced by <a href="http://pragprog.com/the-pragmatic-programmer">The Pragmatic Programmer</a>.</p>
<h2>Problem #1</h2>
<p>We are writing code and there&#8217;s not such thing as writing code without bugs. Sometimes our oldest, most used code, that code that we trust each of our games with gets into a specific spot where a hidden bug appears and we spend hours and hours figuring out what&#8217;s happening.</p>
<h2>Solution #1 is Problem #2</h2>
<p>There are several solutions to this. Writing code that includes testing is in my opinion the best. The problem with this, game development wise and specifically in scripted languages such as AS3, is that this makes the code much slower. The solution was checking for inconsistencies and not performing operations instead of throwing errors and exceptions.</p>
<p>I ended up creating conditions for use. For instance our blit package uses three different types: the core, the object and the texture. The core keeps the state of the whole system, the object keeps the state of what and where to render and the texture keeps the state of BitmapData. If the object did not have a texture it would simply not render. Sounds pretty cool, right?</p>
<p>To be honest&#8230; wrong&#8230;</p>
<h3>Problem #2.1</h3>
<p>First problem was the times where the position had NaN value instead of a Number. This rarely happened but every time it did it was a huge headache to identify why and then track the source of the bug down. While this seems unrelated, the fact was the it looked like the texture did not exist. So I had to check if the texture was created, if it was passed, if it was there at all and the worst part was that if the texture was there as it should, where the hell was the problem?</p>
<h3>Problem #2.2</h3>
<p>Performance wise checking if there is a texture is absolutely dumb! 99% of the times there is a texture present. More, the object class has a visible variable. If the object does not have a texture why is it visible in the first place?</p>
<p>So while apparently I solved a problem by checking if the texture was present and not performing any blit operation if it wasn&#8217;t, the truth is that both performance wise (not that serious by the way, it&#8217;s just a if statement) and the unwanted problems it induced in the code backfired from time to time.</p>
<p>I spread this type of behavior through the code. While one if statement does not have a large impact in performance, a lot of checking piles up and I had a lot!</p>
<h2>Solution #2</h2>
<p>A short story and a riddle both taken from those books that explain my thoughts on the &#8216;final&#8217; (we&#8217;ll see about that!) solution for these problems.</p>
<p>The first one was when one of the authors was hired as a consultant for a development project where the coders sent broken code to the version control system. What he did was to create a routine where the version control server would compile the code that was pushed. Every time the compilation didn&#8217;t work the server would send an email with the error. With the amount of mail with errors constantly piling up on mailboxes, one of the coders asked if there was a way of not getting that much email. The consultant replied: &#8220;Sure, don&#8217;t push code with errors!&#8221;</p>
<p>The riddle is&#8230; what code takes not time to be executed? The one that is not compiled.</p>
<p>So the solution is to write code that allows zero error tolerance while not compiling it. The way to achieve this is with <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html">conditional compilation</a> which can be used in several way but these are the ones I believe the most useful is to use code blocks, like this:</p><pre class="crayon-plain-tag"><code>private function someFunction():void {
	CONFIG::debug {
		// Development code
	}

	CONFIG::release {
		// Final code
	}

	// Both dev and final code
}</code></pre><p>
Inside the same function, different code is compiled depending on the current configuration. We can have several checks with exceptions and errors being thrown and then have a &#8216;don&#8217;t check at all&#8217; version in the release configuration.</p>
<p>This is a two stage solution really. On one hand every time I do something stupid, I get errors so my code has to be perfectly implemented at least when it comes to our framework. On the other hand the same code that make me code as best as I can is also the code that does not run in the final version.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/performance-vs-error-checking/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Enhancing by refactoring</title>
		<link>http://blog.vortixgames.com/enhancing-by-refactoring</link>
		<comments>http://blog.vortixgames.com/enhancing-by-refactoring#comments</comments>
		<pubDate>Sat, 28 Jan 2012 02:00:03 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[Dev Journal: Danger Zone]]></category>
		<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[Danger Zone]]></category>
		<category><![CDATA[Encapsulation]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=1091</guid>
		<description><![CDATA[Two years ago I read a lot about OOP. Every time I picked a new concept in some forum or chat I&#8217;d do my best to understand and apply it. I was eager to improve my coding knowledge and skills but everything we code as a purpose and an audience and if we forget the [...]]]></description>
			<content:encoded><![CDATA[<p>Two years ago I read a lot about OOP. Every time I picked a new concept in some forum or chat I&#8217;d do my best to understand and apply it. I was eager to improve my coding knowledge and skills but everything we code as a purpose and an audience and if we forget the purpose or the audience we are introducing more problems with the knowledge we have than solving problems.</p>
<p>That happened with Bold Pixel. At some point in time Bold Pixel became a monster to please developers instead of a tool to be more productive in my purpose to my audience: create games for players! People play games, not code!</p>
<p>I stopped over-engineering sometime ago and started reading about how to become a better programmer not by writing better code, but by writing the exact code to solve the exact problem. This brought a new problem: what to do with Bold Pixel and how to maintain and evolve it? First thing was to start a new package and only bring in classes that I needed but wire the classes up to be as slim and straight to the point as possible. I do that all the time to build up my code base right now, but that&#8217;s not all. Here&#8217;s the whole process I&#8217;m using right now.</p>
<h2>Start simple</h2>
<p>&nbsp;</p><pre class="crayon-plain-tag"><code>class BlitObject {

	// Position
	public var x:Number = 0;
	public var y:Number = 0;

	// Rendering
	public var visible:Boolean = true;

	public function BlitObject():void {
		// Constructor
	}

	internal function render():void {
		// Render stuff here
	}
}</code></pre><p>The class above can be a stub for a simple blit object. From a OOP perspective it breaks encapsulation completely since x, y and visible variables should be private but seriously, do I really need those to be private or protected and have getters and setters? No I don&#8217;t so no need to over-engineer it. The only thing I want to have contained is the render method that should only be called by the blit engine that lives in the same package.</p>
<p>The blit object only responsibility is to copyPixels or draw on a given world position translating camera position on the fly.</p>
<p>Writing a simple class like this is fast, performs fast, case closed.</p>
<h2>Evaluate new needs</h2>
<p>Now I need a tile map class. This class is also a blit object so following the <a href="http://en.wikipedia.org/wiki/Is-a">&#8220;is a&#8221;</a> versus <a href="http://en.wikipedia.org/wiki/Has-a">&#8220;has a&#8221;</a> rule tile map should inherit blit object. Considering the blit engine has a camera, the tile map won&#8217;t move. This brings two new problem.</p>
<p>1. If the tile map doesn&#8217;t move, why do I have x and y publicly accessible?<br />
2. I want my camera to follow blit objects so blit objects must have x and y variables (or properties). How can I make tile map be recognized as a blit object, have x and y and have none of those altered?</p>
<p>Sounds messy&#8230;</p>
<p>I could write a Blittable interface that would define a render function and getter and setter methods for x and y. The problem is that if there&#8217;s something I want to keep in the package scope is the render function and interfaces define public interfaces.</p>
<p>The solution is to convert blit object in an abstract class and have its original functionality moved to a new graphic class.</p><pre class="crayon-plain-tag"><code>class BlitObject {

	// Rendering
	public var visible:Boolean = true;

	internal function render():void {
		throw new Error(&quot;Abstract function called. Override render()!&quot;);
	}

	public function get x():Number {
		return NaN;
	}

	public function set x(v:Number):void {
		throw new Error(&quot;Abstract function called or property x not available.&quot;);
	}

	public function get y():Number {
		return NaN;
	}

	public function set y(v:Number):void {
		throw new Error(&quot;Abstract function called or property y not available.&quot;);
	}	
}

class Graphic extends BlitObject {

	// Position
	private var _x:Number = 0;
	private var _y:Number = 0;

	override internal function render():void {
		// Render stuff here
	}

	// Position
	override public function get x():Number { return _x }
	override public function set x(v:Number):void { _x = v }
	override public function get y():Number { return _y }
	override public function set y(v:Number):void { _y = v }
}

class TileMap extends BlitObject {

	override internal function render():void {
		// Render the tile map
	}
}</code></pre><p><p>
Problem solved. The class responsibilities are much better defined.</p>
<p>1. A blit object renders and has x and y coordinates. Since it is an abstract class everything we try to do with it directly will result in an error.<br />
2. A graphic is a world movable blit object that renders by copyPixel or draw.<br />
3. A tile map is a world static blit object that renders very large objects by copyPixel or draw  based on a predefined xml specification.</p>
<h2>Conclusion</h2>
<p>What&#8217;s the conclusion here? Well for starters by this time I&#8217;d have a couple of interfaces and probably a helpers. I&#8217;m not saying it is wrong to have interfaces and helpers, actually it is preferable, but it would be coding for the sake of coding instead of coding for the sake of making a game. It took me 10 minutes to do this and while I was at it the BlitObject class also extends a ListObject class that really speed up the iteration, addition and removal of objects from the blit engine.</p>
<p>Still&#8230; I did repeat my self and the code has suffered another refactoring since then. I&#8217;ll leave that for another post but I wonder if you know what&#8217;s repeated&#8230; <img src='http://blog.vortixgames.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/enhancing-by-refactoring/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Application Design vs Game Design Round 1</title>
		<link>http://blog.vortixgames.com/application-design-vs-game-design-round-1</link>
		<comments>http://blog.vortixgames.com/application-design-vs-game-design-round-1#comments</comments>
		<pubDate>Wed, 25 Jan 2012 00:15:06 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[Dev Journal: Danger Zone]]></category>
		<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[The design of VGS]]></category>
		<category><![CDATA[Danger Zone]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>
		<category><![CDATA[Topdown]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=1083</guid>
		<description><![CDATA[Hi everyone, Vlad here. Let me start by saying that the title is a bit misleading. For starters it is not an actual bout but more a decision making process. It also gives the impression I&#8217;ll write more about this or that I have some kind of plan about this subject. I don&#8217;t, it just [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone, Vlad here.</p>
<p>Let me start by saying that the title is a bit misleading. For starters it is not an actual bout but more a decision making process. It also gives the impression I&#8217;ll write more about this or that I have some kind of plan about this subject. I don&#8217;t, it just happens that I think I&#8217;ll travel this road again.</p>
<h2>Game Design</h2>
<p>The game design for this game states that:</p>
<p>1. The player&#8217;s objective is to reach the top of the &#8220;structure&#8221; (named just to make sense) where the action rolls;<br />
2. The &#8220;structure&#8221; has several &#8220;floors&#8221; (again just for easier comprehension);<br />
3. The player can fall to the previous &#8220;floor&#8221;;<br />
4. It is guaranteed that the player will see at least three &#8220;floors&#8221;;</p>
<h2>Application Design</h2>
<p>One thing that I know for sure is that we will be blitting all graphics and that the player token has three different blit objects and two of those rotate thus negating copyPixels and putting the dreadful draw method to work.</p>
<p>Another thing I know is that each &#8220;floor&#8221; is a tilemap, also blitted and that each tile is 64&#215;64.</p>
<p>And now the assumptions begin. How big is each &#8220;floor&#8221;? I have no idea but let&#8217;s say that a rather large &#8220;floor&#8221; has 50&#215;50 tiles. If the player will see at least three floors and on later stages all &#8220;floors&#8221; are rather large we are talking about 7,500 tiles to be rendered with a astonishing number of 30,720,000 pixels to be copied&#8230; each frame.</p>
<p>The &#8220;floor&#8221; where the player is will only render the tiles on screen (88 max) but the other two lower &#8220;floors&#8221; can potentially be fully rendered given the camera specs. Even if all three &#8220;floors&#8221; only rendered tiles on screen (which won&#8217;t happen by design) there would still be 7,500 objects to manage and that&#8217;s tiles only since we need to add to this all the remaining entities: player, enemies, decorations, effects, etc, but to make it worse the bottom two levels will be zoomed and probably in full view which means not only that all their blit objects will be visible but also that at least 5,000 of those objects will use draw instead of copyPixels&#8230; Did the headache kicked in already or is it just pure performance insanity?</p>
<h2>Implementation</h2>
<p>One of the great things about copyPixels is that it only renders the intersection between the target bitmapData rectangle and the source rectangle positioned at the destination point. What this means is that if we have 1,000 objects to render but only one actually has an intersecting rectangle, most of the processing time is running the array, vector or list and &#8211; more important and processor heavy &#8211; calling the functions that will in the end render.</p>
<p>The draw method also does this with a matrix&#8230; more on this later.</p>
<p>The solution was to write a BlitTileMap class that builds the tilemap in one big texture before it is used. While it uses much more RAM this class allows to address pretty much every problem stated earlier.</p>
<p>First and foremost the number of objects managed and therefor the performance lost with running their container (in our case, a linked list) and calling functions. From a potential 7,500+ we now have 3. The other issue that this addresses is the number of pixels it will render or try to render, from potentially 30,000,000+ to the worst case scenario of 1,050,000. And last but not least, considering the lower &#8220;floors&#8221; will be zoomed out, instead of using draw to render 5,000+ objects it will render&#8230; 2!</p>
<p>But the draw method also has a funny and helpful consequence. The smaller the scale, the faster draw executes which in terms of performance is relevant considering the zoom out will be achieved through scale. Less objects taking less time to render will be (I hope) quite a performance boost.</p>
<p>Did I just write all this? Wow!&#8230; Later!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/application-design-vs-game-design-round-1/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bold Pixel&#8217;s Namespaces and Interfaces</title>
		<link>http://blog.vortixgames.com/bold-pixels-namespaces-and-interfaces</link>
		<comments>http://blog.vortixgames.com/bold-pixels-namespaces-and-interfaces#comments</comments>
		<pubDate>Wed, 01 Sep 2010 00:46:23 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=911</guid>
		<description><![CDATA[After much thought and discussion by myself or at the FGL chat I made some decisions about how to make Bold Pixel more modular in order to simplify my own work. Since we are still on top of contracts, I couldn&#8217;t give enough attention to this but my brain was dealing with it in the [...]]]></description>
			<content:encoded><![CDATA[<p>After much thought and discussion by myself or at the FGL chat I made some decisions about how to make Bold Pixel more modular in order to simplify my own work. Since we are still on top of contracts, I couldn&#8217;t give enough attention to this but my brain was dealing with it in the background.</p>
<h3>Inheritance Spaghetti</h3>
<p>The problem presented was somewhat simple. My early coding of the blit engine got tangled in the dreadful inheritance headaches. My solution to it was to create one class per major responsibility. It worked fine until the time I decided to expand one of the classes to do something it wasn&#8217;t designed to do. So on one hand I solved the inheritance problems but on the other I lost modularity. At this time I had a OOP doubt that I expressed in the FGL forums and the discussion that started there really helped me to move in a different direction, one that I had never considered.</p>
<p>More over I said that I would not support requests that didn&#8217;t deal with deal with real problems we had in our own development. And while I stick to that, I couldn&#8217;t help but to think: what if Bold Pixel could help someone but it missed one little tiny feature? While this was puzzling me, there was real problem, one with impact in our development that was taunting me&#8230;</p>
<h3>The case of Blit vs Physics</h3>
<p>So Bold Pixel has a blit engine and it will wrap a physics engine (more about the physics engine this later this month) so the question that was on top of the table was: considering there is a blit entity and a physics entity, which one should access the other? Whatever the answer was, modularity was lost in the sense I imagine it. I don&#8217;t want blit to know physics and I don&#8217;t want physics to know blit!</p>
<p>After a nice chat with Antriel at FGL (thanks mate!) I got to know the <a href="http://en.wikipedia.org/wiki/Strategy_pattern" target="_blank">Strategy Pattern</a> and all my problems were solved. In simple terms, I will be defining interfaces for all interchangeable objects but the implementations of the interfaces can exist anywhere. In the case presented, a blit entity will have its spatial properties (rotation, x, y and scale) defined by a spatial interface. By default it will be a simple class and it&#8217;s needed since the properties of the spatial interface are needed to render bitmapdata. A physics entity will be a implementation of  the spatial interface, so if I want to use physics on a blit entity, I simply write: myBlitEntity.position = myPhysicsEntity;</p>
<h3>Visibility and Access Issues</h3>
<p>This brought another problem. Bold Pixel has always kept its inner &#8220;stuff&#8221; hidden. The objective was this was to keep the auto-completion short and the use easy preventing mistakes. In order to implement interfaces I would have to make a lot of code public.</p>
<p>The answer to this would be <a href="http://en.wikipedia.org/wiki/Abstract_class" target="_blank">abstract classes</a>, but ActionScript3 does not support it. That will be addressed with simple naming and convention over configuration. Any class in any namespace in Bold Pixel that starts with Abstract will only have the simplest shortest implementation needed for something to work. For instance, if I want a blit entity that draws pixels I will have to extend a AbstractBlitEntity class (I guess that will be the name) but that brings another problem&#8230;</p>
<p>So ActionScript does not support abstract classes&#8230; convention will say that Abstract defines an abstract class.</p>
<h3>Namespaces (to wrap this up!)</h3>
<p>To have a better code organization I will need more packages and to have more packages I will need to provide access to classes in different packages. This will be done with namespaces. The only thing that annoys me is that Flash Develop in the current version (3.2.2) does not support code-completion with custom namespaces, but what matters is that using custom namespaces solves two problems. First I can have a bunch of private functionality like I like, but second, any coder can with a simple namespace use extend Bold Pixel to his own needs in a full modular way.</p>
<p>While I reckon that this is all just in my head and that a lot of work will have to be done and even considering that probably this will make Bold Pixel a little bit more complicated to the average coder, I feel it sorts a lot of questions, so: Namespaces and Interfaces FTW!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/bold-pixels-namespaces-and-interfaces/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bold Pixel Engine Toolkit Video</title>
		<link>http://blog.vortixgames.com/bold-pixel-engine-toolkit-video</link>
		<comments>http://blog.vortixgames.com/bold-pixel-engine-toolkit-video#comments</comments>
		<pubDate>Sat, 20 Feb 2010 16:10:53 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=813</guid>
		<description><![CDATA[Hi all, Just a heads up for a YouTube video we just uploaded that goes through the toolkit package of Bold Pixel Engine. Remember to watch it in full-screen HD! Clicky! Later!]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>Just a heads up for a YouTube video we just uploaded that goes through the toolkit package of Bold Pixel Engine.</p>
<p>Remember to watch it in full-screen HD! <img src='http://blog.vortixgames.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <a href="http://www.youtube.com/vortixgamesstudio" target="_blank">Clicky!</a></p>
<p>Later!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/bold-pixel-engine-toolkit-video/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Brain Melt</title>
		<link>http://blog.vortixgames.com/brain-melt</link>
		<comments>http://blog.vortixgames.com/brain-melt#comments</comments>
		<pubDate>Tue, 16 Feb 2010 13:00:09 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[Feedback]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=797</guid>
		<description><![CDATA[I&#8217;ve been writing and re-writing a lot of code lately. Somewhere between the work to be done and the work I want to see done, there are dozens of thoughts and discoveries that are worth sharing. Some are puzzling, others are simply brain melting. Behaviors A long time goal: behaviors! What is it? How does [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing and re-writing a lot of code lately. Somewhere between the work to be done and the work I want to see done, there are dozens of thoughts and discoveries that are worth sharing. Some are puzzling, others are simply brain melting.</p>
<h3>Behaviors</h3>
<p>A long time goal: behaviors! What is it? How does it work? Well&#8230; imagine you write this line of code in a Bold Pixel Engine entity:</p><pre class="crayon-plain-tag"><code>entity.behaviors.face.mouse();</code></pre><p>
And from that moment on, the entity will always rotate to the mouse position. That&#8217;s a behavior.</p>
<p>Imagine that you could say that instead of facing you&#8217;d want it to rotate to the mouse position at a given speed, or with a tween, or that you want it to evade another entity or to find the path to a certain point. Now imagine that behaviors could applied to time&#8230; that you could tell your engine time would slow down so you could see all in slow motion&#8230;</p>
<p>Well&#8230; I wrote two behaviors and it works like a charm!</p>
<h3>Flash Player is somewhat smart</h3>
<p>I&#8217;ve noticed that if you copyPixels() or draw() outside the target bitmapData area, it won&#8217;t render anything. Having thousands of objects outside the rectangle area is absolutely meaningless, even if you apply a transformation matrix and draw.</p>
<p>I thought about the possibility of creating a camera object&#8230; suddenly this possibility became obviously closer since there will be no need to verify if an object is supposed to be rendered, Flash Player does that for me, I just have to pass the right rectangle&#8230; awesome! or at least I&#8217;m thinking it will be!</p>
<h3>Filters</h3>
<p>I really needed a rest a couple of nights ago&#8230; so nothing better than writing some new functionalities! My goal was to write filters to apply in layers. After noticing that most flash filters need a BlurFilter applied on top of it, I decided to make it simple and just work with one BlurFilter and one ColorTransform in each layer.</p>
<p>BlurFilter is a huge performance killer, so I played around with only applying the filter to whatever the area the filter needed to be applied to and it works great! The bigger the area, the bigger the performance impact that&#8217;s for sure!</p>
<p>ColorTransform seems to have no impact. I&#8217;m betting that the pixel color is calculated directly when drawing&#8230; if this is true&#8230; it&#8217;s quite smart!</p>
<p>All in all and since I didn&#8217;t want to use any other filters for performance issues, I noticed that with just a little tiny bit of patience, blur and color transform can do most of the cute effects we might need, from shadows to glows to motion blur.</p>
<h3>Brain melting the possibilities</h3>
<p>A camera with behaviors, like moving to an area with tweening. Flames coming out of a structure and then exploding in thousands of particles flying around with fire trails. Zillions of projectiles flying around in a huge map&#8230; wow&#8230; this weekend really caused a brain melt.</p>
<p>Need to finish the tutorials to Bold Pixel Engine v1 because v2 is already shaping.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/brain-melt/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introduction to BPE&#8217;s Blit Engine</title>
		<link>http://blog.vortixgames.com/introduction-to-bpes-blit-engine</link>
		<comments>http://blog.vortixgames.com/introduction-to-bpes-blit-engine#comments</comments>
		<pubDate>Tue, 09 Feb 2010 20:14:38 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=785</guid>
		<description><![CDATA[Hi everyone! Just a heads-up to let you know that a video with an introduction to BPE&#8217;s Blit Engine is up on our YouTube Channel. Thanks to everyone that has voiced an opinion about BPE, good, bad, bugs and whatnot, we appreciate it.]]></description>
			<content:encoded><![CDATA[<p>Hi everyone!</p>
<p>Just a heads-up to let you know that a video with an introduction to BPE&#8217;s Blit Engine is up on our YouTube Channel.</p>
<p>Thanks to everyone that has voiced an opinion about BPE, good, bad, bugs and whatnot, we appreciate it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/introduction-to-bpes-blit-engine/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bold Pixel Engine Released</title>
		<link>http://blog.vortixgames.com/bold-pixel-engine-released</link>
		<comments>http://blog.vortixgames.com/bold-pixel-engine-released#comments</comments>
		<pubDate>Sun, 07 Feb 2010 19:23:42 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=775</guid>
		<description><![CDATA[Hi all! Great day today! We are releasing Bold Pixel Engine today. Along with this release we are also opening our YouTube channel. Is that nice or what? Visit our Bold Pixel Engine Page for information and download and our YouTube channel for the first glimpse of it. See you later&#8230;]]></description>
			<content:encoded><![CDATA[<p>Hi all!</p>
<p>Great day today! We are releasing Bold Pixel Engine today. Along with this release we are also opening our YouTube channel.</p>
<p>Is that nice or what?</p>
<p>Visit our <a href="http://blog.vortixgames.com/contact-us/bold-pixel-engine" target="_blank">Bold Pixel Engine Page</a> for information and download and <a href="http://www.youtube.com/VortixGamesStudio" target="_blank">our YouTube channel</a> for the first glimpse of it.</p>
<p>See you later&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/bold-pixel-engine-released/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bold Pixel Engine Blit Performance Test</title>
		<link>http://blog.vortixgames.com/bold-pixel-engine-blit-performance-test</link>
		<comments>http://blog.vortixgames.com/bold-pixel-engine-blit-performance-test#comments</comments>
		<pubDate>Thu, 04 Feb 2010 11:52:40 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=589</guid>
		<description><![CDATA[Hi all, Vlad here! Wrote a quick performance test yesterday comparing movieclips with our own blit engine. Usually tests are performed with a number of objects. To test several loads, usually a different number of objects is used to test the results. I didn&#8217;t want that since we all know that many games don&#8217;t have [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all, Vlad here!</p>
<p>Wrote a quick performance test yesterday comparing movieclips with our own blit engine. Usually tests are performed with a number of objects. To test several loads, usually a different number of objects is used to test the results. I didn&#8217;t want that since we all know that many games don&#8217;t have a fixed ammount of objects rendered. Even if object pooling is used, what concerns me is the objects rendered.</p>
<p>What I did was to create one object per frame and then move all the existing objects away from the starting point. This would give an instant visual reference about how well blit performs against movieclips.</p>
<p>Give it a try and then read on.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="512" height="384" align="center">
      <param name="movie" value="http://blog.vortixgames.com/wp-content/uploads/2010/02/blit_performance_test.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://blog.vortixgames.com/wp-content/uploads/2010/02/blit_performance_test.swf" width="512" height="384" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>Tried it? Cool!</p>
<p>Movement is time-based in both tests, this means that test 1, ran with movie clips took longer since the spread is bigger. This indicates a frame drop, but if you run it again and notice that there are different spreads, so not only it drops but it drops in a rather inconsistent way. Obviously the test also took longer to conclude.</p>
<p>On the other hand, blit engine performs rather smoothly, to the point where frame drop is not inconsistent and allows the objects to stay pretty close to each other. Above that, the test is damn quick compared to the first one, proved by the small spread (although I could&#8217;ve included a clock, I admit).</p>
<p>This is nothing we didn&#8217;t already know, I agree! The true testing will be with animation, rotation and scaling of blit entities.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/bold-pixel-engine-blit-performance-test/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Bold Pixel Engine v0.9 refactor</title>
		<link>http://blog.vortixgames.com/bold-pixel-engine-v0-9-refactor</link>
		<comments>http://blog.vortixgames.com/bold-pixel-engine-v0-9-refactor#comments</comments>
		<pubDate>Sat, 30 Jan 2010 23:52:56 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=570</guid>
		<description><![CDATA[Hi everyone! As promised, as soon as BPE has a couple of games under its belt, it will be made available. There are a couple of games going on with it and those are almost done, but the engine&#8217;s part is finished. With all we&#8217;ve been through with it, refactoring was needed so I put [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone!</p>
<p>As promised, as soon as BPE has a couple of games under its belt, it will be made available. There are a couple of games going on with it and those are almost done, but the engine&#8217;s part is finished.</p>
<p>With all we&#8217;ve been through with it, refactoring was needed so I put a bit of work in the engine this evening (coding on a Saturday evening&#8230; geek!) and I&#8217;d like to show you how to do something with it.</p>
<p>I&#8217;d love that you take a look at the code and let me know if you think it is easy to follow, since this is the philosophy behind most of BPE&#8217;s classes.</p>
<pre class="crayon-plain-tag"><code>package 
{
    import bpe.blit.*;
    import bpe.managers.*;
    import flash.display.MovieClip;
    import flash.events.Event;
    
    public class BoldPixelEngine extends MovieClip
    {
        public function BoldPixelEngine():void
        {
            addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event)
        {
            var engine:Engine = new Engine(640, 480);
            var layer:Layer = engine.layer.create();
            var actor:Entity = layer.entity.create();
            var animation:uint = TextureManager.createCollectionFromMovieClip(idle);
            
            addChild(engine.render.window);
            
            actor.x = 320;
            actor.y = 140;
            actor.animation.loop(animation);
            
            Loop.AddListener(engine.update);
        }
    }
}</code></pre>
<p>What this code does is to create a blit engine instance in the stage and draw a time based animation in it.</p>
<p>What I&#8217;d like to know is, without any further explaining, does this look simple and intuitive to you?</p>
<p>Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/bold-pixel-engine-v0-9-refactor/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

