PDC 2008: Cross-platform .NET surprisingly makes a fast game scripting engine

By Scott M. Fulton, III | Published October 31, 2008, 2:48 AM

An open source project to make a common language runtime for Linux, Mac, and iPhone that's .NET-compatible, has ended up succeeding in an area no one may have expected at first: as an artificial intelligence provider for gaming engines.

LOS ANGELES - The annual Microsoft PDC conference is perhaps the least likely place you'd expect to find a demonstration of an open source programming and scripting environment that runs on Linux and Mac. But the scripting language in this case is C#, created by Microsoft. And what's most impressive about Mono, the open source implementation of the .NET Framework CLR (which also, by the way, has a version for Windows) is that it's being implemented as host of a replacement for the scripting language in one of the most popular cross-platform MMO gaming engines: Unity3D.

"A game is an engine that has to render between 30 and 60 frames per second; it has to take user input, it has to take network input, it has to run the simulation, figure out where objects are...It needs to invoke all of the enemies' AI, and the enemy needs to make a decision on a given position, all of this stuff. And eventually it can push this to the rendering pipeline and the audio pipeline, and update this on the screen. And you have a very short amount of time to do it," explained Miguel de Icaza during PDC on Wednesday. De Icaza is best known in the development community for having spearheaded the GNOME project, one of the leading GNU-licensed desktops for Linux.

But more recently, he's been leading Mono, which is enabling .NET to compete against Java on platforms that Sun thought it might have all to itself.

"One of the problems that people were talking to us about was, it turns out that a lot of games have limitations on how much AI they can put on a game, because it's the slowest piece of everything," de Icaza continued. "So it turns out that the display, the simulation, and the supporting infrastructure tend to be built on C, C++, or assembly language. There are people tuning shaders, tuning physics, using templates and that sort of thing. But when it came to the game logic, this is not something that you want to render in C++. This is something that you wanted to keep high-level, you want a different team of people to actually build that, so you have people from MIT doing the graphics and the simulations and the physics. But you want an artist to be tweaking the behavior of light, and you don't want those guys forgetting to free a blob of memory, so you give them a safe language.

"And what has happened in the game industry for the last eight years or so, people have adopted LUA in droves." LUA is a so-called lightweight scripting language. It's easy to embed in other systems, it's comfortable to developers who already understand C, but it's slow. And with game programming being sequential in nature -- update the screen, check for user control, perform cleanup, do some AI, rinse, repeat -- the time slice for the AI scripting language to operate is becoming narrower and narrower by virtue of quicker graphics.

But development houses don't want the AI team to have to deal with the graphics team, lest too much communication end up slowing down the process somehow. So the guys doing what used to be called "gaming theory" end up using a safe scripting language like LUA, or maybe UnrealScript. "The safer the language is, the slower it is," said de Icaza. "It's easy to program, but you lose some performance."

The Unity3D engine and development environment were originally built in Objective-C for Mac OS. But after having started out with its own scripting language, de Icaza demonstrated, Unity switched to Mono, which enabled all of the "living" objects inside of Unity universes to be scripted using the Mono implementation of C#.

As a demonstration, de Icaza ran some of Unity3D's test universes, including a kind of virtual jungle where a species of wild stork is simulated using instances of bird objects. All of the birds as a class, or each bird as an instance, is scriptable directly in the IDE using C# code. In fact, adding the code triggers Unity3D to add class members and their running state to the IDE itself, so they can be changed graphically as well.

A demonstration of the Unity3D gaming environment for Mac, where a virtual universe's creatures are manipulated now using C# scripts.

Just to show how versatile C# has become in this environment, he created a class of spotlight which blinked on and off within this universe at a random interval. Doing this next to one of the birds caused it to be scared -- a behavior which was also controllable using a C# script.

The move to Mono has sped up the performance of games created with Unity3D by unbelievable double-digit factors, and has also improved the compile time of live objects -- as de Icaza showed attendees first-hand -- by an astounding 3000%.

"What we've done with Mono so far is, we've managed to get the game AI to be faster...But we were talking to another game company," related de Icaza, "and they were telling us, 'You know what, we have been using C# for the entire game on the client and the server, and it actually has improved our productivity tremendously. We're actually way ahead of schedule than what we would have done with C++."' And the amazing thing about that, he continued, was that this expediting of processes was on account of implementing managed code -- something which on paper, you'd think, would be slower.

Comments

View comments by with a score of at least

well if they are comparing it to LUA then its being used for high level scripting as an example World of Warcraft uses LUA for its GUI programming and has made a library available to users to make their own modifications.

Score: 0

|

And who is Miguel de Icaza working for now? The article doesn't say. I assume it's MS. That's bad (or maybe deceptive) journalism.

Score: 0

|

Miguel works for Novell via their 2003 purchase of Ximian. He does NOT work for Microsoft.

Score: 0

|

"so you have people from MIT doing the graphics and the simulations and the physics. But you want an artist to be tweaking the behavior of light,"

I am not following. The article is talking about scripting the AI, then comes the quote above... The behavior of light clearly falls into Physics whereas AI in a game is typically behavioral (as the rest of the article states)..?

Also does this have merit? "game programming being sequential in nature -- update the screen, check for user control, perform cleanup, do some AI, rinse, repeat". On a highly abstract level these are related but the detailed sub-tasks should be possible to parallelize heavily (I am not b****ing for a change. Game programming is a domain I have no hands-on experience but curiosity...).

Score: 0

|

You can watch the presentation with the actual details filled in at http://channel9.msdn.com/pdc2008/PC54/

There are some details omitted from this article that are in the talk.

Score: 0

|

PDC 2009: What have we learned this week?

There was the freebie that no one will forget, the heebie-jeebies courtesy of Scott Guthrie, and a teensy bit clearer picture of how this cloud thingie should work.

Live report: Will Google Chrome OS change Linux?

The mysteries of just what Chrome OS is, and how much of an operating system it truly is, may be resolved today.

PDC 2009: Microsoft cares about Web browser performance

The effort to give users of the world's dominant Web browser the impression of quality, is a personal one for the man who leads that battle.

Nokia re-affirms its commitment to Symbian, sort of

Maemo won't necessarily be replacing Symbian in the Nokia N-Series, but that's definitely a place where it will be found.

E-book readers will be in short supply this holiday season

E-readers are hot this year, and a lot of compelling new products have been released, but are there enough electrophoretic displays to go around?

Sony looks to finally open a single storefront for downloads

Sony has had many different download portals for movies, music, e-books, and games, and now it's looking to make a single shop for all of it.

Tuning out the tablet: Time to give the endless speculation a rest

Wide Angle Zoom: Wishing and hoping and thinking and praying....won't put an iTablet on the market.

Five improvements for IT managers in 2010

If businesses are to improve their efficiency for next year, they need to stop and reassess the basic tenets of their job.

AOL's spinoff from Time Warner to shed 2,500 jobs

As AOL moves toward become an independent company again, it will cut nearly a third of its workforce.

Gartner: SMS-based money transfer will be bigger than mobile browsing, search

Gartner issues its predictions for the 10 things our phones will be doing in 2012.

Don't forget to upgrade to Firefox 3.6 beta 3 today

Mozilla has released the latest beta its Firefox 3.6 browser software, just over one week after beta 2.