Programming, Visualization and Game Development Theory

07Apr FlashMVC Update: addResultListeners

flashmvc

I have just finished up making another addition to my framework FlashMVC. The update effectively removes the need to use ActionBinder as I will indicate below. ActionBinder was a neat utility, but ultimately I wanted solution that was just as simplistic but could be usable for both Flash and Flex. I couldn’t find any easy solutions until I thought about retrofitting addEventListener with an alternate form to allow callback functions to fire for specific commands on the SuperModel. Hence, I have added these three new methods to SuperModel:

.addResultListeners(actionName:String, onSuccess:Function, onFail:Function)
.addStatusListeners(actionName:String, enabled:Function, disabled:Function)
.addHasActionListeners(actionName:String, added:Function, removed:Function)

Now in your view, you can do something like this in your view:

var app:MySuperApplication = MySuperApplication.getInstance();
app.addResultListeners(MySuperApplication.Login, onSuccess, onFail);
// SuperModel.perform(name of the action, optional onComplete function, ...Rest for the parameters of the action class)
app.perform(MySuperApplication.Login, null, "test@invalidemail@.com");

function onSuccess(result:*):void {
   trace("Login was successful");
}
function onFail(result:*):void {
   if(result==MySuperApplication.RESULT_INVALID_EMAIL)
         trace("invalid email used");
}

Updated ASDocs Here

Aside from this addition, I added in some safeguards like throwing an error if a command tries to call ActionHelper.complete() more than once as well as some other fixes. ActionBinder is still useful in the Flex world as it can help increase readability in some cases, but SuperModel now has most of the nice features built into it.

Please let me know if you have any comments! I am still working on adding in the replay feature to the framework which hopefully I will have done soon.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis

Tags:

02Apr HaXe vs Unity3D vs XNA vs others

For the past couple months, I have been trying to determine the best platform to become my primary language for game AI unit development, shaders, and working on theories of improving the Fridge-A* algorithm. However, choosing the right language has become an arduous task. Hardcore programmers will scream “C++ is the only way to go!” while the elites say “C is so much better than C++” and of course there is that one guy who comments “Why would you use anything other than Assembly language?” The problem lies in the fact that I am doing this work on my own and do not have XX hours to write an elaborate garbage collector, manage raw threads, or constantly keep track of hundreds of pointers. On the other hand, I must have enough speed and processing power to do the research and development I want.

Some suggest Java as a game platform as the language is respectable. However, graphics rendering speed and the Java gaming community is poor at best in my humble opinion. I did enjoy using BlitzMax back in the day, but the engine is simply not powerful enough to create something near commercial quality. Also, the popularity of the language is low, and I would have little professional use for learning more of the language. Flash AS3 is my primary profession; however, its performance leaves much to be desired at times. On the other side, Silverlight 3 is looking rather nifty, but the API still looks funky and doesn’t seem like the engine is really mature enough to do any major development in. Perhaps, if Silverlight 4 has near XNA speeds, better shaders and bitmap drawing, and the XAML to C# connection has less oddities in the API… it would be a contender for my list. Aside from the web platform, I could also go for a super high-end engine like Unreal Engine 3 or Source, but I couldn’t ever hope to produce something commercial with it because of the insanely expensive licensing (hundreds of thousands we are talking about!). Of course this is also Torque, but I have not been impressed with any of the games made on the platform, and there is a moderate cost to get started with it.

So I eventually evaluated my choices to XNA, haXe, and Unity3D:

xna logo

Pros:

  • Very fast (Fastest of the choices)
  • Great shader support
  • C# is a nice language with advanced OOP support
  • Xbox and Windows deployment
  • Free for indie users

Cons:

  • Meant really for just the xbox… there is little support for Windows only deployment and DRM concerns. Also, no luck for Macs.
  • Unlike the other two, XNA cannot steam which means a smaller audience because of the hassle of downloading
  • Super new so the community is not that large in general

haxe_logo

Pros:

  • Compiles out to Flash which 98% of users have already installed
  • Real-world benchmarks show 2x the speed of Flash 9 using code performance optimizations unique to haXe
  • From working with haXe, I will use that same knowledge to build javascript and neko scripts in the future if I wanted
  • I can use my existing knowledge of Flash to accelerate my development
  • Totally free

Cons:

  • No Flash IDE
  • Also super new with a small community and little to speak of tutorials
  • Still slower than unity3D and XNA
  • Currently does not support importing Flash libraries which reduces the amount of existing libraries I can bring over versus just using Flash AS3.

unity3d logo

Pros:

  • Fastest of the web 3D engine… also nice looking
  • Supports developed on Macs and now Windows
  • Uses Python for scripting
  • Supports large number of users for networking and shaders

Cons:

  • No free version to try things out (only 30 day trial)
  • Costly software (the indie license has a terrible roster of features making the Pro version the ideal choice)
  • Little resources and support for making 2D games… everything is geared for 3D development. This can be a negative thing for me as I like to develop quick 2D testing scenarios for AI scripts. From what I can see, there are few tools for doing advanced bitmap drawing.

Final thoughts:

In truth, I have not made up my mind yet. The pros and cons of all the solutions seem to make every choice the same weight in how it appeals to me. I could forsake all the above options and just go with C++ with Allegro or SDL, but they too have their ups and downs. Allergro is really slow without full DirectX/OpenGL support and SDL seems to have an aged API with little in the future for it. Also, neither of those libraries natively support shaders. XNA would give me all the speed I would need for what I am trying to accomplish, but using a language that streams over the internet would give me a much wider audience.

Well, what do you say readers? Are there other languages I should be looking at? For my next post on the subject, I will try to make some benchmarks in all of the three languages to test their true strengths.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis

27Mar Further Reading on Design Patterns

As a followup on my Wednesday lecture on design patterns, I wanted to post some informative resources for learning more about design patterns outside the next lecture on the topic. Also, I wanted to say thanks for everyone who showed up to hear me rant about code structure (not the most exciting topic in the world mind you)!

Design Pattern Definition
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved.
- read more at WikiPedia

MVC Definition (the most common principle of Design Patterns)
mvc
Model–View–Controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the model represents the information (the data) of the application; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages the communication of data and the business rules used to manipulate the data to and from the model.
- read more at WikiPedia

Books:

AS3 Design Pattern Informational Websites:

Flash Design Pattern Frameworks:
(for now, it’s best to avoid these until you understand the fundamentals of MVC)

Good Design Priniciples:

  • ALWAYS type your variables (not really design principle but I too often see people doing this still)
  • An object/MovieClip should contain the actions that it performs (as oppose to objects outside the class forcing it to perform actions)
  • A class should never be able to “break” if the user sets a property or calls a function on it when they are not suppose to. Keep preventive logic in the class that’s doing the work.
  • A good chosen design pattern for a problem will not take any longer to implement than not using it with spaghetti code.

Feel free to leave comments or email me about any further questions you have about Design Patterns or where to find additional materials on it. Have a great weekend everyone!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis

25Mar Detroit Design Pattern Seminar

DAAUG

On Thursday 3/26/2009, I will be giving an open seminar on design patterns for the Detroit Adobe User Group. I should have blogged about this much earlier but my free time has been spread thin of late unfortunately. It will be hosted at ePrize starting at 7:00pm and ending about 9:00pm. I will be covering just some introductory topics of good programming practices with AS3 while diving into some design pattern concepts. There is also a good chance that I will do a more advanced seminar on design patterns in the near future at the user group meetings. This conference will be free to the public so please leave a comment or shoot me an email for directions or more information.
-[ Jonathan_Dunlap::email="jonathan AT jadbox.com" ]-


View Larger Map

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis

07Mar State of the Developers

The past week has been extremely busy for me as both work and my personal research projects consume most of my waking moments. However, I believe that it is important more than ever to continue my blogging as it helps me remember the little bits of wisdom I stumble upon and to keep a working achieve of notes to reflect on. Otherwise these things become forgotten in the hussle of the present. Well without further ado, here are some collected tidbits of information from across the internet:

love_city4Quelsolaar Blog (http://news.quelsolaar.com/)
This is a fantastic blog of Eskil Steenberg who is both an amazing C developer but also humanitarian. He has a fantastic knowledge of shaders, networking, color theory, real-time modeling, and abstract game theory. His blog covers some of these items as well as some great topics on humanitarian subjects.

Scarygirl being developed by Touchmypixel is a very impressive Flash game. However, I couldn’t find any information on when it will be released.

studio21Shred Nebula, a small game studio in California, released its documents (http://www.shrednebula.com/design.html) that details their XBLA game used for pitching to Microsoft. With over 35 pages of amazing conceptual illustrations and information, they where accepted, and their game sold fairly well. Below is a picture of their home brew studio. I love the comfy armchairs for the projector demo setup and the arcade machine in the corner.

Last but not least, I found an interesting video on FORA that talks about the concept of metacognition:

Have any links about the development world that you found interesting? Please do post them below!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis

21Feb FlashMVC API Update

While having time this weekend to review a few of the Flash projects I’ve been working on, I became aware of the idea that every software “action” has the anticipated state of failing. Login will fail if the user enters incorrect credentials or leaves a field empty; A user cancels a file copy operation; A reg form may fail if the user is not permitted to enter the site based off their information. It’s not that the application is failing because it can’t reach a web service or something unexpected happened, but rather a planned reaction was developed to give the user a negitive response to their action. In light of this, I have updated FlashMVC to allow actions to designate that it’s result is negitive/failed. Then on the SuperModel side, the view can optionally supply a fail callback function for when the action designates that it failed.

//  Action class
public class Login {
    public function Login(helper:ActionHelper, name:String, password:String) {
        if(name=="user" && password=="pw") {
            SuperSimpleApp.getInstance().userFirstName = "John Doe";
            helper.complete();
        } else {
            if(name=="" || password=="") helper.result = SuperSimpleApp.RESULT_EMPTY_FIELDS;
            helper.complete(false); // "false" tells the caller that this was not successful
        }
    }
}

The line “helper.complete(false)” tells the SuperModel that the action completed but it was a negative response. In this example, it was failing the login action. So we have the action created, now we need to create the SuperModel that its attached to and the SuperModel will also service as its model.

// SuperModel
public class SuperSimpleApp extends SuperModel {
    public static const LOGIN:String = "Login"; // String reference to the class name for the view to call
    // Flag a response to use in special situations where the view needs to know more about the result
    public static const RESULT_EMPTY_FIELDS:String = "emptyFields";
   
    public var userFirstName:String;
    public function SuperSimpleApp() {
        // Register the class to the SuperModel for use.
        // Note: once the action is added, use the string name of the class to reference it
        actionAdd(Login);
    }
    public static const getInstance():SuperSimpleApp = new SuperSimpleApp();
}

Now in Flash or in your Flex MXML you can run your Login action like this:

var superModel:SuperSimpleApp = SuperSimpleApp.getInstance();
// loginAction will hold the action class we want to call and setup the onSuccess and onFail callbacks.
var loginAction:Performance = new Performance(SuperSimpleApp.LOGIN, onSuccess, onFail)
// ...
// Now later in the code, run the action now on the SuperModel with a test username and password
function onSubmitButtonClick(e:Event) {
    superModel.process(loginAction, "user", "pw");
}
// If the user is logged in successfully
private function onSuccess(result:*):void {
    trace("Hello "+ superModel.userFirstName);
}
// If the login action designated a negative response to the request:
private function onFail(result:*):void {
    // Check the result against known responses flagged in the super model... otherwise give generic message.
    if(result==SuperSimpleApp.RESULT_EMPTY_FIELDS) trace("Please fill out all fields");
    else trace("Invalid username or password");
}

This should help having to deal with common success and fail responses from actions. Let me know what your thoughts are!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis

Tags: ,

16Feb Tegra + Android = iPhone Crusher

badge_tegra_2d_large

NVIDIA announced today that they are using Google’s Android OS for their Tegra platform. In case you don’t know what NVIDIA has been cooking up, Tegra pushes an incredible amount of GPU and CPU processing capability into mobile devices. We are talking like outputting 1080p resolution with 3D animation systems. By using a new technology called ULP (Ultra-Low-Power), it can retain an impressive battery life which can outlast any cell phone that is currently out in the market. It is very exciting that they have chosen the open source platform Android for their OS as both Android and Tegra naively support OpenGL development. If Apple isn’t on the ball, Android backed by such powerful hardware could certainly become the new smart mobile device king.

Also worth mentioning, once Android gets Flash Player, a Tegra device would be able to play robust developed Flash games and applications that other platforms would be sluggish running.

Read the press release at:
http://www.nvidia.com/object/io_1234769972591.html

UPDATE:
Nvidia Promises Tegra-Based Android Mobile Internet Devices for $99
!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis

13Feb AS3 Best Practice for Callback Evals

Callback pun

UPDATED: Thanks to my readers- there is an even easier way to evaluate a function as being not null without a compiler warning. One suggested a method using a type check (functionName is Function) however this is process intensive task for the compiler especially if this has to be done within a game loop. I believe the most efficient solution was suggested by Mije for doing a strict comparison by !== against null. This is better than != as the previous evaluation executes faster.

One of the techniques I am fond of is callback functions when using a custom event may be overkill for the situation. However, trying to actually explain callbacks verbally is almost impossible. In a nutshell, it’s a method (lets say A) that accepts another a method (lets say B) as a property. Method A will perform its action and then call method B. This allows the class that uses Method A to have one of its methods called once Method A completed.

Here is an example; however, in practice, callbacks are only useful when the method that uses it is in a different class otherwise you could just call the method directly instead of using the callback.

// Example function that calls the method that uses a callback
private function gameEnded():void {
saveScore(10, onSave);
}
private function saveScore(score:int, onSaveCallback:Function):void {
// saving score...
// once done:
onSaveCallback();
}
// This is the function that gets past into saveScore
private function onSave():void {}

Okay okay, now here is the problem at hand. What if the callback function was optional? You could write it like this:

// onSaveCallback is now optional with a default value of null
private function saveScore(score:int, onSaveCallback:Function=null):void {
onSaveCallback();
}

Not so fast! If the callback function is not specified and gets set to null, Flash will throw an error since you cannot call null as a function like this: null().
Well, you could do a conditional check:

// onSaveCallback is now optional with a default value of null
private function saveScore(score:int, onSaveCallback:Function=null):void {
if(onSaveCallback) onSaveCallback();
}

This way we can check to see if onSaveCallback does not equal null. Well, this angers the Flash compiler and it will throw the below message:
Warning: 3553: Function value used where type Boolean was expected.  Possibly the parentheses () are missing after this function reference.
This is because Flash is confused that you are trying to evaluate a function as a Boolean instead of using it normally as a function. So, how can we evaluate if the function is not null without throwing a Flash warning? Well, I scowered the internet and could not find a best practice for Flash. After a discussion with my readers, the best solution here is to do a strict type check to null as shown below:

private function saveScore(score:int, onSaveCallback:Function=null):void {
if( onSaveCallback !== null ) onSaveCallback();
}

Well there you have it- let me know if this works for you!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis

Tags:

01Feb ActionScript Reference for Android!

ActionScript Reference for AndroidAfter seeing that someone wrote an ActionScript reference application for the iPhone called ActionScript 3 API Reference for iPhone, I decided to take matters into my own hands and make the same application for the Android platform which the t-mobile G1 works on. The Android OS is a fantastic platform for a developer as I made this whole application over just two weekends. For the first release, I included a view to see all classes and a class search functionality. You can now download this from the Market on your Android phone! You can find it under the Application – Reference section, and it’s called ActionScript Reference. See the below screenshots…

Classes View:
screen1

Class Information View:
screen2

For more information on Android: http://www.android.com/

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • E-mail this story to a friend!
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis

Tags: ,




Bad Behavior has blocked 307 access attempts in the last 7 days.