<?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; Software Engineering</title>
	<atom:link href="http://blog.vortixgames.com/tag/software-engineering/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>BADJ Day 13: How the project is organized</title>
		<link>http://blog.vortixgames.com/badj-day-13-how-the-project-is-organized</link>
		<comments>http://blog.vortixgames.com/badj-day-13-how-the-project-is-organized#comments</comments>
		<pubDate>Fri, 08 Oct 2010 12:09:42 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[Dev Journal: Bruce Ali]]></category>
		<category><![CDATA[Bruce Ali]]></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=972</guid>
		<description><![CDATA[I&#8217;ve been asked quite a lot how we organize our projects. I tried to explain the best I could and today I was going to write a huge blog post about it. Instead of that, I&#8217;ve put 9 minutes of video that show how and why Bruce Ali is organized the way it is. By [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been asked quite a lot how we organize our projects. I tried to explain the best I could and today I was going to write a huge blog post about it. Instead of that, I&#8217;ve put 9 minutes of video that show how and why Bruce Ali is organized the way it is.</p>
<p>By the way&#8230; choose 720p and full-screen it. <img src='http://blog.vortixgames.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="542" height="368" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/U3l9FtEUOT4?fs=1&amp;hl=pt_BR&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="542" height="368" src="http://www.youtube.com/v/U3l9FtEUOT4?fs=1&amp;hl=pt_BR&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/badj-day-13-how-the-project-is-organized/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>BADJ Day 11: A successful frustration</title>
		<link>http://blog.vortixgames.com/badj-day-11-a-successful-frustration</link>
		<comments>http://blog.vortixgames.com/badj-day-11-a-successful-frustration#comments</comments>
		<pubDate>Wed, 06 Oct 2010 23:56:01 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[Dev Journal: Bruce Ali]]></category>
		<category><![CDATA[Bold Pixel Engine]]></category>
		<category><![CDATA[Bruce Ali]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=967</guid>
		<description><![CDATA[So I coded and recoded, tested and retested a Object Pool class with a high degree of success and frustration. I wrote and tested three different pool managers, here&#8217;s the story&#8230; Objective: Centralized management of pools This one was easy. There is a PoolManager that has a static method to get a pool for a [...]]]></description>
			<content:encoded><![CDATA[<p>So I coded and recoded, tested and retested a Object Pool class with a high degree of success and frustration. I wrote and tested three different pool managers, here&#8217;s the story&#8230;</p>
<h3>Objective: Centralized management of pools</h3>
<p>This one was easy. There is a PoolManager that has a static method to get a pool for a certain class. If the pool for that class does not exist, it is created, if it does, it is returned. Objective achieved.</p>
<h3>Objective: Lightweight pools</h3>
<p>I don&#8217;t need pools to be amazingly complex, I just need the pools to get the job done, which is: be faster at getting new objects at the expense of memory. That didn&#8217;t go very well. The pools were lightweight alright, but I was not able to make it any faster than creating a objective directly.</p>
<p>This lead to the three versions of the pool manager and still the best performance gain is below 5% for any Bold Pixel entity. I was so frustrated, but then I saw the light!</p>
<h3>Not my fault really</h3>
<p>After testing and more testing I had a epiphany! What if Bold Pixel&#8217;s entities are simply too light to make pooling worth. It would not be something I&#8217;d consider. It really never crossed my mind that a instancing a object could be faster than getting it from a linked list kind of pool, but it is and the classes I was dealing with are somewhat heavy considering the inheritance and and composition of several.</p>
<p>The highest gain I got was 8ms in 1000 object. Creating 1000 objects took 54ms and getting 1000 objects from the object pool took 46ms.</p>
<h3>The unexpected success</h3>
<p>So either my classes are very light or flash behaves rather poorly in managing this. So I tested against some movie clip I had around. Creating 1000 movie clips took 102ms, almost doubling the worst case scenario.</p>
<p>Not only I was happy to note that my classes are lightweight, both pool manager and entity type classes, but I also proved that getting movie clips would make a difference.</p>
<h3>Conclusion</h3>
<p>I&#8217;m not happy with the pool manager for now, but I&#8217;ll work on it some other day. It gets the job done, but the objects I really wanted to make a better use of pooling are the ones that problably will have less impact.</p>
<p>If I regret anything in this bits of code is that I over engineered it at first. Tomorrow blit engine!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/badj-day-11-a-successful-frustration/feed</wfw:commentRss>
		<slash:comments>8</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>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>Engine misconceptions</title>
		<link>http://blog.vortixgames.com/engine-misconceptions</link>
		<comments>http://blog.vortixgames.com/engine-misconceptions#comments</comments>
		<pubDate>Tue, 18 Aug 2009 03:25:29 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=499</guid>
		<description><![CDATA[Maybe I&#8217;m a bit overwhelmed with what happened this last week, but the topic that doesn&#8217;t seem to leave my head is our engine. While I was discussing the topic in FGL chat I noted again two distinct definitions of engine. What I&#8217;m aiming for with this post is to address the common misconceptions that, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" src="http://www.bikerworld.co.uk/roadtests/Hayabusa/GSX1300R_Hayabusa_Engin_sm.gif" alt="" width="240" height="261" />Maybe I&#8217;m a bit overwhelmed with what happened this last week, but the topic that doesn&#8217;t seem to leave my head is our engine. While I was discussing the topic in FGL chat I noted again two distinct definitions of engine. What I&#8217;m aiming for with this post is to address the common misconceptions that, in my humble opinion, exist to many flash developers.</p>
<h3>Each game is an engine</h3>
<p>This is the start of the difference of opinions. For many developers reusing a game engine equals to creating a sequel to a game with small tweaks and new graphics. To me, reusing a game engine is reusing multiple classes across games, but not game logic.</p>
<p>Coding your engine is nothing more than to write separate classes for the code you often use. Great simple examples are keyboard input, sound and music handling. On the more complex side we have collisions, AI and bliting. All of these can be coded separately to create a library of code that we can reuse with ease across games. That is the game engine.</p>
<h3>It&#8217;s impossible to code a cross-genre game engine</h3>
<p>Again, this misconception comes from not separating engine from logic. If we detect keyboard input the same way across games, if we preload the same way across games, if we blit the same way across games, regardless of genre, why can&#8217;t we write code that fits all genres? It is better to manage some exceptions to your code than to rewrite it over and over again.</p>
<p>If you think about it, that&#8217;s how cost is cut in other game development markets, like consoles and PC development. The use of engines is more than common. Huge corporations like EA have their own technology to serve their cross-platform needs, others use commercial engines, like Cry Engine for their target specific development.</p>
<p>So, if a high-end, complex environment like console development can pick up a game engine and write different genres, where lies the difference for a much low-end environment like Actionscript based development?</p>
<h3>Extending the core classes of Actionscript is enough for me</h3>
<p>This is not a misconception, it is more of a easy way out kind of thing. When I started coding in AS3 I had this exact opinion. To be honest, extending MovieClips was pretty much all I was doing. I can assure you that it is easier but it made my life harder in the long run, as soon as we needed to move forward it became obvious that this presented some performance issues, not to mention that extending classes is probably the least reusable way of coding in AS3.</p>
<h3>Final thoughts&#8230;</h3>
<p>I believe that this generic opinion towards flash game development and engine technology happens because many developers don&#8217;t separate engine from logic, for example, a game that needs collision detection has the collision detection code written within the class that controls the level, assuming there is a class in the first place.</p>
<p>Yet, and with our own engine slowly but steadily maturing, I feel that it makes all sense to take the first step which is to create our own reusable classes and then take the second step and code an engine that makes our life as easy as it can possibly be in the long run. We wrote the first class because it would save work, considered a &#8220;full&#8221; engine because extending MovieClips was clearly damaging our work and right now, I can&#8217;t imagine the amount of code I would need to write to sort some design issues that appear almost weekly.</p>
<p>Vlad out!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/engine-misconceptions/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>More testing on Actionscript&#8217;s Math class</title>
		<link>http://blog.vortixgames.com/more-testing-on-actionscripts-math-class</link>
		<comments>http://blog.vortixgames.com/more-testing-on-actionscripts-math-class#comments</comments>
		<pubDate>Sun, 09 Aug 2009 00:00:42 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=492</guid>
		<description><![CDATA[As you may have noticed I&#8217;m somewhat critical regarding the AS3 Math class. I&#8217;m a bit sick to be honest and work was flowing as I wanted to so I took 30 minutes off to test some stuff. Flooring a number Getting the nearest low integer of a number is usually achieved with Math.floor(number). If [...]]]></description>
			<content:encoded><![CDATA[<p>As you may have noticed I&#8217;m <a href="http://blog.vortixgames.com/the-make-it-fast-demo" target="_blank">somewhat critical</a> regarding the AS3 Math class. I&#8217;m a bit sick to be honest and work was flowing as I wanted to so I took 30 minutes off to test some stuff.</p>
<h3>Flooring a number</h3>
<p>Getting the nearest low integer of a number is usually achieved with Math.floor(number). If we didn&#8217;t have it, we would probably typecast the number to an integer and get the same result. So I looped both methods one million times and measured the results.</p>
<blockquote><p>Math.floor(number) performed around 150 milliseconds<br />
int(number) performed around 5 miliseconds</p></blockquote>
<p>Now the bad news is that this works for positive numbers, using int(number) for negative signed numbers doesn&#8217;t produce a floored integer. For example int(-2.4) returns -2 where it should return -3.</p>
<h3>Rounding a number</h3>
<p>Rounding a number will return the closest integer of that number. Again this is usually achieved with Math.round(number) but we can also do this:</p>
<p>One million iterations after the results are as follow:</p>
<blockquote><p>Math.round(number) took around 165 milliseconds<br />
int(number + 0.5) took around 5 miliseconds</p></blockquote>
<p>Same issue applies regarding negative signed numbers though, so keep that in mind, but the question is&#8230;</p>
<h3>Are you feeling the urge of writing a new Math class?</h3>
<p>This way we could deal with both performance and doing some arrangements to make negatives work correctly. Problem with this is that we will be calling a static method from an external class. A full working rounding method called one million times took 180 milliseconds against the 165 milliseconds from Math.round(number) method, so there&#8217;s loss instead of gain.</p>
<p>Bottom line is that this kind of stuff is a bit like using multiplications over divisions. Depends on a lot of stuff. If your display objects move on a positive x and y axis, you can do it like there&#8217;s not tomorrow, just typecast to integer whatever you need to round, but all in all, unless you have millions of Math class operations to do, you won&#8217;t even notice the difference.</p>
<p>See you soon,<br />
Vlad</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/more-testing-on-actionscripts-math-class/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The art of game development refactoring</title>
		<link>http://blog.vortixgames.com/the-art-of-game-development-refactoring</link>
		<comments>http://blog.vortixgames.com/the-art-of-game-development-refactoring#comments</comments>
		<pubDate>Tue, 04 Aug 2009 00:00:59 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=463</guid>
		<description><![CDATA[Every thing that starts with &#8220;The art of&#8230;&#8221; sounds so cool doesn&#8217;t it? Can&#8217;t say I&#8217;m a real master at what I&#8217;m about to write. This &#8220;vision&#8221; appeared before my eyes when I made a question about game loop performance techniques in the Portuguese game development community. Out of many answers, one had this pearl [...]]]></description>
			<content:encoded><![CDATA[<p>Every thing that starts with &#8220;The art of&#8230;&#8221; sounds so cool doesn&#8217;t it? Can&#8217;t say I&#8217;m a real master at what I&#8217;m about to write. This &#8220;vision&#8221; appeared before my eyes when I made a question about game loop performance techniques in the Portuguese game development community. Out of many answers, one had this pearl of wisdom:</p>
<blockquote><p>Make it work, make it nice, make it fast!</p></blockquote>
<p>And I&#8217;ll be damned if this simple sentence didn&#8217;t influence me since that day&#8230; not so long ago.</p>
<h3>How I handled my code before&#8230;</h3>
<p>To put it in simple terms: my code was written to be as close to the end form from start. I coded all the possible performance tricks immediately, wrote reusable code asap and my refactoring was usually very short. This made all well planned projects to be coded in very short terms.</p>
<p>I always had one major problem though: every time the project needed one or more deeper changes I had to recode a lot and, naturally with the same degree of &#8220;end code&#8221; vision. This means that I used to pre-plan too much and that my code changes were not that agile. More than often this meant that the game was slave to the code and not to the design and this is usually a game killer.</p>
<p>After that sentence, all was different&#8230;</p>
<h3>Make it work</h3>
<p><img class="  alignright" style="margin: 10px;" src="http://www.grimmemennesker.dk/data/media/1/8_ugly_people.jpg" alt="Is it ugly?" width="216" height="298" /></p>
<p>First objective of every line of code: making it work, no matter what. Is it slow? Is it ugly? Often yes! Does it work? YES! And this is a good thing. Code that works as soon as possible offers you the possibility of being able to access if you need changes or not sooner. This is very important in game development, especially short development like with flash based games.</p>
<p>You will go through all the same design issues, but you&#8217;ll do it sooner, you can adapt sooner. That&#8217;s the whole point of agile development: you can make changes without compromising features changes or feature additions.</p>
<p>It is very important that you don&#8217;t do anything stupid, like having duplicated code. Be fast, don&#8217;t be sloppy. It&#8217;s OK if you are not paying attention to a lot of details and you are writing in the easiest possible form, but it is not OK if you are copy/pasting code and this is just an example.</p>
<p>Is it has intended? Is everyone happy with the current form?</p>
<p>If yes, refactoring is in order&#8230;</p>
<h3>Make it nice</h3>
<p>If everything is according to plan, you can, you should and you will (I command thee) refactor your code to make it nice. I&#8217;m very fashion victim code wise. I like my variables of the same context to have the same length for instance, but it is more than enough if you comment your code, cut the loose ends and have your code ready for you to forget about it. That&#8217;s right, move it away from your brain, you&#8217;ll need the room for the next iteration. If it is well documented and easy to read, you can return to it anytime.</p>
<p>Here&#8217;s a good cliche: Hold in your brain only the things you can&#8217;t have written down.</p>
<div>
<dl class="wp-caption alignleft" style="width: 278px;">
<dt class="wp-caption-dt"><img class=" " src="http://janeheller.mlblogs.com/road-runner.jpg" alt="As fast as this..." width="268" height="202" /></dt>
<dd class="wp-caption-dd">As fast as this&#8230;</dd>
</dl>
</div>
<h3>Make it fast</h3>
<p>Well&#8230; now it&#8217;s the tricky part. Your code is probably not the fastest thing in the world, why? Well, you made what you were supposed make, you probably added changes to it, you commented it and made it nice and tidy, but maybe you have some stuff there that could use a little help. Actually I&#8217;m pretty sure you do. This is due mostly to the fact that making it work as fast as you can usually doesn&#8217;t mean you made it as fast as it can work. Wow&#8230; am I on a cliche thing or what?</p>
<p>Every piece of software needs its own set of performance tweaking. It can be anything really.</p>
<p>A world of performance tweaking stuff has been written, maybe I should add mine also one of these days, but there are things that are pretty common.</p>
<p>Heavy calculations come to mind&#8230; it&#8217;s quite common to use really heavy math operations on a per frame basis instead of pre-calculating this kind of stuff. If you have dozens of objects calculating sines and cosines, making divisions, calculating distances and so on, you will have a lot of performance tweaking ready to be made.</p>
<p>Object creation is a major issue with Actionscript also. A lot of the code snippets I find have new objects created inside some methods that are supposed to be called most if not all frames.</p>
<p>Another common issue is that a part of your code is bottle necking the rest, often causing frame drops. Identify what causes the bottleneck, then either run it from time to time, use a maximum iterations value or segment it in your game loop.</p>
<p>I guess I should just write some optimization articles soon or I can be here forever&#8230;</p>
<p>See you all soon,<br />
Vlad</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/the-art-of-game-development-refactoring/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Model&#8230; revisited&#8230;</title>
		<link>http://blog.vortixgames.com/model-revisited</link>
		<comments>http://blog.vortixgames.com/model-revisited#comments</comments>
		<pubDate>Fri, 19 Jun 2009 10:25:16 +0000</pubDate>
		<dc:creator>Vlad</dc:creator>
				<category><![CDATA[The code of VGS]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[FlashGameBlogs]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.vortixgames.com/?p=330</guid>
		<description><![CDATA[Hi everyone, it&#8217;s Vlad again. It&#8217;s 10:52AM, 30 degrees Celsius if you stand in the shadow and just a couple of hours ago I hit an issue with our current project. Basically static data regarding gameplay was becoming completely unmanageable. Before moving forward I decided to rethink and drew how my classes were organized. Let [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone, it&#8217;s Vlad again.</p>
<p>It&#8217;s 10:52AM, 30 degrees Celsius if you stand in the shadow and just a couple of hours ago I hit an issue with our current project. Basically static data regarding gameplay was becoming completely unmanageable. Before moving forward I decided to rethink and drew how my classes were organized.</p>
<p style="text-align: center;"><img class="size-full wp-image-331 aligncenter" title="no_actual_model" src="http://blog.vortixgames.com/wp-content/uploads/2009/06/no_actual_model.jpg" alt="no_actual_model" width="512" height="232" /></p>
<p>Let me tell you what this is&#8230; Data and Gameplay are folders, packages in AS3 terms. Tokentype1, Tokentype2 and Constants are classes that hold data in the form of static functions and constants. LevelController, LevelView, TokenController and TokenView are classes that are either controllers or views of my gameplay objects.</p>
<p>This is how I&#8217;ve organized most projects until now, so what&#8217;s the problem? For starters, all games until now have only one token type. This game has two but it will have more. I was about to actually copy/paste a method from TokenType1 class to the TokenType2 class&#8230; you know how bad this is right?</p>
<p>On top of that a new problem was present for a couple of days. Some variables names, class names and query methods conflicted, not logically but in terms of what I was reading while coding. Building, IsBuilding, buildings, building and so on&#8230; variables like type, code and state also weren&#8217;t 100% clear.</p>
<p>So I decided that it was time to redesign and refactor before it became too nasty. Here&#8217;s the result:</p>
<p style="text-align: center;"><img class="size-full wp-image-332 aligncenter" title="now_with_a_model" src="http://blog.vortixgames.com/wp-content/uploads/2009/06/now_with_a_model.jpg" alt="now_with_a_model" width="512" height="232" /></p>
<p>I simply took the MVC pattern seriously and created models for both level and tokens. On top of that I changed all ambiguous variables, states and methods to be named consistently throughout the project.</p>
<p>The LevelModel is nothing more than the old Constants class. There&#8217;s no big difference for now except that when gameplay is closed and we move to other stuff, I&#8217;ll have to create models for all the other stuff instead of having all constants inside one &#8220;global&#8221; constants class.</p>
<p>The TokenModel is the big change! It holds all the stuff from TokenType1 and TokenType2 classes, but now I can guarantee that there are no duplication of methods, arrays and so on. Big part of this arrangement was to deal with the inconsistent naming of variables and so on.</p>
<p>I&#8217;m very happy with the solution, now, if you excuse me, I&#8217;ll get back to coding game functionalities.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vortixgames.com/model-revisited/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

