Archive for the ‘Architecture’ Category

Tip: Adding version checking to your external code library

Friday, October 24th, 2008

Since version 1.0 of a code library that I’m sure you’re tired of me talking about came out, I have been making steady updates, some of which break legacy code. I was also having trouble keeping track of which version of the library a particular demo was written for. In order to make sure that the new code library doesn’t cause unpredictable results for the old implementations I added a version check to the main class.

This version check is very simple. It checks a version number in the client code against a version number of the library (or external classes) when the main class of the library is initialized. It is also completely optional (so average users don’t need to mark up their code with version numbers).

Here’s an example:

Say you normally initialize your library using:

MyLibrary.initialize();

Which calls the initialize method:

public static function initialize():void {
   // initialize library here
}

If the external code changes unexpectedly (say through an SVN update) this could cause problems that are difficult to trace. The solution is to modify the initializer to match the client code version with the initializer version.

public static const VERSION:String = "1.6";
public static function initialize(versionCheck:String = VERSION):void {
   if (versionCheck != VERSION) {
       throw new Error ("The version check failed! This library is version " + VERSION + ". Update your code or GTFO!");
   }
   // initialize library here
}

And when you run the initializer, use the version number you’re expecting.

MyLibrary.initialize("1.6");

Some things to notice with this approach:

  • I used a string instead of a number for the version number so that it would allow for sub-sub version numbers and other markers, e.g. “1.6.24 beta r545″
  • Because there is a default value for versionCheck in the initializer, providing a version number is optional. Using MyLibrary.initialize() will still work and throw no errors.
  • Unfortunately, there is not much you can do if the version numbers don’t match except to warn the client that the external code has changed. Still, I’ve found this to be very useful.

The code for my initializer in its entirety after the jump…
(more…)

See Mims present KitchenSync at Singularity <head> web conference!

Thursday, September 11th, 2008

I’m honored to announce that I will be presenting at the <head> web conference (formerly called Singularity) this October 24-26th!  I’ll be talking about the basics of KitchenSync and what makes it so special. I’m very excited, not only to be a speaker (it will be my first time to speak at a conference), but also to be an attendee. This is the first(?) ever web conference to be presented exclusively online… so I expect you to be there!

<head> web conference: October 24-26, 2008

+
KitchenSync

Papervision3D Part 3: Features continued

Sunday, August 17th, 2008

This posting is part 3 of a series. If you find that you’d rather start from the beginning, check out Part 1 and Part 2 first. In this post, I’ll cover Papervision animation, the ASCollada project, render statistics, performance optimization.

Animation
Animation in Papervision3D can be performed the exact same way animation would be performed in 2D. Simply apply any tween or algorithm to an object property (like x, y, rotationX, scaleY, etc) and re-render the scene. But, for imported animations its not quite that simple. Lately Moses’s GoASAP package is being adopted in testing for the Papervision engine. It could soon become adopted by the system.

The Collada DAE Parser
Imported animations come in plenty of flavors but must conform to the same system. That’s the reason the animations package exists. Papervision has long supported externally created 3D assets. You’ll find those file parsers in pv3d.objects.parsers. Although, these importers are nice to have, a big part of Great White was the introduction of the open source project ASCollada. ASCollada is an amazing parser for the standard 3D asset interchange format known as Collada. Collada files are basically very dense XML files that use a .dae file extension. Collada files can be exported from Maya, 3D Studio Max, Blender, Google Sketchup, and XSI. However, level of support for those programs probably follows this order: 3D Studio Max, Maya, Blender, Google Sketchup, XSI. Also, if you’re importing MD2 models, the MD2 file parser will import most animations as well.

(more…)

Papervision3D Part 2: Features

Friday, July 25th, 2008

This is part 2 of a 4 part series outlining 3D in Flash by dissecting the open source Papervision3D library. Before getting deep into features let me first make a few points about using Papervision3D.

The Papervision3d source SVN location includes the standard AS3 version of Papervision3D (version 1.7 as of this writing). If you look at the branches folder inside trunk you will find version 2.0 which is code-named “Great White”. This series is focused on that branch, and NOT version 1.7. Also, its important to know that Great White is probably the fastest and most frequently changing part of the Papervision source and thus details in this article will likely change over time.

Also, as a convention in these posts, I’ll be putting direct references to actual Google Code hosted repository files inside this page. If you don’t wish to open that repository each time you want to know the path of a class, then simply mouse over the link and look at the link address or the tool tip that shows up for the link. All references to Papervision3D classes assume that all uses of the term “pv3d” refer to the root Papervision3D package.

(more…)

Papervision3D Part 1: Introduction

Friday, July 18th, 2008

I have many friends asking me for more information on Papervision 3D. Usually, they’re just genuinely interested in learning about it and also how they can use it. These friends are bright people, but generally unfamiliar with the topic of computer graphics. I’ve consistently directed them to Wikipedia articles that I think will make everything clear to them (in this order):

  1. Computer Rendering
  2. Rasterisation
  3. 3D Projection
  4. Matrix Multiplication

Unfortunately, I think people are reluctant to read those articles because they’re half written in math formulas. Those formulas are critical for getting a real understanding of what’s going on “under the hood” but I admit they’re annoying to read if you don’t really want to learn the math. And also, those articles won’t mention a single Papervision class file anywhere (naturally). I’m sure this is a little less exciting for someone who’s into 3D in Flash. Therefore, I’m reviewing and dissecting Papervision3D 2.0 (Great White) in a multi-part series for those who are curious about 3D in Flash.

Part 1 will review those Wikipedia articles and relate them to Papervision along the way. If you’re already familiar with computer graphics as a topic of CS, you may wish to skip this post. Parts 2 & 3 will review the details of many features of Papervision3D. Part 4 will be a set of useful notes and tips for anyone who’s not already experienced with Papervision3D.

(more…)

Actionscript 3 performance tuning review

Wednesday, July 9th, 2008

After late-night conversations amongst coworkers and friends over beers, I’ve discovered that many flash developers remain unfamiliar with AVM2’s inter workings. A while ago, I found a couple documents which have benefited me greatly in understanding AVM2 and AS3:

Actionscript 3.0 and Performance Tuning

AVM2 Overview

There are definitely some big take-aways in these two documents. I would list them here, but then you might not read them for yourself! ;)

The first document is 74 powerpoint slides (prepared by Gary Grossman of Adobe) which is very useful for getting a quick understanding of AVM2 topics such as garbage collection, the benefits of strong typing, the Actionscript byte code (abc) format, the code interpreter and JIT compilation. For an AS3 developer this is a must-read.

The second document is a bit more dense. It contains 108 pages of more formally described underpinnings of the virtual machine. It focuses a lot on how your AS3 code will ultimately be run as processor instructions. Its a great follow-up to the first document. If you’re a geek, I would highly recommend reading this overview.

Code Documentation

Saturday, May 24th, 2008

I recently finished a campaign site for Starbucks in order to promote the Starbucks brand of coffee available in grocery stores. The address is www.starbuckscoffeeathome.com. It was a very pleasant project to work on, but it was also quite fast paced. The project also remained in a state of high flux until launch. These two aspects combined made it nearly impossible to keep accurate comments on my code. So, after this project was complete I decided to re-write my UML for it based on the way it ended up (rather than the way I originally designed it). After doing so I’ve come to believe this serves as better and more digestible documentation for a developer than most inline commenting. Thats not to say it would completely replace code commenting, but I feel as though its more useful for another developer to see in order to get a grasp on how a body of code works. For this diagram I didn’t have the right tools available to me immediately so I used what I had (which was Adobe Illustrator). This required a greater investment of time, but the time consumed was likely on par with the amount of time required to produce sufficient written documention. For most practical situations, a simple sketch would suffice. Have a look at the diagram (and submit your critiques if you like).

Download the Starbucks basic class UML (PDF).

I’ve also conducted a certain amount of performance profiling that I will write up in the near future.

The State pattern in Flex - combining view states with logical states

Wednesday, January 23rd, 2008

If you’ve used Flex, you’ve no doubt (er, hopefully) been using View States (AKA <mx:State>) to change the look of your RIA as it progresses through different situations of use. While this is immeasurably useful, it does not necessarily qualify as an implementation of the State Design Pattern which allows you to change not only how a component looks but how it functions as well.
(for more on design patterns, read my favorite book Head first design patterns).
(more…)

Introducing KitchenSync - an open-source animation library for AS3

Tuesday, January 22nd, 2008


After about 6 months in development, I’m very proud to announce the release of KitchenSync, a multi-purpose tool written in ActionScript 3.0 for doing tween based animations and timing of functions and much more. The project is open-source under the GNU LGPL and hosted at Google Code. Please take a moment to check it out and feel free to write to me with questions, comments or suggestions for improvement!

KitchenSync is more than an animation library

KitchenSync is more than an animation library. Tweens are a major part of KitchenSync but that is not the end. It also allows you to sequence sounds, functions, and event dispatches among other actions. The framework is open-ended allowing you to come up with new ways to work with the virtual timeline.

KitchenSync was designed with developers in mind

KitchenSync was designed for developers who want a smart way to handle animation or other time-based functionality with code. Written from the ground up in ActionScript 3.0, KitchenSync relies on smart object-oriented architecture rather than complicated shorthand. It includes a number of features and shortcuts, such as the clone() method, that save effort for developers. KitchenSync makes extensive use of events and informative runtime errors and is quite flexible when it comes to extending the functionality.

KitchenSync aims to…

  • offer a well-architected, extensible framework for working with time-based animations and events.
  • take advantage of the power of ActionScript 3.0 while using OOP best practices and design patterns and without requiring the Flex framework.
  • respond to the needs of developers with a rich set of features.
  • be a full-featured library for animation and timeline based actions.

Links

Flex 3 Tips, Tricks, and Gotchas (A Series)

Thursday, September 13th, 2007

At Your Majesty, I just launched a small (2.5kloc outside libraries, 2 weeks dev/qa time) site using Flex 3: the Axe Vice Naughty to Nice sweepstakes site. I chose Flex for this project because of the exceedingly short dev cycle, and because it contained forms and validation I could take out-of-the-box. However, like any project, I ran into a fair share of problems from annoying to outrageously aggravating, and I feel like it always helps to document what I learned, not just for everyone else but for my future self. You’d be surprised how often I have to open up chapters I wrote myself for the AS3 Bible or Introduction to Flex 2 and refresh my “memory,” if you can even call my rattling collection of underused neurons such a thing. Read on for tons of tips, tricks, techniques, and tilapia.
(more…)