Monday, 26 April 2010

Awakener: Reloaded

With the recent release of Silverlight v4, Awakener has received a small but much-needed update:
  • Right Mouse Button support - One long-running gripe with Flash is that any right click will open a context menu that usually can't be disposed of without selecting an item or, if you're determined not to let the pesky menu win, alt-tabbing your way out of it. It is a relief that Microsoft has opted to allow developers to override the existing right mouse button events to their own ends. No more awkward CTRL + LMB needed.
  • Full Screen Mode - Awakener can now be scaled up and down at runtime (previously just down due to a SilverSprite bug). This means we can now use Silverlight's Full Screen mode, as XAGE will scale the game up depending on the user's resolution.
  • Performance improvements - As mentioned recently, load times in particular are more brisk, although this perhaps isn't as noticeable given Awakener's small size.
These few changes make Awakener feel less like a clunky web app and more like the original AGS incarnation. I'd argue that it's even more intuitive as you don't have to worry about installations etc. Judge for yourself:
I've got a few more ideas for optimisations specifically for Silverlight but for now it's back to adding new functionality. Next up: Expressions.

Wednesday, 21 April 2010

More Optimisations

Talking about optimisations isn't especially exciting, though recent changes have been crucially important to making larger, more complex games viable on XAGE. The super-secret game, for instance, wasn't running at all well on the 360. After a productive weekend it now performs rather admirably, which is a major relief.

Engine - Load Times

Xml serialization is great, but - cripes - it's incredibly slow on the xbox. The main game content was taking in the region of 60 to 70 seconds to load, which might be passable for a Triple-A title but very undesireable for an Indie Game with a short time period in which to make a good impression.

The Automatic XNB serialisation built into Xna Game Studio wasn't really an option, and would have added a an extra layer of complexity to the publishing process. The only remaining solution was to write all data to a binary stream, which is blazing fast and supported on all platforms, but has obvious downsides:
  • You have to write load & save code for EACH class you want persist (at 70+ classes, this is a huge job).
  • Each time you change a class, you also have you to update and test the IO code (adding a painful maintenance overhead).
The eureka moment came from realizing that I could write a routine to generate the C# IO code automatically, and use this to extend my existing classes. I've written a summary of my solution on the Xna Forums.

The load time is now down to about 10 seconds, including all the initial graphics and audio - much better!

Engine - Garbage Collection

As mentioned previously, the X360 garbage collector is also horrifically slow. The super-secret game was causing XAGE to generate 1mb of garbage a second, causing a stuttering that was particularly noticeable when moving the cursor.

Using Collection Pools for the scripting routines and removing some sloppy CopyTo commands have reduced this to about 120k per second, meaning the GCs now occur once every 8 or 9 seconds and are less noticeable. I'll return to this in the future and should be able to reduce it further still.

Editor - AGS Conversions

The scripts are now processed in smaller chunks, speeding up some of the string manipulations dramatically. The HitchHiker's demo, quite frankly, used to take an absolute age to convert to XAGE and now the whole thing takes less than half a minute.

Friday, 9 April 2010

Hodge Podge

This post was started about three weeks ago, which may give some indication of how limited time is at the moment. It's a bit of a hodge-podge of news.


Work has begun on the next AGS game conversion - I'm not really in a position to reveal anything other than to say that it's a super-exciting project (as well as a massively complicated challenge).

Due to its size, some frailties within both XAGE Editor and the engine itself have been exposed. I've addressed some of these accordingly: items for scripts are now selected via dropdowns & lists rather than the previous big shiny buttons, the treeview refreshes a bit more efficiently and conversions have been speeded up after ...


Converting small games is reasonably fast, though the process involves a lot of string manipulation and lookups and so takes exponentially longer the larger the game is. This was a problem for two games inparticular, taking anything between 5-10 minutes to convert - not a particularly productive length of time when testing small tweaks and changes.

I've managed to reduce this time by profiling the application. Using a profiler to identify a bottleneck is immensely satisfying. I'd gotten into the bad habit of using ToUpper() a lot when comparing strings, when there's much better performance to be had using String.Compare and ignoring case sensitivity. Other simple changes like using String Builders instead of concatenations have helped speed up the process.

Another useful outcome from profiling is identifying where garbage collection is occurring. One of the benefits of C# is not worrying too much about memory management. The xbox360 Garbage Collector isn't great however, and forces you to be mindful of what you're instatiating within each game loop. As it turns out, some rather innocuous code can be the difference between a game that runs at 2 fps and one that runs smoothly.

There are plenty of further optimisations to be made; XAGE's scripting creates more garbage than I'd like it to. When you have certain scripts with 10+ conditional statements that run 40 times per second, the garbage can quickly add up and cause stuttering. I'm also going to run a few tests using Automatic XNB serialization to improve load times on the 360 (assuming it's possible to do this using MSBuild).

New features

Support for AGS-style custom modules has been tentatively added, albeit in a slightly clunky way (slotted into standalone rooms for now). It's not ideal but it works, and will do until I get around to implementing a more elegant solution.

Other bits and bobs have been added, some of them purely to cater for some legacy AGS design oddities (like having room co-ordinates that operate at different resolutions). I've jotted out a few designs for designs for things like Expressions & Extension Methods so they should be getting rolled out over the coming months.

iPhone Support

Apple's T&C's for iPhone/iPod Touch firmware v4 (I do find it quite odious that they charge for firmware updates!) include the following:

Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited.

Sadly, this would appear to rule out developers ever using things like Flash-to-iPhone compilers, MonoXna and MonoTouch. Consequently, it is now looking very unlikely that XAGE will ever support the iPhone. Bah.

On a happier note, Silverlight v4 should be released in a few days so Awakener will shortly be getting an update.