Game System Development Notes (4)-Introduction to game programs

Source: Internet
Author: User

Game programs or other functions are not very different from developers. The major difference lies in product design.

 

However, gaming is one of the largest and most complex applications in the software world, and the code scale is basically on the order of millions of lines. Therefore, the implementation requires careful architectural design and flexible application of programming languages and skills, otherwise, the legendary software crisis may easily occur during the development process... for a commercial software, the first thing to solve is the feasibility problem, and then the cost problem to be solved. The software technology becomes the art of balance between availability and development efficiency.

 

Of course, simply put, the online game program is nothing more than a simple C/S architecture software, on the basis of the basic network communication function, the client adds some interface logic, the server adds some game logic, and then each client sends a request to the server to interact with other clients.

 

The following is a brief introduction to online games in the program structure:

 

I have seen two main types of programs. One is functional programs designed to solve a specific problem. The general structure is:

Input-> algorithm-> output is basically a pure algorithm.

 

Another type of application is a self-contained application. To implement the functions of multiple modules and take into account the overhead issues, it is usually designed as follows:

WHILE(COND) DO   DO STH.END

 

To make the software look normal, there are usually some blocking operations (such as read) inside the loop or directly calling sleep to suspend the thread to reduce unnecessary performance overhead.

Game programs use the second type, which is called gameloop.

 

By extension, a simple game server looks like this:

 
Gameinit (); // initialize each resource data while (gamestate! = Game_exit) {flush_net_event (); // process the network message flush_tick_event (); // process the scheduled event game_sleep (); // run the cycle at a certain frame interval, when the amount of time is too large, sleep is required. If the calculation amount is too large, the system runs the next loop directly .} Release (); // cleanup and record operations

 

Some typical examples of game functions, suchProcess of role MovementThe program is roughly divided into the following steps:

1. The player a client receives a key message and converts it to a moving target point in the game world coordinates and then sends it to the server.

2. After receiving the message, the server first heap it in the network message queue for processing (at this time, the current frame may have processed the network message, but the next logical frame has not started yet)

3. The pop queue on the server starts to process the mobile message (flush_net_event)

4. After verification, the server changes the role location information on the server and sends a mobile message to the client to agree to move the message.

5. the server sends a mobile message to other clients, notifying other clients to move "a player" to the target location.

6. After receiving the "indication" from the server, other clients will show a moving image.

 

Of course, more things should be considered in the actual game, such as obstacles, finding the path, location synchronization, feeling of delay, and synchronized data volume, it is necessary to optimize the above process.

 

Another example isHow gamers fight monsters:

1. When the player client clicks a monster, the client determines what operations the player wants to perform Based on the mouse clicking position (or role position ).

2. Send a message to inform the server that I want to blame

3. flash_net_event on the server

4. The server verifies the request and determines whether the attack conditions are met.

5. The server notifies the gamer client and other gamer clients to fight against the monster.

6. The server determines and settles the damage to the monster Based on the player's skill information.

7. The client displays an animation after it receives the "alarm indicator ".

 

The specific implementation will also have some optimizations. The above process is actually relatively dependent on the server. Some games have strong action elements, and such a process may lead to latency issues, you need to submit more tasks to the client. The main problem in doing so is that it is difficult to make multiple clients have better synchronization effects, and it is also easy to breed plug-ins.

 

During these processes, some operations may need to be scheduled, so register a scheduled event and run it in the logical frame where the time already meets the requirements.

 

Of course, this year is just Online mobile and combat, and it is basically difficult to call it a game. It is necessary to have rich gameplay, props, and NPC systems. Most of these functions are actually not special in this process. You only need to get tired of code.

 

It is also worth mentioning that,Game Products are highly dependent on DataEven for a simple bullet screen game, it is also necessary to design many levels, different bullets have different shapes, flight speeds, lethality, and boss blood volume. It is unrealistic to include all these things into the code. You must extract the logic and data from the method and associate them in a simple way.

 

So nowadays, large games usually have a lot of data tables, some design equipment, some design items, some design skills, some design NPC, some design values, tasks, and so on. According to the previously described division of labor, it is generally a method agreed by both parties in terms of procedures and planning (in fact, the program compromises the planning) to fill in the data table, the program also parses data files according to this specification. In this way, when the game program is started, it loads the data into the memory, and parses and forms an easy-to-use data structure of the program. Then it will be easier to develop.

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.