2D online game development (network) (10)

xiaoxiao2021-04-05  250

2D

Online game development (network) (10)

Author:

akinggw

Foreword

In fact, I also want to simplify the game development, no matter how hard I work, the game development is still so difficult, or it involves so much knowledge. Similarly, here, I also hope that my translation and explanation will let you understand, in order to make you more easily understand the content of the game development, so your feedback is very important to me.

My email is akinggw@126.com

. You are welcome to make your valuable comments. Recently, the weather is hot, so I also changed to translation, I hope that there is no mistake.

Send packet

Decide your data

About this thing, I have already explained the packet, you'd better flip the previous content.

Decided to use that way

You usually want to send a logo triggering, not the result of sending actions. Generally, a source of packets is mainly concentrated in the following three aspects:

From a function to trigger the action

From a logo drive function to trigger

From a data manager

Each method has its own advantages and disadvantages.

From a function to trigger the action

example:

If we have a function called

Shootbullet

A large number of parameters, including shooting, where is shooting and noutine shot. Each

Shootbullet

Once the function is called, then I will send a packet to tell the network, and there is already something happening.

Advantages of this method

It is easy to maintain.

Shootbullet

Functions may be called in many different places (for example, the mouse output, the keyboard output,

Ai

Wait, therefore, we have to guarantee the consistency of each received place. This method is easy to achieve in the current single player game.

Disadvantages of this method

Programming is difficult. If I use

Shootbullet

Go to the initial package, then what will it call when the network wants this function? in case

Shootbullet

Initial data package, and network call

Shootbullet

The function, then another packet will be sent to establish a feedback loop. So I can write another function, such as

Doshootbullet,

Or transfer a parameter to

Shootbullet

Tell it to send a packet. We have to consider authorization, the client is issued directly, or before the bullet is issued, it is authorized to authorize it. If you need to authorize, then

Shootbullet

A packet will be sent and return it immediately, only one situation will not return, that is, it is called by the network and it cannot send a packet. That network may also need some

Shootbullet

The additional information does not have, such as the number of bullets. Sometimes these can be obtained from the context, but sometimes they cannot.

From a logo drive function to trigger

We still use the above example, but this time there is a difference, we are in this time

Shootbullet

The data package is sent inside, and when sending a packet is determined by a flag. For example, when the user clicks the mouse,

Ai

Deciding the shooting or space bar was pressed.

advantage

I can call in the network.

Shootbullet

Function, without worrying about returning loops. And I will get more information other than functions. Therefore, the data can be easily transmitted using the network.

Disadvantage

It is difficult to maintain. If I add another method shooting bullet, I will forget to send a packet.

From a data manager

example

Every time, a player's health arrives

0

Send a packet. Anyway, I will not do this. I will add it to some functions running each frame, perhaps implement the player's update in the code. When the code finds that the player's health is 0

When it immediately sends a packet. Then register this already sent packet to avoid retransmit again.

advantage

From the network, it is very clear. I have to worry about feedback and change the function in actual action. No maintenance, unless some people change it. There is also very efficient.

Disadvantage

However, from the perspective of the design, it is very unclean and can only be used for a certain type of data. Also, it has to be set up.

Deciding the type of reliability and what kind of order you need

PcaketPriority.h

The type of reliability is included. You need to make a choice from the third level:

HIGH_PRIORITY, MedIUM_PRIORITY, LOW_PRIORITY

.

High reliability data package ratio in the data of reliability, and the medium reliability data packet is sent first higher than the low reliability data. In the game, you will use

Reliable_order

To set the packet.

Send function of calling the client's server

The send function does not change your data, but will make a copy.

Sequential flow

For sequential packets, there is

32

Sequence flow, and for continuous data packets,

32

Sequence flow. You can imagine the stream into a related order, all of which have the same order type. We can give an example to describe this thing. Suppose you want to sort all chat information, sort all players mobile packets, sort all players open pack, continuous all-in-one ammunition packets. You want chat information to arrive in order, and don't want to chat information, because you can't easily get the player moving packet. The player's mobile packet is not associated with chat information, so you don't have to worry that they arrive in order. This way, you can use different sequential flows, maybe,

0

Represents chat information,

1

Indicates the player's mobile data package. It is worth mentioning that the order of the player's fire packet should be related to the packets moving by the player, because you don't want to fire in the wrong location. Therefore, you should put the player's fired data package in the same data stream as the player's mobile data package. The advantage of this is that if the fire data package arrives after compared with the mobile data package, the fire packet will not give you anything, it will wait for the arrival of the mobile packet.

The sequence will keep the old packet, so if you get the order of the package

2

,

1

,

3

Then you will start receiving

2

,

1

, Then these packages are removed, and finally you will get a packet.

3

. This is very useful for ammunition, because the ammunition is just a continuous decline. If you get a very old package, you will get a lot of ammunition, which is obviously a mistake. It is worth noting that the sequence packet is different from the order packet because the sequential packet is represented by a set of streams.

For more information, please visit the Jinqiao Science website (

http://popul.jqcq.com

The game development section, if you need a book development, please refer to Jinqiao Book City Game Channel (

http://book.jqcq.com/category/1_70_740.html

).

If you have any good suggestions when you read this article, please let me, mine.

E_mail: akinggw@126.com.

If you are using

SDL

What is wrong with it, please go to Jinqiao Scot,

http://popul.jqcq.com

) The game development section, I will answer your questions in detail.

转载请注明原文地址:https://www.9cbs.com/read-132150.html

New Post(0)