Skip to content

Commit

Permalink
upgrade godot-rust-script (builtin hotreload)
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Jan 5, 2024
1 parent 5af9b12 commit 55fed63
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 160 deletions.
74 changes: 49 additions & 25 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
[workspace]
resolver = "2"

members = [
"scripts",
]

[workspace.dependencies]
godot-rust-script = { git = "https://github.com/titannano/godot-rust-script", rev = "928159e6f6a73a249d5504ca6c136809b5ed07c0", default-features = false }

[package]
name = "native"
version = "0.4.0"
Expand All @@ -17,11 +7,12 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
godot = { git = "https://github.com/titannano/gdext", rev = "a5d17342b7b47e8af652a6a733f497c468bbd59a" }
godot = { git = "https://github.com/titannano/gdext", rev = "4ce4714" }
lerp = "0.4.0"
backtrace = "0.3.64"
num = "0.4.0"
rayon = "1.5.1"
itertools = "0.10.3"
godot-rust-script = { workspace = true, features = ["runtime"] }
scripts = { path = "./scripts" }
num_enum = "0.7.1"

godot-rust-script = { git = "https://github.com/titannano/godot-rust-script", rev = "a2a5c018fcf0247f1d242ec2bf8a994cc975c1ee" }
12 changes: 0 additions & 12 deletions native/scripts/Cargo.toml

This file was deleted.

19 changes: 5 additions & 14 deletions native/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
mod scripts;
mod terrain_builder;

use std::cell::RefCell;

use godot::prelude::{gdextension, ExtensionLibrary, InitLevel};
use godot_rust_script::{self, RustScriptExtensionLayer};

godot_rust_script::setup!(scripts);
use godot_rust_script;

struct NativeLib;

thread_local! {
static RUST_SCRIPT_LAYER: RefCell<RustScriptExtensionLayer> = RefCell::new(godot_rust_script::init!());
}

#[gdextension]
unsafe impl ExtensionLibrary for NativeLib {
fn on_level_init(level: InitLevel) {
match level {
InitLevel::Core => (),
InitLevel::Servers => (),
InitLevel::Scene => {
RUST_SCRIPT_LAYER.with_borrow_mut(|layer| layer.initialize());
}
InitLevel::Scene => godot_rust_script::init!(scripts),
InitLevel::Editor => (),
}
}

fn on_level_deinit(level: InitLevel) {
match level {
InitLevel::Editor => (),
InitLevel::Scene => RUST_SCRIPT_LAYER.with_borrow_mut(|layer| layer.deinitialize()),
InitLevel::Servers => {}
InitLevel::Scene => godot_rust_script::deinit!(),
InitLevel::Servers => (),
InitLevel::Core => (),
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use godot_rust_script::{
#[script(base = Node3D)]
struct CarSpawner {
default_car: Option<Gd<PackedScene>>,
car: Option<Gd<PackedScene>>,

#[export]
pub road_network_path: NodePath,
Expand All @@ -31,10 +30,6 @@ impl CarSpawner {
"res://resources/Objects/Vehicles/car_station_wagon.tscn",
))
.map(|res| res.cast());

self.car = loader
.load(GString::from("res://src/Objects/Vehicles/Car.gd"))
.map(|res| res.cast());
}

pub fn spawn_car(&mut self) {
Expand Down Expand Up @@ -88,7 +83,7 @@ impl CarSpawner {

timer.connect(
StringName::from("timeout"),
Callable::from_object_method(self.base.clone(), "start_auto_spawn"),
Callable::from_object_method(&self.base, "start_auto_spawn"),
);

self.timer.as_mut().unwrap()
Expand Down
File renamed without changes.
19 changes: 18 additions & 1 deletion native/src/terrain_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ struct ThreadContext<'a> {
}

#[derive(GodotClass)]
#[class(base=RefCounted)]
#[class(base=RefCounted, init)]
pub struct TerrainBuilder {
tile_size: u8,
city_size: u16,
Expand All @@ -186,6 +186,23 @@ pub struct TerrainBuilder {

#[godot_api]
impl TerrainBuilder {
#[func]
fn new(
tilelist: Dictionary,
rotation: Gd<TerrainRotation>,
materials: Dictionary,
) -> Gd<TerrainBuilder> {
Gd::from_object(TerrainBuilder {
tile_size: 16,
city_size: 0,
tile_height: 8,
sea_level: 0,
rotation,
tilelist,
materials,
})
}

#[func]
fn set_city_size(&mut self, value: u16) {
self.city_size = value;
Expand Down
16 changes: 7 additions & 9 deletions resources/Objects/Helis/Helicopter.tscn
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[gd_scene load_steps=8 format=3 uid="uid://dl34exjsm3sq4"]

[ext_resource type="Material" uid="uid://cjoloelf8ku4k" path="res://resources/Materials/dust_material.tres" id="1"]
[ext_resource type="Material" uid="uid://cjoloelf8ku4k" path="res://resources/Materials/dust_material.tres" id="2_8yiqd"]
[ext_resource type="Script" path="res://native/src/scripts/particles/dust_particles.rs" id="2_ocmjg"]
[ext_resource type="Script" path="res://src/Objects/Helicopters/Helicopter.gd" id="3"]
[ext_resource type="AnimationNodeStateMachine" uid="uid://xbcrg5mghpup" path="res://resources/Animations/HelicopterRotorSoundStates.tres" id="4_8iee2"]
[ext_resource type="AnimationLibrary" uid="uid://uec74t4jqdxi" path="res://resources/Animations/Helicopter.tres" id="5_ayahk"]
[ext_resource type="Script" path="res://src/Objects/Particles/DustParticles.gd" id="12"]

[sub_resource type="PhysicsMaterial" id="20"]
friction = 0.5
bounce = 0.7

[sub_resource type="QuadMesh" id="9"]
material = ExtResource("1")
[sub_resource type="QuadMesh" id="QuadMesh_e0n42"]
material = ExtResource("2_8yiqd")

[node name="Helicopter" type="RigidBody3D" node_paths=PackedStringArray("child_engine_sound_tree", "child_dust_particles")]
mass = 929.8
Expand All @@ -35,14 +35,12 @@ amount = 100
lifetime = 0.4
visibility_aabb = AABB(-8.76025, -1.34854, -8.13392, 17.451, 2.29104, 17.5903)
draw_order = 2
draw_pass_1 = SubResource("9")
script = ExtResource("12")
draw_pass_1 = SubResource("QuadMesh_e0n42")
script = ExtResource("2_ocmjg")
strength = null

[node name="RotorAudioTree" type="AnimationTree" parent="."]
root_node = NodePath(".")
libraries = {
"": ExtResource("5_ayahk")
}
tree_root = ExtResource("4_8iee2")
advance_expression_base_node = NodePath("")
anim_player = NodePath("../RotorAudioPlayer")
Expand Down
Loading

0 comments on commit 55fed63

Please sign in to comment.