@@ -29,14 +29,15 @@ mod single_threaded {
29
29
use std:: any:: type_name;
30
30
use std:: cell;
31
31
32
- use crate :: obj:: GodotClass ;
32
+ use crate :: obj:: { Base , Gd , GodotClass , Inherits } ;
33
33
use crate :: out;
34
34
35
35
use super :: Lifecycle ;
36
36
37
37
/// Manages storage and lifecycle of user's extension class instances.
38
38
pub struct InstanceStorage < T : GodotClass > {
39
39
user_instance : cell:: RefCell < T > ,
40
+ base : Base < T :: Base > ,
40
41
41
42
// Declared after `user_instance`, is dropped last
42
43
pub lifecycle : cell:: Cell < Lifecycle > ,
@@ -45,11 +46,12 @@ mod single_threaded {
45
46
46
47
/// For all Godot extension classes
47
48
impl < T : GodotClass > InstanceStorage < T > {
48
- pub fn construct ( user_instance : T ) -> Self {
49
+ pub fn construct ( user_instance : T , base : Base < T :: Base > ) -> Self {
49
50
out ! ( " Storage::construct <{}>" , type_name:: <T >( ) ) ;
50
51
51
52
Self {
52
53
user_instance : cell:: RefCell :: new ( user_instance) ,
54
+ base,
53
55
lifecycle : cell:: Cell :: new ( Lifecycle :: Alive ) ,
54
56
godot_ref_count : cell:: Cell :: new ( 1 ) ,
55
57
}
@@ -101,6 +103,13 @@ mod single_threaded {
101
103
} )
102
104
}
103
105
106
+ pub fn get_gd ( & self ) -> Gd < T >
107
+ where
108
+ T : Inherits < <T as GodotClass >:: Base > ,
109
+ {
110
+ self . base . clone ( ) . cast ( )
111
+ }
112
+
104
113
pub ( super ) fn godot_ref_count ( & self ) -> u32 {
105
114
self . godot_ref_count . get ( )
106
115
}
@@ -113,7 +122,7 @@ mod multi_threaded {
113
122
use std:: sync;
114
123
use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
115
124
116
- use crate :: obj:: GodotClass ;
125
+ use crate :: obj:: { Base , Gd , GodotClass , Inherits , Share } ;
117
126
use crate :: out;
118
127
119
128
use super :: Lifecycle ;
@@ -146,6 +155,7 @@ mod multi_threaded {
146
155
/// Manages storage and lifecycle of user's extension class instances.
147
156
pub struct InstanceStorage < T : GodotClass > {
148
157
user_instance : sync:: RwLock < T > ,
158
+ base : Base < T :: Base > ,
149
159
150
160
// Declared after `user_instance`, is dropped last
151
161
pub lifecycle : AtomicLifecycle ,
@@ -154,11 +164,12 @@ mod multi_threaded {
154
164
155
165
/// For all Godot extension classes
156
166
impl < T : GodotClass > InstanceStorage < T > {
157
- pub fn construct ( user_instance : T ) -> Self {
167
+ pub fn construct ( user_instance : T , base : Base < T :: Base > ) -> Self {
158
168
out ! ( " Storage::construct <{}>" , type_name:: <T >( ) ) ;
159
169
160
170
Self {
161
171
user_instance : sync:: RwLock :: new ( user_instance) ,
172
+ base,
162
173
lifecycle : AtomicLifecycle :: new ( Lifecycle :: Alive ) ,
163
174
godot_ref_count : AtomicU32 :: new ( 1 ) ,
164
175
}
@@ -206,6 +217,13 @@ mod multi_threaded {
206
217
} )
207
218
}
208
219
220
+ pub fn get_gd ( & self ) -> Gd < T >
221
+ where
222
+ T : Inherits < <T as GodotClass >:: Base > ,
223
+ {
224
+ self . base . clone ( ) . cast ( )
225
+ }
226
+
209
227
pub ( super ) fn godot_ref_count ( & self ) -> u32 {
210
228
self . godot_ref_count . load ( Ordering :: Relaxed )
211
229
}
0 commit comments