After cloud computing, Go's next battlefield: the game industry

Since its birth, Go has attracted the attention and practice of developers because of its simple and efficient processing efficiency and excellent support for concurrency. And in 2013, with the birth and development of the heavyweight project Docker, it gradually formed a prairie prairie in the field of cloud computing. After occupying cloud computing, where will Go's next strength be?

At the 10th anniversary event of ECUG Con, Xu Shiwei, CEO of Qiniuyun and chief evangelist of Go, gave the answer in his heart: the game industry.

The following is a transcript of the content of his speech

As a technical CEO, I think that technical personnel are very pure, data-oriented, and rationally judge trends, so today I will analyze from a rational perspective and talk about the future trend of Go, focusing on the game industry.

Game Development with Go

Image 1 Go @ Mobile

figure 1

From Figure 1, we can see the development timeline of Go in Mobile. It started from the beginning of 2012. In fact, its attention was not high at the beginning, and its activity increased significantly until the middle of 2014.

Image 2 Go @ Web

figure 2

Figure 2 shows that although Go officially supports Mobile more than Web, gophers support Web front-end far more than Mobile. The activity of Gopherjs in the community has been very high since August 2013. We can see from the figure that Gophers also have the same dream as JavaScript programmers, using one language to unify the front and back ends.

Through the comparison of the above two figures, a very important conclusion is drawn, which is the development of Go on the desktop side. Even if the Go language is used to write desktop programs, of course, many people are currently trying, including two genres: general UI and vertical. Industry (Game Industry). The official answer given by the Go team focuses more on the latter, focusing on the vertical industry - the game industry.

Why the gaming industry? The feasibility can be seen from the following two points:

  1. Market reasons The game market space is huge;
  2. Technical reasons Compared with other industries, the standard controls of the desktop OS are often abandoned in the game industry, so the demand is relatively convergent and easier to meet.

Next, we will discuss the feasibility of using Go to write games. For GUI, the basic support is OpenGL, which supports PC (Windows/Mac/Linux/FreeBSD), Mobile (Android/iOS) and Web (based on WebGL). For games, it is divided into the following points: PC games (PC), web games (Web), and mobile games (Mobile). These three items can also be developed using Go: OpenGL can be used on the PC side, and Go can be used for mobile games. Mobile, the page game uses GopherJS (compiles the Go code into JavaScript). The Go page game is very mature and uses relatively few technology stacks. You only need to use WebGL and GopherJS, and you can also call JavaScript frameworks such as 

WebGL (https://github.com/gopherjs/webgl)、 jQuery (https://github.com/gopherjs/jquery)、 Websocket (https://github.com/gopherjs/websocket)

In general, Go's support for the Web is very mature, and its application is not limited to page games. As shown in Figure 3, it is a React-like project "vecty", which was developed using Go. From the picture, we can see that this project was launched in 2015, and the activity is quite impressive.

image 3

image 3

Cross-platform gaming with Go

Compared with the Web, the use of Go for full-platform game support will converge a lot, and many libraries like Javascript can no longer be used.

At this time, the technical solution I chose is: use Go to do cross-platform Scratch.

First of all, let’s talk about what Scratch is. It is a programming language for children. It can teach children to write games. At present, its ranking has been squeezed into the top 20 engineering languages. Why use Go to rewrite Scratch? One is out of my love for it, and the other is that Scratch still has some flaws, and I hope to improve it slowly.

Version 2.X ( https://github.com/LLK/scratch-flash) can only be  written based on Flash and can only run on PC, while version 3.0 written based on Google Blockly + React ( https://github.com /LLK/scratch-gui) is already available, but there are still problems in compatibility, such as incompatibility with  2.X in many places, but the user group of 2.X is very large. Therefore, Scratch still has a lot of room for improvement, which is very worth looking forward to.

Goals and Challenges

It is because of the insufficiency of Scratch that I see the challenge. I set a goal for myself to make a Scratch script executor that is compatible with Scratch 2.X across PC, mobile, and Web multi-terminal platforms. Here are the various challenges I faced:

1. Script support - Json script

Scratch2.X is a Json script, which is not difficult from the perspective of parser, but the difficulty from the perspective of executor is consistent with the difficulty of using other scripts. Secondly, its scripts are single-threaded pseudo-parallel. Since variables may be shared between different Scratch scripts and Scratch does not have a mutex syntax, true parallelism will lead to system logic confusion. Simulating a single-threaded pseudo-parallel program in Go is relatively complex, so this was my first challenge.

2. Multi-line text layout and display

Support for True Type fonts, small typesetting systems need to consider line prohibition (for example: punctuation cannot be at the beginning of a line, English words cannot be split into two lines for display)

3. Audio playback

Common audio formats need to be supported, and mixing should be supported (multiple sounds can be played at the same time, and there should be the effect of multiple people speaking at the same time)

4.SVG format support

The built-in sprites in Scratch 2.X are all in vector format and are based on the SVG format. SVG has a very complex instruction set, and the complete support is equivalent to writing a set of GDI Canvas (the current Go community does not have mature SVG rendering s project)

5. Complex graphics

Figure 4.

Figure 4

The graphics shown in Figure 4, although seemingly simple, are difficult to support. Of course, once SVG is supported, this is just an instruction of SVG.

6. Collision detection

This is basically the most basic requirement of game programs: collision detection between two sprites

Practice Results

After half a month of actual development, and because of the 2 years of experience I have accumulated when teaching my son to learn programming, I have accumulated a lot of materials. Now all the Scratch tutorials I have written can basically be executed normally. The following is my 2 years. Some examples of accumulated materials:

1. Social 

Conversation: weather-conversation.sb2; includes audio playback, multi-line text typesetting and display, as well as many complex graphics and scripts behind it. Figure 5 shows it.

Figure 5

Figure 5

2. Chess and Cards

 Gomoku: five-chess.sb2; Go: go-chess.sb2; Chess: chess.sb2, these seem simple, but to be complete, it is more complicated to include coroutines (processing of shared global variables), complex scripts, etc. s things. Figure 6 shows a schematic diagram of Go.

Image 6

Image 6

3. Mini Games

Eat cake: eat-cake.sb2; this is written by my son, the difficulty lies in collision detection, as shown in Figure 7

Figure 7

Figure 7                                                                                

The Cross-Platform Battle: React Vs.Go

Scratch 3.0 is made with React, and I am doing it with Go for a new challenge. Scratch 3.0 has done a lot of things, it took more than a year, and the functions are relatively complete, but for me, I only made an actuator, and the difficulty is different, so I will make a comparison between the two in the end. Take a look at the pros and cons between them.

1.React+React Native

Advantages: The scene is more general, and games can be developed based on WebGL; Disadvantages: It tends to move the Web to the Native (mobile) technology stack, which is complex and has relatively low performance; the React framework basically does not reduce the difficulty of developing games.

2.Go+GopherJS

Advantages: The technology stack is simple, easy to use, and the performance is excellent; Disadvantages: Relatively small; Scenario: Relatively vertical, with relatively complete support for games.

Summarize

Go's desktop side battlefield has just started, but the technology is relatively mature. Although it is very early, the improvement of R&D efficiency brought by Go has eliminated the shortage of resources caused by the early stage to a certain extent. Therefore, even if the front-end The lack of knowledge, but after years of development, the rich resources of the Go community just make up for this lack.

It is suggested that you can pay appropriate attention and choose the right time to enter the "battlefield". You can choose the direction of entry: one is to use Go to write games, which can support all platforms; the other is to use Go to write web applications instead of frameworks such as React.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325445614&siteId=291194637
Recommended