Skip to content

Commit a488fe1

Browse files
committed
applying more PR feedback
1 parent e1b69d2 commit a488fe1

File tree

6 files changed

+46
-40
lines changed

6 files changed

+46
-40
lines changed

godot-codegen/src/special_cases/codegen_special_cases.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ const SELECTED_CLASSES: &[&str] = &[
140140
"ClassDB",
141141
"Engine",
142142
"OS",
143-
"ProjectSettings",
144143
//
145144
// Editor plugins
146145
"EditorPlugin",

godot-codegen/src/special_cases/special_cases.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ pub fn get_derived_virtual_method_presence(class_name: &TyName, godot_method_nam
10031003
/// - register_server_singletons() ...another weird one.
10041004
/// - Autoloads, etc.
10051005
#[rustfmt::skip]
1006-
pub fn classify_codegen_level(class_name: &str, godot_classification: &str) -> Option<ClassCodegenLevel> {
1006+
pub fn classify_codegen_level(class_name: &str) -> Option<ClassCodegenLevel> {
10071007
let level = match class_name {
10081008
// See register_core_types() in https://github.com/godotengine/godot/blob/master/core/register_core_types.cpp,
10091009
// which is called before Core level is initialized.
@@ -1017,8 +1017,8 @@ pub fn classify_codegen_level(class_name: &str, godot_classification: &str) -> O
10171017
| "ProjectSettings" | "Engine" | "OS" | "Time"
10181018
=> ClassCodegenLevel::Core,
10191019

1020-
// Anything that comes from another extension could be available in Core but since there would be load order dependencies,
1021-
// instead don't allow calls until Server level.
1020+
// Symbols from another extension could be available in Core, but since GDExtension can currently not guarantee
1021+
// the order of different extensions being loaded, we prevent implicit dependencies and require Server.
10221022
| "OpenXRExtensionWrapperExtension"
10231023
=> ClassCodegenLevel::Servers,
10241024

@@ -1050,18 +1050,8 @@ pub fn classify_codegen_level(class_name: &str, godot_classification: &str) -> O
10501050
"ResourceImporterOggVorbis" | "ResourceImporterMP3" if cfg!(before_api = "4.3")
10511051
=> ClassCodegenLevel::Editor,
10521052

1053-
_ => {
1054-
// NOTE: Right now, Godot reports everything that's not "editor" as "core" in `extension_api.json`.
1055-
// If it wasn't picked up by the whitelist, and Godot reports it as "core" we will treat it as a scene class.
1056-
match godot_classification {
1057-
"editor" => ClassCodegenLevel::Editor,
1058-
"core" => ClassCodegenLevel::Scene,
1059-
_ => {
1060-
// we don't know this classification
1061-
return None;
1062-
}
1063-
}
1064-
}
1053+
// No special-case override for this class.
1054+
_ => return None,
10651055
};
10661056
Some(level)
10671057
}

godot-codegen/src/util.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,25 @@ pub fn make_sname_ptr(identifier: &str) -> TokenStream {
5353
pub fn get_api_level(class: &JsonClass) -> ClassCodegenLevel {
5454
// NOTE: We have to use a whitelist of known classes because Godot doesn't separate these out
5555
// beyond "editor" and "core" and some classes are also mis-classified in the JSON depending on the Godot version.
56-
if let Some(forced_classification) =
57-
special_cases::classify_codegen_level(&class.name, &class.api_type)
58-
{
56+
if let Some(forced_classification) = special_cases::classify_codegen_level(&class.name) {
5957
return forced_classification;
6058
}
6159

62-
// Fall back to just trusting the categorization. Presently, Godot only reports "core" and "editor".
63-
for level in ClassCodegenLevel::with_tables() {
64-
if level.lower() == class.api_type {
65-
return level;
60+
// NOTE: Right now, Godot reports everything that's not "editor" as "core" in `extension_api.json`.
61+
// If it wasn't picked up by classify_codegen_level, and Godot reports it as "core" we will treat it as a scene class.
62+
match class.api_type.as_str() {
63+
"editor" => ClassCodegenLevel::Editor,
64+
"core" => ClassCodegenLevel::Scene,
65+
"extension" => ClassCodegenLevel::Scene,
66+
"editor_extension" => ClassCodegenLevel::Editor,
67+
_ => {
68+
// we don't know this classification
69+
panic!(
70+
"class {} has unknown API type {}",
71+
class.name, class.api_type
72+
);
6673
}
6774
}
68-
panic!(
69-
"class {} has unknown API type {}",
70-
class.name, class.api_type
71-
);
7275
}
7376

7477
pub fn ident(s: &str) -> Ident {

itest/rust/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8-
use std::sync::Mutex;
9-
108
use godot::init::{gdextension, ExtensionLibrary, InitLevel};
9+
use godot::sys::Global;
1110

1211
mod benchmarks;
1312
mod builtin_tests;
@@ -20,22 +19,25 @@ mod register_tests;
2019
// ----------------------------------------------------------------------------------------------------------------------------------------------
2120
// Entry point
2221

23-
static LEVELS_SEEN: Mutex<Vec<InitLevel>> = Mutex::new(Vec::new());
22+
static LEVELS_SEEN: Global<Vec<InitLevel>> = Global::default();
2423

2524
#[gdextension(entry_symbol = itest_init)]
2625
unsafe impl ExtensionLibrary for framework::IntegrationTests {
2726
fn min_level() -> InitLevel {
2827
InitLevel::Core
2928
}
3029
fn on_level_init(level: InitLevel) {
31-
LEVELS_SEEN.lock().unwrap().push(level);
30+
LEVELS_SEEN.lock().push(level);
3231
match level {
3332
InitLevel::Core => {
34-
// make sure we can access early core singletons
33+
// Make sure we can access early core singletons.
3534
object_tests::test_early_core_singletons();
3635
}
3736
InitLevel::Servers => {}
38-
InitLevel::Scene => {}
37+
InitLevel::Scene => {
38+
// Make sure we can access server singletons by now.
39+
object_tests::test_general_singletons();
40+
}
3941
InitLevel::Editor => {}
4042
}
4143
}
@@ -44,7 +46,7 @@ unsafe impl ExtensionLibrary for framework::IntegrationTests {
4446
// Ensure that we saw all the init levels expected.
4547
#[crate::framework::itest]
4648
fn observed_all_init_levels() {
47-
let levels_seen = LEVELS_SEEN.lock().unwrap().clone();
49+
let levels_seen = LEVELS_SEEN.lock().clone();
4850
assert_eq!(levels_seen[0], InitLevel::Core);
4951
assert_eq!(levels_seen[1], InitLevel::Servers);
5052
assert_eq!(levels_seen[2], InitLevel::Scene);

itest/rust/src/object_tests/init_level_test.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,20 @@ impl SomeObject {
3434
}
3535
}
3636

37-
// Run during core init level to ensure we can access core singletons.
37+
// Runs during core init level to ensure we can access core singletons.
3838
pub fn test_early_core_singletons() {
39-
// ensure we can create and use an Object-derived class during Core init level.
39+
// Ensure we can create and use an Object-derived class during Core init level.
4040
SomeObject::test();
4141

42-
// check the early core singletons we can access here.
43-
let project_settings = godot::classes::ProjectSettings::singleton();
44-
project_settings.get("application/config/name");
42+
// Check the early core singletons we can access here.
43+
#[cfg(feature = "codegen-full")]
44+
{
45+
let project_settings = godot::classes::ProjectSettings::singleton();
46+
assert_eq!(
47+
project_settings.get("application/config/name").get_type(),
48+
godot::builtin::VariantType::STRING
49+
);
50+
}
4551

4652
let engine = godot::classes::Engine::singleton();
4753
assert!(engine.get_physics_ticks_per_second() > 0);
@@ -53,6 +59,12 @@ pub fn test_early_core_singletons() {
5359
assert!(time.get_ticks_usec() <= time.get_ticks_usec());
5460
}
5561

62+
// Runs during scene init level to ensure we can access general singletons in the Scene init call for the extension as a whole.
63+
pub fn test_general_singletons() {
64+
let mut rendering = godot::classes::RenderingServer::singleton();
65+
assert!(rendering.get_test_cube() != godot::builtin::Rid::Invalid);
66+
}
67+
5668
// Ensure that the above function actually ran.
5769
#[itest]
5870
fn class_run_during_servers_init() {

itest/rust/src/object_tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ mod virtual_methods_niche_test;
3333
mod virtual_methods_test;
3434

3535
// Need to test this in the init level method.
36-
pub use init_level_test::test_early_core_singletons;
36+
pub use init_level_test::*;

0 commit comments

Comments
 (0)