- Why most of the game engines use C++ to develop game?.
- Why not java or C#?.
closed as not constructive by Byte56, Gajoo, Maik Semder, Sean Middleditch, Sam Hocevar Jan 26 at 21:01
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.
I would say it's because C++ is, among major languages, the one that works at the highest level, without sacrificing access to low level control.
In C++ you have complete control of what is going on with your program, which may be desirable, especially for severely restricted platforms such as consoles.
For example: garbage collection as available in C# and Java is usually non-deterministic. Not only there is no accurate way for you to know exactly how much memory you're consuming at a given moment, but also you don't know when the garbage collector will run, probably slowing your main thread.
In consoles, even up to the Game Cube and dare I say the Wii, having extreme control of your program's timing is crucial to develop games that perform well. Many games time the game processing exactly while after a scanline has finished, and before the next one comes in. You only have a few microseconds to do work, which translates to a fixed amount of CPU ticks, so unless you know how exactly your code will be assembled, where your cache misses will be, and how long they will take, you won't be able to push the console to the limit. Doing this is impossible if a garbage collector is randomly popping in and messing with your timings.
This is of course historical. Modern consoles and PCs are more relaxed, and you can do a lot without really pushing the machine to the limit, so now you have XNA and PSM that let you program in C#, Android which lets you program in Java, and even Flash and HTML5 which let you program in variants of ECMAScript.
But even so, C++ will let you go to the edge when doing optimizations, as you can even eventually do inline assembly wherever you want. Java and C# simply don't let you do this.
The generally used graphics libraries API, like DirectX and OpenGL are written in C, and provides you an C interface for usage. They have bindings to other languages, but most of these based on the C implementation, or tries to use the API procedures through his own native interface (eg. Java - JNDI) which is written mostly in C...
C++ is generally considered "better" than other languages, for several reasons. Mainly, almost all professional programmers know C++, but aren't as familiar with other languages. Therefore, there is a larger variety of third-party libraries and tools available for C++.
Also, Java and similar languages must run in a virtual machine, which is considered slower or less efficient than native code produced by C++.
However, in my experience, the speed and efficiency of these languages is not what makes the decision, it is only familiarity.
It should be noted that many games run on a C++ engine, but most (if not all) of the game's logic is implemented in a scripting language, such as Lua.