[Discussion] distributed computing action, my solution [sumtec]

Source: Internet
Author: User
Let's take a look at the sequence diagram:

Let's take a look at some additional instructions. On the left is the machine of tank and on the right is the machine of building. The first two receivedata calls lack senddata calls. In addition, some of them are actually asynchronous operations, such as some receivedata. I have used them to represent them for easy drawing. I hope you can check the code of the latest version when looking at this figure.


In the code of the latest version, eight (2*2 pairs) virtual functions are added for action. Getxxinfo/setxxinfo and getxxresult/setxxresult, respectively. XX is subject and target (subject and object ). To put it simply, in action. before onaction calculation, you may first need to know some specific data of both parties. At this time, the information will be sent to the owner of the subject and target, requesting that the data required for the calculation be given. The owner generates the same action object locally when receiving the message and calls setxxinfo. Then the local engine sends the set information. After receiving the message, the engine calls action. getxxinfo to update the copy of the local object. It can be seen that only a small amount of information is obtained and updated here. This information is necessary for an action to calculate onaction. Other information departments will update it here, to reduce the amount of computing and traffic. After onaction, the object or even some data of the subject will be updated. I suppose a more complex action, such as heal treatment, then healaction. onaction should reduce the MP of the subject and increase the target's HP. At this time, onaction should call the local setxxresult to publish the corresponding result information. When the original object owner receives the information, the engine calls healaction. getxxresult to update the corresponding information of the local object.

Now I should understand that there are three elements in my design: subject, action, and target. In this design, these three elements do not need to be on the same machine, but can be on the same machine. If the subject, action, and target are all on the same machine, it is a standalone version. If the subject and target are on different machines and the action is on one of them, the 1vs1 game is used. If the subject and target are on different machines, the action may or may not be on the same machine, that is, the langame mode of SC. If the subject, target, and action can be on any machine without any constraints related to the above, it is what I call the ultimate goal-distributed computing mode. We can see that this design theory should be able to adapt to several different modes, and this does not need to change the design of action and character. Action and character only need one version, you do not need to split it into the client and server versions. In this way, the development is less difficult. In what mode, you only need to make some settings in the engine.

One problem that has not been carefully considered here is the synchronization mutex problem. Dudu raised the issue of synchronization mutex. Two examples are given: one is the situation where a group of tanks attack a building, and the other is the situation where two tanks attack each other. In my opinion, the previous situation is not a problem. At least you do not need to lock the object for synchronization. We only need to transmit the Delta value in resultdata. For example, if HP is reduced by 12, HP <0, then immediately "explosion" and enter the "waste" state, which will not be reflected when HP is reduced. In fact, SC or C & C often see this situation: a sends a shell to the building, and HP is less than 0 when the shell arrives at the building. However, the building Hp was greater than 0 in the moment before the shell was launched. At this time, other tanks also attacked him. When other tank shells arrive, the building has crashed, but the game still has no effect, and we are not surprised. Therefore, in this case, we do not need to lock the object for synchronization. However, for the second case, I have not yet considered it clearly. Maybe there are some problems. What do you think?

I hope you will have some suggestions after reading this article so that we can take it to another level. Thank you.

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.