From 00d14a30cb976c19a5cadeadbaa9d217cd6bfb31 Mon Sep 17 00:00:00 2001 From: Jovan Gerodetti Date: Tue, 9 Jan 2024 00:56:57 +0100 Subject: [PATCH] update godot-rust-script / gdext --- native/Cargo.lock | 24 ++- native/Cargo.toml | 4 +- .../src/scripts/particles/dust_particles.rs | 88 ++++---- native/src/scripts/spawner/car_spawner.rs | 189 +++++++++--------- native/src/terrain_builder.rs | 4 +- resources/Shaders/ocean_visualshader.tres | 1 - resources/Textures/tex39-39.png.import-2VCCBd | 0 resources/Textures/tex40-2.png.import-47AJay | 0 resources/main.tscn | 3 +- src/native.gdextension | 12 +- 10 files changed, 168 insertions(+), 157 deletions(-) create mode 100644 resources/Textures/tex39-39.png.import-2VCCBd create mode 100644 resources/Textures/tex40-2.png.import-47AJay diff --git a/native/Cargo.lock b/native/Cargo.lock index 33e4eb0..eae13c8 100644 --- a/native/Cargo.lock +++ b/native/Cargo.lock @@ -286,7 +286,7 @@ checksum = "8e4afd9ad95555081e109fe1d21f2a30c691b5f0919c67dfa690a2e1eb6bd51c" [[package]] name = "godot" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" +source = "git+https://github.com/titannano/gdext?rev=e3644a0348b4d6fe952007cebd94d1d3f5ddfd86#e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" dependencies = [ "godot-core", "godot-macros", @@ -295,15 +295,20 @@ dependencies = [ [[package]] name = "godot-bindings" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" +source = "git+https://github.com/titannano/gdext?rev=e3644a0348b4d6fe952007cebd94d1d3f5ddfd86#e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" dependencies = [ "godot4-prebuilt", ] +[[package]] +name = "godot-cell" +version = "0.1.0" +source = "git+https://github.com/titannano/gdext?rev=e3644a0348b4d6fe952007cebd94d1d3f5ddfd86#e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" + [[package]] name = "godot-codegen" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" +source = "git+https://github.com/titannano/gdext?rev=e3644a0348b4d6fe952007cebd94d1d3f5ddfd86#e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" dependencies = [ "godot-bindings", "godot-fmt", @@ -317,10 +322,11 @@ dependencies = [ [[package]] name = "godot-core" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" +source = "git+https://github.com/titannano/gdext?rev=e3644a0348b4d6fe952007cebd94d1d3f5ddfd86#e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" dependencies = [ "glam", "godot-bindings", + "godot-cell", "godot-codegen", "godot-ffi", ] @@ -328,7 +334,7 @@ dependencies = [ [[package]] name = "godot-ffi" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" +source = "git+https://github.com/titannano/gdext?rev=e3644a0348b4d6fe952007cebd94d1d3f5ddfd86#e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" dependencies = [ "gensym", "godot-bindings", @@ -339,7 +345,7 @@ dependencies = [ [[package]] name = "godot-fmt" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" +source = "git+https://github.com/titannano/gdext?rev=e3644a0348b4d6fe952007cebd94d1d3f5ddfd86#e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" dependencies = [ "proc-macro2", ] @@ -347,7 +353,7 @@ dependencies = [ [[package]] name = "godot-macros" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" +source = "git+https://github.com/titannano/gdext?rev=e3644a0348b4d6fe952007cebd94d1d3f5ddfd86#e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" dependencies = [ "godot-bindings", "proc-macro2", @@ -358,7 +364,7 @@ dependencies = [ [[package]] name = "godot-rust-script" version = "0.1.0" -source = "git+https://github.com/titannano/godot-rust-script?rev=a2a5c018fcf0247f1d242ec2bf8a994cc975c1ee#a2a5c018fcf0247f1d242ec2bf8a994cc975c1ee" +source = "git+https://github.com/titannano/godot-rust-script?rev=b06f02fdbb320a3cb3cd79ad4589593aba5f4b47#b06f02fdbb320a3cb3cd79ad4589593aba5f4b47" dependencies = [ "abi_stable", "const-str", @@ -372,7 +378,7 @@ dependencies = [ [[package]] name = "godot-rust-script-derive" version = "0.1.0" -source = "git+https://github.com/titannano/godot-rust-script?rev=a2a5c018fcf0247f1d242ec2bf8a994cc975c1ee#a2a5c018fcf0247f1d242ec2bf8a994cc975c1ee" +source = "git+https://github.com/titannano/godot-rust-script?rev=b06f02fdbb320a3cb3cd79ad4589593aba5f4b47#b06f02fdbb320a3cb3cd79ad4589593aba5f4b47" dependencies = [ "darling", "proc-macro2", diff --git a/native/Cargo.toml b/native/Cargo.toml index a57feb7..8ff2488 100644 --- a/native/Cargo.toml +++ b/native/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -godot = { git = "https://github.com/titannano/gdext", rev = "4ce4714" } +godot = { git = "https://github.com/titannano/gdext", rev = "e3644a0348b4d6fe952007cebd94d1d3f5ddfd86" } lerp = "0.4.0" backtrace = "0.3.64" num = "0.4.0" @@ -15,4 +15,4 @@ rayon = "1.5.1" itertools = "0.10.3" num_enum = "0.7.1" -godot-rust-script = { git = "https://github.com/titannano/godot-rust-script", rev = "a2a5c018fcf0247f1d242ec2bf8a994cc975c1ee" } +godot-rust-script = { git = "https://github.com/titannano/godot-rust-script", rev = "b06f02fdbb320a3cb3cd79ad4589593aba5f4b47" } diff --git a/native/src/scripts/particles/dust_particles.rs b/native/src/scripts/particles/dust_particles.rs index e11664e..0a78784 100644 --- a/native/src/scripts/particles/dust_particles.rs +++ b/native/src/scripts/particles/dust_particles.rs @@ -1,9 +1,9 @@ use godot_rust_script::{ - godot::{ - engine::{GpuParticles3D, PrimitiveMesh, StandardMaterial3D}, - prelude::{godot_error, Gd}, - }, - godot_script_impl, GodotScript, + godot::{ + engine::{GpuParticles3D, PrimitiveMesh, StandardMaterial3D}, + prelude::{godot_error, Gd}, + }, + godot_script_impl, GodotScript, }; /// Dust Particle behavior for a particle system. @@ -11,58 +11,58 @@ use godot_rust_script::{ #[derive(GodotScript, Debug)] #[script(base = GpuParticles3D)] struct DustParticles { - /// The strength of the emitted dust. - /// This is used for the rotor effects - /** - * This is more documentation - * please read it carefully - */ - #[prop(get = Self::strength, set = Self::set_strength)] - #[export(range(min = 0.1, max = 1.5, step = 0.05))] - strength: f64, - base: Gd, + /// The strength of the emitted dust. + /// This is used for the rotor effects + /** + * This is more documentation + * please read it carefully + */ + #[prop(get = Self::strength, set = Self::set_strength)] + #[export(range(min = 0.1, max = 1.5, step = 0.05))] + strength: f64, + base: Gd, } #[godot_script_impl] impl DustParticles { - pub fn _ready(&mut self) { - self.set_strength(0.0); - } + pub fn _ready(&mut self) { + self.set_strength(0.0); + } - /// get effect strength - fn strength(&self) -> f64 { - self.strength - } + /// get effect strength + fn strength(&self) -> f64 { + self.strength + } - pub fn set_strength(&mut self, value: f64) { - self.strength = value; + pub fn set_strength(&mut self, value: f64) { + self.strength = value; - let is_emitting = value > 0.0; + let is_emitting = value > 0.0; - if self.base.is_emitting() != is_emitting { - self.base.set_emitting(is_emitting); - } + if self.base.is_emitting() != is_emitting { + self.base.set_emitting(is_emitting); + } - if !self.base.is_emitting() { - return; - } + if !self.base.is_emitting() { + return; + } - let Some(mesh) = self.base.get_draw_pass_mesh(1) else { - godot_error!("Draw pass 1 does not exist!"); - return; - }; + let Some(mesh) = self.base.get_draw_pass_mesh(0) else { + godot_error!("Draw pass 1 does not exist!"); + return; + }; - let mesh: Gd = mesh.cast(); + let mesh: Gd = mesh.cast(); - let Some(material) = mesh.get_material() else { - godot_error!("mesh has no material!"); - return; - }; + let Some(material) = mesh.get_material() else { + godot_error!("mesh has no material!"); + return; + }; - let mut material: Gd = material.cast(); + let mut material: Gd = material.cast(); - let distance = (100.0 * (1.0 - value)).max(2.0); + let distance = (100.0 * (1.0 - value)).max(2.0); - material.set_proximity_fade_distance(distance as f32); - } + material.set_proximity_fade_distance(distance as f32); + } } diff --git a/native/src/scripts/spawner/car_spawner.rs b/native/src/scripts/spawner/car_spawner.rs index 5a357ef..0a08cd4 100644 --- a/native/src/scripts/spawner/car_spawner.rs +++ b/native/src/scripts/spawner/car_spawner.rs @@ -1,107 +1,108 @@ +use godot::obj::NewAlloc; use godot_rust_script::{ - godot::{ - engine::{ResourceLoader, Timer}, - prelude::{ - godot_error, Callable, GString, Gd, Node3D, NodePath, PackedScene, StringName, ToGodot, - }, - }, - godot_script_impl, GodotScript, + godot::{ + engine::{ResourceLoader, Timer}, + prelude::{ + godot_error, Callable, GString, Gd, Node3D, NodePath, PackedScene, StringName, ToGodot, + }, + }, + godot_script_impl, GodotScript, }; #[derive(Debug, GodotScript)] #[script(base = Node3D)] struct CarSpawner { - default_car: Option>, + default_car: Option>, - #[export] - pub road_network_path: NodePath, - timer: Option>, + #[export] + pub road_network_path: NodePath, + timer: Option>, - base: Gd, + base: Gd, } #[godot_script_impl] impl CarSpawner { - pub fn _init(&mut self) { - let mut loader = ResourceLoader::singleton(); - - self.default_car = loader - .load(GString::from( - "res://resources/Objects/Vehicles/car_station_wagon.tscn", - )) - .map(|res| res.cast()); - } - - pub fn spawn_car(&mut self) { - let inst = self - .default_car - .as_ref() - .expect("failed to load default_car") - .instantiate(); - - let Some(mut inst) = inst else { - godot_error!("failed to instantiate car scene!"); - return; - }; - - inst.set( - StringName::from("road_network_path"), - self.road_network_path.to_variant(), - ); - - if let Some(mut parent) = self.base.get_parent() { - parent.add_child(inst.clone()); - } - - let Some(current_scene) = self - .base - .get_tree() - .and_then(|tree| tree.get_current_scene()) - else { - godot_error!("there is no active scene!"); - return; - }; - - inst.set_owner(current_scene); - - let mut inst: Gd = inst.cast(); - - inst.global_translate(self.base.get_global_transform().origin); - inst.call(StringName::from("activate"), &[]); - } - - pub fn start_auto_spawn(&mut self) { - let timer = match self.timer.as_mut() { - None => { - let mut timer = Timer::new_alloc(); - self.timer = Some(timer.clone()); - - self.base - .add_child_ex(timer.clone().upcast()) - .force_readable_name(true) - .done(); - - timer.connect( - StringName::from("timeout"), - Callable::from_object_method(&self.base, "start_auto_spawn"), - ); - - self.timer.as_mut().unwrap() - } - - Some(timer) => timer, - }; - - timer.start_ex().time_sec(2.0).done(); - - self.spawn_car(); - } - - pub fn stop_auto_spawn(&mut self) { - let Some(timer) = self.timer.as_mut() else { - return; - }; - - timer.stop(); - } + pub fn _init(&mut self) { + let mut loader = ResourceLoader::singleton(); + + self.default_car = loader + .load(GString::from( + "res://resources/Objects/Vehicles/car_station_wagon.tscn", + )) + .map(|res| res.cast()); + } + + pub fn spawn_car(&mut self) { + let inst = self + .default_car + .as_ref() + .expect("failed to load default_car") + .instantiate(); + + let Some(mut inst) = inst else { + godot_error!("failed to instantiate car scene!"); + return; + }; + + inst.set( + StringName::from("road_network_path"), + self.road_network_path.to_variant(), + ); + + if let Some(mut parent) = self.base.get_parent() { + parent.add_child(inst.clone()); + } + + let Some(current_scene) = self + .base + .get_tree() + .and_then(|tree| tree.get_current_scene()) + else { + godot_error!("there is no active scene!"); + return; + }; + + inst.set_owner(current_scene); + + let mut inst: Gd = inst.cast(); + + inst.global_translate(self.base.get_global_transform().origin); + inst.call(StringName::from("activate"), &[]); + } + + pub fn start_auto_spawn(&mut self) { + let timer = match self.timer.as_mut() { + None => { + let mut timer = Timer::new_alloc(); + self.timer = Some(timer.clone()); + + self.base + .add_child_ex(timer.clone().upcast()) + .force_readable_name(true) + .done(); + + timer.connect( + StringName::from("timeout"), + Callable::from_object_method(&self.base, "start_auto_spawn"), + ); + + self.timer.as_mut().unwrap() + } + + Some(timer) => timer, + }; + + timer.start_ex().time_sec(2.0).done(); + + self.spawn_car(); + } + + pub fn stop_auto_spawn(&mut self) { + let Some(timer) = self.timer.as_mut() else { + return; + }; + + timer.stop(); + } } diff --git a/native/src/terrain_builder.rs b/native/src/terrain_builder.rs index 4bd66cd..3dafe4d 100644 --- a/native/src/terrain_builder.rs +++ b/native/src/terrain_builder.rs @@ -396,8 +396,8 @@ impl TerrainBuilder { } fn build_terain_chunk(context: &ThreadContext, surfaces: SurfaceMap) -> Shared> { - let mut generator = SurfaceTool::new(); - let mut mesh = ArrayMesh::new(); + let mut generator = SurfaceTool::new_gd(); + let mut mesh = ArrayMesh::new_gd(); let mut vertex_count = 0; for (surface_type, surface) in surfaces { diff --git a/resources/Shaders/ocean_visualshader.tres b/resources/Shaders/ocean_visualshader.tres index 9fb00b5..b729dfe 100644 --- a/resources/Shaders/ocean_visualshader.tres +++ b/resources/Shaders/ocean_visualshader.tres @@ -754,7 +754,6 @@ void fragment() { } " -graph_offset = Vector2(483.027, -307.492) nodes/vertex/0/position = Vector2(2720, -520) nodes/vertex/5/node = SubResource("42") nodes/vertex/5/position = Vector2(-560, -120) diff --git a/resources/Textures/tex39-39.png.import-2VCCBd b/resources/Textures/tex39-39.png.import-2VCCBd new file mode 100644 index 0000000..e69de29 diff --git a/resources/Textures/tex40-2.png.import-47AJay b/resources/Textures/tex40-2.png.import-47AJay new file mode 100644 index 0000000..e69de29 diff --git a/resources/main.tscn b/resources/main.tscn index bd74e52..3537476 100644 --- a/resources/main.tscn +++ b/resources/main.tscn @@ -75,9 +75,10 @@ render_target_update_mode = 4 script = ExtResource("3_2c332") current_camera_controller = NodePath("Schweizer_300/MainCameraAnchor") -[node name="Schweizer_300" parent="SubViewportContainer/SubViewport" node_paths=PackedStringArray("child_camera", "child_main_camera", "child_debug_camera") groups=["player"] instance=ExtResource("16_e6k8r")] +[node name="Schweizer_300" parent="SubViewportContainer/SubViewport" node_paths=PackedStringArray("child_camera", "child_rotor", "child_main_camera", "child_debug_camera") groups=["player"] instance=ExtResource("16_e6k8r")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -45.4393, -9.81614e-07, 17.9155) child_camera = NodePath("MainCameraAnchor") +child_rotor = NodePath("rotor") child_main_camera = NodePath("MainCameraAnchor") child_debug_camera = NodePath("DebugCameraAnchor") diff --git a/src/native.gdextension b/src/native.gdextension index 508c648..89e451c 100644 --- a/src/native.gdextension +++ b/src/native.gdextension @@ -1,11 +1,15 @@ [configuration] entry_symbol = "gdext_rust_init" compatibility_minimum = 4.1 +reloadable = true [libraries] +macos.universal="res://native/target/universal-apple-darwin/release/libnative.dylib" macos.debug.arm64="res://native/target/aarch64-apple-darwin/debug/libnative.dylib" macos.release.arm64="res://native/target/aarch64-apple-darwin/release/libnative.dylib" -macos.x86_64="res://native/target/x86_64-apple-darwin/release/libnative.dylib" -macos.universal="res://native/target/universal-apple-darwin/release/libnative.dylib" -windows.x86_64="res://native/target/x86_64-pc-windows-msvc/release/native.dll" -linux.x86_64="res://native/target/x86_64-unknown-linux-gnu/release/libnative.so" \ No newline at end of file +macos.debug.x86_64="res://native/target/x86_64-apple-darwin/debug/libnative.dylib" +macos.release.x86_64="res://native/target/x86_64-apple-darwin/release/libnative.dylib" +windows.debug.x86_64="res://native/target/x86_64-pc-windows-msvc/release/native.dll" +windows.release.x86_64="res://native/target/x86_64-pc-windows-msvc/release/native.dll" +linux.debug.x86_64="res://native/target/x86_64-unknown-linux-gnu/debug/libnative.so" +linux.release.x86_64="res://native/target/x86_64-unknown-linux-gnu/release/libnative.so"