Latest News
spacer View All spacer
 
February 10, 2010
 
Analysts: EA On The Right Track At Last
 
GamesBeat@GDC Confirms OnLive, GameStop, PlayStation Home Speakers
 
Ubisoft Q3 Sales Edge Down, As It Ramps Up Big Franchises
spacer
Latest Features
spacer View All spacer
 
February 10, 2010
 
arrow Television, Meet Games
 
arrow Two Halves, Together: Patrick Gilmore On Double Helix [1]
 
arrow The Road To Hell: The Creative Direction of Dante's Inferno [20]
spacer
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
February 10, 2010
 
Konami Digital Entertainment Co., Ltd.
Programmer
 
THQ
Animator - Motion Builder (contract)
 
LucasArts
Senior Systems Designer
 
Trion Redwood City
<b>Sr. Brand Manager</b>
 
Telltale Games
Game Designer
 
Telltale Games
Senior Software Engineer - Core Technology
 
Airtight Games
IT System Administrator
 
Roblox
Apple Game Engineer - Kids' Virtual World
spacer
Blogs

  An Argument For Mono In Games
by Chris Howe on 08/08/09 01:55:00 pm   Expert Blogs
10 comments
Share RSS
 
 
  Posted 08/08/09 01:55:00 pm
 

Most developers these days have moved on from C++ and its lower-level cousins. Higher-level languages are now the norm, including Java, Python, Ruby and C#. Developers have adopted these languages because of the productivity gains that are enabled by working in a higher-level language. Garbage collection frees a programmer from worrying about several common classes of bug. These languages also stress expressiveness over performance, meaning that you have to do less work to get the results that you need.

Games programming can be split neatly into two halves. There is games coding, which involves all the runtime components of the actual game, such as 3D rendering, physics and AI. Then there is tools coding, which is everything else. This commonly includes level editors, DCC plugins and backend data-processing tools.

In games development we have seen widespread adoption of .Net (and C# specifically) for tools coding, but for game coding C++ is almost the only choice. There are certain barriers to using anything other than C++ for game coding. Game coders typically have to worry about performance to a much larger extent than their tools coding colleagues. While it is true that most of the game code does not need to be optimal, there is still that 10% that does (this varies greatly depending on the specific game and the target hardware of course). The other barrier is portability. C++ is the only language that is supported on every major gaming platform, so if you are making a cross-platform game it is your only choice.

Games do make use of higher-level languages for scripting game logic, but typically this is limited to high-level game logic. Languages commonly used for scripting in games include Lua, Python and UnrealScript. If scripting is limited to a small portion of the overall code base then the productivity gains are also very limited. The gains are even further reduced by a couple of other factors. Since the use of scripting is limited there isn't much effort put into making debugging easy. Generally print statement debugging is the most you can hope for. Even some of the biggest, most-used game engines around suffer greatly from this. Since the scripting is limited to simple game logic it is often given to the designers, who won't be able to fully leverage the benefits of the language (I apologize to those rare designers who are comfortable writing code).

The use of scripting is so limited purely because it is terribly slow. If the scripts were faster then we could think about implementing more functionality in the scripts rather than in C++. Then it would become more profitable to work on proper debugging tools, which further increases productivity.

In non-games development there is a solution for this problem called Just-In-Time (JIT) compilation. Put simply, the scripts are converted to native code at runtime. So instead of parsing text or interpreting bytecode we are running actual native code.

So how do we get JIT technology into games? Since C++ is still the only language supported on every gaming platform we will have to embed a JIT scripting engine into our C++ application. There are several choices here (e.g., LuaJIT for JIT Lua scripting), but the one we are going to focus on is Mono.

Mono has the benefit of supporting several languages. Indeed any language that can be converted into CIL (Common Intermediate Language) format, can be supported by Mono. Mono currently supports C#, VB, Boo (a Python derivative) and Lua (via Lua2Il) among others. This means that we can choose our language based on the task at hand, and we can even mix several languages within the same program. Mono also has the benefit of having been ported to several different platforms, including the Wii and PS3.

If we can embed the Mono scripting engine into a game engine then we should be able to move a great deal of the game code into higher-level languages. Indeed it is feasible that most of the game could be written in a Mono language, just calling into C++ libraries where neccessary for rendering, physics, etc. This would look very similar to XNA, which is a C# platform for game creation that provides libraries to handle the lower-level tasks such as rendering.

 
 
Comments

Sander van Rossen
profile image
I've heard about mono being used as a scripting engine. You've mentioned Wii and PS3 support, both which i didn't know about. But what about Xbox360 support?

Chris Howe
profile image
What I've read is that with the 360 you're basically on your own and you'll have to do the port yourself. But since Mono has already been ported to several other platforms, and because we only need embedded support (we don't need full Mono apps to run natively) I believe that a 360 port should be relatively straight-forward.

gama sutra
profile image
Chris, there are static (Ahead-Of-Time) compilers for both Java and .NET:

http://en.wikipedia.org/wiki/AOT_compiler

For instance, Mono:iPhone had to provide one to circumvent the Apple Store restrictions:

http://www.mono-project.com/Mono:Iphone

Sander van Rossen
profile image
@Chris Howe: Well relatively straight forward.. if you're into building compilers.. although I suspect that the xbox360 instruction set is very similar to the PS3 instruction powerpc set, I don't think your average game developer who develops for the xbox360 would want to take the risk or financial burden to invest the development of a compiler..
Which would be a shame, because I would love to use mono as a scripting engine

Chris Howe
profile image
@gama sutra
I knew about the Mono AOT compiler, but I didn't know that Java and .Net had AOT compilers too. Mono still offers the same benefits over Java and .Net of course (open source, cross platform and multiple languages supported).

@Sander van Rossen
I agree it is something of a risk, because it hasn't been done before, but you shouldn't have to rewrite the compiler. I haven't done enough research into this yet to say for sure, but I think you'd just have to replace any OS-level stuff (file handling, etc) and make it output the 360 instruction set. Definitely not trivial, but some developer might consider it worth a bit of research time/money.

Sander van Rossen
profile image
@Chris Rowe:
In the past I was involved in a group effort to build a managed OS, and one of the things that needed to be done was building an AOT compiler for .net. It was anything but trivial unfortunately

Miguel de Icaza
profile image
Mono's PowerPC backend for the PlayStation and the Wii should be enough to port it to the XBox360. The port challenge is really is in the platform layer, which should be a pretty straightforward port for a programmer.

We could do the port to the device, but the Xbox team has consistently turned us down for the port.

Their loss. Unlike XNA, Mono can integrate with existing C++ code just fine.

Chris Howe
profile image
That's good to know Miguel, thanks.

It's a shame that they turned you down, because it's our loss too as developers.

Daniel Rodriguez
profile image
A lot of engines are moving to scripted languajes more and more, for example Gamebryo Lightspeed which uses lua scripting a lot. Others (more casual ones) are aiming at purely scripted games (unity, dxstudio). C# is great for that. Mono FTW!

Tom Higgins
profile image
Yeah, we use Mono as part of Unity and it's proven an excellent solution for both us, and our growing community of developers. And with that in mind we're on the desktop, the web, the Wii console and the iPhone/iPod touch. Good stuff all around!


none
 
Comment:
 


Submit Comment