Skip to content

Commit 0851cb9

Browse files
committed
Add networking example
* Adds new client_server project under examples * The project contains a very simple network communication example using rpc calls * Updates root Cargo.toml to add the new project
1 parent 57973d7 commit 0851cb9

15 files changed

+256
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ members = [
1414
"examples/dodge_the_creeps",
1515
"examples/resource",
1616
"examples/native_plugin",
17+
"examples/rpc",
1718
"impl/proc_macros"
1819
]
1920

examples/rpc/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "rpc"
3+
version = "0.1.0"
4+
authors = ["The godot-rust developers"]
5+
publish = false
6+
edition = "2018"
7+
8+
[lib]
9+
crate-type = ["cdylib"]
10+
11+
[dependencies]
12+
gdnative = { path = "../../gdnative" }

examples/rpc/Client.tscn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://ServerPuppet.gdns" type="Script" id=1]
4+
5+
[node name="Server" type="Node"]
6+
script = ExtResource( 1 )

examples/rpc/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# RPC Demo
2+
3+
A very simple example to show peer to peer communication with Godot's high level multiplayer API calls.
4+
5+
6+
## Setup
7+
8+
1. Build the library with `cargo build`.
9+
10+
2. Import the Godot project in the Godot editor.
11+
12+
3. Open the `Server.tscn` scene and start the current scene with `F6`.
13+
14+
4. Start a second instance of the Godot editor.
15+
16+
5. Set a separate "Remote Port" for the second editor (e.g. 6012). The two editor instances need to have different debug ports so that they can connect to their own running scenes. Needed to show the godot print messages.
17+
18+
`Editor > Editor Settings > Network > Debug`
19+
20+
5. Open the `Client.tscn` scene and start the current scene with `F6`
21+
22+
23+
## References
24+
25+
* [Godot hih-level multiplayer API](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html)

examples/rpc/Server.gdns

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_resource type="NativeScript" load_steps=2 format=2]
2+
3+
[ext_resource path="res://client_server.gdnlib" type="GDNativeLibrary" id=1]
4+
5+
[resource]
6+
resource_name = "Server"
7+
class_name = "Server"
8+
library = ExtResource( 1 )

examples/rpc/Server.tscn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://Server.gdns" type="Script" id=1]
4+
5+
[node name="Server" type="Node"]
6+
script = ExtResource( 1 )

examples/rpc/ServerPuppet.gdns

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_resource type="NativeScript" load_steps=2 format=2]
2+
3+
[ext_resource path="res://client_server.gdnlib" type="GDNativeLibrary" id=1]
4+
5+
[resource]
6+
resource_name = "ServerPuppet"
7+
class_name = "ServerPuppet"
8+
library = ExtResource( 1 )

examples/rpc/client_server.gdnlib

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[general]
2+
3+
singleton=false
4+
load_once=true
5+
symbol_prefix="godot_"
6+
reloadable=true
7+
8+
[entry]
9+
10+
X11.64="res://../../target/debug/libclient_server.so"
11+
OSX.64="res://../../target/debug/libclient_server.dylib"
12+
Windows.64="res://../../target/debug/client_server.dll"
13+
14+
[dependencies]
15+
16+
X11.64=[ ]
17+
OSX.64=[ ]

examples/rpc/default_env.tres

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[gd_resource type="Environment" load_steps=2 format=2]
2+
3+
[sub_resource type="ProceduralSky" id=1]
4+
5+
[resource]
6+
background_mode = 2
7+
background_sky = SubResource( 1 )

examples/rpc/icon.png

3.23 KB
Loading

0 commit comments

Comments
 (0)