Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gdevelop5:all-features:p2p [2020/07/28 07:04]
arthuro555 Finish dataloss
gdevelop5:all-features:p2p [2020/08/03 15:37] (current)
4ian [About data loss]
Line 1: Line 1:
 # Peer-to-peer # Peer-to-peer
  
-<wrap em>This is a draft for a potential future feature of GDevelop.</​wrap>​ +<note important>​This is an experimental feature, it is potentially subject to change and may contain bugs. Your feedback is welcome to improve this feature.</​note>​
- +
-<note important>​This is an experimental feature, it is potentially subject to change and may contain bugs.</​note>​+
  
 GDevelop supports peer-to-peer (P2P) connections to enable basic multiplayer games. This works through the concept of *remote events*. ​ Connect multiple instances of the game using their **ID**, before remotely triggering conditions on the other instances. GDevelop supports peer-to-peer (P2P) connections to enable basic multiplayer games. This works through the concept of *remote events*. ​ Connect multiple instances of the game using their **ID**, before remotely triggering conditions on the other instances.
  
-<note warning>​This extension is not suitable for all types of multiplayer games and is potentially unsafe against cheating. As every instance of the game is connected, there is no machine ​more trusted than others ​that can verify if someone is cheating (unlike dedicated servers). P2P supports a maximum of 250 simultaneous connections,​ and is therefore also not suited for multiplayer-focused games like Agar.io or MMOs.</​note>  ​+<note warning>​This extension is not suitable for all types of multiplayer games and is potentially unsafe against cheating. As every instance of the game is connected ​directly to each other, there is no machine that can be considered trusted more than anothor. As such, it is hard to verify if someone is cheating (unlike dedicated servers). P2P supports a maximum of 250 simultaneous connections,​ and is therefore also not suited for very large multiplayer-focused games like MMOs.</​note>  ​
  
 ## Selecting a broker server ## Selecting a broker server
  
-Computers can't just connect to each other without ​being able to indentify themselves, to know where to send the data. To do so we need a broker servera server with a fixed adress (so that he can be identified) ​that stores all the adresses of the connected clients and give them to the clients so that they can connect to each other. You have two options here:  ​+Before ​being able to send dataa running game, called a "​client",​ must connect ​to other clients. For this, it needs a way to self identify and find other clients. To do so we need a broker server. It'​s ​a server with a fixed, well-known address ​that stores all the adresses of the connected clients and give them to the clientsso that they can connect to each other. You have two options here:  ​
  
-####  Set up your own server+* Setting ​up your own server ​(recommended),​ which you can run on your computer as a test. 
 +* Using a default, public server.
  
-You can set up your own server easily. You will need to [install Node JS](https://​nodejs.org/​en/​download/​). The LTS version is recommended. +####  Set up your own (local) server 
-Then open a command line. To do so on Windows, you can press the Windows and r keys, then type `cmd` in the popup, and enter. + 
-In the command line, type the first time only (to install the server) `npm install peer -g`+You can set up your own server easily. You will need to [install Node.js](https://​nodejs.org/​en/​download/​). The LTS version is recommended. 
 + 
 +Open a command line. To do so on Windows, you can press the Windows and r keys, then type `cmd` in the popup, and enter. 
 + 
 +In the command line, type the first time only (to install the server)`npm install peer -g`
 Then, whenever you want to start the server, just type in a command line `peerjs --port <the port>​`. ​ Then, whenever you want to start the server, just type in a command line `peerjs --port <the port>​`. ​
-I will use the port 9000 through the article, but you can use any that is not already used by your machine. +You can use any port that is not already used by your machine. 
-You can pass other options to the PeerJS server, see [it'​s ​website](https://​github.com/​peers/​peerjs-server) for more informations.   + 
-You can the use the "Use custom broker server ​action" to connect to your server. You can enter localhost as host to point directly to your own address. ​  +You can pass other options to the PeerJS server, see [its website](https://​github.com/​peers/​peerjs-server#​config--cli-options) for more information.   
-<note tip>Note that this is a local server, so it will only work on your machine. When releasing your game you will need to deploy one to a hosting ​website ​like heroku.</​note>  ​+You can then use "Use custom broker server" ​action ​to connect to your server. You can enter `localhostas the host to point directly to your own address. 
 + 
 +<note tip>Note that this is a local server, so it will only work on your machine. When releasing your game you will need to deploy one to a Node.js compatible ​hostinglike Heroku.</​note>  ​
  
 ####  Use the default server ####  Use the default server
  
-<note important>​It is not recommended to use that server, you should use your own if possible. The default server is not operated by GDevelop and GDevelop is not responsible if anything goes wrong using that server.</​note>​+<note important>​It is not recommended to use that server, you should use your own if possible. The default server is not operated by GDevelop and GDevelop ​team is not responsible if anything goes wrong using that server.</​note>​ 
 You can also use the default server provided by PeerJS. You can also use the default server provided by PeerJS.
-To use that server use the action "Use default server"​.  ​+To use that server use the action "​Use ​the default server"​.  ​
  
 ## Connecting ## Connecting
Line 34: Line 40:
 To connect instances, you need to enter their ID in the other instances. The ID can be found with the expression `P2P::​GetID()`. To connect, use the "​Connect to other instance"​ action and pass as parameter the ID of another instance. Both instances will then connect automatically. You can then send an event from one instance to the other one to make sure that the connection is established.  ​ To connect instances, you need to enter their ID in the other instances. The ID can be found with the expression `P2P::​GetID()`. To connect, use the "​Connect to other instance"​ action and pass as parameter the ID of another instance. Both instances will then connect automatically. You can then send an event from one instance to the other one to make sure that the connection is established.  ​
  
-## Interracting ​with connected games+## Interacting ​with connected games 
 + 
 +Once you got connected, you can trigger actions remotely. You can select another specific game instance (using its id) or send an event to all connected instances. 
 + 
 +### Choosing if you want to activate data loss mode 
 + 
 +You might be wondering what the "data loss" parameter is for.  
 +Due to how GDevelop is made, only one occurence of a remote event can be handled when the the event sheet is executed (this happens roughly 60 times per second). To help optimize events execution, we provide the choice to use the dataloss mode.  
 + 
 +* With the *no dataloss* mode, every remote event is queued, and on every frame if there is one in the queue, we take the oldest one and handle it. **This makes sure every data is processed/​taken into account.** 
 +* With the *dataloss mode* activated, it doesn'​t queue the data but only store the latest occurence of the remote event. **This means only the latest data is processed and outdated data will be discarded.** ​
  
-Once you got connected, you can trigger actions remotely. You can select a specific other game instance (by it's id) or send an event to all  ​ 
  
-#### Data loss+Here are two examples: ​
  
-You might be wondering what the data loss is for. Who would want to lose data right? Well it has to do with data handling. Due to how GDevelop is made, only one occurence of a remote event can be handled by execution of the event sheet. So to help optimize events execution we provide the dataloss mode. On the //no dataloss// mode, every remote event is queued, and on every frame if there is one in the queue, we take the oldest one and handle it. **This makes sure every data is processed/​taken into account.** The //dataloss mode// doesn'​t queue the data but only reminds the latest occurence of the remote event. ** This means only the latest data is processed and outdated one might be ignored.** As an example, ​if you use a synchronised score counter, you don't want to lose any data, as missing only one point of the counter would //​desynchronize// ​the counters, so the dataloss mode would be deactivated. If you want to synchronize ​positions ​tho, only the last position sent is relevant, not older positions, ​so you would activate the dataloss mode //to prevent delays/lag//.+* if you use a synchronised score counter, you don't want to lose any data, as missing only one point of the counter would *desynchronise* ​the counters, so the dataloss mode would be deactivated. ​ 
 +If you want to synchronise ​positions, only the last position sent is relevant, not older positions. In this canse, you would activate the dataloss mode *to prevent delays/lags*.