Game Fog algorithm

Source: Internet
Author: User

Beijing Liu Language Breast Enhancement tea

Fog of war in addition to the client to show, the server also to calculate, because the server to calculate that this enemy is what you can see, can see to send its data to you. If the server does not calculate, it is easy to cheat, such as CF game, by using the plug can be worn through the wall to see the enemy. This is because the server does not calculate, all the enemy's data are sent to the client, the client based on the obstacle calculation that the enemy is invisible. So in order to prevent fraud, the best aspect is that the server (data layer) and the client (presentation layer) are computed. The performance is very important, after all, a map has a lot of people, and must always calculate.

1, fog algorithm-no obstacle situation

We divide a transparent element into 4 parts (gray-invisible, green-visible), get 4 translucent elements, and number to 1,2,4,8.

Why is the number 1,2,4,8, not 1,2,3,4? (Read this section, then see the answer)

4 Elements Free combination, we can use 4 0 or 1 to indicate whether there are corresponding elements in the composition.

For example, 0101 means 1th None, 2nd Leen, 3rd No, 4th Leen.

So each of the 0101 sequences represents an entity. Change the following binary into decimal:

1000=1,1 Number of elements

0100=2,2 Number of elements

0010=4,4 Number of elements

0001=8,8 Number of elements

Press the OR operation. Number 1th + 2nd + 4th no. + 8th = 15th. (1|2|4|8 = 15)

So, with these 4 primitives, we can get 16 different primitives. Why is it 16? number No. 0 How did you get that?

1, why are 16 entities?

According to the "combinatorial fraction" of high school Mathematics, 4 basic elements, free combination, there are 16 combinations of total. Like what:

Number 1th + 2nd + 4th no. 8th = 15th

Number 2nd + 8th = 10th

Number 5th + 12th = 13th (by or algorithm)

2, No. 0, how did you get that?

It is known from question 1 that when there is no 1,2,4,8 entity, you can get the number No. 0 element.

Based on 4 basic Primitives (1,2,4,8), let's consider the actual situation in the game.

1. If a teammate stands on a map, then the visibility around him is as follows:

2. If two teammates stand on the map, then the visibility around them is as follows:

Why do 5th and 10th elements appear?

The 5th element is composed of "teammate 1 's 1th element" and "teammate 2 's 4th element".

The 10th element is composed of "teammate 1 's 2nd element" and "teammate 2 's 8th element".

The following 5 teammates appear together at the same time.

2, fog algorithm-there are obstacles to the situation

Basically all of the game maps have obstacles, so "fog algorithm-no obstacle" is not suitable.

So how can reality have the fog algorithm of obstacles? From the human mind, if the line of sight is blocked by obstacles, behind the obstacles are not visible.

The following is a case of lol:

If a teammate stands on a map, the following is the case.

So we can get 8 basic primitives, numbered 1,2,4,8 ..., and generate 256 different entities with a free combination.

1, if a teammate's visibility is 3 meters, there is an obstacle in the middle.

After the obstacle should be invisible, how to deal with the program to get this effect?

1, first we determine whether there are obstacles in front of the line of sight?

2, next we determine to encounter obstacles, how to do?

Take a lattice as an example, we use 1, 3rd line of sight to determine whether a lattice is blocked by obstacles.

Junior High School Mathematics knowledge, 1,3 straight line for rectangular diagonal, seek straight through the small square? This is easy.

1, if the two straight lines are not encountered obstacles, then the lattice is fully visible. (This can be seen, not the lattice is completely transparent, but not the visibility when obstacles are not considered)

2, if the two straight lines have obstacles, then the lattice is completely invisible (such as: B lattice. 2,4 the sight of the obstruction).

3. If a piece encounters a barrier, one does not encounter a barrier, then half of the visible area of the lattice is visible (half of the visible area, not half of the entire lattice visible. For example: a lattice).

Then the entity visible area is half visible, how to achieve? Is it split?

It is not possible to use split, split-up primitives, which cannot be combined with 8 primitive primitives, but we only have 256 elements. Like what:

Since the segmentation is not possible, it can only be blurred, from 256 (8 basic elements of the free combination) entity to find an element similar to the partition diagram. For a single teammate in the absence of obstructions only need 8 basic elements and a fully visible image, you can implement the fog algorithm, there are obstacles are just some need to split. So just find these 9 images showing half of the visible elements (about 18 photos).

Game Fog algorithm

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.