Design of game frame based on Cocos2d-x

Source: Internet
Author: User
Tags memory usage socket touch

March 31, the fourth session of the Cocoachina developer Conference and COCOS2D-X Technology seminar was held in Beijing Theatre,

Renren Game development Engineer Li Cheng has a speech titled "Game Frame Design based on Cocos2d-x".

The following is a transcript

Host:

Everyone in the cocos2d community will be sharing technology solutions like today, but they are very fragmented. Next we welcome the Renren game Engineer,

The title of his speech is "game frame design based on Cocos2d-x".

Li:

Hello everyone.

I am from the game of everyone Li Cheng, my speech today is "based on Cocos2d-x game Framework Design", we have any good ideas can be related to everyone's game colleagues to communicate.

Why do I want to say this ppt, my classmate in the Cocos2d-x development time will discover the network above has a lot of examples, but did not put the technical point together as a whole experience design.

Today, a lot of people are talking about the transplant of Cocos2d-x platform, what I am talking about today is how to do the development of game class for Cocos2d-x platform. In the early hope that we have some better design

Ideas to avoid problems that are difficult to scale or difficult to reuse in the middle and later stages of a project. I personally experienced the development of PC-type games, and the development of web-type games, so I felt the end of

The development experience of game and page tour traditional game is worth drawing lessons from, apply to the mobile game development process.

This speech is divided into three parts:

First, software design is not just game development, it has a direct relationship with the traditional construction industry. You can draw lessons from each other in two ways. When the building was built, if the building stepped

It's the equivalent of a game crash, which leads directly to what results. If a lot of people on the building must be re-built, relative to the programmer, it must be re-reworked, many

Other projects have been working overtime with you. If you crash the game, the project does not, and no girlfriend, no one else is willing to talk to you, if you have a girlfriend

If you mother, say you have broken the game, and what you do not dare to do.

In a nutshell, game development has something in common with building buildings. First, the early design planning is very important, the second is the construction of infrastructure, basic modules is very important; third, extensibility, reusability

Aspect is very important, four is the robustness, the security is very important, five is starts from the foundation to start from the detail, rejects the Tofu slag project.

Second, the main talk about how Cocos2d-x and iOS platform is combined.

First introduce the advantages of Cocos2d-x engine development, because cocos2d C + + version, there is a lot of cocos2d experience to share, so if it is the C + + version of Cocos2d,

You can share your previous experience. The C + + version may be a boon for my non-born people. Supports platforms such as iOS, Android, Windows, and cross-platform developers.

Gospel. It is open source free, easy to learn and easy to use, a large tool chain support; In the morning, many students have shared some tools. Strong technical support, active technical community communication

Platform, including I also have QQ group, that QQ group often flash, cause I work when not to turn off QQ. A variety of online game application experience, if a thing is not proven

In fact, we blindly use to do a project, the risk is very large. Cocos2d-x constantly improve and improve, and gradually add more new technologies, such as the combination of HTML5.

Introduce the Cocos2d-x engine frame diagram, I thought the author would speak this in the morning and I'll make up the piece. Cocos2d-x overall frame diagram The entire engine has a director, in the engine module director

There is the concept of scene, the scene can hang a lot of layers, the game performance is done on the layer, you can add some special effects on the layer, and add some effects, this constitutes a dynamic picture, and then in the dynamic

On the screen to do their own game development logic to form a product.

The following is a brief introduction to the iOS application framework, because this PPT is mainly about how cocos2d-x is combined with the iOS framework, so it is important to have a mechanism for what the iOS framework itself is.

First of all, iOS application framework is the simplest of the main class is six modules, five have a whole client, which is mainly to do the initialization of the program, as well as the response of the message, loop, followed by

Delegate is the extension to the perimeter, in the key point through the callback way, let us know now the game began to load, now the game into the background, the game to close, through this can move

State to get the game running status and make some adjustments. Next is the UIScreen, that is, the screen size can be obtained through this, the following is UIWindow, UIView, this window

The mouth is very intuitive, a game has at least one uiwindow, will have a message response, will put the message response on the uiview above, the view also has a controller, control view running state.

iOS This frame diagram, describes the response of the message, sent to UIWindow through the message, and then up to the various UIView, this is the overall framework. The overall operating cycle, just beginning to have a initialization,

Message to register this sort of thing. If you're interrupted and you lose focus, what do you want to do? It is necessary to remove the sound effects, otherwise the sound effects are not human when answering the phone. When you exit, if you

You have to quit the game, to do the saving of resources, the elimination of the game. There are several existing states, in the foreground or backstage, in these states to the game to deal with the corresponding, otherwise the power

When you answer the phone, the game sound is still playing.

The next step is to introduce how cocos2d-x and iOS are combined. iOS is mainly view and UIWindow, so a platform must have a view, if there is no view otherwise there is no way to express anything.

The main view interface for clients is capture, wind, and distribution system touch events. The rootviewtontroller of the outer layer is the controller, and the Eaglview can be controlled by the objective device.

Opengl-es No rendering updates.

Describes the overall update process for the engine, which we must play for game developers, and what each running state is. Generally, after we have uiview initialized completely, we will pass

Delegate, initializing EAGL view invokes the run () interface that caused the ccapplication. General logic updates are placed inside the ccdirector and are not updated until they are transferred. The first step

For a logical update, the second step is to render updates to the client.

Third, the game client overall architecture Chapter

Give a brief introduction to the overall architecture of client-side game development, which describes what is in the game development architecture in the form of layered modules. We usually cocos2d-x the engine library, the player that will have the sound,

If you have your own basic public library can also be placed on the previous layer. To use a simple parsing tool, the next is the script. Client Main Module division, the general client needs so many modules, such as input

The output module. Game client will generally face a lot of data, including resource data, props data, sound effects data, level data, so we put forward the data layer, mainly to the static resources to unify

Management, such as loading, unloading, getting interfaces, and so on. In addition, is the log module, the development process, generally to remember the log is very much, if the log through a way to remember the file, you can

It's not very efficient. If on-line, a large number of data is not required, so we have in the Log module classification, sub-switch mode, can be divided into several files log, the general debug log put into a text

Pieces inside, the wrong log put in a place, causing the crash of the log into a place, so in the development of the time is very convenient, the log is separate, not a mess, it is not convenient for us to record

Some questions. These log switches can be turned off to improve performance when on-line.

Network layer generally to the network, the use of the native development, the original must be encapsulated, we will explain in detail below. On top of so many basic modules, the game logic, and then to the next layer,

In addition to the game logic layer of the other modules can be reused, which is a strong reusability of the overall framework design.

Client Main module Design: First we use a single ccscene, because it can support multiple scene jumps, we reject unnecessary fancy performance to simplify the implementation of the Code. Game based on frame rate

Update processing, such as the client's mini finger integrated from the Ccnode, and in the initialization of the INIT function through schedule set the game logic main update function tick (), to ensure that before each rendering,

will be processed first for logical updates. Completely based on the frame rate of the timer scheduling, all the timer processing, completely dependent on the game frame rate, simple and direct. Network module Overall design diagram, the network layer is divided into UDP

is a well-known design pattern in network programming. The idea is to put different blocks of memory nodes, in a pool of the way in a queue, this way is very fast and simple.

Native socket package, native socket programming, simple and straightforward, the code can be controlled conveniently to locate the problem. non-blocking I no O-charge plug-in IO mode, no need to open up Network Line object TCP,

A simple connection thread. Selector rotation mode, monitor all processing.

TCP&UDP specific differences do not say, the main point for TCP, in order to solve the problem of rice cakes, because TCP is a self-throttling way, so there are rice cakes problem, for the rice cake problem technology generation

Code control has a way of memnode to receive data. For UDP, because it is unordered, it uses the sequence number method to handle clutter, unordered packets.

Custom Memory Pool Manager: Most of the packet size is limited to 4096bytes;free-list memory pool technology, no-memcpy; avoid frequent new/delete.

XOR encryption: Network game in the server has a very strong check rule, if there is an exception server will be forced to disconnect, so we have to do some simple XOR or encryption. A different or plaintext change of ciphertext;

Two times the XOR is the ciphertext becomes clear.

Only the game data layer: The data layer in the normal development of non-iOS, specially designed in-game static data layer.

Clients often require a lot of static resources: Picture Resources & Sound Resources, window layout files, and other game planning data.

Rejecting flat file storage, a file is put in a file in a way that we want to reject this way. It is recommended to use SQLite, a lightweight database is recommended on mobile platforms. Unify the static data

Read and write, improve IO reading efficiency.

Unified management: Establish unified load, update and uninstall registration system, convenient game logic management and monitoring. Because we can monitor each module, is not the memory is super, the memory of the server is not too

Large, always have a monitoring of memory.

Data module schematic: Each of the above specific data manager will be developed from the DB, which generated a lot of sound, levels, props and other data manager.

UI layout diagram: The bottom of the client to do a layer, do gravity-induced events, the unified management of these events distributed. In the root window to do the game interface layout, for example, there is now a

The game layout file, which is also a layer, has multiple sub-layers on top, with control areas and panels, which form a tree structure that forms the UI layout of the entire game.

The following is a brief introduction to the UI System module:

Window Layout group: The same feature UI build merged into one layout layouts, unified management: Initialization/load/update/event response/unload operation; Based on the processing mode of message event, it is convenient to expand the script.

Use external configuration to process/support dynamic configuration.

Independent root window (uilayer): The bottom of the System window layer, all the layout of the parent window, the game's only monitoring Touch,accelerometer event Cclayer, using user input, unified processing.

Scripting Development: The Lua language expands to separate the specific logic from the game framework to enhance robustness.

UI layout configuration file schematic: Now start the UI layout, there is a window below, create a layer, in the game will create a cclayer, name, color, location, size and other things.

On top of this you have to do a tab, which can also be initialized. If you do knowledge scripting, this place can write a clear picture of what to do with what events.

Game UI System modules: About modal windows, modifying source code, adding the concept of precedence in Ccnode, and then increasing the priority of the parent window. All added UI builds need to be explicitly set to inherit

The priority of the parent node in order to form a priority response queue, in order to achieve the function of modal windows, with the help of system UIView, to implement a separate view interface, attached to Eaglview.

Related optimizations: All layout delays loading, unloading immediately when not in use, freeing up memory, merging required picture resources.

Game Sound module: This is a more enthusiastic module, I recommend the use of Fmodex, mature and efficient, simple and unified interface, no test platform differences; powerful, support 3D sound,

Settings such as mute, pause, volume, and so on are perfect for everyday music development, and of course need to be purchased. Reference count: The same sound effect requires only a single copy of the resource data, eliminating unwanted sound resources in a timely manner and reducing memory consumption.

humanized setting: Add humanized setting panel, enhance user's feeling; provide dynamic on/off, set volume and other functions; According to the purpose, divide the sound type, manage separately; Through application Delegate, the program gets the focus while playing sound, and when it is lost, it is muted. For sound resources, sound files are as small as possible, reducing memory usage.


Message Event Management module: The whole client is based on message event-driven, implementation and scheduling separation, maximum program reduces coupling.

Debugger Manager module: Xcode's own debugger tool is not enough, need more detailed monitoring for rendering, network, logical data, the combination of the two, macro micro, both hands caught together.

Log module: Log classification, sub-input mode, fully configurable, different types of logs, according to the level of separate records.

What else is needed. Message push: Borrow local and remote message push mechanism, improve product annual fit; Mobilize player's enthusiasm with "social engineering";

What does "social engineering" mean? Do anti-virus software and do trojan people to this kind of thing very understanding, for example I yesterday my mailbox also received social engineering guidance,

Say What lonely girl lonely plus friends have a link, with this provocative things guide you, you a little your computer hangs. UI interface design for mobile products,

Mobile product UI interface as simple as possible, direct, personalized operation. The characteristics of mobile products: Consider the characteristics of mobile products and people's usage habits, such as targeted design.

This is the end of my speech. Thank you.

Questions:

First, you just talked a lot of modules, I want to ask you these modules, or whether these architectures are a plan or have been implemented. Or is it in fact.

Li:

These modules have already been used in the mobile, or are already in use.

Questions:

We develop the end, the development of mobile games or, indeed, many are very real modules, I personally have a small suggestion, if you personally or say your company allows, or say

At some point in the future, you can contribute some modules or something to the cocos2d-x community, as these modules are indeed for a large game, or a complete tour

Play, there are a lot of modules are cocos2d-x community relatively missing. In addition, since so much has been done, it would be better to have the time to add the 3D stuff in.

We develop the game is a bit similar to the SPF of the substantive requirements are relatively high, you have not done such games, there is no experience, we agreed to use the time is UDP or TCP.

Li:


In the mobile or TCP way. In traditional sports games, the main data is still through TCP, but insignificant game can be done by UDP, a few frames to repeat the

Once, and then a TCP way, say, 20 frames and then repeat.

Questions:

UDP requires a reliable verification code.

Li:

Do not need, just need to do a good deal of messy package can be, to very timely position movement, the difference between 1 frames is 1 frames, you can move directly past.

Questions:

You mean that UDP and TCP are used together, and UDP does the message to verify the piece.

Li:

Right. Http://tech.163.com/12/0402/03/7U2BMGKE000915BF.html

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.