![]() |
|||||
|
|
MULTIPLAYER GAMES
In this tutorial we assume you understand
this document.
Specific functions allow you to synchronize physics simulations running on different connected computers. For example, imagine the interactive ball demo running on the server and all client computers. By synchronizing the ball body you ensure that any behavior performed by the ball on the server is replicated on all connected clients. All connected users will see the same simulation at the same time. The simulation, synchronized at regular intervals, will tend to run identically on all computers. It means that only small and infrequent adjustments will be necessary to keep it the same for all users. The whole simulation, including collision detection, sound effects, game logic and so on, is performed locally on each connected computer. This approach minimizes the amount of data to share, thus ultimately maximizing the number of simultaneous players. While body synchronization data can usually be exchanged infrequently, other game specific data may need to be shared often and immediately. Imagine a scenario in which, on a certain client computer, the user presses the left arrow key. The arrow key state is saved into a float variable named, for example, LeftKeyState (0.0f if not pressed, -1.0f if pressed). Because a force is applied to the ball while LeftKeyState is -1.0f, we should immediately share LeftKeyState variable among all connected computers, in order to ensure that the ball will have the same force applied and behave the same in all running simulations. Specific functions allow you to share (synchronize) float variables at any desired frequency. Additionally, the engine provides functions to transfer binary data from clients to the server and from the server to each specific client. You will typically use low-level data transfer functions to implement chat systems, to upload/download files, to share game databases and even to code custom synchronization systems. Fully commented source code, showing how to synchronize the default ball demo simulation, can be accessed, modified and compiled as follows. Note that we just needed to add 11 (eleven) function calls to transform the original ball game to a network playable demo! Open, compile and test the NetBallGame project by following the procedure described in the Quick Start Tutorial for the BallGame project. The source code is fully commented and examining it is strongly recommended! Don't forget to refer to Reference document for details on all functions called in the source code! See the last section of this tutorial for more on running/testing network projects. Fully commented source code, implementing a simple multiplayer chat system, active in the foreground, with no need to stop the game simulation, can be accessed, modified and compiled as follows: Open, compile and test the NetChat project by following the procedure described in the Quick Start Tutorial for the BallGame project. The source code is fully commented and examining it is strongly recommended! Don't forget to refer to Reference document for details on all functions called in the source code! See the last section of this tutorial for more on running/testing network projects. Fully commented source code, showing a technique to transfer a file from the server to a client, can be accessed, modified and compiled as follows: Open, compile and test the NetFileUpload project by following the procedure described in the Quick Start Tutorial for the BallGame project. The source code is fully commented and examining it is strongly recommended! Don't forget to refer to Reference document for details on all functions called in the source code! See the last section of this tutorial for more on running/testing network projects. The fully commented source code of a simple multiplayer ball-fighting game can be accessed, modified and compiled as follows: Open, compile and test the NetBallArena project by following the procedure described in the Quick Start Tutorial for the BallGame project. The source code is fully commented and examining it is strongly recommended! Don't forget to refer to Reference document for details on all functions called in the source code! See the last section of this tutorial for more on running/testing network projects. When developing multiplayer games, the gold rule is minimizing the amount of data that clients and server need to exchange. The less data exchanged the more players connected and better playability. In order to test compiled network DLL code samples, you need at least two connected computers, both with DirectX8.1 or greater installed. 1. Compile and make a stand-alone executable version of your .dll, as explained here (5.). 2. Copy the stand-alone demos to all the connected computers. 3. Launch the demo on a computer and, when asked, choose to run as server (host). Then launch it on all other computers and choose to run as client. 4. On client machines, you should be able to join the demo session by clicking 'Start Search', selecting it from a (one-item) list and clicking 'Join'. 5. On a LAN, you don't have to specify any IP address to join a session. On the Internet, you should specify the IP address for the server followed by the port number to use (25857). For example: 66.189.234.12:25857 |
||||
![]() |
|||||