Monday, April 9, 2007

WPF and Frame-Independent Animation

Recently I came across a good description on Ars of what Vista brings to the table in display, print, and sound. Since I used to work on the Vista team, I can verify that the article is mostly accurate (and probably more accurate than any other 3rd-party commentary I’ve seen, with the exception of Paul Thurrot’s).

The new Vista UI gets most of the limelight. This is a shame, because many of the coolest improvements to the operating system are under the hood. There are literally thousands and thousands of new features that just don’t make good “demos,” so everyone thinks Vista is just the same old thing with new makeup (check out these cool kernel improvements for a small sample). Conversely, some of the new features that make good demos are actually pretty lame in day-to-day use. For example, I remember when I was a PM at Microsoft and they showed off this new replacement for the Windows Task Switcher. It seems some dude in the Avalon group had come up with this really “clever” way for switching between windows (now called Flip3D).

Now, before we go any further, you need to understand that cleverness in software design is generally a Very Bad Thing.

While walking back to our building after the demo, one of my friends (who happened to be the lead user experience designer on our team) whipped out a verbal chair and started beating the new task switcher over the head. “How could they do this!” he ranted. Had they absolutely ignored Fitt’s Law? Don’t they realize how slow it is to (a) acquire one of those little edges of a window with your mouse (b) cycle through each window, pausing at each one to think “is this is the one I want?”, and then stopping the scroll wheel just in time. Not to mention it totally throws away the spatial layout information of your windows on the desktop.

My friend was terribly afraid this would become some manager’s pet project (because it was just so clever, and so pretty), leading to complete and utter embarrassment of the Vista user experience team.

Oops.

This is how Steve Jobs gets away with saying Mac OS is the “world’s most advanced operating system.” All he has to do is compare Flip3D to Exposé and he’s done. He can just walk off the stage. In my not-so-humble opinion, Vista is much more advanced under the hood. But the one who puts on the best show will win the hearts of the press and the consumers. Steve Jobs is simply a better story teller than Bill Gates (sad, but true).

(Now, if I have any of you really ticked off about now, just wait; I am sure I can offend you even better in some future posts... ;)

Well, all this is important to understand when you consider targeting the Windows Presentation Platform. WPF puts some incredible graphics wizardry at your fingertips. Please make sure the thing you build doesn’t just look good, but that it is also useful (by the way, the definition of a useful game is one that wastes the maximum amount of a user’s day because they can’t stop playing it).

In this week’s demo you will see some groovy shooting and a nice demonstration of how gravity works. The two most important lessons you should get from looking at the source code is (a) how to do smooth, frame-independent animation in WPF, and (b) that bitmap effect such as the “Glow” slow your animations way down (uncomment the code that applies the effect to the planets, and you will see what I mean whenever the screen tries to zoom.) I couldn’t understand what was going on with (b) until I saw this: “WPF bitmap effects are rendered in software mode. Any object that applies an effect will also be rendered in software. Bitmap effects should not be applied to large visuals or animations as this can degrade performance.” I should have seen this coming a while back, when I noticed that creating a custom bitmap effect required thunking down to hand-crafted, “unmanaged” code (for performance reasons, I’m sure).

Note that you will need to install the .NET 3.0 before trying to run the demo on Windows XP.

Demo Download 3 at the WPF Scorched Earths Game Project.