1
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
2
- mod hot_reloader;
3
1
mod metadata;
4
2
mod resource_loader;
5
3
mod resource_saver;
@@ -9,7 +7,6 @@ mod rust_script_language;
9
7
10
8
use std:: { collections:: HashMap , rc:: Rc , sync:: RwLock } ;
11
9
12
- use cfg_if:: cfg_if;
13
10
use godot:: {
14
11
engine:: { Engine , ResourceLoader , ResourceSaver } ,
15
12
prelude:: { godot_print, Gd } ,
@@ -25,35 +22,6 @@ use crate::{
25
22
26
23
use self :: rust_script_language:: RustScriptLanguage ;
27
24
28
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
29
- use hot_reloader:: { HotReloadEntry , HotReloader } ;
30
-
31
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
32
- #[ macro_export]
33
- macro_rules! setup {
34
- ( $lib_crate: tt) => {
35
- #[ $crate:: private_export:: hot_module( dylib = stringify!( $lib_crate) , lib_dir=process_path:: get_dylib_path( ) . and_then( |path| path. parent( ) . map( std:: path:: Path :: to_path_buf) ) . unwrap_or_default( ) ) ]
36
- mod scripts_lib {
37
- use $crate:: private_export:: RVec ;
38
-
39
- // manually expose functions.
40
- #[ hot_functions]
41
- extern "Rust" {
42
- pub fn __godot_rust_script_init(
43
- binding: Option <$crate:: private_export:: BindingInit >,
44
- ) -> RVec <$crate:: RemoteScriptMetaData >;
45
- }
46
-
47
- // expose a type to subscribe to lib load events
48
- #[ lib_change_subscription]
49
- pub fn subscribe( ) -> hot_lib_reloader:: LibReloadObserver { }
50
-
51
- pub use :: $lib_crate:: __GODOT_RUST_SCRIPT_SRC_ROOT;
52
- }
53
- } ;
54
- }
55
-
56
- #[ cfg( not( all( feature = "hot-reload" , debug_assertions) ) ) ]
57
25
#[ macro_export]
58
26
macro_rules! setup {
59
27
( $lib_crate: tt) => {
@@ -63,7 +31,6 @@ macro_rules! setup {
63
31
} ;
64
32
}
65
33
66
- #[ cfg( not( all( feature = "hot-reload" , debug_assertions) ) ) ]
67
34
#[ macro_export]
68
35
macro_rules! init {
69
36
( ) => {
@@ -74,28 +41,8 @@ macro_rules! init {
74
41
} ;
75
42
}
76
43
77
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
78
- #[ macro_export]
79
- macro_rules! init {
80
- ( ) => {
81
- $crate:: RustScriptExtensionLayer :: new(
82
- scripts_lib:: __godot_rust_script_init,
83
- scripts_lib:: __GODOT_RUST_SCRIPT_SRC_ROOT,
84
- scripts_lib:: subscribe,
85
- )
86
- } ;
87
- }
88
-
89
44
thread_local ! {
90
45
static SCRIPT_REGISTRY : RwLock <HashMap <String , ScriptMetaData >> = RwLock :: default ( ) ;
91
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
92
- static HOT_RELOAD_BRIDGE : std:: cell:: RefCell <HashMap <rust_script_instance:: RustScriptInstanceId , std:: cell:: RefCell <HotReloadEntry >>> = std:: cell:: RefCell :: default ( ) ;
93
- }
94
-
95
- cfg_if ! {
96
- if #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ] {
97
- type HotReloadSubscribe = fn ( ) -> hot_lib_reloader:: LibReloadObserver ;
98
- }
99
46
}
100
47
101
48
pub struct RustScriptExtensionLayer {
@@ -104,33 +51,19 @@ pub struct RustScriptExtensionLayer {
104
51
res_saver : Option < Gd < RustScriptResourceSaver > > ,
105
52
res_loader : Option < Gd < RustScriptResourceLoader > > ,
106
53
scripts_src_dir : Option < & ' static str > ,
107
-
108
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
109
- hot_reload_subscribe : HotReloadSubscribe ,
110
-
111
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
112
- hot_reloader : Option < Gd < HotReloader > > ,
113
54
}
114
55
115
56
impl RustScriptExtensionLayer {
116
57
pub fn new < F : RustScriptLibInit + ' static + Clone > (
117
58
lib_init_fn : F ,
118
59
scripts_src_dir : & ' static str ,
119
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
120
- hot_reload_subscribe : HotReloadSubscribe ,
121
60
) -> Self {
122
61
Self {
123
62
lib_init_fn : Rc :: new ( lib_init_fn) ,
124
63
lang : None ,
125
64
res_saver : None ,
126
65
res_loader : None ,
127
66
scripts_src_dir : Some ( scripts_src_dir) ,
128
-
129
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
130
- hot_reload_subscribe,
131
-
132
- #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ]
133
- hot_reloader : None ,
134
67
}
135
68
}
136
69
@@ -141,18 +74,6 @@ impl RustScriptExtensionLayer {
141
74
let res_loader = RustScriptResourceLoader :: new ( lang. clone ( ) ) ;
142
75
let res_saver = Gd :: from_object ( RustScriptResourceSaver ) ;
143
76
144
- cfg_if ! {
145
- if #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ] {
146
- use godot:: prelude:: StringName ;
147
-
148
- let mut hot_reloader = Gd :: from_init_fn( |base| HotReloader :: new( ( self . hot_reload_subscribe) ( ) , self . lib_init_fn. clone( ) , base) ) ;
149
-
150
- hot_reloader. call_deferred( StringName :: from( "register" ) , & [ ] ) ;
151
-
152
- self . hot_reloader = Some ( hot_reloader) ;
153
- }
154
- }
155
-
156
77
self . lang = Some ( lang. clone ( ) ) ;
157
78
self . res_saver = Some ( res_saver. clone ( ) ) ;
158
79
self . res_loader = Some ( res_loader. clone ( ) ) ;
@@ -186,15 +107,7 @@ impl RustScriptExtensionLayer {
186
107
}
187
108
188
109
fn load_rust_scripts ( lib_init_fn : Rc < dyn RustScriptLibInit > ) {
189
- cfg_if ! {
190
- if #[ cfg( all( feature = "hot-reload" , debug_assertions) ) ] {
191
- let ffi_init = Some ( unsafe { godot:: sys:: get_binding( ) } ) ;
192
- } else {
193
- let ffi_init = None ;
194
- }
195
- }
196
-
197
- let result = lib_init_fn ( ffi_init) ;
110
+ let result = lib_init_fn ( ) ;
198
111
199
112
let registry: HashMap < String , ScriptMetaData > = result
200
113
. into_iter ( )
0 commit comments