Why most game server is written in C + +

Source: Internet
Author: User
Tags lua



The early development of the game must use C + +, it is not to say, 2000-2004, Java has no NIO, other dynamic language is not heavy, only C + + can develop a fully available game server. Until 2005, many Korean games are still pure C + + write service side, Jinshan has also developed a lot of pure C + + game server, and then everyone cut.

There are many modern choices: Java + JavaScript, C+python, C+lua, Scala, go, Erlang. We use Java for performance-oriented servers, for logical server Python, for high concurrency to choose Scala, sub-level high concurrency or performance test programs (bots) to choose Gevent. Is that why we don't use C + +? We use C to do the network, not C + +, but the proportion of C is limited in all the code.

Does this mean that we can abandon C + +? Also not: C is a sharp dagger, and modern dynamic language is a sword. Usually the dagger can be hidden in the body, most of the time with a long sword is enough, but when you encounter the hard stone, the sword no matter the use, then take out a dagger to decisively cut him.

For a mature area, my advice is to use a higher-level development language as much as possible, because many of the core technologies of game development have a more appropriate solution. A lot of service-side logic is actually waiting, waiting for the network, waiting for the database, in this case with C outweigh the gains. But there are some places on the service side still can't hide C/s, such as when the server involves 3D computing (many 2D servers in China, many foreign 3D service), a large number of vector matrix, in addition to using C + + encapsulated a good set of math library, even if directly in Java write, it is very troublesome. For example, now more and more fast action, in order to allow the player to operate more smoothly, I need to base on UDP fast and reliable protocol, protocol development with Java or Scala, performance is no way to meet the requirements, and after the implementation of the Protocol to communicate with the client, you can not let all clients follow you with Java/scala. For example, some CPU-intensive high-abstraction modules, such as AOI or AI modules.

In the case of an emerging area, C/s + + is a lot of things you have no choice. For example, when the mobile wave started, there is no cocos or unity you really want to develop the game, you must quickly use OpenGL es and OPENSL, and then overlay a script to quickly win, the first batch of mobile wave on the rich is these games. Or, you can avoid at all, not intervene, wait until a few years later cocos and unity Mature, you are involved in writing programs with lua/c#. such as the server if you leave the familiar game and the web, to develop a strange field, streaming media services, you will find out how this is the same as the game 10 years ago, what advanced tools do not give me the use, then you can wait another four or five years should be advanced tools will appear, or you want to lead others, you will be decisive to take out C /c++ to solve, this is the C unique pioneering new areas of ability.

Most of the answers are black or white. Do not just C will not be a dynamic language, to avoid becoming a fool, do not only dynamic language will not C, avoid leaving the familiar greenhouse to live. For a novice, if nothing has been learned, my advice is to use the rapid development of things, the project to get up again, there is the opportunity to have energy, and can not completely give up some of the basic things, so that they are incomplete.

PS: In the same architecture, in terms of pure performance, what is the difference in language performance? If you only develop turn-based slow-paced games, or HTTP interfaces, most of the situation is waiting for the database to wait for user messages, the difference is really small, it is possible that 5% is not. If the CPU is dense, then you can refer to the chart below, which is 10-50 times the overall performance difference:
<img src= "https://pic3.zhimg.com/36ce0e9ad05a38e9c12cf52e24179ae6_b.jpg" data-rawwidth= "289" data-rawheight= "339" class= "Content_image" width= "289" >
Some people ask, said for a long time, this also not, that is not perfect, and I am limited, is there a more cost-effective method? How to reach the other shore at once? Is there a better choice for time-limited projects? I said yes! That's java.

Domestic game development around to go around or script +c+erlang+go, do we not have anything else? Most of the cases, in addition to the non-C + +, I recommend that you seriously consider Java, the performance of the most close to C, can bear the majority of CPU-intensive transactions, but will not be like C as crash to find the problem where. At the same time, native JVM-based Scala for high concurrency can provide simple ways like Erlang, functional programming & massively concurrent Coprocessor & actor, while Java can be easily combined with JavaScript, JS speed should be the fastest in the dynamic language inside it. In addition, Java also has groovy, can provide python/ruby generic programming, with ultra-high development efficiency and python/ruby comparable, but also with Scala to achieve high concurrency. The most important thing is to write a good job in Java, all over the writing of Java engineers, most of the language-level training can be omitted.

A lot of domestic game developers refused to learn Java, because many developers themselves have not touched. People who reject Java now, most of whom are just circles in the game circle, occasionally develop the web and lack experience in other industries and fields. See how many world-class open source servers are developed in Java today, in addition to games? Is the game really that special? I do not think, the foreign a lot of Java Development game server, if you know what the game server domain has what Java technology stack can not solve things, trouble tell me. And look at the Java downstream of Scala, JavaScript, groovy stuff. Therefore, we suggest that there is plenty of conditions, seriously consider the Java technology stack, the world is big, not only the game, even if the game, the current development method is really right?

Why most game server is written in C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.