Skip to content

Commit 0d055a0

Browse files
bors[bot]leiter-jakabKreyren
authored
Merge #648 #659
648: Networking example r=toasteater a=leiter-jakab Hi godot-rust team, please review my networking example project. I would appreciate any comments and improvement points if you think this would be a useful example. Thanks and cheers, Gergo 659: example/dodge_the_creeps: Replace unsafe code r=toasteater a=Kreyren This merge request replaces the currently used `unsafe` code with safe implementation using `get_viewport_rect` Discovered during quality assurance for RXT0147/unnamedGame#1 Signed-off-by: Jacob Hrbek <[email protected]> Co-authored-by: Gergely Tabiczky <[email protected]> Co-authored-by: Jacob Hrbek <[email protected]>
3 parents 361a935 + 0851cb9 + 2112e6c commit 0d055a0

File tree

16 files changed

+258
-2
lines changed

16 files changed

+258
-2
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/dodge_the_creeps/src/player.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl Player {
3232

3333
#[export]
3434
fn _ready(&mut self, owner: &Area2D) {
35-
let viewport = unsafe { owner.get_viewport().unwrap().assume_safe() };
36-
self.screen_size = viewport.size();
35+
let viewport = owner.get_viewport_rect();
36+
self.screen_size = viewport.size.to_vector();
3737
owner.hide();
3838
}
3939

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 )

0 commit comments

Comments
 (0)