Differences
This shows you the differences between two versions of the page.
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/12/26 13:56] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
# Peer-to-peer | # Peer-to-peer | ||
- | <wrap em>This is a draft for a potential future feature of GDevelop.</ | + | <note important> |
- | + | ||
- | <note important> | + | |
GDevelop supports peer-to-peer (P2P) connections to enable basic multiplayer games. This works through the concept of *remote events*. | GDevelop supports peer-to-peer (P2P) connections to enable basic multiplayer games. This works through the concept of *remote events*. | ||
- | <note warning> | + | <note warning> |
+ | |||
+ | As such, it is hard to verify if someone is cheating (unlike dedicated servers). P2P supports a maximum of 250 simultaneous connections, | ||
## Selecting a broker server | ## Selecting a broker server | ||
- | Computers can't just connect to each other without | + | A running game, called a **client**, must connect to other clients before |
- | #### Set up your own server | + | There are two options for setting |
- | You can set up your own server easily. | + | * Setting up a custom server (recommended), |
- | 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. | + | * Using a default, public server. |
- | 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, | + | #### Set up a custom (local) |
- | I will use the port 9000 through the article, but you can use any that is not already used by your machine. | + | |
- | You can pass other options | + | A local server can be set up easily. |
- | You can the use the "Use custom broker server action" | + | |
- | <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 | + | Open a command line. To do so on Windows: |
+ | - Press the **Windows** and **R** keys. This will open the **run** window | ||
+ | - Type **cmd** in the popup. | ||
+ | - Press the **enter** key. | ||
+ | |||
+ | After opening a command line, complete the following: | ||
+ | - If this is the first time completing these steps, | ||
+ | - After the server is installed, and every subsequent time (to start the server), type **peerjs -p <the port>** | ||
+ | * Any port that is not already used by the computer can be used. | ||
+ | Other options | ||
+ | After the above has been completed, | ||
+ | * **localhost** can be used as the host 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 | ||
#### Use the default server | #### Use the default server | ||
- | <note important> | + | <note important> |
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 " |
## Connecting | ## Connecting | ||
Line 34: | Line 48: | ||
To connect instances, you need to enter their ID in the other instances. The ID can be found with the expression `P2P:: | To connect instances, you need to enter their ID in the other instances. The ID can be found with the expression `P2P:: | ||
- | ## Interracting | + | ## Interacting |
+ | |||
+ | 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 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/ | ||
+ | * With the *dataloss mode* activated, it doesn' | ||
- | 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/ | + | * 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* |
+ | * If you want to synchronise |