views:

722

answers:

7

The question might look subjective but considering Microsoft:

  • Owns the Xbox 360 platform
  • Owns the Windows platform
  • Have their own game studio (MGS)
  • Own other 3rd party developers
  • Is a major publisher

makes me wonder why Microsoft doesn't push their flagship language to prove that not only you can cut down significant development time, and therefore money, but also show that you can release a next gen title where the real time interactivity doesn't suffer.

If Microsoft were to do this once, I am sure many AAA developers would jump on that wagon too.

+26  A: 

You need to ask a slightly different question.

Why doesn't Microsoft rewrite it's existing highly tuned gaming engines in a completely different language.

This is hopefully a more self explanatory question.

I know virtually nothing about the gaming system code base but I certainly don't imagine it to be small. Converting anything other than a trivial application from C++ to any other managed language is a huge undertaking.

Forgetting all of the syntax differences and C++ features / hacks that can't be done in C#, with a gaming application one issue at the front of the conversation will be perf. C# is not slow but it has vastly different performance characteristics. It's almost certain that highly tuned C++ gaming code will not perform nearly as well if it's directly ported to C#. A whole new round of performance tuning would have to happen and would not be cheap.

JaredPar
Reminds me of Windows 7 question..
Mehrdad Afshari
And the answer for Windows 7. I'd love to ask a slightly different question, if C# can be appropiate for a game such as Halo. I'd imagine you could and when you find yourself in performance critical sceanrio you'd drop into c++ cli or just c++
JoshBerke
@Mehrdad, very much so.
JaredPar
+5  A: 

Quite simply, for real-time-like performance problems such as is presented by First Person Shooters, C# isn't up for the task. Not that it's not a good language, I use it and like working with it, but the fact is that the indeterminacy introduced by the Garbage Collection in C# makes it inappropriate for games which have high performance requirements. The same would be true of Java. Only when you get to a point where you have a certain amount of excess performance available can you really do something like this; the problem really is that somebody else is going to take that extra performance, and instead of sinking it into the runtime requirements of C# (or Java, which would have similar issues), they will just make a better-looking game. Since the consumer doesn't really care what technology the game was developed with, they'll usually go with the better-looking game, which puts any games developed with C# (or Java, like I said) at a significant disadvantage.

McWafflestix
Eh, assuming we were still in the mid-90's, I'd agree with you. But today, the GC doesn't have to be a problem at all. The .NET GC is pretty damn good, and it's fairly easy to avoid noticeable pauses during a collection. That's only true for the full .NET framework though. The Compact Framework uses a far more primitive garbage collector, which I definitely wouldn't trust in a performance-sensitive project like this.But GC's *in general* do not have to be a problem.
jalf
I'll agree that GCs have gotten much better, although I'd be fascinated to see the performance of the C# garbage collector in the mid 90's (CSharp appeared in 2001). The simple fact is, though, that it applies a performance overhead penalty, even if it IS smoothly spread out over the entire runtime, and that overhead cost is something that other developers who are not working with an IL can use to optimize and make a better-looking game. The simple fact is, games are so highly optimized even now that any performance penalty can seriously affect shippability.
McWafflestix
If there's a performance liability, I'd say it's floating point performance (for physics mostly), not GC. I can't really think of an instance where the GC would be *the* botteleneck as the objects most frequently constructed (vectors, matrices, etc) are value types that don't need GC (individually at least, they get GC'd when part of a reference type) and the heavier objects that are frequently created can come out of an object pool initialized at start-up. This might not be true for Java which doesn't know structs. I'm no expert though :)
JulianR
Reality is though, most modern game engines have a roll your own garbage collector as it is. I don't think this is near the issue it used to be even a couple years ago. I think you would fine the memory impact of the runtime would be more of a performance hindrance ( on consoles ) than GC would be. Even then, memory constraints are almost a thing of the past, but the Wii definatly ( 96MB?) and PS3 ( 256MB non video ) are still pretty starved for RAM.
Serapth
Yes, GC has overhead, but doesn't the alternative have overhead? You're forgetting that not using a GC doesn't mean that (de)allocation is free. In fact, and again I'm no expert, I believe that malloc is slower than .NET/Java memory allocation and if you want equal or better performance you would need to write a custom memory allocator that allocates (large) chunks at a time that are partitioned using pointer arithmetic. Which is what the GC already does.
JulianR
First, I didn't mean C#'s GC in mid-90's, but GC's in general. Second, no, there is no performance overhead to a GC. It is usually *more* efficient than the alternative overall. (less memory fragmentation, faster allocations, and much much less overhead than refcounting). That overhead is not entirely smoothly distributed, and that's where you *might* encounter problems. Not because GC's take up too much time (they don't), but because the time they do take up isn't evenly distributed. But in practice, even that is pretty much a non-issue with a good generational GC.
jalf
I have to agree here. When people talk about garbage collection, they often forget that (de)allocation is not free. It's not like, if you don't use a garbage collector, your memory just magically gets cleaned up with no performance impact. Any time you manage memory (or any I/O for that matter), you're going to incur a performance impact.Jalf is right when he suggests that, in many allocation tests, C#/Java/(insert managed language here) performs as good as if not better than C++ when it comes to memory management because of the overhead of malloc.
Ed Altorfer
+5  A: 

Microsoft has a platform like this, called XNA, that they have been developing for the past three years. There are a number of proofs of concept, starter kits, and other resources for hobbyist developers and AAA studios.

XNA enables all kinds of developers to use their existing C# skills and the power of the Xbox 360 / Windows to build games for either / both platforms. They haven't developed a commercial game themselves using the platform yet, but there have been a number of pretty cool projects to use XNA already.

Take a look at some of the games that have been created using XNA.

Also, for the comments about C#'s performance, you might be interested in a forum discussion on the topic. It's definitely fast enough for many games; in fact, XNA's execution engine on the Xbox is optimized in a number of ways for game development scenarios and at reducing the cost of garbage collection (I have no source to cite, but I worked as an intern on the .NET execution engine for the Xbox 360).

Ed Altorfer
+5  A: 

Actually, if you look at the way things are, MS doesn't have nearly as much involvement in game studios. Bungie is now a semi-independant entity, they shuttered Ensemble ( Age of Empires, Halo Wars ) for who knows what reason... they shut down the Flight Simulator group, they let their exclusivity with Bioware ( Dragon Age, Baldurs Gate, NWN ) and Bizarre ( Project Gotham Racing ) go and they shut down FASA Interactive ( Shadowrun ). At this point, what do they have really have in house? All I can think of is.... Rare and Lionhead.

As to why didn't they make AAA titles with C#. I imagine a big chunk of it was legacy issues. PGR, Forza, Age of Empires, Halo, Flight Sim, pretty much every game they made was an iteration of a previous series, so would have already had substantial investments in existing infrastructures.

That leaves 3rd parties. Why wouldn't third parties use C#? That easy, its not available on Wii or PS3.

Serapth
+17  A: 

First, XNA wouldn't be an option. It is made with the goal of abstracting away the differences between the PC and 360. A high-performance game can't do that. It has to exploit the differences. Where the 360 shines, the performance has to be leveraged. Where it sucks, workarounds have to be developed. And vice versa for the PC.

That's also why other DirectX wrappers exist (SlimDX comes to mind as a much more direct D3D wrapper).

As for managed code in general, several problems come to mind:

  • They have a large codebase already that they'd like to keep using. The way to cut down on development time is not to throw everything out the window and start over from scratch in another language.
  • Most game studios still have some autonomy, even if they're owned by Microsoft. If they prefer to write their game in C++, can Microsoft overrule it? Would it be a good idea to do so? It would certainly piss off the developers, and pissed off developers aren't usually a good thing.
  • Performance: Yes, C# and .NET performs very well on PC, but on consoles, it's a different story. It uses the .NET CF which, among other things, has a terribly primitive garbage collector. Its JIT compiler frankly sucks. .NETCF is not designed to outperform well-tuned native code.
  • Control: The way you usually write AAA console games is to exploit everything the console has to offer. Every byte of memory should be more or less accounted for, every CPU cycle used. Managed code is simply less predictable. When does the GC run? How much memory is in use at any given time? We don't know. Consoles only have very limited amounts of memory. (The 360 has 512MB iirc. That's not much for a modern game, and it is only possible to make games like Halo 3 if you know exactly who's using how much of that memory).
  • Most features on the 360 are simply not exposed to .NET. Many hardware features require either C++ interop or assembler to exploit.

When that is said, using .NET for a high-profile PC game would work a lot better. The full .NET framework has much better performance characteristics, and the available hardware on a PC is going to vary anyway, so tight control over the exact memory usage is less critical.

But ultimately, why would they do this? It'd be a big risk, it'd require a lot of code rewriting, and what exactly are they trying to prove? Most studios make cross-platform games, and for them, .NET is not an option no matter how awesome it is. They want to be able to run their code on the PS3 as well, or the Wii, or....

jalf
Very nice answer. +1.
McWafflestix
You need to check out Unity http://unity3d.com/This is an award wining cross platform 3d game system using mono.The mono project even added SIMD instruction support especially for Unity. Something a native game developer could not do without dropping support for too much hardware.
trampster
Thanks Daniel. Unity 3d is pure C#?
Joan Venge
A: 

Similar question and similar answers... http://stackoverflow.com/questions/783238/why-windows-7-isnt-written-in-c

ktulur
+1  A: 

The .NET framework in general is not designed for game development. .NET's intended audience is primarily business applications (I know it can be used for a lot more but hang with the abstract for a minute).

When you are writing games, you want a language that let's you get as intimate as possible with the hardware. C++ and Assembly are classical examples where you can squeeze every last ounce of performance from a processor, GPU, and graphics library.

The .NET framework was not developed with that kind of control in mind. .NET is suited for building applications quickly in a very expressive manner - not necessarily to drive the minute details of a high-performance GPU.

j0rd4n