首页 > 学院 > 开发设计 > 正文

MMO position synchronization and sample

2019-11-08 20:30:26
字体:
来源:转载
供稿:网友

Summary

         ThePRoblem of location synchronization involves three aspects: client, server, andother clients.

         Gameplayer feel is the most priority to meet the conditions, so the position of theclient game player is a benchmark, but depends entirely on the game playerclient data is in danger of being cheated, so the server per second will bebased on the general state of the projection of a game player client position.

         Theposition that other clients see depends entirely on the state of the baseclient, and if there is a delay or pause, the state will be reset according tothe latest status.

         movingenvironment of gird

         Howdo clients perceive each other's presence? The server map is divided into agrid of the same specifications, each client and NPC are assigned to differentlattices. As shown in the following figure

         3Dor 2D games can be divided in this way, the difference is that the height of the3D game will be much larger than the grid X or Y, so that the same XY areaunder the 3D game to have more space.

Server synchronization grid data.

         Inthe MMO game, players want to see all the players in the visible range, whichrequires other players to synchronize data over the network. Synchronoususually use 9 house grids determine what data need to be synchronized over thegame player, and then their behavior to be synchronized to what game player.

         Thesize of the server large grid to 3*3 lattice to the client than to show alarger range of principles. Larger than the client, is to reserve the time toload the resources.

         Asshown below, green represents the display area of the mobile client, when thecharacter A is in grid 6, he could see the contents of the 9 lattices of1,2,3,5,6,7,9,10,11, so when his state changes, you need to synchronize all theplayers in the 9 grids. also, when there is a change in the player or monsterin the 9 grids, it also needs to be synchronized to the character A.

Server synchronization grid data.

         Inthe MMO game, players want to see all the players in the visible range, whichrequires other players to synchronize data over the network. Synchronoususually use 9 house grids determine what data need to be synchronized over thegame player, and then their behavior to be synchronized to what game player.

         Thesize of the server large grid to 3*3 lattice to the client than to show alarger range of principles. Larger than the client, is to reserve the time toload the resources.

         Asshown below, green represents the display area of the mobile client, when thecharacter A is in grid 6, he could see the contents of the 9 lattices of1,2,3,5,6,7,9,10,11, so when his state changes, you need to synchronize all theplayers in the 9 grids. also, when there is a change in the player or monsterin the 9 grids, it also needs to be synchronized to the character A.

Player state is divided into 8 directions,corresponding to the keyboard up, dawn, right, lefe. When you press the"up" button will trigger the state of the broadcast, the player'scurrent location, state sent to the server, and through the server to allvisible players broadcast. see HelloWorldScene.cpp onKeyPressed () function.The client coordinates the current player's coordinates x, y, and status(setstatus) to the server. The server handles this request via status.lua.Status.lua first get the length and width of the grid into g_x_len, g_y_len. calculatethe current player client request. get the server to calculate the currentposition of the player to calculate the coordinates of the grid. and set theplayer's new status to path. the path is then put into the output buffer"script.out" and the "helpregist" script is used tocalculate the grid and the grid that the player is going to enter. and call"client/clientregist", "client/clientunregist" script.

         Theserver has two lists for each grid. "Client/clientregist" is thescript executed by the server when the client enters the grid. first, the datain the "listclient" table is sent to the client, Here are all theclient data stored in the grid. the player's data is then sent to otherclients. the NPC data in the listnpc table is then sent to the client. thendetermine whether the input parameter r is 1 if it is 1 to record the currentgrid. "s.replyid" will format the content of "script.out"to xml and return it to the client.

         The"parabuf" function in the client HelloWorldScene.cpp is used tohandle all the returned data from the server. the "regist" commandcontains the NPC data within the visible range of the player. among them arethe initial coordinates of NPC "P0" and the "P1" start timestamp "stamp". the client determines whether the current NPC existsand creates a, and according to the timestamp exists, if it does not exist as a"bomb" object.and according to the NPC coordinates and playercoordinates to calculate the coordinates of the screen in the NPC, the NCP willbe placed into the screen.

 

         Sampleprogram download

         https://sourceforge.net/projects/starrydb-publice/files/2017-2-9/

         Compiledclient relies on cocos2dx, download address

         http://www.cocos2d-x.org/download

starrydb is game server engine


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表