【摘抄】Is C# Good for Game Development?

2007-11-7 Nie.Meining Coding

There are constantly forum threads on sites like www.GameDev.net discussing the differences between C++ and C#. Usually after a few posts they all end in a senseless language war. Back in the early days of .NET (2002) I discussed quite a lot in those threads, but it was way too depressing when 99.9% of the programmers were on the C++ side and there was no way to convince anyone because they didn’t even take you seriously. The language war does not really have anything to do with C# as a language, except it might have some bad taste because Java failed as a game programming platform except for cell phone games, because both Java and C# are managed languages and look very similar. But if you think about it the same kind of wars happened in the days when C replaced Assembler and C++ replaced C. Even to this day, more than 20 years after C++ was developed by Bjarne Stroustrup, some game programmers still use C and do not really take full advantage of C++. Even if you take a look at the source code for popular game engines like Quake or Half-Life it looks more like C than C++.

This is something really strange in the game programming world; everyone is afraid of losing too much performance by switching to a new language, and additionally might also lose their old code base or have a lot of work converting it to a new language. However, game programmers quickly adopt new techniques and scripting languages, and are always on the very latest hardware developments. One year before Shader Model 4 cards are even available we game developers had Direct3D 10 available and many people checked this out without even having the hardware to run it.

I adopted .NET and C# pretty quickly in the beginning of 2002 after checking out the early betas at the end of 2001. I just started a new game engine and our team had a new project we wanted to do. There were absolutely no graphic engines or anything but some simple 2D games around in the early years of .NET. This made it very hard to use OpenGL or DirectX directly in C#. It required a lot of calls to unmanaged dlls and involved a lot of nasty pointer logic, which is only available in the unsafe mode of C#. In 2003 Microsoft finally released the first beta of Managed DirectX, which made it possible to program new DirectX applications quite easily in .NET. It proved that using Managed DirectX instead of the native DirectX dlls has only a performance impact of 1%–2%, which is really not important if you think about it (just the CPU has a little more work; most games are GPU bound anyway).

However, this did not mean that game developers were jumping on C#; everyone was still very skeptical and even after I released the first commercial .NET game ever, Arena Wars, in 2004, it took another year until more and more developers finally gave .NET another chance. Students and beginners especially really appreciate the simplicity of C#, and more and more people started to develop games in .NET. C++ versus C# discussions still exist and the discussion points are still the same, but the result is more balanced right now (I stopped looking at any topic that has “vs” in the name a long time ago; it is just a waste of time reading the same arguments over and over again).

Always remember this when you run into guys that might tell you C++ is superior and that C# is only for newbies. The same thing happened with Assembler and C++ few years ago, and in the future there will be new languages that make our life easier and there will still be people hesitant to adopt them right away. Most big game studios also can’t just adopt every new technology right away; they might be in the middle of some big project and they also have a very big code base, which is not easy to port. In the long run, however, code will get converted and we will move up the ladder of high-level languages.

Taken from 《Professional XNA Game Programming》
 
PS:在搞安全以前,我一直觉得自己将来会去写游戏……

评论(0) 浏览(2285)

Powered by emlog