Skip to content

Commit 2fa0d86

Browse files
author
RealAstolfo
authored
Merge branch 'master' into astolfo-feature/builtin-quaternion
2 parents 000d056 + cc82849 commit 2fa0d86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2482
-1178
lines changed

.github/workflows/full-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ on:
1414
- trying
1515

1616
env:
17-
GDEXT_FEATURES: '--features godot-core/convenience'
17+
GDEXT_FEATURES: ''
18+
# GDEXT_FEATURES: '--features crate/feature'
1819
# GDEXT_CRATE_ARGS: '-p godot-codegen -p godot-ffi -p godot-core -p godot-macros -p godot'
1920

2021
defaults:

.github/workflows/minimal-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ on:
1414
- master
1515

1616
env:
17-
GDEXT_FEATURES: '--features godot-core/convenience'
17+
GDEXT_FEATURES: ''
18+
# GDEXT_FEATURES: '--features crate/feature'
1819
# GDEXT_CRATE_ARGS: '-p godot-codegen -p godot-ffi -p godot-core -p godot-macros -p godot'
1920

2021
defaults:

check.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ function findGodot() {
6767
fi
6868
}
6969

70-
features="--features godot-core/convenience"
70+
#features="--features crate/feature"
71+
features=""
7172
cmds=()
7273

7374
for arg in "${args[@]}"; do

examples/dodge-the-creeps/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ publish = false
88
crate-type = ["cdylib"]
99

1010
[dependencies]
11-
godot = { path = "../../../godot", default-features = false, features = ["formatted", "convenience"] }
11+
godot = { path = "../../../godot", default-features = false, features = ["formatted"] }
1212
rand = "0.8"

godot-codegen/input/gdextension_interface.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
#include <stddef.h>
3939
#include <stdint.h>
40-
#include <stdio.h>
4140

4241
#ifndef __cplusplus
4342
typedef uint32_t char32_t;
@@ -415,9 +414,12 @@ typedef struct {
415414
void *(*mem_realloc)(void *p_ptr, size_t p_bytes);
416415
void (*mem_free)(void *p_ptr);
417416

418-
void (*print_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line);
419-
void (*print_warning)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line);
420-
void (*print_script_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line);
417+
void (*print_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
418+
void (*print_error_with_message)(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
419+
void (*print_warning)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
420+
void (*print_warning_with_message)(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
421+
void (*print_script_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
422+
void (*print_script_error_with_message)(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify);
421423

422424
uint64_t (*get_native_struct_size)(GDExtensionConstStringNamePtr p_name);
423425

@@ -552,7 +554,7 @@ typedef struct {
552554
GDExtensionVariantPtr (*array_operator_index)(GDExtensionTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr
553555
GDExtensionVariantPtr (*array_operator_index_const)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); // p_self should be an Array ptr
554556
void (*array_ref)(GDExtensionTypePtr p_self, GDExtensionConstTypePtr p_from); // p_self should be an Array ptr
555-
void (*array_set_typed)(GDExtensionTypePtr p_self, uint32_t p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script); // p_self should be an Array ptr
557+
void (*array_set_typed)(GDExtensionTypePtr p_self, GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script); // p_self should be an Array ptr
556558

557559
/* Dictionary functions */
558560

godot-codegen/src/api_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub struct ClassMethod {
172172
pub name: String,
173173
pub is_const: bool,
174174
pub is_vararg: bool,
175-
//pub is_static: bool,
175+
pub is_static: bool,
176176
pub is_virtual: bool,
177177
pub hash: Option<i64>,
178178
pub return_value: Option<MethodReturn>,

godot-codegen/src/class_generator.rs

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ fn make_builtin_class(
282282

283283
let methods = make_builtin_methods(&class.methods, class_name, type_info, ctx);
284284
let enums = make_enums(&class_enums, class_name, ctx);
285+
let special_constructors = make_special_builtin_methods(class_name, ctx);
285286

286287
// mod re_export needed, because class should not appear inside the file module, and we can't re-export private struct as pub
287288
let tokens = quote! {
@@ -303,7 +304,7 @@ fn make_builtin_class(
303304
sys_ptr: outer.sys(),
304305
}
305306
}
306-
307+
#special_constructors
307308
#methods
308309
}
309310

@@ -426,6 +427,24 @@ fn make_enums(enums: &Option<Vec<Enum>>, _class_name: &TyName, _ctx: &Context) -
426427
}
427428
}
428429

430+
/// Depending on the built-in class, adds custom constructors and methods.
431+
fn make_special_builtin_methods(class_name: &TyName, _ctx: &Context) -> TokenStream {
432+
if class_name.godot_ty == "Array" {
433+
quote! {
434+
pub fn from_outer_typed<T>(outer: &TypedArray<T>) -> Self
435+
where T: crate::builtin::meta::VariantMetadata
436+
{
437+
Self {
438+
_outer_lifetime: std::marker::PhantomData,
439+
sys_ptr: outer.sys(),
440+
}
441+
}
442+
}
443+
} else {
444+
TokenStream::new()
445+
}
446+
}
447+
429448
#[cfg(not(feature = "codegen-full"))]
430449
fn is_type_excluded(ty: &str, ctx: &mut Context) -> bool {
431450
let is_class_excluded = |class: &str| !crate::SELECTED_CLASSES.contains(&class);
@@ -510,20 +529,21 @@ fn make_method_definition(
510529
/*if method.map_args(|args| args.is_empty()) {
511530
// Getters (i.e. 0 arguments) will be stripped of their `get_` prefix, to conform to Rust convention
512531
if let Some(remainder) = method_name.strip_prefix("get_") {
513-
// Do not apply for get_16 etc
514-
// TODO also not for get_u16 etc, in StreamPeer
532+
// TODO Do not apply for FileAccess::get_16, StreamPeer::get_u16, etc
515533
if !remainder.chars().nth(0).unwrap().is_ascii_digit() {
516534
method_name = remainder;
517535
}
518536
}
519537
}*/
520538

521539
let method_name_str = special_cases::maybe_renamed(class_name, &method.name);
522-
let receiver = if method.is_const {
523-
quote! { &self, }
524-
} else {
525-
quote! { &mut self, }
526-
};
540+
541+
let (receiver, receiver_arg) = make_receiver(
542+
method.is_static,
543+
method.is_const,
544+
quote! { self.object_ptr },
545+
);
546+
527547
let hash = method.hash;
528548
let is_varcall = method.is_vararg;
529549

@@ -546,10 +566,10 @@ fn make_method_definition(
546566
let __call_fn = sys::interface_fn!(#function_provider);
547567
};
548568
let varcall_invocation = quote! {
549-
__call_fn(__method_bind, self.object_ptr, __args_ptr, __args.len() as i64, return_ptr, std::ptr::addr_of_mut!(__err));
569+
__call_fn(__method_bind, #receiver_arg, __args_ptr, __args.len() as i64, return_ptr, std::ptr::addr_of_mut!(__err));
550570
};
551571
let ptrcall_invocation = quote! {
552-
__call_fn(__method_bind, self.object_ptr, __args_ptr, return_ptr);
572+
__call_fn(__method_bind, #receiver_arg, __args_ptr, return_ptr);
553573
};
554574

555575
make_function_definition(
@@ -579,11 +599,8 @@ fn make_builtin_method_definition(
579599

580600
let method_name_str = &method.name;
581601

582-
let receiver = if method.is_const {
583-
quote! { &self, }
584-
} else {
585-
quote! { &mut self, }
586-
};
602+
let (receiver, receiver_arg) =
603+
make_receiver(method.is_static, method.is_const, quote! { self.sys_ptr });
587604

588605
let return_value = method.return_type.as_deref().map(MethodReturn::from_type);
589606
let hash = method.hash;
@@ -602,7 +619,7 @@ fn make_builtin_method_definition(
602619
let __call_fn = __call_fn.unwrap_unchecked();
603620
};
604621
let ptrcall_invocation = quote! {
605-
__call_fn(self.sys_ptr, __args_ptr, return_ptr, __args.len() as i32);
622+
__call_fn(#receiver_arg, __args_ptr, return_ptr, __args.len() as i32);
606623
};
607624

608625
make_function_definition(
@@ -746,6 +763,28 @@ fn make_function_definition(
746763
}
747764
}
748765

766+
fn make_receiver(
767+
is_static: bool,
768+
is_const: bool,
769+
receiver_arg: TokenStream,
770+
) -> (TokenStream, TokenStream) {
771+
let receiver = if is_static {
772+
quote! {}
773+
} else if is_const {
774+
quote! { &self, }
775+
} else {
776+
quote! { &mut self, }
777+
};
778+
779+
let receiver_arg = if is_static {
780+
quote! { std::ptr::null_mut() }
781+
} else {
782+
receiver_arg
783+
};
784+
785+
(receiver, receiver_arg)
786+
}
787+
749788
fn make_params(
750789
method_args: &Option<Vec<MethodArg>>,
751790
is_varcall: bool,

godot-codegen/src/godot_version.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn parse_godot_version(version_str: &str) -> Result<GodotVersion, Box<dyn Er
3030
let regex = Regex::new(
3131
// major minor [patch] official|custom_build|gentoo
3232
// v v v v
33-
r#"(\d+)\.(\d+)(?:\.(\d+))?\.(alpha|beta|dev|stable)[0-9]*\.(?:mono\.)?(?:[a-z_]+\.([a-f0-9]+)|official)"#,
33+
r#"(\d+)\.(\d+)(?:\.(\d+))?\.(alpha|beta|dev|rc|stable)[0-9]*\.(?:mono\.)?(?:[a-z_]+\.([a-f0-9]+)|official)"#,
3434
)?;
3535

3636
let fail = || format!("Version substring cannot be parsed: `{version_str}`");
@@ -71,6 +71,7 @@ fn test_godot_versions() {
7171
("4.0.dev.custom_build.e7e9e663b", 4, 0, 0, "dev", s("e7e9e663b")),
7272
("4.0.alpha.custom_build.faddbcfc0", 4, 0, 0, "alpha", s("faddbcfc0")),
7373
("4.0.beta8.mono.custom_build.b28ddd918", 4, 0, 0, "beta", s("b28ddd918")),
74+
("4.0.rc1.official.8843d9ad3", 4, 0, 0, "rc", s("8843d9ad3")),
7475
];
7576

7677
let bad_versions = [

godot-codegen/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ const SELECTED_CLASSES: &[&str] = &[
269269
"CollisionShape2D",
270270
"Control",
271271
"FileAccess",
272+
"HTTPRequest",
273+
"Image",
274+
"ImageTextureLayered",
272275
"Input",
273276
"Label",
274277
"MainLoop",
@@ -289,6 +292,9 @@ const SELECTED_CLASSES: &[&str] = &[
289292
"SceneTree",
290293
"Sprite2D",
291294
"SpriteFrames",
295+
"Texture",
296+
"Texture2DArray",
297+
"TextureLayered",
292298
"Time",
293299
"Timer",
294300
];

godot-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ default = []
1212
trace = []
1313
codegen-fmt = ["godot-ffi/codegen-fmt"]
1414
codegen-full = ["godot-codegen/codegen-full"]
15-
convenience = []
1615

1716
[dependencies]
1817
godot-ffi = { path = "../godot-ffi" }

0 commit comments

Comments
 (0)