<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Stephen Calender Programming Blog</title>
	
	<link>http://www.stephencalenderblog.com</link>
	<description />
	<pubDate>Thu, 08 Jul 2010 05:44:38 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/StephenCalenderProgrammingBlog" /><feedburner:info uri="stephencalenderprogrammingblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Building Lego Universe</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/vzlmuOCfVMc/</link>
		<comments>http://www.stephencalenderblog.com/?p=268#comments</comments>
		<pubDate>Tue, 06 Jul 2010 00:25:38 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=268</guid>
		<description><![CDATA[






In May 2009, I joined NetDevil so I could work on LEGO Universe.  After working there for over a year, and as our ship date nears, I thought I would share what the experience has been like.  
LEGO Universe marks a significant number of milestones in my career: first MMO, largest development team, [...]]]></description>
			<content:encoded><![CDATA[<table cellspacing="4" cellpadding="4" width="480" border="0">
<tr>
<td width="480" align="center" valign="top">
<img src="http://www.stephencalenderblog.com/images/LEGO-Universe-Teaser-1.jpg" alt="LEGO Universe Teaser" />
</td>
</tr>
</table>
<p>In May 2009, I joined <a href="http://www.netdevil.com/">NetDevil</a> so I could work on <a href="http://universe.LEGO.com/en-us/default.aspx">LEGO Universe</a>.  After working there for over a year, and as our ship date nears, I thought I would share what the experience has been like. <span id="more-268"></span> </p>
<p>LEGO Universe marks a significant number of milestones in my career: first MMO, largest development team, largest project, most expensive project, and the longest I have worked on a project.  We still want to squeeze in a bunch of work before the initial launch, so the excitement of the release is intertwined with some terror and pressure to get it all done and polished.  </p>
<p><object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/iTEQqmLW4HE&amp;hl=en_US&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/iTEQqmLW4HE&amp;hl=en_US&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;hd=2" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object></p>
<p>If you haven’t checked out the game yet here is the <a href="http://www.youtube.com/watch?v=iTEQqmLW4HE">link for the trailer</a>.  You can even find some really old video actually filmed at the NetDevil Studio showing some of the <a href="http://video.google.com/videoplay?docid=2370734429663567535#">early game ideas </a>.  There was some public in game footage at <a href="http://en.wikipedia.org/wiki/Consumer_Electronics_Show">CES</a> way back in January <a href="http://www.youtube.com/watch?v=ewfVz3_33Nc">part 1</a>  <a href="http://www.youtube.com/watch?v=eQVmLzzYxQo">part 2</a>.  More recently, we just went to <a href="http://en.wikipedia.org/wiki/Electronic_Entertainment_Expo">E3</a> and won several awards there; <a href="http://www.massively.com/">Massively</a>, <a href="http://www.1up.com/">1UP</a>, and <a href="http://www.gamepro.com/">Gamepro</a> all awarded us <a href="http://www.triplepointpr.com/enthusiasm-for-LEGO-universe-builds-at-e3-2010-awards-impressions">best of E3 honors</a>.  Of course there were more interviews and game footage as well, the best of which was probably the <a href="http://g4tv.com/videos/46991/The-MMO-Report-E3-2010-Special-Part-1/">feature on g4tv</a>.  If you just watched any of those and decided that this is something you need to have, <a href="http://shop.LEGO.com/Product/?p=2855133&#038;CMP=KAC-UNIVGOOGUS&#038;HQS=pre-order+LEGO+universe">preorders of the game</a> just became available.  The official launch date has been set, you can begin building, adventuring, and exploring on October 26th, 2010 – although preorders get an early start to the action and can play as early as October 12th. </p>
<p><object classId="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="418" id="VideoPlayerLg46991"><param name="movie" value="http://g4tv.com/lv3/46991" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><embed src="http://g4tv.com/lv3/46991" type="application/x-shockwave-flash" name="VideoPlayer" width="480" height="382" allowScriptAccess="always" allowFullScreen="true" /></object>
<div style="margin:0;text-align:center;width:480px;font-family:Arial,sans-serif;font-size:12px;color:#FF9B00;"></div>
<p>So rewinding back to early 2009, <a href="http://www.semiotictech.com">Semiotic Technologies</a> ran out of work and became insolvent (although we latter received an offer to become acquired that never solidified), so I was in need of a new job.  Despite having made some dear friends in Pittsburgh, I think I was also ready for a change of scenery.  When I originally talked with the people at <a href="http://www.gazillion.com/">Gazillion </a> (the parent company of several studios), they were looking to place me at another studio, <a href="http://www.amazingsociety.com/">The Amazing Society</a>.  I don’t even think that I got to an interview because they canceled the position.  A week or so later they emailed me back asking if I would be interested in interviewing for the LEGO Universe (abbreviated LU) project with NetDevil – YES (obviously).  I probably spent as much time playing with LEGO as I did playing video games when I was a kid.  Fast forward a couple weeks and I was on my way out to Colorado.  </p>
<p>While the LEGO project has some incredible potential, I was still a bit apprehensive about joining the team.  I never wanted to work at a big company (NetDevil has grown to roughly 200 strong presently, the majority of us working on LEGO) for the fear that I would become just another cog in the machine.  Fortunately, NetDevil is pretty good about letting you dip your toes in other areas every now and then.  I was also worried that I would just be told what to do and not really share in the creative process.  I’m not designing anything but there is some decent give and take.  Honestly, there isn’t that big of difference between large and small teams other than the time it takes for decisions to be made, and even with all that extra time we still throw out just as much.  Even though LEGO has some experience with games and we have a good relationship with them I am glad to be rid of client meetings that I had to deal with in my old job.  I do miss being able to call the shots, I don’t have a giant ego, its just that producers and designers are always pushing for new content and it can be frustrating to have to make a case for standard best practices of maintaining a code base.  Besides having more time to focus on programming, the other advantage a larger company has to offer is that you have more opportunities to learn from others. </p>
<table cellspacing="4" cellpadding="4" width="480" border="0">
<tr>
<td width="480" align="center" valign="top">
<img src="http://www.stephencalenderblog.com/images/LEGO-Universe-Teaser-2.jpg" alt="LEGO Universe Teaser" />
</td>
</tr>
</table>
<p>Working on LU is an amazing opportunity for a video game veteran, even more so for me being pretty green to game development at the time I was hired.  Just think about the draw to the LEGO intellectual property and think about the MMO potential.  Any game that I have ever marathon played I eventually got tired of the theme, grinding, or my character class.  LEGO has a seemingly endless number of themes: underwater, pirates, ninjas, space, urban, medieval, mining, combinations thereof, and some I am sure I left out.  Second, LU was beautifully designed to be item based so if you get bored of being whatever you first picked you can switch it up to be just about anything else from the giant catalog of minifigures (there are factions later in the game but you can still be pretty much anything you want).  This is going to be the first LEGO MMO and the first LEGO game were you can actually build brick by brick.  What you see built with LEGO in LEGO Universe you can build in real life; that part of the game world spilling over into reality is shared with other LEGO games.  LEGO Universe is unique in that, at some point in the future, we will even have it set up so you can purchase whatever you build in the game (including instructions on how to assemble it).</p>
<p>LU is not without its challenges.  Making the world safe for kids requires loads of work and labor to upkeep.  In addition, our target demographic of 8-12 rarely have high end computers, if they even have computers of there own.  So, we do our best to reach way back into computer history to make sure the game still runs on very old machines and try to design so you can log in quickly, get to the action and your friends, and are not penalized if you have to log off.  Of course, LU is all about building, and building in the real world is very different from building virtually.  The LEGO bricks in real life have a very nice tactile feeling to them that you just cannot recreate virtually with a keyboard and mouse.  However, there are a number of things you can do virtually that are a pain in the real world.  A computer is much faster at finding the brick you want, no more dealing with bricks that refuse to separate, you don’t have to rip your masterpiece apart to change brick colors, and being able to clone sections of wall or towers actually lets you build faster than in real life after you have had some practice. </p>
<p><object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/Zt8rxOTf7Pk&amp;hl=en_US&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Zt8rxOTf7Pk&amp;hl=en_US&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object></p>
<p>Soon after I joined NetDevil I found out how difficult the road ahead was going to be.  The system I was now responsible for was by far the most broken part of the game.  For a while it was run by someone that didn’t fully understand the proper way to build it, and then for a while no technical person at all.  When my boss started six months or so before I did, the game was grinding to a halt on our code.  My boss removed most of the really horrifying stuff, so by the time I arrived it was just a matter of completely rewriting the system.  I’d like to think that together we turned our piece of the game around, but it was definitely crippling in many respects to start off on such a bad foot.  Just the other day I was removing some of the lingering bad bits (and it promptly cut our execution time in half) and there are still a few left.  Older code, even when it is bad, has a nasty way of ingraining itself into the architecture.  As if fixing the code base wasn’t challenging enough, people opinions are slow to change too.  When a system develops a bad reputation, it continues to be a usual suspect or scapegoat when new problems arise.</p>
<p>My particular role in the development of LEGO Universe is UI programming, not the most glamorous job, but it suites me well.  User Interface has some definite perks, like my code is on screen like 90% of the time, a number I think is only beaten by character animators / programmers.  Despite my technical aptitude, I have a creative side, and I like working with the mix of artists, design, and tech that form a UI team.  It doesn’t hurt that they are all crazy talented.  Some of my favorite moments have been when art and tech need to combine efforts to accomplish effects, animations, and usability.  The other interesting part of UI is the variety, there needs to be an interface for every part of the game, which results in working with many different people and learning how most of the game works.</p>
<p>Brass tacks, day to day I do a bunch of ActionScript 2, which gets into the <a href="http://www.emergent.net/">Gamebryo</a> engine via <a href="http://www.scaleform.com/">Scaleform</a>.  I programmed in AS2 when I was first learning the Flash platform, however, Scaleform throws a few curveballs at you.  Not every feature of AS2 is supported in Scaleform, some functions work differently, and then being a PC game you use a different subset of ActionScript than you normally would for the web.  Every once and a while I do some C++ and Lua to optimize messages, stun the player, call shaders, and get and set data from the database or server.  </p>
<table cellspacing="4" cellpadding="4" width="480" border="0">
<tr>
<td width="480" align="center" valign="top">
<img src="http://www.stephencalenderblog.com/images/LEGO-Universe-Teaser-3.jpg" alt="LEGO Universe Teaser" />
</td>
</tr>
</table>
<p>So what is like to work at NetDevil? You would think that in our information hungry society info about our studio would be blasted all over the web.  Honestly, the <a href="http://www.westword.com/2010-01-07/news/LEGO-universe-colorful-plastic-s-answer-to-world-of-warcraft-is-the-brainchild-of-colorado-based-netdevil/">best article to date</a> was done by our local paper, <a href="http://www.westword.com/">The Westwood</a>.  We converted a warehouse into our workspace in Louisville, Colorado; which is actually really nice, I have heard horror stories from other studios about teams being on different floors or even split into different buildings.  They have an extremely generous benefits package, and feed us all the time (perhaps even too much).  There is a very obvious effort to keep the studio an enjoyable place, its not uncommon for people to stay late to hang out, have a beer, or play video games (although lately it’s been to crunch to meet our release goals). </p>
<p>The support we receive from LEGO is nuts as well.  Usually you deal with clients that just want to get the game out the door; LEGO has stressed the importance for quality since day one and has been willing to bend deadlines to round out the feature list for our launch.  We are looking to be much more polished for our initial release than most typical MMOs.  I’m sure there will still be some lingering bugs that we have to patch, but for the most part we should be ready to have meaningful content updates soon after launch.  It has been very interesting to watch the machinery of LEGO in motion. The marketing arm alone has some very cool plans for the game.  LEGO is also handling the customer service and moderation to keep the game safe and fun for everyone.  LEGO has ensured that our environment inspires us and reminds us what the game is all about; to date NetDevil has received over 10 million LEGO bricks, including one 12-foot tall juggernaut – which I am told similar pieces line the drive to the LEGO headquarters in Billund, Denmark (<a href="http://maps.google.com/maps?hl=en&#038;q=LEGO+billund+denmark&#038;ie=UTF8&#038;hq=LEGO&#038;hnear=Billund,+Denmark&#038;ll=55.732806,9.122126&#038;spn=0,0.001725&#038;t=h&#038;z=19&#038;layer=c&#038;cbll=55.732664,9.122276&#038;panoid=HhKGFN0nrRse9z8h-OHIig&#038;cbp=12,325.78,,0,9.2">check google maps street view</a>).   </p>
<p>It’s a lot of hard work, definitely a labor of love.  Everyone involved is absolutely determined to make LEGO Universe awesome.  I feel very lucky and blessed to be at NetDevil and to be creating a digital world out of one of my most cherished childhood toys.  I’m not entirely looking forward to the late nights ahead of me, but I’ll be able to power though it knowing the joy this game will bring to everyone whose heart has been touched by these little bricks.</p>
<p><object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/zf-U8uM8nOE&amp;hl=en_US&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/zf-U8uM8nOE&amp;hl=en_US&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;hd=2" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object></p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>

<p><a href="http://feedads.g.doubleclick.net/~a/xI6YwdC8-43iajmUj81jw9DWbJ4/0/da"><img src="http://feedads.g.doubleclick.net/~a/xI6YwdC8-43iajmUj81jw9DWbJ4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/xI6YwdC8-43iajmUj81jw9DWbJ4/1/da"><img src="http://feedads.g.doubleclick.net/~a/xI6YwdC8-43iajmUj81jw9DWbJ4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/vzlmuOCfVMc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=268</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=268</feedburner:origLink></item>
		<item>
		<title>Attitudes Towards Video Games</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/F9sQW0P7LQs/</link>
		<comments>http://www.stephencalenderblog.com/?p=245#comments</comments>
		<pubDate>Tue, 01 Jun 2010 13:48:12 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=245</guid>
		<description><![CDATA[I stumbled across this paper that I wrote in 2007 while earning my Master’s at Carnegie Mellon University.  The dichotomy of society’s perception of video games affect on civilization seems to have become even more polarized.  In addition, it has unintentionally gotten funnier over time – this was written just a few months [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled across this paper that I wrote in 2007 while earning <a href="http://www.etc.cmu.edu/">my Master’s at Carnegie Mellon University</a>.  The dichotomy of society’s perception of video games affect on civilization seems to have become even more polarized.  In addition, it has unintentionally gotten funnier over time – this was written just a few months after Rob Blagojevich’s ‘Safe Games Illinois Act’ denouncing amoral games was ruled unconstitutional (I’m so glad we had an ethical guy like Rod in office).  Enjoy. <span id="more-245"></span></p>
<p>It is inherently interesting that the attitudes towards video games reside, at least to the public, in two extreme factions.  One party believes that video game addiction is “…most reckless endangerment of children today … this century&#8217;s most increasingly worrisome epidemic … All the while, the video game industry continues to market and promote hatred, racism, sexism, and the most disturbing trend: clans and guilds” (<a href="http://www.mavav.org/">MAVAV</a>) and range to “Too many of the video games marketed to our children teach them all of the wrong lessons and all of the wrong values” (<a href="http://www.safegamesillinois.org/">Blagojevich</a>).  While the pro games camp, often referred to as hardcore, believes that games are just that, games.  Often rebutting that to draw such extreme conclusions that what you do in a video game has any affect on your life as a whole is laughable, which is evident in Jack Johnson’s sarcasm:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
After playing Tony Hawk: Pro Skater, I went outside and did an ollie, then a kickflip, then a 50/50 nose grind down a twenty-foot steel railing, and then I landed a perfect 900. Videogames have a dark power over you. Did you know that playing Tony Hawk: Underground 2 for just one hour will turn you into a pro skateboarder? It&#8217;s true. We have scientific evidence somewhere to prove this. Furthermore, skateboarding is illegal, and this only goes to show you that videogames will turn your child into a heartless criminal. (<a href="http://www.actiontrip.com/offbeat/videogamesareevil.phtml">Johns</a>)
</div>
<p>It is also something that I have had to deal with personally; being a graduate student in a program designed for placement in the entertainment software industry, I have witnessed first hand comments from both sides of this debate.  Studying these two philosophies towards games is meritorious because it reflects on the audience of games and what effects, actual or believed, video games have on the people who play.  I firmly believe that there is some truth in both sides of this argument and desire to give an unbiased insight of the validity of each group’s claims.</p>
<p>Some individuals believe that video game culture and attitudes towards games is merely a generational gap that will change with time.  An article in The Economist shares this position:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
‘IT IS an evil influence on the youth of our country.’ A politician condemning video gaming? Actually, a clergyman denouncing rock and roll 50 years ago. But the sentiment could just as easily have been voiced by Hillary Clinton in the past few weeks, as she blamed video games for ‘silent epidemic of media desensitization ’and ‘stealing the innocence of our children’(<a href="http://www.economist.com/displaystory.cfm?story_id=4247084">“Breeding evil?”</a>).
</div>
<p>In addition, the article continues to allude to other transitions in media particularly Socrates skepticism of Plato’s stance on the value of written text (<a href="http://www.economist.com/displaystory.cfm?story_id=4247084">“Breeding evil?”</a>).  As intriguing as their acceptance model is, I know that it is not completely accurate.  Anti video game sentiments grow far deeper than generational differences or are merely between gamers and non-gamers.</p>
<p>“You are going to contribute to the downfall of our society” was one response from an undergraduate colleague to my chosen field.  While he did not exactly say why games would cause the unraveling of our culture, I know he believed that video games support an asocial lifestyle.  I can honestly see why he felt that way; many games are single player experiences that can draw attention away from friends and family.  Although appearances can be deceiving, in response to the statement that video games are socially isolating, M.I.T. director of comparative studies, Henry Jenkins states:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
Much video game play is social. Almost 60 percent of frequent gamers play with friends. Thirty-three percent play with siblings and 25 percent play with spouses or parents. Even games designed for single players are often played socially, with one person giving advice to another holding a joystick. (<a href="http://www.pbs.org/kcts/videogamerevolution/impact/myths.html">Jenkins</a>)
</div>
<p>Furthermore, some of the most intriguing and popular games today are games that require players to work together and form communities.  Obviously, experiences in a game are not as rich as an interaction with an actual person, but with the establishment of multiplayer online games, you have a chance to meet people beyond geographical, social, and cultural boundaries.  You have a way to interact with people with whom you would have never met otherwise (although the quality of that interaction is debatable – yes I am talking about you Xbox Live community).  Even the games that are not multiplayer sometimes have sophisticated artificial characters that players can interact with in games.  There is fundamental curiosity that people have in exploring social situations and outcomes, games with these qualities usually did not happen by accident.  Game designers want games to be a safe place for people to experiment and perhaps even learn from all kinds of situations, even social.  All game artisans are aware that we are social beings and successful games incorporate social aspects.</p>
<p>There is also great concern in the world today that people are not active enough, leading increasingly sedentary and indoor lives.  Video games share some blame for this problem.  If you want the richest audio, visual, and technical experience, you are stuck in front of a desktop computer or home console system.  There are exceptions, Nintendo game boys have allowed for mobile gaming for a long time.  Cellular phones and laptops are just as capable of playing games these days.  Beyond just being to take games with you, there have been a number of recent games creating engaging active experiences, most notably Dance Dance Revolution and the Nintendo Wii console.  There are also a number of companies trying to develop memorable experiences for exercise equipment.  For instance, cycling machines networked together into a virtual cycling world could motivate individual physical challenges, let you train with your friend across the country, or compete in virtual online races.  Video games have just begun to scratch the surface on what could be possible to promote physical well being.</p>
<p>One claim that is indisputable is that video games can be addicting.  Some individuals come across a game and they just can not put it down.  This problem seems arise uniquely, a game that is addicting to one person may or may not be addicting to another and addiction can reach varying degrees.  Wired magazine published an interesting article about game addiction:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
Some games are more reviled than others by the loved ones. EverQuest &#8212; or EverCrack as some people call it -– tops the list. Yahoo has two clubs devoted to the sword-and-sorcery game where players slip into the bodies of barbarians and erudites and chase each other around the fantasy world of Norrath: <a href="http://games.groups.yahoo.com/group/spousesagainsteverquest/">Spouses Against EverQuest</a> and <a href="http://health.groups.yahoo.com/group/EverQuest-Widows/">EverQuest Widows</a>. (<a href="http://www.wired.com/news/holidays/0,48479-0.html?tw=wn_story_page_prev2">Scheeres</a>)
</div>
<p>The article goes on to state that at one point EverQuest Widows reached over one thousand members.  Wired pulled some of the more interesting articles off the online forums:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
And then there&#8217;s the business of EQ marriages. In addition to being snubbed for a piece of software, many EQ widows fear getting snubbed for a virtual lover. EverQuest characters frequently marry online and sometimes the romance carries over into real life. </p>
<p>&#8220;It&#8217;s really destroyed a lot of marriages,&#8221; said Tony, whose wife had an affair with her make-believe husband. He allowed her to return home for the sake of their three children. &#8220;I told her that if it happens again, I&#8217;m not going to take her back.&#8221; </p>
<p>Some former players have gone online to preach the evils of gaming themselves. </p>
<p>Jeffrey Stark, a high-school student from Ontario, Canada, wrote an impassioned <a href="http://www.selfpsychology.org/_forum/0000014b.htm">essay</a> in a self-help forum in which he charged that EQ had ruined his life. </p>
<p>When his not-too-tech-savvy parents threatened to unplug the machine, he told them that doing so would destroy it (they believed him). He&#8217;d go for a week without bathing or eating a proper meal. He finally stopped going to school for a semester because he couldn&#8217;t tear himself away. </p>
<p>…</p>
<p>Stark eventually reached the highest EQ levels and sold three characters on eBay for $4,500, he said. Now he advocates that parents regulate their child&#8217;s game playing at all times.(<a href="http://www.wired.com/news/holidays/0,48479-0.html?tw=wn_story_page_prev2">Scheeres</a>)
</div>
<p>Clearly, there have been other games besides EverQuest that have been addicting.  Wired goes on to state in its article that often compulsive playing is masking several underlying symptoms of anger, depression, low self-esteem, and boredom (<a href="http://www.wired.com/news/holidays/0,48479-0.html?tw=wn_story_page_prev2">Scheeres</a>).  There was another article in Time magazine regarding why and how video games can be addicting:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
So is this stuff addictive? Psychologists say some players of intense video games show symptoms similar to those induced by drug taking or other pleasurable activities. Participating in the action of a game&#8211;pushing buttons to score, shoot, bomb, fight or fly&#8211;entails neuromuscular coordination. &#8220;So the brain not only is seeing the images and getting stimulated, but it&#8217;s also practicing a response,&#8221; says Carole Lieberman, a psychiatrist at UCLA. &#8220;When the person is exposed to these violent media stimuli and it excites the psychoneurological receptors, it causes the person to feel this excitement, to feel a kind of high&#8211;and then to become addicted to whatever was giving him the high.&#8221; </p>
<p>This is no secret to game developers. Though none of the game companies TIME contacted was willing to openly discuss violence in e-games, one game developer agreed to talk on the condition that he not be named. &#8220;A video game is all about adrenaline, and the easiest way to trigger adrenaline is to make someone think they&#8217;re going to die,&#8221; he explained. One of the tricks of the trade is to concentrate on the &#8220;blink rate.&#8221; It&#8217;s an old Madison Avenue ad-agency gimmick, he said. &#8220;People stop blinking if an ad has their attention. Same here&#8211;if you&#8217;re into a game, your pupils dilate and your blink rate slows down.&#8221; The body and brain become fully involved&#8211;so much so that dopamine, a neurotransmitter that some believe is the master molecule of addiction, gets produced while you&#8217;re playing. </p>
<p>I&#8217;ve played lots of video games, at times obsessively. Invariably, though, the obsession gives way to boredom. Even the best games run their course. As a gamer, I always find it sort of sad when a favorite title just doesn&#8217;t evoke that old spark anymore. But as parents, we may find that this is the best thing we have working for us. (<a href="http://www.time.com/time/asia/asia/magazine/1999/990510/video3.html">Quittner</a>)
</div>
<p>Where does video game addiction fit into consideration for being a serious problem?  People become addicted to many different things caffeine, nicotine, television, alcohol, gambling, sport teams, texting, sex, beanie babies, pornography, exercise, drugs, collectables, and food are a few examples.  While any obsessive behavior is concerning you must agree that video game addiction is slightly less serious than a drug addiction or an eating disorder.  Whether addictions are appropriate in society or not seems largely based on society views the individual action and the side effects of that action.  Given that the majority of Americans play video games it seems that it is an acceptable addiction.  Although it is depressing to look at some of the results of compulsive gaming, video games could serve as a learning tool.  By dealing with a ‘less serious addiction’ to video games people could potentially avoid or break ‘more serious additions’, or serve as an identifier of a more serious underlying issue.</p>
<p>The largest criticism of video games by far is content; sex, drugs, and violence.  Just like television broadcasts and movies, video games must comply with a ranking system so that people are aware of mature content.  One topic that almost everyone agrees on is that not all games are made for kids, and there are certain games that minors should not play.  There is some disagreement between how minors are exposed to adult content games, but it must be either parents buying the games for their minors without checking the label or retailers selling mature content games to kids.  While Jack Thompson may rub people the wrong way, and as often as I myself disagree with what and how he phrases some things, I do agree with what he says here in his interview with Play.tm:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
All I am trying to do is get the US to the UK (and elsewhere) system that stops the sale of adult games to kids. Very simple. If some idiot parent wants to buy a 9-year-old GTA and give it to him, then that&#8217;s okay, but if the kid then goes next door and batters some neighbour&#8217;s kid, then I would love the lawsuit against the moron parent who ignored the warning and gave his kid a violence simulator that the American Psychological Association has proven results in those types of events. But any policy to stop the sale of adult games to adults? No way. (<a href="http://play.tm/story/8809">Play.tm team</a>)
</div>
<p>And in response to whether some games should be completely banned or not:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
No, of course not. In a free society, adults can pretty much get what they want and should. You gamers need to get off the &#8220;Jack Thompson wants to ban video games&#8221; nonsense. (<a href="http://play.tm/story/8809">Play.tm team</a>)
</div>
<p>If you are eighteen and can be enlisted and go to war, I do not see how you could make a game more violent than that experience.   Thompson’s is not the only one looking at games.  The Governor of Illinois, Rob Blagojevich, passed legislation to ban the sale or rental of games with excessive violence to persons under the age of 18, in excess of the E.S.R.B. ratings already in place. The E.S.A. (Entertainment Software Association) filed suit and the legislation was appealed with this interesting excerpt included:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
An integral part of the court&#8217;s analysis was its concern that the statute would criminalize the sale of material &#8220;without concern for the game considered in its entirety or for the game&#8217;s social value for minors.&#8221; As a case in point, the court looked to the game God of War, which tracks the Homeric epic Odyssey in content and theme. Although that game shows exposed breasts, the court held that &#8220;there is serious reason to believe that a statute sweeps too broadly when it prohibits a game that is essentially an interactive, digital version of the Odyssey.(<a href="http://www.internetcases.com/archives/2006/11/seventh_circuit_1.html">Brown</a>)
</div>
<p>I still remember when Schindler&#8217;s List came out, despite the fact that I was only nine years old, my parents rented it and wanted me to watch it with them.  Some important lessons are violent although no video games come to mind that are quite as moving as Schindler’s List was, at least not yet.  This brings up another interesting point, why are video games eliciting such response when there are other mediums like television and film that are just as violent if not more.   Thompson sums up the opinion well: “… video games are the most dangerous of all violent media, because they are interactive. You actually enter into doing the violence.”(<a href="http://play.tm/story/8809">Play.tm team</a>) Jenkins has similar feelings and adds that completely shielding children from violence would leave them unequipped for the real world:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
Federal Court of Appeals Judge Richard Posner noted: &#8220;Violence has always been and remains a central interest of humankind and a recurrent, even obsessive theme of culture both high and low. It engages the interest of children from an early age, as anyone familiar with the classic fairy tales collected by Grimm, Andersen, and Perrault are aware.&#8221; Posner adds, &#8220;To shield children right up to the age of 18 from exposure to violent descriptions and images would not only be quixotic, but deforming; it would leave them unequipped to cope with the world as we know it.&#8221; Many early games were little more than shooting galleries where players were encouraged to blast everything that moved. Many current games are designed to be ethical testing grounds. They allow players to navigate an expansive and open-ended world, make their own choices and witness their consequences. The Sims designer Will Wright argues that games are perhaps the only medium that allows us to experience guilt over the actions of fictional characters. In a movie, one can always pull back and condemn the character or the artist when they cross certain social boundaries. But in playing a game, we choose what happens to the characters. In the right circumstances, we can be encouraged to examine our own values by seeing how we behave within virtual space. (<a href="http://www.pbs.org/kcts/videogamerevolution/impact/myths.html">Jenkins</a>)
</div>
<p>Parents should always watch what their kids are playing, and if it is an online multiplayer game who they are playing with, just like how they should watch with mediums like television, movies, and the internet.  Violence can be acceptable for minors if done for the appropriate reasons and some violence may even be necessary to help young people deal with the real world.</p>
<p>So far, I have painted a practically ideal picture of games, but I would be lying if I did not admit that there are many ugly games out there that are nothing but pointless gratuitous shooting and fighting.  Legally the first amendment protects these games but that really is not what bothers people.  Many people believe that violence in these kinds of games, regardless of age, desensitizes people to violence.  Many of these sentiments are not new either, there were questions raised about games even in the early 1980’s:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
As far back as 1982, when video games consisted of simple fare like Space Invaders—a two-dimensional arcade game—a rabbi warned on The MacNeil/Lehrer NewsHour about their dehumanizing effects: “When children spend hours in front of a screen playing some of these games that are inherently violent, they will tend to look at people as they look at these little blips on the screen that must be zapped—that must be killed before they are killed. And it is my concern that 10, 20 years down the line we’re going to see a group of children who then become adults who don’t view people as human beings, but rather view them as other blips to be destroyed—as things.” (<a href="http://www.wilsoncenter.org/index.cfm?fuseaction=wq.essay&#038;essay_id=193155">Suellentrop</a>)
</div>
<p>There is a large abstraction to go from pixilated space invaders to people, but as games have grown more lifelike do gamers still rationalize the difference between games and reality?  Nate Anderson describes a study in an article on video game violence: “Desensitization can be a good thing. It&#8217;s the body&#8217;s way of filtering out repeated stimuli, and it&#8217;s a necessary part of surgical training and warfare”(<a href="http://arstechnica.com/news.ars/post/20060726-7356.html">Anderson</a>).  People worry that being exposed to violence and taking part in violence in video games would make you more accepting of real violence, criminal acts, and drugs.  This has been such a source of concern that there have been hundreds of tests done with various conclusions; despite the fact that it is nearly impossible to come up with and accurate methodology to test this hypothesis, most tests only judge the short-term effects when really almost all that matters are long-term effects.  Virtually all studies conducted do not publish their full findings or statistics which leads you to believe that their findings were unsound and are twisting the results to whichever side of the argument that they were on.  One of the more unbiased studies I came across was done by Dr. Sonya Brady a postdoctoral fellow in the Health Psychology Program at the University of California, San Francisco.  Her only motives were that she wanted to teach her students research methodology with a controversial and relevant topic.  While their results, which the statistics are not available for, “concluded that exposure to videogame violence led to more aggressive thoughts and behavior” (<a href="http://www.gamespy.com/articles/702/702785p3.html">Kuo</a>) she also mentions:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
I think it&#8217;s important to understand that researchers are not claiming that every person who plays a violent videogame will become more aggressive, have more permissive attitudes towards alcohol or marijuana use, etc. Rather, the studies show that groups of people exposed to more violent forms of media may, on average, behave more aggressively, have more permissive attitudes towards alcohol or marijuana use, etc., in comparison to groups of people exposed to less violent forms of media.(<a href="http://www.gamespy.com/articles/702/702785p3.html">Kuo</a>)
</div>
<p>Not everyone that plays a violent video game will become more permissive towards what is displayed in the game.  Jenkins states “…no research has found that video games are a primary factor or that violent video game play could turn an otherwise normal person into a killer.” (<a href="http://www.pbs.org/kcts/videogamerevolution/impact/myths.html">Jenkins</a>) However, he will not say how something like that can be incredibly difficult to prove.  If games actually do condition you to be violent, the release of America’s Army, a video game from the department of defense, is very frightening.  An article about the release of the game reads:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
Psychology professor Brad Bushman of the University of Michigan&#8217;s Institute for Social Research hasn&#8217;t played &#8220;America&#8217;s Army,&#8221; but he&#8217;s no fan. &#8220;As a taxpayer,&#8221; he said, &#8220;I&#8217;m not very happy about it.&#8221;<br />
Video games such as &#8220;America&#8217;s Army&#8221; that rely on teamwork &#8220;may teach people how to coordinate better, but they also teach people how to behave more violently and aggressively,&#8221; he said. Players identify with the violent character they control, Bushman added, and they become desensitized to the on-screen mayhem. &#8220;After a medical school student does his first autopsy, it gets easier and easier every time.&#8221;<br />
…<br />
Soldiers were videorecorded in simulated action &#8220;because soldiers move differently than actors, giving the game more realism,&#8221; Wardynski said, and their motions were transferred into the game using the Unreal 2 game engine. Missions and locations were taken from real life, including action in Iraq and Afghanistan, although terrain and events were altered in some cases. (<a href="http://www.notinourname.net/resources_links/video-game-7nov03.htm">Gwinn</a>)
</div>
<p>The Department of Defense has a long tradition of using video games to help train soldiers, in a variety of different areas including shooting.  It would be conceivable that video games are raising a generation of soldiers.  At this point, gamers would refute this line of thought with remarks about their personal experiences, about how games did not have any effect on themselves so this could not possibly be true.  Gamers become very defensive about this topic.  After all, the player is the one controlling the game, to infer that the game could be controlling the player is absurd; or is it?  Good games give the player a sense of power, and part of the novelty of video games is that you can play with situations that would be dangerous or impossible in reality.  Most good games also practice a technique termed indirect control.  Using lighting, scale, and other audiovisual cues that are subtle or subliminal players are lead throughout a world.  The goal of this technique is to guide players through the more interesting parts of the game without them realizing that they are being helped.  Games can definitely control people inside their worlds, but do they have any bearing on what happens outside of the game?  There have been several cases where video games have been involved in violent and deadly incidents.  In 2005 a man was stabbed to death because he sold a friend’s virtual sword (<a href="http://news.bbc.co.uk/2/hi/technology/4072704.stm">BBC News</a>).  Researchers are constantly trying to answer the role of violent behavior and playing video games.   Among all of this debate, some scientists and psychologist have looked to other simpler models in nature.  Humans are not the only animal that plays, almost any nature program will show animal young mock fighting.  Even domesticated pets have what seem to be playful wrestling matches.  Jenkins describes this phenomenon:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
Classic studies of play behavior among primates suggest that apes make basic distinctions between play fighting and actual combat. In some circumstances, they seem to take pleasure wrestling and tousling with each other. In others, they might rip each other apart in mortal combat. Game designer and play theorist Eric Zimmerman describes the ways we understand play as distinctive from reality as entering the &#8220;magic circle.&#8221; The same action — say, sweeping a floor — may take on different meanings in play (as in playing house) than in reality (housework). Play allows kids to express feelings and impulses that have to be carefully held in check in their real-world interactions. Media reformers argue that playing violent video games can cause a lack of empathy for real-world victims. Yet, a child who responds to a video game the same way he or she responds to a real-world tragedy could be showing symptoms of being severely emotionally disturbed.(<a href="http://www.pbs.org/kcts/videogamerevolution/impact/myths.html">Jenkins</a>)
</div>
<p>I would like to believe that most children have at least the same amount of reasoning capabilities as a primate.  It may very well be that play fighting is so deeply ingrained in our psyche that we cannot resist fulfilling that instinct.  The E.S.A. always likes to point out several national trends, since the 1990’s video game usage has gone up and violence, particularly among the young, has gone down.  While the relationship between these to events is not known, it seems probable that video games may have a very importance social niche in dissipating violent play needs.  The boundaries between play and reality seem to be intrinsic.  Play is fun because there are few negative real life consequences; it is fun because of the very fact that it is not reality.</p>
<p>The final controversy worth noting is the idea that even if video games are not bad, they are a waste of time with no personal benefit whatsoever.  Admittedly, there are some games that exist without any redeeming qualities, the so-called ugly games.  Although games are entertainment and are supposed to be leisure activities, they are not completely without merit.  Chris Suellentrop wittily remarks about the history of this debate:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
Despite their popularity, video games remain, in the opinion of many (particularly those who don’t play them), brainless or, worse, brain-destroying candy. But for as long as critics have decried video games as the latest permutation in a long line of nefarious, dehumanizing technologies, others have offered a competing, more optimistic vision of their role in shaping American society. Opposite the rabbi on that MacNeil/Lehrer broadcast a quarter-century ago was Paul Trachtman, an editor for Smithsonian magazine, who argued that video games provide a form of mental exercise. Ignore the dubious content, the “surface or the imagery or the story line,” he suggested, and you will see that games teach not merely how best to go about “zapping a ship or a monster.” Underneath the juvenilia is “a test of your facility for understanding the logic design that the programmer wrote into the game.” Games, in short, are teachers. And electronic games are uniquely suited to training individuals how to navigate our modern information society (<a href="http://www.wilsoncenter.org/index.cfm?fuseaction=wq.essay&#038;essay_id=193155">Suellentrop</a>).
</div>
<p>As video games have grown up, so have their capabilities for being good as stated in The Economist:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
So are games good, rather than bad, for people? Good ones probably are. Games are widely used as educational tools, not just for pilots, soldiers and surgeons, but also in schools and businesses (<a href="http://www.economist.com/displaystory.cfm?story_id=4246109">see article</a>). Every game has its own interface and controls, so that anyone who has learned to play a handful of games can generally figure out how to operate almost any high-tech device. Games require players to construct hypotheses, solve problems, develop strategies, learn the rules of the in-game world through trial and error. Gamers must also be able to juggle several different tasks, evaluate risks and make quick decisions. One game, set in 1930s Europe, requires the player to prevent the outbreak of the second world war; other games teach everything from algebra to derivatives trading. Playing games is, thus, an ideal form of preparation for the workplace of the 21st century, as some forward-thinking firms are already starting to realise.(<a href="http://www.economist.com/displaystory.cfm?story_id=4247084">&#8220;Breeding evil?&#8221;</a>)
</div>
<p>Video games have been developed to educate and teach peace to Palestinians and Israelis.  The development of video games have allowed for construction of complex simulators to train firefighters and police in Hazmat procedures that would have been too expensive to do otherwise.  In a world bent on instant gratification, Suellentrop offers this insight about games:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
The best video games are brilliantly designed puzzles. The Grand Theft Auto titles can take as long as 60 hours to complete. Finishing them requires discipline, problem solving, decision making, and repeated trial and error.<br />
In a recent New York Times column, David Brooks suggested that delayed gratification is the key to success in school, work, and life, and that it is a learned trait. If that’s true, and if the mental gymnasium of video games teaches delayed gratification, then gamers should be, on average, more successful than nongamers. No researcher has proffered that comprehensive a thesis yet, but the authors of Got Game: How the Gamer Generation Is Reshaping Business Forever suggest that gamers do come out ahead in the world of business (<a href="http://www.wilsoncenter.org/index.cfm?fuseaction=wq.essay&#038;essay_id=193155">Suellentrop</a>).
</div>
<p>The other statistic that gamers enjoy referencing is that while video games are gaining popularity the average IQ has been rising.  Games have the potential to be incredible educators ‘The important thing to find out about video games isn’t whether they are teachers. ‘The question is,’ as game designer Raph Koster writes in A Theory of Fun for Game Design (2004), ‘what do they teach?’  (<a href="http://www.wilsoncenter.org/index.cfm?fuseaction=wq.essay&#038;essay_id=193155">Suellentrop</a>).”</p>
<p>Whether the results of all of the tests and studies are correct really does not matter.  Time and money would not be spent on these endeavors unless people believed that there was evidence in the first place.  Even then, there exist people who no level of convincing will change their mind.  Suppose that tests confirmed that video games could make people more violent and desensitized.  Would that not also conclude that video games have the power to make people less violent and more caring?  Optimism of video games potential is seen on both sides of the controversy.   Jack Thompson’s stance is that:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
…video games are a neutral technology. You can electrify or incinerate a city with nuclear fission. The fission is not the problem. The problem is what you do with it. Likewise, video games are tremendous teaching tools, because of their powerful nature, but what we do with them is what is problematic (<a href="http://play.tm/story/8809">Play.tm team</a>).
</div>
<p>Similarly, Dr. Brady&#8217;s opinion is:</p>
<div class="quote" style="border: 1px solid #208A06; background-color: #EEEEEE; font-size:0.8em; width:350px; margin-left:50px; padding-right:25px; padding-left:25px;">
I have mixed feelings about videogames. I think they have the potential to be positive educational tools and to reinforce skills necessary for success later in life. For example, some children&#8217;s games help to reinforce mathematical concepts. More advanced games for adolescents and adults model economics and help to reinforce the idea of spending within one&#8217;s means financially and cooperating with other members of one&#8217;s community. Games that feature the frequent use of violence model a problem solving strategy that is not very successful in the long run (<a href="http://www.gamespy.com/articles/702/702785p3.html">Kuo</a>).
</div>
<p>Consumers also mimic this response with their spending habits.  While violent games may be more publicized some of the most popular games of 2006 were sports titles.  Game artisans are still discovering how their medium can be used.  Based on the development of video games since their inception, I am optimistic that they will continue to show benefits to society.  There are instances where games can be misused, but it pales in comparison to how much good can be done.</p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>
<p>Works Cited</p>
<p>Anderson, Nate. “Violent video games numb players to real violence.”  Ars Technica.  26 July 2006.  1 Feb. 2007 <<a href="http://arstechnica.com/news.ars/post/20060726-7356.html">http://arstechnica.com/news.ars/post/20060726-7356.html</a>>.</p>
<p>Blagojevich, Rod.  “Governor Blagojevich’s initiative that ban minors from buying violentand sexually explicit video games”.  SafeGamesIllinois.org.  1 Feb. 2007 <<a href="http://www.safegamesillinois.org/">http://www.safegamesillinois.org/</a>>.</p>
<p>“Breeding evil?”  Economist.com.  4 August 2005.  1 Feb. 2007 <<a href="http://www.economist.com/displaystory.cfm?story_id=4247084">http://www.economist.com/displaystory.cfm?story_id=4247084</a>>.</p>
<p>Brown, Evan.  “Seventh Circuit: explicit video game law unconstitutional – Ban of sale to minors and labeling requirements not narrowly tailored to meet compelling state interest.”  InternetCases.com.  27 November 2006.  1 Feb. 2007.  <<a href="http://www.internetcases.com/archives/2006/11/seventh_circuit_1.html">http://www.internetcases.com/archives/2006/11/seventh_circuit_1.html</a>>.</p>
<p>“Chinese gamer sentenced to life: A shanghai online gamer has been given a suspended death sentence for killing a fellow gamer.”  BBC News. 8 June 2005.  1 Feb. 2007.  <<a href="http://news.bbc.co.uk/2/hi/technology/4072704.stm">http://news.bbc.co.uk/2/hi/technology/4072704.stm</a>>.</p>
<p>“Facts and Research: Game Player Data.”  ESA.  1 Feb. 2007 <<a href="http://www.theesa.com/facts/">http://www.theesa.com/facts/</a>>.</p>
<p>Ferlazzo, Mike.  “ISU psychologists produce first study on violence desensitization from video games.”  Iowa State University.  24 July 2006.  1 Feb. 2007.  <<a href="http://www.iastate.edu/~nscentral/news/06/jul/desensitized.shtml">http://www.iastate.edu/~nscentral/news/06/jul/desensitized.shtml</a>>.</p>
<p>Gwinn, Eric.  “Army targets you with video game.”  Not in our Name.  7 November 2003.  Chicago Tribune.  1 Feb. 2007.  <http://www.notinourname.net/resources_links/video-game-7nov03.htm>. (this webpage is no longer available)</p>
<p>Jenkins, Henry.  “Reality Bytes: Eight Myths About Video Games Debunked.”  PBS. 1 Feb. 2007.  <<a href="http://www.pbs.org/kcts/videogamerevolution/impact/myths.html">http://www.pbs.org/kcts/videogamerevolution/impact/myths.html</a>>.</p>
<p>Johns, Jackson.  “Video Games are Evil.”  ActionTrip.  1 Feb. 2007.  <<a href="http://www.actiontrip.com/offbeat/videogamesareevil.phtml">http://www.actiontrip.com/offbeat/videogamesareevil.phtml</a>>.</p>
<p>Kuo, Li C.  “Dr Sonya Brady on Violence in Gaming.”  Gamespy.  24 April 2006.  31 Jan. 2007 <<a href="http://www.gamespy.com/articles/702/702785p3.html">http://www.gamespy.com/articles/702/702785p3.html</a>>.</p>
<p>MAVAV Mothers Against Videogame Addiction and Violence.  1 Feb. 2007 <<a href="http://www.mavav.org/">http://www.mavav.org/</a>>.</p>
<p>Play.tm team, The. “Jack Thompson Interview.”  Play.tm.  4 January 2007.  1 Feb. 2007. <<a href="http://play.tm/story/8809">http://play.tm/story/8809</a>></p>
<p>Quittner, Joshua. “Are Video Games Really So Bad?  They mesmerize children.  They frighten parents.  But take heart: there are ways to tame the monsters in the box.”  TIMEasia.com.  1 Feb. 2007 <<a href="http://www.time.com/time/asia/asia/magazine/1999/990510/video3.html">http://www.time.com/time/asia/asia/magazine/1999/990510/video3.html</a>>.</p>
<p>“S Korean dies after games session: A South Korean man has died after reportedly playing an online computer game for 50 hours with few breaks.” BBC News.  10 August 2005.  1 Feb. 2007.  <<a href="http://news.bbc.co.uk/1/hi/technology/4137782.stm">http://news.bbc.co.uk/1/hi/technology/4137782.stm</a>>.</p>
<p>Scheeres, Julia.  “The Quest to End Game Addiction.”  Wired News.  5 December 2001.  1 Feb. 2007  <<a href="http://www.wired.com/news/holidays/0,48479-0.html?tw=wn_story_page_prev2">http://www.wired.com/news/holidays/0,48479-0.html?tw=wn_story_page_prev2</a>>.</p>
<p>Sieberg, Daniel.  “War games: Military training goes high-tech.”  CNN.com.  23 November 2001.  1 Feb. 2007.  <<a href="http://archives.cnn.com/2001/TECH/ptech/11/22/war.games/index.html">http://archives.cnn.com/2001/TECH/ptech/11/22/war.games/index.html</a>>.</p>
<p>Suellentrop, Chris.  “Are Video Games Evil?”  Woodrow Wilson International Center for Scholars.  Summer 2006.  1 Feb. 2007.  <<a href="http://www.wilsoncenter.org/index.cfm?fuseaction=wq.essay&#038;essay_id=193155">http://www.wilsoncenter.org/index.cfm?fuseaction=wq.essay&#038;essay_id=193155</a>>.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/17E4Q8JjyKgTk3Mx9KMciuhFY6Y/0/da"><img src="http://feedads.g.doubleclick.net/~a/17E4Q8JjyKgTk3Mx9KMciuhFY6Y/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/17E4Q8JjyKgTk3Mx9KMciuhFY6Y/1/da"><img src="http://feedads.g.doubleclick.net/~a/17E4Q8JjyKgTk3Mx9KMciuhFY6Y/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/F9sQW0P7LQs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=245</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=245</feedburner:origLink></item>
		<item>
		<title>Flash Particle System</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/j0XP3TutDQo/</link>
		<comments>http://www.stephencalenderblog.com/?p=213#comments</comments>
		<pubDate>Sun, 02 May 2010 00:57:22 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[ActionScript 3.0]]></category>

		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=213</guid>
		<description><![CDATA[


AC_FL_RunContent = 0;


	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '200',
			'height', '200',
			'src', 'ParticleTeaser',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'ParticleTeaser',
			'bgcolor', '#000000',
			'name', 'ParticleTeaser',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', 'ParticleTeaser',
			'salign', ''
			); //end AC code
	}


	
	




A particle system is the quintessential video game effect used for clouds, fog, mist, smoke, rain, snow, fire, explosions, dust, debris, sparks, [...]]]></description>
			<content:encoded><![CDATA[<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="210" align="center" valign="top">
<script language="javascript">AC_FL_RunContent = 0;</script><br />
<script src="AC_RunActiveContent.js" language="javascript"></script><br />
<script language="javascript">
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '200',
			'height', '200',
			'src', 'ParticleTeaser',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'ParticleTeaser',
			'bgcolor', '#000000',
			'name', 'ParticleTeaser',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', 'ParticleTeaser',
			'salign', ''
			); //end AC code
	}
</script><br />
<noscript><br />
	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="200" height="200" id="ParticleTeaser" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="ParticleTeaser.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="ParticleTeaser.swf" quality="high" bgcolor="#000000" width="200" height="200" name="ParticleTeaser" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /><br />
	</object><br />
</noscript></p>
</td>
<td width="260" align="left" valign="top">
<p>
A particle system is the quintessential video game effect used for clouds, fog, mist, smoke, rain, snow, fire, explosions, dust, debris, sparks, magic, spray, splatter, and other phenomenon.  They have been around since the early 1980s, William T. Reeves is the inventor, but its most notable debut to the public was when the group that eventually became Pixar (employed by Lucasfilm Ltd. at the time) used a particle system in <a href="http://www.youtube.com/watch?v=3AU_GnIxanM&#038;feature=related">Star Trek: The Wrath of Khan (1982)</a> for the ‘genesis effect’.  It is mystifying that such a classic creative tool is missing from Flash.
</p>
</td>
</tr>
</table>
<p><span id="more-213"></span></p>
<p>Real time particle systems have been used in games for years and there are loads of knowledgeable resources, as well as source code, available.  I stuck close to <a href="http://www.pixar.com/companyinfo/research/pbm2001/pdf/notesc.pdf ">Pixar’s ‘Physically Based Modeling: Particle System Dynamics’ by Andrew Witkin</a>.  If you are looking for some code to get you started there are a number of open source particle systems for Flash, I did not look at the code myself but it looks like Richard Lord took the correct approach in his <a href="http://www.bigroom.co.uk/blog/flint-as3-particle-system">‘Flint’ particle system</a>.  </p>
<p>This is some of the most optimized Flash code that I have written.  On my minimum spec machine (the 8 year old dinosaur aka <a href="http://www.stephencalenderblog.com/?p=7">‘Computer A’ from my benchmarking series</a>) the system can crank out 2000 simple point particles, my average specification machine has no problem running 5500 point particles with multiple forces (assuming you want to stay at 60fps).  Honestly, what can you really do with just points? All I can think of is some cheap sparks and lame rain and snow.  The real mark of a high quality particle system is having enough features so you can create convincing effects with few particles, not the volume of particles it can handle.  I really wanted to hit the 10,000 particle at 60fps mark, but in order to do so I would have needed to strip out some important functionality.  I will talk about some of the special features of this particle system, if you are inspired to write your own, but this article is mainly about optimization tactics for any large system in Flash - using the particle system as an example.</p>
<p>All right, first a couple quick notes of the basics of setting up a Flash particle system.  All of my particles exist inside of one bitmap; this is what I was referring to earlier as the correct approach to a Flash particle system.  If you want to draw something besides just points in a bitmap, you need to write your own drawing routines and pixel blending code (the bitmap draw method isn’t going to cut it). You really do not have any other alternative. Using a sprite to represent a particle is going to have a very steep initialization cost and bloat the render tree.  The other option would be to use the graphics class on one sprite, but there is no render point and you do not want render a vector shape that complex.  Rendering is going to take the bulk of the CPU time so you really need to go with the fastest option here, not the easiest.  Rendering a point in a bitmap is trivial and you can look up <a href="http://en.wikipedia.org/wiki/Alpha_Blend">how to alpha blend two colors</a>.  By the way, I am incredibly annoyed that bitmaps store color data pre-multiplied but when you get and set values it gives and expects un-multiplied – which means that I have to do a divide every time I blend colors and that flash is internally wasting a bunch of time translating values.  I used the <a href="http://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm">Xiaolin Wu algorithm for drawing lines</a>, and wrote my own sphere and light drawing routines.</p>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="210" align="center" valign="top"><img src="http://www.stephencalenderblog.com/images/EditorStrip.jpg" alt="Flash Particle System Editor" /></td>
<td width="260" align="left" valign="top">
<p>
 The hidden cost of writing a particle system is that you need to write a particle system editor to go with it.  There are so many options and settings that having to recompile every time to test will cripple your iteration time, you need real time feedback, think about it as efficiency for the user.  It was a significant time sink since I needed to write custom user interface widgets for things like selecting an angle, a 3D orientation selector, and a widget to show color interpolation over time.  The most valuable feature is that it generates code for me, so I do not have to copy down settings by hand.  It was a significant time sink for me, so keep that in mind if you plan to write your own system.
</p>
<p>
Before we get to optimization strategies there are two advanced features I want to mention briefly: vortex forces and a more sophisticated method for updating particle positions. I had trouble finding sources on vortex forces that were not concerning the vorticity advection process of fluids (which is an n-squared problem and requires inter particle forces or voxels which this system was trying to avoid calculating).
</p>
</td>
</tr>
</table>
<p>Once you have your force components properly aligned, creating vortexes, which are typically crafted as cylinders in three-space, it is actually easier than you would think.  In order to create the proper vector field, the force in the direction of the center of the vortex (the normal force) needs to equal the force orthogonal to it causing the spin.  Those two forces can be scaled relative to the distance to the singularity (the center of the vortex). </p>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="260" align="left" valign="top">
<p>
 While you want to increase the forces as you approach the singularity, you will also want to construct some kind of die off to prevent particles uncharacteristically jettisoning themselves from the pull of the vortex.  If you were trying to mimic the shape of a vortex similar to natural occurring phenomenon, like a tornado or whirlpool, you would want a force in the direction of the orientation of the cylinder as well, which would increase as you approach the singularity.  Accurately moving particles through the vector field is the challenging part.
</p>
</td>
<td width="210" align="center" valign="top">
<img src="http://www.stephencalenderblog.com/images/IrrotationalVectorField.jpg" alt="Vector Field" />
</td>
</tr>
</table>
<p>Moving an object through a complex vector field is a tough concept to wrap your head around if you have not studied calculus.  Even tougher, we need to approximate an unknown, and often changing vector field based on our known forces.  This involves an area of mathematical relationships called differential equations.  Taking an Euler step (the classic position, velocity, and acceleration relationship from introductory physics that assumes constant acceleration) is akin to a linear approximation forward in time based on the forces in the object’s current position.  The calculus informed reader will recognize this as approximating a function based on its derivative.  If you only need forces that act uniformly on all particles, like gravity, Euler integration is fine.  If you are trying to model a space that contains non-uniform forces, you need an approximation with less error.  Runge-Kutta of order 4, often abbreviated as RK4, is the common method for calculating positions through these kinds of vector fields.  If you computed an Euler step, evaluate the vector field again at the midpoint of the Euler step, and moved forward in time based on the midpoint value – that would be Runge-Kutta of order 2.  If you are interested in more information, I would again suggest Pixar’s Physically Based Modeling series <a href="http://www.pixar.com/companyinfo/research/pbm2001/pdf/notesb.pdf">‘Physically Based Modeling: Differential Equation Basics’ by Andrew Witkin and David Baraff</a>.  </p>
<p>This first optimization tip is not specific to Flash, but is going to be critical to any large system’s performance.  Take the time to analyze your math, often some simple factoring can save a ton of cycles.  The other major mathematical optimization comes from revising your project’s math and identifying where you need full accuracy and where it is acceptable to increase performance by using an approximation.  As I mentioned before, I wrote all of my own drawing routines for the particle system.  Drawing the anti-aliased edge of a circle represents a particularly weighty math problem that I needed to speed up.  Finding the area that a pixel overlaps the edge of a circle requires a rather complex integral.  </p>
<p>A quick refresher, a circle whose center is at the origin satisfies the equation:<br />
<img src="http://www.stephencalenderblog.com/images/circleEquation.jpg" alt="y^2 + x^2 = r^2" /><br />
where ‘r’ is the radius of the circle.  Rearranged we have:<br />
<img src="http://www.stephencalenderblog.com/images/circleEquationRearanged.jpg" alt="y = +/- (r^2 - x^2)^(1/2)" /><br />
from here on out we will only worry about the positive case.  The integral of that function is particularly nasty:<br />
<img src="http://www.stephencalenderblog.com/images/circleEquationIntegral.jpg" alt="circle integral" /><br />
Not only are arcsine and square roots computationally expensive, they also have limited domains.  You would have to watch for rounding errors that could result in returning NaN.  I desired something faster.  I calculated this approximating function:<br />
<img src="http://www.stephencalenderblog.com/images/approxCircleEquation.jpg" alt="circle function approximation" /><br />
which approximates the curvature of the positive semi-circle with an average relative error margin of 2%; and has a much nicer continuous integral:<br />
<img src="http://www.stephencalenderblog.com/images/approxCircleEquationIntegral.jpg" alt="circle function approximation integral" /></p>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="210" align="center" valign="top"><img src="http://www.stephencalenderblog.com/images/circleFunctionGraphs.jpg" alt="Comparing circle approximation with actual" /></td>
<td width="260" align="left" valign="top">
<p>
which, with some intelligent factoring,  can be coded to execute 10 times faster than the actual integral.  I am sure that those of you that favor accuracy are crying out in protest; however, a 2% relative error is well below the tolerance the human eye can detect.  Furthermore, pixels are squares; we are using squares to represent a curve, so you might as well discard the notion of being perfectly accurate.  Circles have to be large before the approximation function can actually contribute to the shape and you can see artifacts.
</p>
</td>
</tr>
</table>
<p>Particles are usually tiny, so tiny that pixels usually cover large portions of the curve and you are comparing relative luminosity of pixels, not overall shape.</p>
<p>The other trick to quickly rendering spheres and light is to use symmetry.  You have an object that is symmetric about both the x and y axis (assuming it is centered at the origin).  You only need to do the math for one quadrant and you can mirror the results to the other quadrants, which will quarter the work that needs to be done.</p>
<p>Just about every property of my particle system can have a linear or normal distribution variance applied to it (initial speed, mass, lifespan, color, initial position, etc).  In the worst case, I need 36 random numbers per birthed particle.  That is not crazy expensive, but that cost is completely avoidable.  The quality of the random numbers here is not that important, I can cache a bunch of random numbers in advance.  I picked a reasonably large prime, 7001, and stored that many random numbers in a circularly linked list, and I just iterate through that list as I need random numbers.  Situations like that are rare though, typically you will only find yourself caching the common cases of expensive operations.  For example, in my circle drawing code, in the cases where a circle is only rendered in 5 or 9 pixels I stored the values for the min and max pixel coverage and linearly interpolate between them to avoid the integral calculation entirely.</p>
<p>An underlying theme I have discovered with Flash is that you are often better off writing your own code than trusting Adobe’s classes and functions, data structures are no exception. Unless you absolutely need random access, you should switch to a <a href="http://en.wikipedia.org/wiki/Linked_list">linked list</a>.  Reading a property on a class is faster (3 to 6 times faster) than reading a value from an array.  Linked lists scale much better if you are storing large objects, and you no longer have to deal with the uncertainty of Adobe’s sort function (they will not tell us what algorithm they use, but it has to be some kind of <a href="http://en.wikipedia.org/wiki/Quick_sort">quick sort</a> since it fails hard when data is nearly sorted).  I implemented and benchmarked several different sorts and got the best performance from <a href="http://en.wikipedia.org/wiki/Merge_sort">tiled merge sort</a>, it was always faster than array sort function for particles (12 times faster when particles were nearly sorted – which they usually are since they are sorted every frame).  It is annoying to have to write, you can find examples in nearly any beginning programming textbook and on the web, but resulted in huge performance gains when I switched.</p>
<p>Memory issues tend to trip up many Flash programmers; usually we don’t make systems that are that large or complex enough to really worry about memory.  We tend to get into a bad habit of casually creating new variables and objects whenever and wherever we need them.  Anytime you are creating and destroying a large amount of objects a little efficiency alarm should go off in your head.  Memory allocation and de-allocation are expensive processes, and there is no sense in freeing an object from memory when you are going to be creating another one right away.  For example, when a particle reaches the end of its lifespan, I store it; when I need to insert new particles in the system, I go to my dead particle list to revive one with new values.  I only create new particle when that dead particle list is empty.</p>
<p>Frequently called functions require careful design and attention to memory use, mainly because ActionScript 3 does not have a compiler directive to inline functions. I have several routines called per particle every frame (accumulate forces, calculate new position, figure out your color), and I have a pixel blending function called many times per particle.  You could easily create many local variables per particle across several functions, flooding memory with tens of thousands of references to be deleted, which can cause your frame rate to falter when garbage collection cycles.  Keep in mind that you are creating a variable for each parameter in the function call, not just when you use the var statement in the function body.  With inline not being an option, and my out right refusal to inline by hand, I revised all of the frequently used functions to use permanently declared class variables (and I made them static as well since we don’t have to worry about concurrency since Flash can’t do that either).  I looked into the performance difference between local and class variables.  A rough rule of thumb is that a local variable would need to be referenced 10 times for reference speed gain out weighs its creation cost, and that value is conceivably higher since we cannot measure the time to remove it from memory. For those not familiar with ActionScript, memory de-allocation is a delayed process that a garbage collector handles (if you assume it equals the creation time the rule would be 20 references for a local variable to pull its weight).  If there are minimal references, class variables will be faster than local variables because of the time it takes to create them.</p>
<p>Reusing work done in previous frames can be an extremely powerful optimization tactic.  Consider the problem of modeling decaying mass of particles, which you would want to do if you were modeling a chemical reaction like combustion.  In sphere and light render modes a particle’s size is determined by its radius, but the relationship between mass and the radius requires a cubed root.<br />
<img src="http://www.stephencalenderblog.com/images/VolumeEquations.jpg" alt="Sphere Volume Radius Relationship" /></p>
<p>It would be nice to avoid doing such an expensive calculation on every particle.  There have been many clever solutions to calculating roots efficiently.  The best of which was first implemented for <a href="http://en.wikipedia.org/wiki/Fast_inverse_square_root">lighting in Quake 3 by Gary Tarolli</a> that leverages the way that numbers are stored as data to get a very close approximation and then applies an iteration of <a href="http://en.wikipedia.org/wiki/Newton%27s_method">Newton’s Method</a>.  Unfortunately, this is Flash and we cannot access the sign, exponent, and mantissa bits of a Number object, but that is no reason to give up.  In fact, we can code a more exact approximation that, if all languages were created equal, is less computationally expensive.  The trick – we just calculated the cubed root on the last frame (which should be 1/60th of a second ago) and we can use that value as our approximation.  </p>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="210" align="center" valign="top">
<img src="http://www.stephencalenderblog.com/images/HalleyApproximation.jpg" alt="Halley's Method Approximation" /><br />
<img src="http://www.stephencalenderblog.com/images/HalleyApproximationExponential.jpg" alt="Halley's Method Approximation Exponential" />
</td>
<td width="260" align="left" valign="top">
<p>
 We can do better than Newton’s Method too, upgrading to <a href="http://en.wikipedia.org/wiki/Halley%27s_method">Halley’s Method</a> allows for cubic convergence at the cost of one more addition and multiplication than Newton’s (which has quadratic convergence).  You cannot use this trick all the time, cubed roots are smooth continuous functions, and relatively, do no change much at our frame rate sampling of them (compared to something like the <a href="http://en.wikipedia.org/wiki/Nowhere_continuous_function">Dirichlet function</a>).  Overall, this approximation is just as accurate as taking the expensive power operation.  The image to the left is of 15 uniformly dispersed samples of the range 0 to 1: analogous to a particle with initial radius 1, quarter second lifespan, at 60 fps.
</p>
</td>
</tr>
</table>
<p>Omitting the case at zero, which is where the particle would be dead anyway, the average relative error is less than one hundredth of a percent.  If mass decays at an exponential rate (greater than 1), the approximation is even more accurate since there are more data points as slope increases.</p>
<p>There you have it, my best advice for writing large Flash systems: Used a linked list wherever you can instead of Flash’s Array class, look for opportunities to cache data, if you find yourself doing some complicated math research some approximation alternatives, evaluate your system to see if it can reuse work it did in a past frame, and pay very close attention to your memory use – reusing allocated memory whenever possible.  Finally, some general wisdom, do not try to optimize code before you even have something that works and benchmarking is essential – your ‘optimization’ could be slower than the original code or you could be wasting time optimizing code that is not your major bottleneck.</p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>

<p><a href="http://feedads.g.doubleclick.net/~a/Wpall64es31Hsnc2cMfgDho0M58/0/da"><img src="http://feedads.g.doubleclick.net/~a/Wpall64es31Hsnc2cMfgDho0M58/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Wpall64es31Hsnc2cMfgDho0M58/1/da"><img src="http://feedads.g.doubleclick.net/~a/Wpall64es31Hsnc2cMfgDho0M58/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/j0XP3TutDQo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=213</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=213</feedburner:origLink></item>
		<item>
		<title>Better Random Number Generation: Mersenne Twister 19937</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/pLp0TsTn6BE/</link>
		<comments>http://www.stephencalenderblog.com/?p=181#comments</comments>
		<pubDate>Sun, 28 Mar 2010 19:48:00 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[ActionScript 3.0]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=181</guid>
		<description><![CDATA[Math.random() is the bane of many Flash game developers, and in this article I am going to help you work around it (free code).

So, Adobe will not release the methodology behind how their Math.random() function works:
“Returns a pseudo-random number n, where 0 ]]></description>
			<content:encoded><![CDATA[<p><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Math.html#random%28%29">Math.random()</a> is the bane of many Flash game developers, and in this article I am going to help you work around it (free code).<br />
<span id="more-181"></span></p>
<p>So, Adobe will not release the methodology behind how their <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Math.html#random%28%29">Math.random()</a> function works:<br />
“Returns a pseudo-random number n, where 0 <= n < 1. The number returned is calculated in an undisclosed manner, and pseudo-random because the calculation inevitably contains some element of non-randomness.” – from Adobe live docs as of the writing of this article.</p>
<p>All random number generators are pseudo-random, because they are all algorithmic in nature.  If you know the seed value and the algorithm, you can exactly predict the numbers the function will return.  In fact, the inability to seed the generator and repeat a string of ‘random’ numbers is a frustration of many people (usually not game developers, but there are plenty of practical applications that require it, cryptography for example).  </p>
<p>The other, more common problem, and the blight of every Flash dice game is that the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Math.html#random%28%29">Math.random()</a> function tends to be ‘streaky’ or becomes ‘stuck’ on a number.  This is due to the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Math.html#random%28%29">Math.random()</a> function deviating from a uniform distribution.  Statistically, and in as plain a language I can manage, you need to meet two criteria to qualify as a uniform distribution.  First, nearly even dispersal across the range.  In the case of a 6 sided die, if it was fair, and you rolled it 60 times, you would expect to see 1 through 6 represented equally – Flash’s random number generator passes this test, but so would a die that roles 10 1s, then 10 2s, then 10 3s&#8230;  The second criteria deals with the probability of specific events happening, in the case of our 6 sided die example, rolling the same number 2 times in a row is 1/6 * 1/6 * 6  = 1/6, there is a 1/36 chance to roll any double, there are 6 pair of doubles (1s, 2s, etc.).  Odds of hitting any 3 streak is 1/36.  Flash’s problem is that these kinds of events happen at a higher frequency than they would in a true uniform distribution.</p>
<p>Anyone that has written game engine code is familiar with the <a href="http://en.wikipedia.org/wiki/MT19937">Mersenne Twister</a> routine, the Playstation 3 even made it its native random number generator.  While it has its critics, it has become widely adopted as the best (not to be read as fastest) number generator out there.  It has seen such wide adoption in games because it is the most cost effective, the best quality numbers for its speed.</p>
<p>I’m a math nerd, and I really enjoy the beauty of the number theory which I elaborate on here; but no one will judge you if you skip to the bottom and just steal the code.  Just remember to seed algorithm and that it returns a random integer i where 0 <= i < 2147483647.  </p>
<p>The <a href="http://en.wikipedia.org/wiki/MT19937">Mersenne Twister</a> gets its name from the <a href="http://en.wikipedia.org/wiki/Mersenne_prime">Mersenne primes</a> – all primes that are of the form: 2 to a power minus 1.  Often abbreviated at MT19937, the number part of the name comes from the length of the period: 2^19937 – 1.  There are only 47 known <a href="http://en.wikipedia.org/wiki/Mersenne_prime">Mersenne Primes</a>, somewhat fantastically, 2147483647, or 2^31 – 1, or the upper bound on a 32 bit integer is one as well.  There is a one-to-one relationship between <a href="http://en.wikipedia.org/wiki/Mersenne_prime">Mersenne Primes</a> and ‘<a href="http://en.wikipedia.org/wiki/Perfect_number">perfect numbers</a>’ 2^(p-1) * (2^p – 1), which written in binary are all of the form p 1s followed by (p – 1) zeros.  <a href="http://en.wikipedia.org/wiki/Perfect_number">Perfect numbers</a> are not entirely relevant but just one of the things I discovered about <a href="http://en.wikipedia.org/wiki/Mersenne_prime">Mersenne Primes</a> and binary numbers that blew my mind, if you need more mind candy check out the connections between <a href="http://en.wikipedia.org/wiki/Mersenne_prime">Mersenne primes</a> and <a href="http://en.wikipedia.org/wiki/Digital_root">digital roots</a>, and the relationship between <a href="http://en.wikipedia.org/wiki/Perfect_number">perfect</a> and <a href="http://en.wikipedia.org/wiki/Triangular_number">triangular numbers</a>. </p>
<p>The prime for the <a href="http://en.wikipedia.org/wiki/MT19937">Mersenne Twister</a> is often written as 2^(nw - r) – 1 to clarify coefficients used in the algorithm.  The values for n, w, and r are 32, 624, and 31 respectively for MT19937.  Then we do a bunch of linear algebra to form a twist transformation (where the twister part of the name is derived) followed by a tempering transform to ensure as uniform of a distribution as possible. </p>
<style type="text/css"><!--
/**
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 */
.actionscript3  {font-size:80%; font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;}
.actionscript3 a:link {color: #000060;}
.actionscript3 a:hover {background-color: #f0f000;}
.actionscript3 .imp {font-weight: bold; color: red;}
.actionscript3 .kw1 {color: #0033ff; font-weight: bold;}
.actionscript3 .kw2 {color: #6699cc; font-weight: bold;}
.actionscript3 .kw3 {color: #339966; font-weight: bold;}
.actionscript3 .kw4 {color: #9900cc; font-weight: bold;}
.actionscript3 .kw5 {color: #004993;}
.actionscript3 .kw6 {color: #004993;}
.actionscript3 .kw7 {color: #004993;}
.actionscript3 .kw8 {color: #004993;}
.actionscript3 .co1 {color: #009900; font-style: italic;}
.actionscript3 .co2 {color: #009966; font-style: italic;}
.actionscript3 .coMULTI {color: #3f5fbf;}
.actionscript3 .br0 {color: #000000;}
.actionscript3 .sy0 {color: #000066; font-weight: bold;}
.actionscript3 .st0 {color: #990000;}
.actionscript3 .nu0 {color: #000000; font-weight:bold;}
.actionscript3 .me0 {color: #000000;}
.actionscript3 span.xtra { display:block; }
--!></style>
<div class="actionscript3"><span class="co1">//Mersenne Twister variables</span><br />
<span class="kw1">public</span> static <span class="kw2">var</span> MT<span class="sy0">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span class="kw5">Array</span></a><span class="sy0">;</span><br />
<span class="kw1">public</span> static <span class="kw2">var</span> indexMT<span class="sy0">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span class="kw5">int</span></a><span class="sy0">;</span></p>
<p><span class="co1">//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span><br />
<span class="co1">//***************************************************************************************</span></p>
<p><span class="co1">//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span><br />
<span class="co1">//these functions compose the algorithm for a Mersenne Twister</span><br />
<span class="co1">//see http://en.wikipedia.org/wiki/Mersenne_twister</span><br />
<span class="co1">//This is a MT19937 implementation</span><br />
<span class="co1">//named because it has a proven 2^19937 - 1 period (approx 4.3 * 10^6001)</span><br />
<span class="co1">//(w, m, n, r) = (32, 624, 397, 31)</span><br />
<span class="co1">//a = 0&#215;9908B0DF</span><br />
<span class="co1">//u = 11</span><br />
<span class="co1">//(s, b) = (7, 0&#215;9D2C5680)</span><br />
<span class="co1">//(t, c) = (15, 0xEFC60000)</span><br />
<span class="co1">//l = 18</span><br />
<span class="co1">//it generates numbers in the range 0 to 2^32 - 1</span><br />
<span class="co1">//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></p>
<p><span class="co1">//while MT is the &#8216;best&#8217; random number generator, it is considerably slower</span><br />
<span class="co1">//then Flash&#8217;s Math.random()</span></p>
<p><span class="kw1">public</span> static <span class="kw3">function</span> initializeRandGenerator<span class="br0">&#40;</span>seed<span class="sy0">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span class="kw5">uint</span></a><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">//the seed can be any positive integer</span><br />
&nbsp; &nbsp; MT = <span class="kw1">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span class="kw5">Array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; indexMT = <span class="nu0">624</span><span class="sy0">;</span><br />
&nbsp; &nbsp; MT<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> = seed<span class="sy0">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">var</span> i<span class="sy0">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span class="kw5">int</span></a><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span>i = <span class="nu0">1</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> <span class="nu0">624</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; MT<span class="br0">&#91;</span>i<span class="br0">&#93;</span> = <a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span class="kw5">uint</span></a><span class="br0">&#40;</span>0xFFFFFFFF <span class="sy0">&amp;</span> <span class="br0">&#40;</span>0&#215;6C078965 <span class="sy0">*</span> <span class="br0">&#40;</span>MT<span class="br0">&#91;</span>i<span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#93;</span> <span class="sy0">^</span> <span class="br0">&#40;</span>MT<span class="br0">&#91;</span>i<span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#93;</span> <span class="sy0">&gt;&gt;&gt;</span> <span class="nu0">30</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">+</span> i<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#125;</span></p>
<p><span class="kw1">public</span> static <span class="kw3">function</span> quickRand<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span class="kw5">uint</span></a><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>indexMT == <span class="nu0">624</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; indexMT = <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; generateRands<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">var</span> <span class="kw7">y</span><span class="sy0">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span class="kw5">uint</span></a> = MT<span class="br0">&#91;</span>indexMT<span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="kw7">y</span> = <span class="kw7">y</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&gt;&gt;&gt;</span> <span class="nu0">11</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw7">y</span> = <span class="kw7">y</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&lt;&lt;</span> <span class="nu0">7</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span> 0&#215;9D2C5680<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw7">y</span> = <span class="kw7">y</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&lt;&lt;</span> <span class="nu0">15</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span> 0xEFC60000<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw7">y</span> = <span class="kw7">y</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&gt;&gt;&gt;</span> <span class="nu0">18</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; indexMT<span class="sy0">++;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw7">y</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw1">public</span> static <span class="kw3">function</span> generateRands<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span><span class="kw1">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> i<span class="sy0">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span class="kw5">int</span></a><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> <span class="kw7">y</span><span class="sy0">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span class="kw5">uint</span></a><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span>i = <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> <span class="nu0">227</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw7">y</span> = <span class="br0">&#40;</span>0&#215;80000000 <span class="sy0">&amp;</span> MT<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="br0">&#40;</span>0&#215;7FFFFFFF <span class="sy0">&amp;</span> <span class="br0">&#40;</span>MT<span class="br0">&#91;</span>i<span class="sy0">+</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; MT<span class="br0">&#91;</span>i<span class="br0">&#93;</span> = MT<span class="br0">&#91;</span>i <span class="sy0">+</span> <span class="nu0">397</span><span class="br0">&#93;</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&gt;&gt;&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&amp;</span> 0&#215;1<span class="br0">&#41;</span> <span class="sy0">*</span> 0&#215;9908B0DF<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="co1">//special case for i + 397 &gt; 624 to avoid a mod operator</span><br />
&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span>i = <span class="nu0">227</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> <span class="nu0">623</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw7">y</span> = <span class="br0">&#40;</span>0&#215;80000000 <span class="sy0">&amp;</span> MT<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="br0">&#40;</span>0&#215;7FFFFFFF <span class="sy0">&amp;</span> <span class="br0">&#40;</span>MT<span class="br0">&#91;</span>i<span class="sy0">+</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; MT<span class="br0">&#91;</span>i<span class="br0">&#93;</span> = MT<span class="br0">&#91;</span>i <span class="sy0">-</span> <span class="nu0">227</span><span class="br0">&#93;</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&gt;&gt;&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&amp;</span> 0&#215;1<span class="br0">&#41;</span> <span class="sy0">*</span> 0&#215;9908B0DF<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">//special case for last value, to avoid mod operator</span><br />
&nbsp; &nbsp; <span class="kw7">y</span> = <span class="br0">&#40;</span>0&#215;80000000 <span class="sy0">&amp;</span> MT<span class="br0">&#91;</span><span class="nu0">623</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="br0">&#40;</span>0&#215;7FFFFFFF <span class="sy0">&amp;</span> <span class="br0">&#40;</span>MT<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; MT<span class="br0">&#91;</span><span class="nu0">623</span><span class="br0">&#93;</span> = MT<span class="br0">&#91;</span><span class="nu0">396</span><span class="br0">&#93;</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&gt;&gt;&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">^</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw7">y</span> <span class="sy0">&amp;</span> 0&#215;1<span class="br0">&#41;</span> <span class="sy0">*</span> 0&#215;9908B0DF<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; <br />
&nbsp; &nbsp; <br />
<span class="br0">&#125;</span></p>
<p><span class="co1">//***************************************************************************************</span><br />
<span class="co1">//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span><br />
&nbsp;</div>
<p>*Special thanks to the <a href="http://quickhighlighter.com/">Quick Highlighter</a> team for the code embed CSS and HTML</p>
<p>So the only real question left is what do you pick for a seed value?  If you always use the same number, the ‘random generator’ will always return the same sequence.  Therefore, you need a random way to seed the generator – quite the paradox.  You can use Flash’s random number generator to provide an initialization integer, personally I think it’s clever to derive a value from the date and time the application runs.</p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>

<p><a href="http://feedads.g.doubleclick.net/~a/2yrbhjexnAr8QvrCI_c5o6IgIrk/0/da"><img src="http://feedads.g.doubleclick.net/~a/2yrbhjexnAr8QvrCI_c5o6IgIrk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/2yrbhjexnAr8QvrCI_c5o6IgIrk/1/da"><img src="http://feedads.g.doubleclick.net/~a/2yrbhjexnAr8QvrCI_c5o6IgIrk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/pLp0TsTn6BE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=181</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=181</feedburner:origLink></item>
		<item>
		<title>Flash Render Profiling</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/M7vsGDxVAnw/</link>
		<comments>http://www.stephencalenderblog.com/?p=135#comments</comments>
		<pubDate>Mon, 23 Feb 2009 22:42:21 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[ActionScript 3.0]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=135</guid>
		<description><![CDATA[




 Use this tool and purge your projects of lethargic art assets!





I am going to show you how to use my Flash render profiling tool.  The source, available under GNU general public license, is available here.  Since you only need basic Flash editor knowledge to use this tool, it should be easy for [...]]]></description>
			<content:encoded><![CDATA[<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="210" align="center" valign="top"><img src="http://www.stephencalenderblog.com/images/RenderProfilerTeaser.jpg" alt="Flash Render Profiling Demo" /></td>
<td width="260" align="left" valign="top">
<p>
 Use this tool and purge your projects of lethargic art assets!
</p>
</td>
</tr>
</table>
<p><span id="more-135"></span><br />
I am going to show you how to use my Flash render profiling tool.  The source, available under GNU general public license, is available <a href="http://www.stephencalenderblog.com/RenderProfiling/Agreement.php">here</a>.  Since you only need basic Flash editor knowledge to use this tool, it should be easy for an artist, designer, or producer to use and take an active role in the optimization of rendering. </p>
<p><object id="csSWF" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="378" codebase="http://active.macromedia.com/flash7/cabs/ swflash.cab#version=9,0,28,0"><param name="src" value="/RenderProfiling/RenderProfilerCamtasia.swf"/><param name="bgcolor" value="#1a1a1a"/><param name="quality" value="best"/><param name="allowScriptAccess" value="always"/><param name="allowFullScreen" value="true"/><param name="scale" value="showall"/><param name="flashVars" value="autostart=false"/><embed name="csSWF" src="/RenderProfiling/RenderProfilerCamtasia.swf" width="480" height="378" bgcolor="#1a1a1a" quality="best" allowScriptAccess="always" allowFullScreen="true" scale="showall" flashVars="autostart=false" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object></p>
<p>I do not want to reiterate everything in the video but I do want to mention a few key points.  All you need to do is drag objects from the library onto the stage and run the application.  The code automatically searches the render tree and tests every art asset.  In the video, I point out where you can add objects to the stage using ActionScript.  My first experiment compared the render speed of a complex object created in ActionScript and the same object using the Flash editor, there was no appreciable difference.  You will get the same results from just dragging objects onto the stage as you would with coding them in ActionScript. </p>
<p>I use the same methodology for this tool as I did in my <a href="http://www.stephencalenderblog.com/?p=9">benchmarking tests</a>.  To have accurate results you need to accumulate a significant amount of time to measure, give the system enough time to recover between tests, and conduct multiple trials.  Testing in the right environment is paramount, rendering time differs greatly between a local Flash player, debugging from the Flash editor, and running from a web browser.  </p>
<p>It takes time to be accurate, and this tool certainly takes some time to do its job, but it would take far more time to find rendering bottlenecks by guessing.  There is no comparison to knowing.  This render profiler will let you target sources for optimization with surgical precision, and let you compare the results of your changes.    </p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>

<p><a href="http://feedads.g.doubleclick.net/~a/f5L_GjZzAWTXm2f7k45y1UpREOg/0/da"><img src="http://feedads.g.doubleclick.net/~a/f5L_GjZzAWTXm2f7k45y1UpREOg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/f5L_GjZzAWTXm2f7k45y1UpREOg/1/da"><img src="http://feedads.g.doubleclick.net/~a/f5L_GjZzAWTXm2f7k45y1UpREOg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/M7vsGDxVAnw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=135</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=135</feedburner:origLink></item>
		<item>
		<title>A Programmer’s Postmortem: Lincoln Era White House</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/u-oMlYbTa7I/</link>
		<comments>http://www.stephencalenderblog.com/?p=131#comments</comments>
		<pubDate>Tue, 17 Feb 2009 22:40:59 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[ActionScript 3.0]]></category>

		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=131</guid>
		<description><![CDATA[




 Featured in:
Pittsburgh Post-Gazette
Pop City Blog
PittsBlog
Tech Burgher Blog
and on AM 1360 WMNY The American Entrepreneur 2/28/09 &#8220;Ron Morris talks with Todd Waits&#8221;





Semiotic Technologies’ White House project seems simple at the surface but there is a lot going on underneath the hood; I’ll discuss the technology, problems, solutions, and results of building a 2.5D world in [...]]]></description>
			<content:encoded><![CDATA[<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="210" align="center" valign="top"><img src="http://www.stephencalenderblog.com/images/WhiteHouseTeaser.jpg" alt="White House Project" /></td>
<td width="260" align="left" valign="top">
<p>
 Featured in:<br />
<a href="http://www.postgazette.com/pg/09055/951140-298.stm?cmpid=newspanel0">Pittsburgh Post-Gazette</a><br />
<a href="http://www.popcitymedia.com/timnews/argentine0218.aspx">Pop City Blog</a><br />
<a href="http://pittsblog.blogspot.com/2009/02/pittsburgh-gaming-not-gambling.html">PittsBlog</a><br />
<a href="http://techburgher.pghtech.org/2009/02/13/tech-news-is-breaking-all-over-the-place/">Tech Burgher Blog</a><br />
and on <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=184123675">AM 1360 WMNY <em>The American Entrepreneur</em> 2/28/09 &#8220;Ron Morris talks with Todd Waits&#8221;</a>
</p>
</td>
</tr>
</table>
<p><span id="more-131"></span><br />
Semiotic Technologies’ <a href="http://www.whitehousehistory.org/whha_tours/lincoln_whitehouse/index.html">White House project</a> seems simple at the surface but there is a lot going on underneath the hood; I’ll discuss the technology, problems, solutions, and results of building a 2.5D world in Flash.  </p>
<p><a href="http://www.semiotictech.com/">Semiotic Technologies</a> partnered with <a href="http://www.argentineproductions.com/">Argentine Productions</a> to deliver an educational piece for the <a href="http://www.whitehousehistory.org/">White House Historical Association</a>.  Argentine Productions was responsible for all of the sound work and writing, Semiotic Technologies built the rest of the experience.  The Semiotic Team:</p>
<table cellspacing="4" cellpadding="4" width="360" border="0">
<tr>
<td width="120" align="left" valign="top"><a href="http://www.toddwaits.com/">Todd Waits</a></td>
<td width="240" align="left" valign="top">CEO, Producer</td>
</tr>
<tr>
<td><a href="http://www.andrew.cmu.edu/user/evanmill/">Evan Miller</a></td>
<td>Art Director</td>
</tr>
<tr>
<td><a href="http://www.stephencalender.com/">Stephen Calender</a></td>
<td>Chief Engine Architect</td>
</tr>
<tr>
<td><a href="http://www.nicoleepps.com/">Nicole Epps</a></td>
<td>Lead Programmer</td>
</tr>
<tr>
<td><a href="http://www.dancoes.net/">Daniel Coes</a></td>
<td>3D Artist, Animator</td>
</tr>
</table>
<p>The production time on the project was about two and a half months.  The experience focuses on the events and opinions surrounding the emancipation proclamation.  Being an educational piece, its goal was to make history come alive, reaching and captivating audiences in a way no traditional medium could.  Being historically accurate was essential, which put considerable limits on game design.  Sometimes gaming attributes like puzzles, challenges, or tough decisions can be barriers to learning the content and being accessible to a large audience.  Since this world lacks those kinds of game mechanics, I prefer to refer to it as an ‘experience’ or ‘world’.</p>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="210" align="center" valign="top"><img src="http://www.stephencalenderblog.com/images/WhiteHouseTower.jpg" alt="White House Project Images" /></td>
<td width="260" align="left" valign="top">
<p>
Visitors to the Lincoln White House are able to speak to important historical figures and find Easter-egg factoids in the world (top two images).  Most of the images in the Easter-eggs have never been published before.  Then there are three menus; the cast of characters at the White House, a character menu where you can change your role in the experience, and a map page with information about the areas of the White House in your visit (middle, second from bottom, and bottom image respectively).  Even with the project being as simple as walking around and talking to people, there was a lot to manage.  There were 10 key figures, 5 avatar characters, and a host of other characters that art team had to put together (this project was more involved for the art team than the programming team).  People can change their avatar at anytime, and they are encouraged to do so since you get different responses depending on the character you are playing.  It was definitely an organizational challenge to manage who says what to whom in which room.  The Emancipation Proclamation was signed on January 1st, 1863, New Years Day, a day where traditionally (at least during this time period) everyone was welcome to come and meet the president.  We were not going for Assassin’s Creed quality crowd dynamics, but there was a need to make the White house feel crowded and busy yet still easy to navigate.  Then there is the engine that runs the world.</p>
<p>In order to talk about the engine I need to start with its inception.  That project was Cents City (featured on the right, below), where players navigated an isometric perspective of a city.  All of the angles made a custom collision system necessary.
</p>
</td>
</tr>
</table>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="335" align="left" valign="top">
<p>
The collision system coupled with the depth manager is what makes these worlds possible.  By design, Semiotic Technologies focused on building an engine that facilitated the construction of immersive worlds (the art team also had fully rigged models ready to go in order to make our two and a half month development timeline possible).  The engine is composed of custom UI components, development tools, data structures, a depth management system, custom collision detection, and a system to manage multiple scenes / room / areas of the world that we termed ‘levels’.  The main reason that the programming team had lighter load than the artists was because the engine was already built and there was a significant amount of code carried over from previous work.
</p>
<p>
If you have read my <a href="http://www.stephencalenderblog.com/?p=120"><em>Obstacles for Flash Game Development</em></a> article, you probably have an idea of what I wanted for my first implementation.   I did not get to do a per-pixel collision system, nor does it handle rotations or scaling well.  Economically, we did not have enough time to do something that detailed, and ultimately we did not need something that powerful.
</p>
</td>
<td width="135" align="center" valign="top"><img src="http://www.stephencalenderblog.com/images/CentsCityScreenShots.jpg" alt="Cents City Project" /></td>
</tr>
</table>
<p>What I did construct was a grid based collision model.  Levels could have different grid cell sizes, so while you could max the system out by setting the cell size to one pixel, it usually made the world grind to a halt (just too many grid cell look ups).  The cell sizes we used most often were 5 and 10 pixels.  Similarly, using a grid imposes a maximum size of the levels, we were not comfortable making our levels larger than 2400 by 1800 pixels (43,200 cells with a 10 pixel by 10 pixel cell size).  Another feature that I wanted, but did not have time to implement, was streaming levels.  All levels are in memory all of the time, which can be taxing on memory resources.  If levels were streamed in as needed, and removed when unused, in theory we could make worlds of infinite size.   While I point out the engine’s, and what seem like my own, shortcomings; we never intended to build the complete engine all at once, it was to be spread out across several projects.</p>
<p>Perhaps most important to a collision system is how it resolves it collisions.  Generally there are two camps <em>a posteriori</em> where you let objects overlap and resolve the collision after it happens and <em>a priori</em> where you look for collisions before you move objects.  I might catch some flak from the game community since I prefer <em>a priori</em> when <em>a posteriori</em> is general implemented.  I think that it is easier to resolve collisions as they happen than to untangle collided objects.  Second, if I was going to add in any kind of physics systems into the engine at a later point, overlapping (i.e. mass sharing objects) could cause some serious problems.  </p>
<p>Collision systems need to be fast, so I spent a long time thinking about and implementing different strategies for parsing space for collisions.  At one point, the system ran an adaptive algorithm, picking the best algorithm for different classes of shapes.  In the end, I just went with brute force.  Brute force, checking every grid intersection or pixel, is the only algorithm that works for every possible shape, it has constant speed, and it uses the least amount of memory.  It was far simpler to have just one algorithm and every other alternative had a worst case scenario that was as slow as brute force, slower, or sacrificed accuracy for speed.  I did leave in an optimization if the object was found to be rectangular, which is essentially the trivial case where you know that the object’s bounding box and collision area are the same (as long as the object has not been rotated).</p>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="210" align="center" valign="top"><img src="http://www.stephencalenderblog.com/images/ToolsFilmStrip.jpg" alt="Custom Collision System" /></td>
<td width="260" align="left" valign="top">
<p>
This collision system, as simple as it is, was remarkably powerful compared to Flash’s axis aligned bounding boxes.  Every object added to a level has a collision sprite assigned to it, and there is a classification to whether it is a stationary object or dynamic object (top).   All static objects are mapped and stored into the level’s grid (black lines in the middle image).  Then dynamic objects are handled against the level and each other.  Instead of having to arrange and keep track of a bunch of rectangles in angled or curved environments, we could just draw where we wanted the collisions to be and only check against one object (collisions for a circular room in the bottom image).
</p>
<p>
Objects change depth automatically based on their position in a level.  I do not believe I did anything novel here, I think I did the same thing that I have seen in other implementations.  I use the registration point of the object, the object’s depth priority is calculated based on its position, and then a priority list class that keeps all of the objects sorted according to their priority.  I used a variation of insertion sort in my priority list class since the depth order stays mostly in order across frames.
</p>
</td>
</tr>
</table>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<td width="210" align="center" valign="top"><img src="http://www.stephencalenderblog.com/images/ToolMenu.jpg" alt="Custom Tool Menu" /></td>
<td width="260" align="left" valign="top">
<p>You already saw one of the engine tools when I discussed the collision system.  In all, there are five runtime tools: a frame rate meter, memory meter, debugger, a teleportation tool to jump to places in the world, and the level information and collision tool.  The frame rate and memory meters are hard to see so I zoomed in on them (that and I wanted to show you that my frame rate really was not that erratic, video capturing the game was a bit intensive).  Many of you might think that a debugger is unnecessary since the Flash editor has a debugger, but I have found great use for it.  </p>
</td>
</tr>
</table>
<p>Some things like steaming and network trouble shooting need the swf to be embedded in a webpage.  Furthermore, the Flash debugger has a limit on how much text it can hold.  I was able to build these tools in about a week and they were well worth the effort (admittedly, I did repurpose a graphing widget that I had previously built).  They saved so much time diagnosing problems that they more than paid for themselves.</p>
<p>Even with all the tools and the engine at our disposal, not everything went as planned.  I did all of my <a href="http://www.stephencalenderblog.com/?p=7">benchmarking</a> after this project was over.  Looking back, some of the character assets should have been bitmaps instead of vector artwork.  However, working with vectors was far easier for the characters since they each have 30 frames, 30 images associated with each character would have been painful to deal with in the library.  I am still bothered by the level manager class.  The level manager is critical to the engine, but each game or experience tends to have its own transitions between levels.  It is just frustrating that an engine component needs that much editing since the whole point of an engine is that it is a highly reusable code base.  Part of my irritation stems from working with Flash’s tween objects for transitions since they are difficult to lay out in a series.  Another, inevitably messy, code issue was the controls for character animations and movement.  There are stationary characters, marching soldiers, characters that move randomly, some that just look around, and some with their own unique animations.  Even something as simple as random movement needs controls so that NPCs avoid doorways and tight spots.  All of that code is amalgamated into the NPC class.  I have no doubt that is where the code belongs; it is just egregiously long when it is combined with the animation playback controls.  </p>
<p>I know that the Semiotic team, Argentine Productions, and the White House Historical Association are all happy with the results.  Any project that is delivered on time and on budget is a good project.  I was thrilled with our artists; they really did make my coding look good.  Not only were they able to create high quality assets, but they were so skillful at image compression that the load time is under 40 seconds for most users and we never had to worry about memory usage.  Everyone involved was fantastic to work with; I hope that there are opportunities in the future to work with them again.  I am biased since I worked on the project, but I do believe stepping into our White House is much more engaging than reading a history book. </p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>

<p><a href="http://feedads.g.doubleclick.net/~a/eYclMfMWbSidKC30dXoA_cXEZ3k/0/da"><img src="http://feedads.g.doubleclick.net/~a/eYclMfMWbSidKC30dXoA_cXEZ3k/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/eYclMfMWbSidKC30dXoA_cXEZ3k/1/da"><img src="http://feedads.g.doubleclick.net/~a/eYclMfMWbSidKC30dXoA_cXEZ3k/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/u-oMlYbTa7I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=131</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=131</feedburner:origLink></item>
		<item>
		<title>3D Rendering and Flash Games</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/Whq5mraNAP4/</link>
		<comments>http://www.stephencalenderblog.com/?p=128#comments</comments>
		<pubDate>Sun, 08 Feb 2009 22:36:03 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=128</guid>
		<description><![CDATA[There has been a lot of recent development in 3D ActionScript engines, the most popular of which is Papervision3D.  What does this advance in technology mean for Flash games?  I believe that it is going to be a while before 3D Flash games become common, and we have a long way to go [...]]]></description>
			<content:encoded><![CDATA[<p>There has been a lot of recent development in 3D ActionScript engines, the most popular of which is <a href="http://www.papervision3d.org/">Papervision3D</a>.  What does this advance in technology mean for Flash games? <span id="more-128"></span> I believe that it is going to be a while before 3D Flash games become common, and we have a long way to go before we see 3D Flash worlds.</p>
<p>3D rendering does not solve any of the <a href="http://www.stephencalenderblog.com/?p=120">current problems with building Flash games</a>, in many ways it creates more problems and augments current issues.  We still have to struggle with Flash’s UI components, and build our own data structures that we need.  Most of the 3D engines do not have any collision support or have very basic collision support like bounding boxes, or spherical systems.  The need for tools increases dramatically which both the new engines and Flash lack.  If we had a 2D render profiler in Flash we would be interested in clipping, render time, objects on the stage, and counts of alpha and opaque renders.  Once we start using models, culling and the number of textures becomes important; we would also want to know polygon and vertex counts as well.  In a way, these 3D engines actually hurt the Flash game community because our audience expects us to incorporate this new technology in our games and we are ill equipped to do so.</p>
<p>The ability to render three dimensional objects is only one piece of the puzzle for 3D objects and environments.  I already mentioned the need for collision detection and tools becomes more important, but there are other necessary features like lighting, shaders, perspective, and camera controls.  Most of the engines have a fair amount of support for perspective and basic camera controls; however, lighting plays and enormous role in creating convincing 3D and not every engine out there supports it.  Lighting is just another example of something that becomes incredibly important in the jump from 2D to 3D.  Lighting also happens to be another intensive operation to calculate and draw.</p>
<p>There are certain issues intrinsic to Flash that cause problems for third party 3D engine development.  Flash’s depth system will not allow two objects to exist on the same plane.  Have you noticed that any Flash 3D example with multiple objects, either keep the objects from getting close to each other or only use shapes like spheres and cubes that are convex hulls?  Models with concavities can cause some real render issues since they can have parts in front of and behind other objects.  There is no nice way in Flash to handle it, sure, you could draw it if you drew both objects into one bitmap, but then you lose any kind of mouse or other interactions from two objects becoming one.  A fundamental issue since games usually require objects to interact.  Another issue is how Flash scales textures.  Flash was built for speed so it does a fast but imperfect job at scaling png and jpg files.  Bitmap smoothing helps but it is too memory intensive to be used for a large number of textures, and using bitmap smoothing would be more efficient than any third party ActionScript implementation of image scaling.  Your work is going to look better if you stick to vector textures on models using current Flash 3D engines, and a lesson learned from <a href="http://www.stephencalenderblog.com/?p=22">benchmarking</a>, vector assets do not have to be that complex to be a burden on the CPU.  Having to stick to cube or sphere shapes and simple vector artwork is considerably limiting.   </p>
<p>These 3D engines are slow.  There is a larger number of textures being drawn and processed, every 3D object is essentially an alpha render (or depending on the implementation many alpha renders), and real time lighting and shadows are remarkably intensive.  This is even before most engines have decent collision systems.  The result is that you drastically cut you audience to only those with top of the line computers.  Once you start using models that require multiple textures per model memory management becomes much more important.  Why would you spend a longer time developing a project only to deliver it to a smaller audience?  The classic counter argument is that computers will get faster, yes, that is true, but you still have to compete with developers that are avoiding the issues of the current 3D Flash engines.  The old tricks to accomplishing 3 or 2.5D in Flash are still faster to render and easier to pull off.  Plenty of developers have built models and scenes in Maya coupling those renders with depth management code to pull off some convincing 3D effects.  The only caveat to this approach is that you have to be careful with the camera.  If you really want more than one camera view of an object, you can store different views in the frames of a MovieClip to give the illusion of 3D (pre-rendered 3D versus real time 3D).     </p>
<p>Assume that there was solid 3D support for Flash, all of the problems discussed were resolved and the 3D rendering was fast enough to make pre-rendered 3D tactics obsolete; Flash will not suddenly become the quality of Playstation 3, Xbox 360, the Wii or any other consol or PC game of the same era.  Since Flash games are downloaded, all of the content needs to fit into a small amount of memory, where PC and Consol games can utilize gigabytes of storage space.  Flash still has a long way to go before it can access graphic card optimizations, and since it is browser based, Flash will always have limits to resources that PC games do not suffer from.  Whenever there is an advance in game technology, it is important to remember that innovation does not automatically make better games.  If someone was terrible at making 2D experiences, they are not magically going to get better by jumping into three dimensions.  Every tool at a developer’s disposal should be used wisely.  Is this new technology worth the cost, and what does it contribute to the entertainment value of the experience?  Currently, I believe that the cost of real time 3D outweighs the benefit, especially when our audience can pick up a consol or PC game with stunning 3D quality.  </p>
<p>Current 3D engines are not going to have much effect on Flash games.  I am as excited as everyone else to see the technology and I am sure it grabbed Adobe’s attention based on the new features of Flash 10; it is hard not to like something that makes people excited about Flash, and gets Adobe to add functionality.  Current support for 3D models is great for websites and interesting widgets, but it is only one small piece of the support needed for 3D games.  In order for 3D to be used for games there is going to have to be a fundamental change in how Flash renders, most likely separate 2D and 3D render trees.  We might see some games with some 3D elements, but it is doubtful that we will see any complete 3D worlds.  Flash developers will always have to rely on intriguing design, not graphic quality, to entertain their audience. </p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>

<p><a href="http://feedads.g.doubleclick.net/~a/ka0HVrbS0mDd7gLVeXa8BW-3FBY/0/da"><img src="http://feedads.g.doubleclick.net/~a/ka0HVrbS0mDd7gLVeXa8BW-3FBY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ka0HVrbS0mDd7gLVeXa8BW-3FBY/1/da"><img src="http://feedads.g.doubleclick.net/~a/ka0HVrbS0mDd7gLVeXa8BW-3FBY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/Whq5mraNAP4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=128</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=128</feedburner:origLink></item>
		<item>
		<title>Obstacles for Flash Game Development</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/0dQecxhBOPw/</link>
		<comments>http://www.stephencalenderblog.com/?p=120#comments</comments>
		<pubDate>Tue, 03 Feb 2009 18:58:58 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=120</guid>
		<description><![CDATA[Flash is far from perfect.  In fact, there is an entire micro economy providing support for things Adobe left out.  Some of the setbacks that Flash game developers suffer from are communal to all Flash developers: having to wrestle with the Flash editor, coping with the rudimentary UI components, and not having access [...]]]></description>
			<content:encoded><![CDATA[<p>Flash is far from perfect.  In fact, there is an entire micro economy providing support for things Adobe left out.  <span id="more-120"></span>Some of the setbacks that Flash game developers suffer from are communal to all Flash developers: having to wrestle with the Flash editor, coping with the rudimentary UI components, and not having access to ActionScript’s source code.  More specific to game development, Flash lacks an acceptable collision system, profiling tools, and other typical features like a particle system and physics classes found in other game development suites.  Flash is not marketed as a game engine so it is unfair to be overly critical; however, there is a Flash game development community and it continues to grow.  Adobe needs to respond to the needs of game developers.</p>
<p>I understand both sides of the open source controversy, having developed proprietary software I can relate to a closed source policy.  However, if your source is closed the community generally expects that your documentation is flawless.  I am not the first person to find several flaws in Flash’s ActionScript language reference.  Flash did do some things right in there documentation, I greatly appreciate all of the examples, there is good use of imagery on pages referring to graphics, and the show / hide functionality of inherited methods, properties, and events keeps pages clean and topic focused.  Typically, the documentation is clear and straightforward and only few instances where the documentation says one thing and ActionScript does another.  My criticisms are when critical information is completely left out.  Case in point, hitTestPoint <em>“Evaluates the display object to see if it overlaps or intersects with the point specified by the x and y parameters. The x and y parameters specify a point in the coordinate space of the Stage, not the display object container that contains the display object (unless that display object container is the Stage).”</em>  What Adobe fails to tell us is that hitTestPoint only evaluates at the last place that the object was drawn.  If the object is moved, re-parented, or added back on the stage you would need to know where the object was the last time it was drawn, which surprisingly includes if the object is still on the stage and was drawn into a BitmapData object.  This kind of imperfection is exactly what needs to be documented the most.  The other painful aspect of working with closed source code is that there is only a general idea about the performance of different functions.  Unless you have done a significant amount of <a href="http://www.stephencalenderblog.com/?p=7">benchmarking</a> rooting out performance bugs is a guessing game.  I doubt Adobe will ever release Flash’s source code, so improved documentation is a necessity.    </p>
<p>There are certain design choices in ActionScript that should be more consistent internally and changed to what has become standard in graphics suites.  There are some instances where Flash has already shown improvement in this regard.  For example, in ActionScript 2.0 the alpha property on an object was in the range 0 to 100, somewhere I remember reading that they thought it would be easier for designers that were programming.  In ActionScript 3.0 Flash 9, they corrected this mistake and used the standard range 0.0 to 1.0; however, they managed to forget to change this for gradients, which still use the 0 to 100 range for alpha values, Flash 10 corrected the oversight.  There are other areas where Flash blatantly breaks the norm.  An example is how Flash handles rotation, ActionScript is the only language that I know of that has a rotation range 0 to 180 then -180 to -1.  Straying from conventions is one source of frustration, the other major issue with ActionScript is that it lacks structures common to most programming languages.  Again, Adobe is working to improve conditions, in the upgrade from ActionScript 2.0 to 3.0 is we finally got a dictionary data structure.  In the release of Flash 10, ActionScript 3.0 has a vector class; it still boggles my mind that a vector rendering program did not provide a vector class.  Other data structures in the game developer wish list are queues, trees, graphs, and finite state machines.  Vectors, queues, and finite state machines are basic components of programming languages.  Tree and graph structures are critical to artificial intelligence routines. </p>
<p>The Flash editor could use some improvements.  This is one area that there has been a great deal of third party development.  Other editors do a much better job of highlighting code, turning functions into links to source code, and superior code show and hide features.  The Flash editor’s help does not rank search results, you are left to sift through every entry containing your request.  CS4 finally promises a long overdue library search feature.  Between the library, help, and the code there is a lot of time wasted searching – something that should be effortless.  Another usability concern, that I myself forget at least once a year, is that the Flash editor absorbs keyboard input when it plays a swf.  The keyboard input bug seems to be one problem that everyone runs into, and having to publish and externally test our desired keyboard setup slows us down.  Lastly, the performance of Flash applications seems to vary widely depending on its environment; results vary if a swf is run from the editor, a local Flash player, or embedded on a webpage.  Combined with being closed source, environmental play differences lead to many false conclusions about performance.  I do not expect Adobe to make performance uniform for every scenario, just to disclose the differences between them.  </p>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<th width="135"> Flash
<th>
<td width="335" rowspan="6" align="left" valign="top">
<p>
Flash aspires to be the premiere program to deliver rich interactive content, so why are its UI components reminiscent of standard HTML?  The composite objects like text areas, lists, combo boxes, and data grids are difficult to theme with colors and textures; often the internal text field reference is private so you cannot perform normal modifications on the text.  There is no reason that it should be so difficult to make a text area have a black background and white text or color alternating rows or columns of a data grid so it is easier to read.  Then there are some components that are useless.  Flash has perhaps the most basic color picker component that I have seen; even Java has a more capable color component for its applications (featured to the left).  Furthermore, there is a complete absence of graph components.  Third party developers are thriving on providing Flash UI components; personally, I took the time to build my own library of components.  Development time that could have been spent working on games.
</p>
<p>
In comparison to other game engines, Flash lacks many typical developer tools.  Flash has a bandwidth profiler and a size reporting feature.  Even simple things like a frame rate and memory meter have to be written.  Unfortunately, some tools are only possible if they are provided, like a runtime render profiler.  It is just another case where development time is wasted on support that would be standard in a game development platform.  For example, take <a href="http://panda3d.org/">Panda3D</a>, it is a free, open source game engine yet it still has sophisticated profiling tools (featured below).  If Adobe ever adds a particle system or other digital effects to Flash, I would expect tools for those systems as well.  </p>
<td></tr>
<tr>
<td><img src="http://stephencalenderblog.com/images/FlashColorPicker.jpg" alt="Flash Color Picker" /> </td>
</tr>
<tr>
<th>Java</th>
</tr>
<tr>
<td><img src="http://stephencalenderblog.com/images/JavaSwatches.jpg" alt="Java Swatches" /> </td>
</tr>
<tr>
<td><img src="http://stephencalenderblog.com/images/JavaHSB.jpg" alt="Java Hue Saturation Brightness" /> </td>
</tr>
<tr>
<td><img src="http://stephencalenderblog.com/images/JavaRGB.jpg" alt="Java Red Green Blue" /> </td>
</tr>
</table>
<table cellspacing="4" cellpadding="4" width="470" border="0">
<tr>
<th> Panda3D Tools </th>
</tr>
<tr>
<td><img src="http://stephencalenderblog.com/images/PandaProfiler.jpg" alt="Panda3D Profiling System" /></td>
</tr>
<tr>
<td><img src="http://stephencalenderblog.com/images/PandaRuntimeTools.jpg" alt="Panda3D Run Time Tools" /></td>
</tr>
</table>
<p>Collision detection is fundamental to making video games and Flash’s collision system is one of the more primitive types. Axis aligned bounding boxes is so limiting that many developers choose to design games that need little or no collision detection.  Some developers elect to implement a distance based collision system to better handle rotation, but there is only so much that you can do with circles and squares.  There is no support for casting rays, typical in most collision systems and used for bullet physics, path finding, and other routines in games.  Some of the previous topics discussed, tools and interface components, are frustrating to have to write but not too difficult.  Writing your own collision system is not something the average user can do, and even those that are able avoid doing so because of the enormous time commitment.  </p>
<p>Even with Flash’s limitations, there are many Flash game companies.  Flash’s widespread use is just too appealing to game developers.  With increased support Flash could become an incredibly powerful game development platform.  Adobe does listen to user comments and make changes accordingly, so hope does exist.  Unfortunately, the Flash gamming market is smaller than the Flash website and Flash video markets so I fear Adobe will be slow to improve the conditions specific to game developers.  Adobe will likely continue to over look and put off gaming features until we see Flash games making as much money or garnering as much attention as the website and multimedia developers.  Until then we will have to design around what Flash lacks or take the time to build what we need ourselves.</p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>

<p><a href="http://feedads.g.doubleclick.net/~a/kFE16gh95UuXq3SLydCzBNfUpks/0/da"><img src="http://feedads.g.doubleclick.net/~a/kFE16gh95UuXq3SLydCzBNfUpks/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/kFE16gh95UuXq3SLydCzBNfUpks/1/da"><img src="http://feedads.g.doubleclick.net/~a/kFE16gh95UuXq3SLydCzBNfUpks/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/0dQecxhBOPw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=120</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=120</feedburner:origLink></item>
		<item>
		<title>Why Flash will be King of Web Development for the Foreseeable Future</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/O1n4m03KGQU/</link>
		<comments>http://www.stephencalenderblog.com/?p=114#comments</comments>
		<pubDate>Thu, 29 Jan 2009 18:15:27 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=114</guid>
		<description><![CDATA[The answer is simple: market share.  A development platform does not need to do everything right, it does not even have to out perform its competitors as long as it maintains the majority market share.  The one thing Flash has done better than any other software to date is dominate its market.
The ‘embedded [...]]]></description>
			<content:encoded><![CDATA[<p>The answer is simple: market share.<span id="more-114"></span>  A development platform does not need to do everything right, it does not even have to out perform its competitors as long as it maintains the majority market share.  The one thing Flash has done better than any other software to date is dominate its market.</p>
<p>The ‘embedded website application’ market is not as tangible as other easily understood markets.  Since I am most familiar with game industry, I will use the current generation video game consoles (Nintendo’s Wii, Playstation’s PS3, and Microsoft’s Xbox 360) as an example of the importance of market share.  To date, I still believe that the Wii has the largest percentage of the consol market.  Put yourself in the shoes of a production house or a video game publisher.  We are trying to make money; if we can only release a game on one platform because of budgets, we are going to pick the consol with the largest market share to try to sell as many titles as possible (assuming that different game audiences are spread proportionally and that each consol is able to support the game).  Then interesting things start to happen.  The next game development cycle comes around and you already have some expertise on one consol so you are more likely to stick with that platform.  Furthermore, the first game you made contributed to the value of owning that consol, so the market share of that platform would increase from your previous game.  Suddenly these upward and downward spirals start to form based mainly on market share.  I know I am oversimplifying things but the most important principle to know about market share is that when you have it, market share should be easy to maintain, when you lack market share, it can be difficult to acquire.  Nintendo got a lot of things right with the Wii.  When the Wii shipped, it had a host of games ready, including exclusive licenses, to increase its value.  The Wii was the most affordable consol, they had the easiest transition between consoles for developers, and it gave everyone something new to play with which expanded the pre-existing gamer community.  There is nothing wrong with the PS3 or Xbox 360; they just have less of the market share.  PS3 was in some ways the opposite of the Wii, where it was the most expensive product and the most difficult development transition; however, it still has its other media capabilities that keep it interesting.  PS3 is also the most capable of all of the platforms, which lead some to think that it will eventually reclaim the majority of the market share; I respectfully disagree.  Compared to the Wii and PS3, Xbox 360 is in the middle of the pack in cost, capabilities, and ease of development.  </p>
<p>Turning our conversation back to Flash and the embedded application market, Flash has an incredible 99% penetration into desktop computers, the vast majority of laptops, and it is actively working on expanding onto phones and other mobile devices.  Director and Java lost the market share war long ago.  I am sure some people out there are still pulling for SVG or UIRA, I think it would be awesome if Sega started making consoles again, but that does not mean I think it will happen.  The Flash Player is free to download and installs quickly.  I still believe that the main reason that it was able to claim such a foothold was that Flash created restrictions so that swf files could not be malicious during a time when dangerous files and applications were running rampant.  Flash has become so prevalent that everyone is learning how to develop Flash applications and audiences have grown accustom to seeing and using Flash applications. Its use is ingrained into the developer and user communities.  It is almost like inertia.  Everything is working to perpetuate the use of the Flash.  Even if someone released a product that was better than Flash in every way it would still have difficulty breaking the market share cycle because of the costs of learning how to program and use something new.  </p>
<p>Honestly, even knowing Flash’s imperfections and limitations, I am fairly pleased with what it is capable of doing.  I also firmly believe that competition is essential to progress, so while I am crowning Flash king of embedded applications I am also willing to support potential usurpers in the future.  In fact, it is exciting to think about what it would take to overcome Flash’s dominance; it would have to be something absolutely incredible.  Ultimately, I think Flash is going to maintain its reign for some time to come.  Similar to the video game consoles I think that there is going to have to be a leap forward in technology (or universal standards) to level the playing field before a product can derail Flash’s market share machine.  </p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>

<p><a href="http://feedads.g.doubleclick.net/~a/uhcD6BdR8ZBJrpgiz7zRCwH2vdU/0/da"><img src="http://feedads.g.doubleclick.net/~a/uhcD6BdR8ZBJrpgiz7zRCwH2vdU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/uhcD6BdR8ZBJrpgiz7zRCwH2vdU/1/da"><img src="http://feedads.g.doubleclick.net/~a/uhcD6BdR8ZBJrpgiz7zRCwH2vdU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/O1n4m03KGQU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=114</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=114</feedburner:origLink></item>
		<item>
		<title>Top Ten ActionScript Performance Tips</title>
		<link>http://feedproxy.google.com/~r/StephenCalenderProgrammingBlog/~3/l-3SQ2hJyAo/</link>
		<comments>http://www.stephencalenderblog.com/?p=109#comments</comments>
		<pubDate>Wed, 28 Jan 2009 22:02:27 +0000</pubDate>
		<dc:creator>Stephen Calender</dc:creator>
		
		<category><![CDATA[ActionScript 3.0]]></category>

		<guid isPermaLink="false">http://www.stephencalenderblog.com/?p=109</guid>
		<description><![CDATA[These are tips I have personally used and have indisputable results.  Of all the things you can do to improve performance these are the most effective and efficient changes that you can make.
10.  Make sure your performance problem is not a memory problem
Debugging 101 is to correctly identify the source of your problem. [...]]]></description>
			<content:encoded><![CDATA[<p>These are tips I have personally used and have indisputable results.  Of all the things you can do to improve performance these are the most effective and efficient changes that you can make.<span id="more-109"></span></p>
<p>10.  Make sure your performance problem is not a memory problem</p>
<p>Debugging 101 is to correctly identify the source of your problem.  If you are using up all of your available RAM with references to artwork or other memory intensive structures your processor will be crippled by having to retrieve and set data from slower memory.   If your application slows over time it is most likely a memory leak issue were objects you intended to delete are still being stored.  The other reason to check for this issue first is that it is very easy to see how much memory that you are using, Flash does everything for you, just call System.totalMemory.  Easier still, just bring up the task manager and consult your page file usage. </p>
<p>9.  Unnecessary import statements </p>
<p>Not the biggest time saver unless you are generating many instances of the class or the class has a large number of function calls made to it.  However, it is a very easy way to improve performance.</p>
<p>8.  Sprites and MovieClips</p>
<p>You only need to use the MovieClip type if the object has multiple frames, you can export for ActionScript Library objects extending the Sprite class instead of the MovieClip class.</p>
<p>7.  Resolve issues of promotion, unknown, or incorrect object types</p>
<p>ActionScript can waste a lot of time determining the type of an object if it does not understand the object type, or if ActionScript has to cast an object type.  Pay close attention the object types of function parameters and types functions return as these are typical problem sources.  Individually, object type compatibility changes are not going to save you that much time.  In most cases this is something that you would need to be doing thousands of times to see a sizable difference in performance.   </p>
<p>6.  Unnecessary operations and function calls</p>
<p>Instead of dividing, multiply.  Instead of calling Flash’s math class for simple things like floor and round, calculate them yourself.  Rank your if statements in order of comparisons most likely to be true.  In for and while statements locally store function values instead of repeated accessing them and reuse objects if possible.  Similar to promotion issues, individual calls are not worth worrying about, but there can be a big difference in loops iterated several hundred times.  </p>
<p>5.  Avoid using masks</p>
<p>If you need to mask a square area use the display object&#8217;s &#8217;scrollRect&#8217; property instead.  If you need a shape that is not a square, place that shape over the object with the scrollRect property.</p>
<p>4.  Disable events that you do not need</p>
<p>Dispatching events is one of the more expensive function calls that you can make.  Every class that extends InteractiveObject (which encompasses every display object) generates a host of events that you most likely do not need.  Take the time to set MouseEnabled and MouseChildren to false to keep your event system as clean as possible.  Also, make sure to remove event listeners and onEnterFrame events when you no longer need them.</p>
<p>3.  Limit your art assets attached to the stage</p>
<p>No sense in traversing render nodes if they are not actively being used.  If it is an object that is not frequently visible I will completely destroy it and recreate it when it is needed again.  The archetype to employ this strategy is menu systems.</p>
<p>2.  Cache appropriate objects </p>
<p>Cache your most expensive objects to render (set cacheAsBitmap property to true).  Caching an object stores it in memory, and if it is static, you will only have to pay to render it once.  Filter effects cause objects to be cached, if many of your objects have filters applied to them they could be the cause of a memory problem.  If a cached object is animated, scaling, or rotating it will be re-cached for every one of those graphic manipulations which is a heavy burden for the processor.</p>
<p>1.  Use the right type of art asset for the job</p>
<p>Use vector art for your simplest objects and png or jpg file types for the more complex graphics.  Rendering and graphic related function calls are the most processor intensive routines; therefore, rendering is usually where you can make the most improvement.   Check out an objects memory consumption by going to File -> publish settings -> flash tab -> generate size report to get a rough idea of which assets to change.</p>
<p>If you are curious about other optimization techniques, want an idea of the expense of related operations, or to get a general idea of where your processor time is being spent I would suggest reading my <a href="http://www.stephencalenderblog.com/?p=7">benchmarking series</a>. </p>
<p>Thanks for reading, and remember, we are all in this together.</p>
<table cellspacing="15">
<tr>
<td>
<a class="DiggThisButton DiggMedium"></a>
</td>
<td>
<a href="http://reddit.com/submit" onclick="window.location = 'http://reddit.com/submit?url=' + encodeURIComponent(window.location); return false"> <img src="http://reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" /> </a>
</td>
<td>
<table>
<tr>
<td>
<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" />
</td>
<td>
<a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&#038;noui&#038;jump=close&#038;url='+encodeURIComponent(location.href)+'&#038;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark this on Delicious</a><br />
</tr>
</table>
</td>
<td>
<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script><br />
</tr>
</table>

<p><a href="http://feedads.g.doubleclick.net/~a/cPo78hPY5ECKYB9ll55EYPUxMyg/0/da"><img src="http://feedads.g.doubleclick.net/~a/cPo78hPY5ECKYB9ll55EYPUxMyg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/cPo78hPY5ECKYB9ll55EYPUxMyg/1/da"><img src="http://feedads.g.doubleclick.net/~a/cPo78hPY5ECKYB9ll55EYPUxMyg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/StephenCalenderProgrammingBlog/~4/l-3SQ2hJyAo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.stephencalenderblog.com/?feed=rss2&amp;p=109</wfw:commentRss>
		<feedburner:origLink>http://www.stephencalenderblog.com/?p=109</feedburner:origLink></item>
	</channel>
</rss>
