Skip to content

Commit 33e1c8f

Browse files
committed
Further reduce classes in minimal codegen (low-hanging fruits)
1 parent 69a7324 commit 33e1c8f

File tree

6 files changed

+62
-52
lines changed

6 files changed

+62
-52
lines changed

.github/composite/godot-itest/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ runs:
142142
targetArgs="--target $TARGET"
143143
fi
144144
145+
# Keep `--no-default-features` even if it's currently redundant. Features may change.
145146
cargo build -p itest --no-default-features ${{ inputs.rust-extra-args }} $targetArgs
146147
147-
# Instead of modifying .gdextension, rename the output directory
148+
# Instead of modifying .gdextension, rename the output directory.
148149
if [[ -n "$TARGET" ]]; then
149150
rm -rf target/debug
150151
mv target/$TARGET/debug target

godot-codegen/src/special_cases/codegen_special_cases.rs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -132,55 +132,62 @@ pub(crate) fn is_utility_function_excluded(
132132
// Classes for minimal config
133133
#[cfg(not(feature = "codegen-full"))]
134134
const SELECTED_CLASSES: &[&str] = &[
135-
"Area2D",
136-
"ArrayMesh",
137-
"BoxMesh",
138-
"Camera3D",
139-
"CanvasItem",
140-
"CanvasLayer",
141-
"ClassDB",
142-
"CollisionObject2D",
143-
"CollisionShape2D",
144-
"Control",
145-
"EditorPlugin",
146-
"EditorExportPlugin",
147-
"Engine",
148-
"FileAccess",
149-
"GDScript",
150-
"HTTPRequest",
151-
"Image",
152-
"ImageTextureLayered",
153-
"Input",
154-
"InputEvent",
155-
"InputEventAction",
156-
"MainLoop",
157-
"Mesh",
135+
// Core class hierarchy
136+
"Object",
158137
"Node",
138+
"CanvasItem", // base of Node2D
159139
"Node2D",
160140
"Node3D",
161-
"Object",
162-
"OS",
163-
"PackedScene",
164-
"PhysicsBody2D",
165-
"PrimitiveMesh",
166141
"RefCounted",
167-
"RenderingServer",
168142
"Resource",
169-
"ResourceFormatLoader",
143+
//
144+
// Runtime + reflection support
145+
"ClassDB",
146+
"Engine",
147+
"OS",
148+
//
149+
// Editor plugins
150+
"EditorPlugin",
151+
"EditorExportPlugin",
152+
//
153+
// I/O and save/load
170154
"ResourceLoader",
171155
"ResourceSaver",
172-
"RigidBody2D",
156+
"FileAccess",
157+
//
158+
// Scene (node_test, rpc_test)
159+
"MainLoop", // base of SceneTree
173160
"SceneTree",
161+
//
162+
// Script instances
174163
"Script",
175164
"ScriptExtension",
176165
"ScriptNameCasing",
177166
"ScriptLanguage",
178167
"ScriptLanguageExtension",
168+
"GDScript",
169+
//
170+
// Example resources
171+
"PackedScene", // manual_extensions
179172
"Texture",
180-
"Texture2DArray",
181-
"TextureLayered",
182-
"Time", // usage: enum_test.enum_hash()
183-
"Timer",
173+
//
174+
// Meshes (virtual_methods_test)
175+
"Mesh",
176+
"ArrayMesh", // enum_test, 1 case, but small API
177+
"PrimitiveMesh",
178+
//
179+
// Windowing + Input (virtual_methods_test)
184180
"Viewport",
185181
"Window",
182+
"Input",
183+
"InputEvent",
184+
"InputEventAction",
185+
//
186+
// Godot servers (for RID support)
187+
"RenderingServer",
188+
//
189+
// Misc
190+
"Time", // usage: enum_test.enum_hash()
191+
"HTTPRequest",
192+
"ResourceFormatLoader", // TODO: replace?
186193
];

godot/src/prelude.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub use super::meta::error::{ConvertError, IoError};
1616
pub use super::meta::{FromGodot, GodotConvert, ToGodot};
1717

1818
pub use super::classes::{
19-
INode, INode2D, INode3D, IObject, IPackedScene, IRefCounted, IResource, ISceneTree, Input,
20-
Node, Node2D, Node3D, Object, PackedScene, RefCounted, Resource, SceneTree,
19+
INode, INode2D, INode3D, IObject, IPackedScene, IRefCounted, IResource, ISceneTree, Node,
20+
Node2D, Node3D, Object, PackedScene, RefCounted, Resource, SceneTree,
2121
};
2222
pub use super::global::{
2323
godot_error, godot_print, godot_print_rich, godot_script_error, godot_warn,

itest/rust/src/builtin_tests/containers/array_test.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,11 @@ fn untyped_array_return_from_godot_func() {
399399
assert_eq!(result, varray![child, Variant::nil(), NodePath::default()]);
400400
}
401401

402-
// TODO All API functions that take a `Array` are even more obscure and not included in
403-
// `SELECTED_CLASSES`. Decide if this test is worth having `Texture2DArray` and `Image` and their
404-
// ancestors in the list.
402+
// Conditional, so we don't need Texture2DArray > ImageTextureLayered > TextureLayered > Texture in minimal codegen.
403+
// Potential alternatives (search for "typedarray::" in extension_api.json):
404+
// - ClassDB::class_get_signal_list() -> Array<Dictionary>
405+
// - Compositor::set_compositor_effects( Array<Gd<Compositor>> )
406+
#[cfg(feature = "codegen-full-experimental")]
405407
#[itest]
406408
fn typed_array_pass_to_godot_func() {
407409
use godot::classes::image::Format;

itest/rust/src/engine_tests/codegen_test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use crate::framework::itest;
1212
use godot::builtin::inner::InnerColor;
13-
use godot::classes::{FileAccess, HttpRequest, IHttpRequest, Image};
13+
use godot::classes::{FileAccess, HttpRequest, IHttpRequest, RenderingServer};
1414
use godot::prelude::*;
1515

1616
#[itest]
@@ -53,7 +53,8 @@ fn codegen_static_class_method() {
5353

5454
#[itest]
5555
fn codegen_constants() {
56-
assert_eq!(Image::MAX_WIDTH, 16777216);
56+
assert_eq!(RenderingServer::CANVAS_ITEM_Z_MIN, -4096);
57+
//assert_eq!(Image::MAX_WIDTH, 16777216);
5758
// assert_eq!(Material::RENDER_PRIORITY_MIN, -128);
5859
}
5960

itest/rust/src/object_tests/object_test.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use std::rc::Rc;
1313

1414
use godot::builtin::{GString, StringName, Variant, Vector3};
1515
use godot::classes::{
16-
file_access, Area2D, Camera3D, Engine, FileAccess, IRefCounted, Node, Node3D, Object,
17-
RefCounted,
16+
file_access, Engine, FileAccess, IRefCounted, Node, Node2D, Node3D, Object, RefCounted,
1817
};
1918
#[allow(deprecated)]
2019
use godot::global::instance_from_id;
@@ -514,10 +513,10 @@ fn check_convert_variant_refcount(obj: Gd<RefCounted>) {
514513
fn object_engine_convert_variant_nil() {
515514
let nil = Variant::nil();
516515

517-
Gd::<Area2D>::try_from_variant(&nil).expect_err("`nil` should not convert to `Gd<Area2D>`");
516+
Gd::<Node2D>::try_from_variant(&nil).expect_err("`nil` should not convert to `Gd<Node2D>`");
518517

519518
expect_panic("from_variant(&nil)", || {
520-
Gd::<Area2D>::from_variant(&nil);
519+
Gd::<Node2D>::from_variant(&nil);
521520
});
522521
}
523522

@@ -526,12 +525,12 @@ fn object_engine_convert_variant_error() {
526525
let refc = RefCounted::new_gd();
527526
let variant = refc.to_variant();
528527

529-
let err = Gd::<Area2D>::try_from_variant(&variant)
530-
.expect_err("`Gd<RefCounted>` should not convert to `Gd<Area2D>`");
528+
let err = Gd::<Node2D>::try_from_variant(&variant)
529+
.expect_err("`Gd<RefCounted>` should not convert to `Gd<Node2D>`");
531530

532531
assert_eq!(
533532
err.to_string(),
534-
format!("cannot convert to class Area2D: {refc:?}")
533+
format!("cannot convert to class Node2D: {refc:?}")
535534
);
536535
}
537536

@@ -705,9 +704,9 @@ fn object_engine_bad_downcast() {
705704

706705
#[itest]
707706
fn object_engine_accept_polymorphic() {
708-
let mut node = Camera3D::new_alloc();
707+
let mut node = Node3D::new_alloc();
709708
let expected_name = StringName::from("Node name");
710-
let expected_class = GString::from("Camera3D");
709+
let expected_class = GString::from("Node3D");
711710

712711
node.set_name(expected_name.arg());
713712

0 commit comments

Comments
 (0)