Analysis of computational 3--efficiency in MMO skill attack area

Source: Internet
Author: User

This article comes from the Fat treasure game , the reference must be indicated by the source!

For the calculation of the attack area, see the article two times:

MMO Game Skill Attack Area calculation

MMO Game Skill Attack area calculation 2--map grid

These two articles have been described in detail in the attack area, divided into the case of no lattice and lattice. It's not in detail here.

In the previous article, it has been concluded that, due to the service-side load-bearing problem, the map needs to be partitioned.

But after dividing the lattice, it can also be used to calculate the shape of circle, sector, rectangle, etc. by lattice configuration. But after a simple calculation, it is the cost of precision.

So today there are two ways to do an efficiency analysis.

First determine some basic conditions:

1. Set the map grid to 20*20, the entire map is 220*220, divided into 11 * 11 squares.

2. Each lattice lets a character stand.

The code is too large, put it at the end!!!

Statistical results:


Column chart:




Final Summary:

1 tested several times, found that the difference is not big, it is not average, only one time to take the data.

2 for the same area calculation, the increase in the number of executions, the basic is a proportional increase.

3 fan may appear at the same time multiple, because in the actual game, may be standing close to the player can not hit the situation, this time with a relatively small radius, the angle of the larger fan to supplement the more appropriate.

4 Grid less time efficiency is very high, but more lattice, efficiency is reduced.

To convert, a rectangle is equivalent to 18 squares of calculation, a sector equivalent to 6 to seven.

As to what is the way to compare, I suggest that all kinds of code need to write, then in accordance with the size of the size of the specific lattice, there is also a skill area to determine how many squares can be used to represent the attack area. In making a selection

5 It must be mentioned that the function parameters are not referenced at the beginning, and the execution time is almost 3 times times the data given now! In particular, the lattice algorithm function calls more, resulting in a lot of overhead, the gap is greater. So there's nothing to use a reference to, otherwise it's always a big thing to create new objects.

6 Unexpected fan These calculations are not very large, do not think that the algorithm is complex, the calculation of consumption is large, or need to be tested, it may surprise you!!!!!!

=======================================================================

Here is the specific test code

MapManager.h

header.h//helloworld//attention to the public number: Legends of the road, we learn together//Created by feiyin001 on 16/4/3.//Copyright (c) 2016 fablegame. All rights reserved.//#ifndef Helloworld_header_h#define helloworld_header_h#include <stdio.h> #include <        vector> #define PI 3.1412;//Pi # define cellbase 20;//Lattice size namespace Fablegame {struct Spoint {int x;    int y;    };        typedef std::vector<spoint> Seqspoint; static const int rectwidth = 500;//width of rectangle area, pixel static const int rectheight = 200;//height of rectangular area, pixels//Map All kinds of processing are placed here CLA SS Cmapmanager {public://Determine if two points are more than a certain distance from static bool Isfarthandistance (spoint& A, spoint& B, I                NT distance);        Determines whether a point is within a rectangle, this requirement is parallel to the axis static bool Inrect (double minx, Double Miny, Double Maxx, Double Maxy, spoint& p); Determines whether a point is within a rectangle, static bool Inrectrelat (spoint& originpoint, spoint& directionpoint, spoint& chec        Kpoint); Determine if the fan is static bool CheckinfaN (seqspoint& angleconfigs, spoint& originpoint, Spoin                t& Directionpoint, spoint& checkPoint);                Calculates the distance between two points static double computedistance (spoint& from, spoint& to); /** * Cartesian coordinates--absolute coordinate to relative coordinate * originpoint origin of relative coordinate system * Directionpoint points to X-axis direction * Changepoint needs to be converted Coordinates */static Spoint changeabsolute2relative (spoint& originpoint, spoint& directionpoint, SPoint&amp ;        Changepoint);                        The axes of this conversion are parallel to the original static Spoint changeabsolute2relative (spoint& originpoint, spoint& changepoint); ====== detects if the ====== static bool Checkincell (seqspoint& pointconfigs, spoint& orig, inside the lattice configuration's graphics)            Inpoint, spoint& checkPoint);                }; } #endif



MapManager.cpp

mapmanager.cpp//helloworld//attention to the public number: Legendary Road, we learn together//Created by feiyin001 on 16/4/3.//Copyright (c) 2016 Fablegam E. All rights reserved.//#include "MapManager.h" #include <math.h>using namespace fablegame;//determine if the two-point is more than a certain distance of bool Cmapmanager::isfarthandistance (spoint& A, spoint& b, int distance) {//Find the relative distance xy int x = (a.x-b.x) * Cellbas    e;//coordinate points are the coordinate points of the lattice, so multiply the length of the lattice int y = (a.y-b.y) * cellbase; if (x * x + y * y > Distance *distance) return true;//over distance (Pythagorean) return false;//not exceeding}//to determine if a point is within the rectangle, this requirement is parallel to the axis bool CMap Manager::inrect (double minx, Double Miny, Double Maxx, Double Maxy, spoint& p) {//Determines whether the xy of the point P is between the upper and lower left of the rectangle if (p.x    ; = Minx && p.x <= Maxx && p.y >= miny && p.y <= Maxy) return true; return false;} Calculates the distance between two points double cmapmanager::computedistance (spoint& from, spoint& to) {return (sqrt (POW (to.x-from.x, 2) + Pow (TO.Y-FROM.Y, 2))) * cellbase;} Cartesian coordinates--absolute coordinate to relative coordinate spoint Cmapmanager::changeabsolute2relaTive (origin of spoint& originpoint,//relative coordinate system    spoint& directionpoint,//points spoint& Changepoint to the x-axis direction)//coordinates to be converted {    Originpoint is a point in the figure, Directionpoint is the B point in the figure, and the Changepoint is the C point spoint repoint in the graph; if (originpoint.x = = Directionpoint.x && Originpoint.y = = directionpoint.y)//The direction point coincides with the origin, the x-axis parallel to the original coordinate to calculate the line {//ab point weight        Close, direction pointing where all not so-called, certainly according to the original do convenient repoint.x = Changepoint.x-originpoint.x;    Repoint.y = Changepoint.y-originpoint.y;        } else {//calculate three sides double A = computedistance (Directionpoint, changepoint);        Double b = computedistance (Changepoint, originpoint);                Double c = computedistance (Directionpoint, originpoint); Double CosA = (b*b + c*c-a*a)/2*b*c;//cosine repoint.x = a * cosa/cellbase;//relative coordinates x REPOINT.Y = sqrt (A*a- A * CosA * a * CosA)/cellbase;//relative coordinates y} return repoint; BOOL CMapManager::inrectrelat (spoint& originpoint, spoint& directionpoint, spoint& checkPoint) {//detects if each role is inside a rectangle. Spoint repoint = changeabsolute2relative (Originpoint, Directionpoint, checkPoint);//Relative coordinates//skillwidth is the width of the graph, Skilllong length int skillwidth = rectwidth/cellbase;//Rectangle attack area width int skilllong = rectheight/cellbase;//Rectangle attack Area Height/width is divided by ab , starting from point A, extend the length of return inrect (0,-SKILLWIDTH/2, Skilllong, SKILLWIDTH/2, repoint);//Relative coordinates attack range}spoint Cmapmanager::changeab    Solute2relative (spoint& originpoint, spoint& changepoint) {spoint repoint;    Repoint.x = Changepoint.x-originpoint.x;    Repoint.y = Changepoint.y-originpoint.y; return repoint;} BOOL Cmapmanager::checkinfan (seqspoint& angleconfigs, spoint& Amp     Originpoint, spoint& directionpoint, spoint& checkPoint) { The unit vector spoint repoint = Cmapmanager::changeabsolute2rela of the primary target firsttive (Originpoint, directionpoint);//The vector of the attacker and the master target double longb = sqrt (repoint.x * repoint.x + repoint.y * repoint.y);//Length    Repoint.x/= LONGB;         Repoint.y/= longb;//to find the unit vector for (seqspoint::iterator aniter = Angleconfigs.begin ();         Aniter! = Angleconfigs.end ();                                           aniter++) {if (Cmapmanager::isfarthandistance (Originpoint,        CheckPoint, Aniter->y))//detection is outside the fan radius range        {return false; }//Then find the vector of the detection point spoint REPOINTC = cmapmanager::changeabsolute2relative (Originpoint, checkPoint);//Figure C        Point relative coordinates double LONGC = sqrt (repointc.x * repointc.x + repointc.y * repointc.y);//length repointc.x/= LONGC;  Repointc.y/= longc;//Find the unit vector//based on the click of the vector to find the angle double jiaodu = ACOs (repoint.x * repointc.x + repoint.y * repointc.y) * 180/pi;//actual angle size double Anglebeta = aniter->x;                if (Jiaodu < Anglebeta) {//The angle of difference is less than the angle of the configuration, so it is under attack. Note that the angle here is between 0° to 360° return true;//within the angle Range}} return false; BOOL Cmapmanager::checkincell (seqspoint& pointconfigs, spoint& originpoint, spoint& checkPoint) {SPoint re Point = Changeabsolute2relative (Originpoint, checkPoint);//Calculate relative position//determine if the same as configured for (Seqspoint::iterator iter = PO         Intconfigs.begin ();//Detect if coincident points of iter! = Pointconfigs.end ();        iter++) {if (iter->x = = Repoint.x && iter->y = = Repoint.y) {return true; }} return false;}



Main.cpp

main.cpp//helloworld//attention to the public number: Legends of the road, we learn together//Created by feiyin001 on 16/4/3.//Copyright (c) 2016 fablegame. All rights reserved.//#include <iostream> #include "stdio.h" #include "stdlib.h" #include "time.h" #include " MapManager.h "using namespace Fablegame;int main (int argc, const char * argv[]) {//========== First determines some underlying content ======== ======== int skilldistance = 1000;//Skill release distance spoint attackerpoint;//attacker location attackerpoint.x = 0;//Attacker location attack Erpoint.y = 1;//attacker location Spoint defenserpoint;//by attacker location or skill release point defenserpoint.x = 8;//by attacker location or skill release point Defenserpoint.y    = 8;//is the attacker's location or skill release point Seqspoint otherroles;//other roles to be detected//other role locations, in order to facilitate testing, put a person in each lattice.             Otherroles other roles to be detected for (int i = 0; I <=, i++) {for (int j = 0; J <=; J + +) {Spoint p;            p.x = i;            P.y = j;        Otherroles.push_back (P); }} int count = 1000000;//increase the number of executions to help reduce the amount of time spent on public spending std::cout << "Fable game! Number of executions "&Lt;<count<<std::endl;        ===== do nothing, look at the time ========= {clock_t startTime = clock ();//start time int i = 0;        while (I < count) {i++; } clock_t endTime = Clock ();//End time Std::cout << "do nothing, loop 1000 times:" << (endtime-starttime)/1000        << "milliseconds" <<std::endl; divided by 1000, because the MacBook uses microseconds, here in milliseconds to//===== the point-to-point detection ========= {clock_t startTime = clock ();//Start time int        i = 0;            while (I < count) {i++; for (Seqspoint::iterator iter = Otherroles.begin (); ITER! = Otherroles.end (); iter++) {if (Cmapmanager::is         Farthandistance (Attackerpoint, *iter, skilldistance)) {//points within the attack range, can be attacked}} } clock_t endTime = Clock ();//End time Std::cout << "point-to-point detection, use time:" << (Endtime-start        Time)/1000 << "milliseconds" <<std::endl; divided by 1000, because the MacBook uses microseconds, here in milliseconds to//===== the sector ====== {seqspoint angleconfigs;//fan configuration for (int cellnum = 1; cellnum <= 3; cellnum++) {SPo The exact value of the int p;//p point is meaningless here, but here you want it to run through the entire loop p.x = 60;//Angle P.y = 1000;//radius angleconfigs.push_back (                    p);            clock_t startTime = Clock ();//start time int i = 0;                while (I < count) {i++;                     for (Seqspoint::iterator iter = Otherroles.begin ();                     Iter! = Otherroles.end ();                    iter++) {if (Cmapmanager::checkinfan (Angleconfigs, Attackerpoint, Defenserpoint, *iter)) { The point within the fan range can be attacked}}} clock_t EndTime = Clock (); End time Std::cout << "sector algorithm detection, Sector number" <<angleconfigs.size () << "Usage Time:" << (Endtime-starttime)            /1000 << "MS" <<std::endl;  divided by 1000, because the MacBook uses microseconds, here in milliseconds}}//===== rectangle ========= {      clock_t startTime = Clock ();//start time int i = 0;            while (I < count) {i++; for (Seqspoint::iterator iter = Otherroles.begin (); ITER! = Otherroles.end (); iter++) {if (cmapmanager::in        Rectrelat (Attackerpoint, Defenserpoint, *iter)) {//points within a rectangular range, can be attacked}} } clock_t endTime = Clock ();//End time Std::cout << "Rectangle algorithm detection, use time:" << (endtime-starttime)/        << "milliseconds" <<std::endl; Divided by 1000, is because the MacBook uses microseconds, here in milliseconds to put}//===== round ========= {clock_t startTime = clock ();//start time int i =        0;            while (I < count) {i++; for (Seqspoint::iterator iter = Otherroles.begin (); ITER! = Otherroles.end (); iter++) {if (Cmapmanager::is         Farthandistance (Attackerpoint, *iter, skilldistance)) {//points within the attack range, can be attacked}} } clock_t endTime = Clock ();//End time Std::cout << "round algorithm detection, use time:" << (endtime-starttime)/1000 << "milliseconds" <<std::endl; divided by 1000, because the MacBook uses microseconds, here in milliseconds to//==========================================================}//============== = = through the configuration of the lattice to achieve a variety of shapes ===================//========================================================== {SeqSPoint        Pointconfigs; for (int cellnum = 1; cellnum <=; cellnum++) {Spoint p;//p point's specific value is meaningless here, but here you want it to run through the loop p.x = 10            000;            P.Y = 10000;                        Pointconfigs.push_back (P);            clock_t startTime = Clock ();//start time int i = 0;                while (I < count) {i++; for (Seqspoint::iterator iter = Otherroles.begin (); ITER! = Otherroles.end (); iter++) {if (cmapmanage                R::checkincell (Pointconfigs, Attackerpoint, *iter)) {//points within the attack range, can be attacked}        }            }                clock_t endTime = Clock ();//End time Std::cout << "lattice algorithm detection, lattice number" <<pointconfigs.size () &lt            ;< "Usage Time:" << (endtime-starttime)/1000 << "MS" <<std::endl; divided by 1000, because the MacBook uses microseconds, here in milliseconds}} return 0;}




Analysis of computational 3--efficiency in MMO skill attack area

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.