|
30 | 30 | use proc_macro2::Ident;
|
31 | 31 |
|
32 | 32 | use crate::conv::to_enum_type_uncached;
|
33 |
| -use crate::models::domain::{Enum, RustTy, TyName, VirtualMethodPresence}; |
| 33 | +use crate::models::domain::{ClassCodegenLevel, Enum, RustTy, TyName, VirtualMethodPresence}; |
34 | 34 | use crate::models::json::{JsonBuiltinMethod, JsonClassMethod, JsonSignal, JsonUtilityFunction};
|
35 | 35 | use crate::special_cases::codegen_special_cases;
|
36 | 36 | use crate::util::option_as_slice;
|
@@ -985,34 +985,85 @@ pub fn get_derived_virtual_method_presence(class_name: &TyName, godot_method_nam
|
985 | 985 | }
|
986 | 986 | }
|
987 | 987 |
|
| 988 | +/// Initialization order for Godot (see https://github.com/godotengine/godot/blob/master/main/main.cpp) |
| 989 | +/// - Main::setup() |
| 990 | +/// - register_core_types() |
| 991 | +/// - register_early_core_singletons() |
| 992 | +/// - initialize_extensions(GDExtension::INITIALIZATION_LEVEL_CORE) |
| 993 | +/// - Main::setup2() |
| 994 | +/// - register_server_types() |
| 995 | +/// - initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS) |
| 996 | +/// - register_core_singletons() ...possibly a bug. Should this be before LEVEL_SERVERS? |
| 997 | +/// - register_scene_types() |
| 998 | +/// - register_scene_singletons() |
| 999 | +/// - initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SCENE) |
| 1000 | +/// - IF EDITOR |
| 1001 | +/// - register_editor_types() |
| 1002 | +/// - initialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR) |
| 1003 | +/// - register_server_singletons() ...another weird one. |
| 1004 | +/// - Autoloads, etc. |
988 | 1005 | #[rustfmt::skip]
|
989 |
| -pub fn is_class_level_server(class_name: &str) -> bool { |
990 |
| - // Unclear on if some of these classes should be registered earlier than `Scene`: |
991 |
| - // - `RenderData` + `RenderDataExtension` |
992 |
| - // - `RenderSceneData` + `RenderSceneDataExtension` |
993 |
| - |
994 |
| - match class_name { |
995 |
| - // TODO: These should actually be at level `Core` |
996 |
| - | "Object" | "OpenXRExtensionWrapperExtension" |
997 |
| - |
998 |
| - // Declared final (un-inheritable) in Rust, but those are still servers. |
999 |
| - | "AudioServer" | "CameraServer" | "NavigationServer2D" | "NavigationServer3D" | "RenderingServer" | "TranslationServer" | "XRServer" |
1000 |
| - |
1001 |
| - // PhysicsServer2D |
| 1006 | +pub fn classify_codegen_level(class_name: &str, godot_classification: &str) -> Option<ClassCodegenLevel> { |
| 1007 | + let level = match class_name { |
| 1008 | + // See register_core_types() in https://github.com/godotengine/godot/blob/master/core/register_core_types.cpp, |
| 1009 | + // which is called before Core level is initialized. |
| 1010 | + // Currently only promoting super basic classes to Core level since this is a brittle hardcoded list (feel free expand as |
| 1011 | + // necessary based on careful evaluation of register_core_types). |
| 1012 | + | "Object" | "RefCounted" | "Resource" | "MainLoop" | "GDExtension" |
| 1013 | + => ClassCodegenLevel::Core, |
| 1014 | + |
| 1015 | + // See register_early_core_singletons() in https://github.com/godotengine/godot/blob/master/core/register_core_types.cpp, |
| 1016 | + // which is called before Core level is initialized. |
| 1017 | + | "ProjectSettings" | "Engine" | "OS" | "Time" |
| 1018 | + => ClassCodegenLevel::Core, |
| 1019 | + |
| 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. |
| 1022 | + | "OpenXRExtensionWrapperExtension" |
| 1023 | + => ClassCodegenLevel::Servers, |
| 1024 | + |
| 1025 | + // See register_server_types() in https://github.com/godotengine/godot/blob/master/servers/register_server_types.cpp |
1002 | 1026 | | "PhysicsDirectBodyState2D" | "PhysicsDirectBodyState2DExtension"
|
1003 | 1027 | | "PhysicsDirectSpaceState2D" | "PhysicsDirectSpaceState2DExtension"
|
1004 | 1028 | | "PhysicsServer2D" | "PhysicsServer2DExtension"
|
1005 | 1029 | | "PhysicsServer2DManager"
|
1006 |
| - |
1007 |
| - // PhysicsServer3D |
1008 | 1030 | | "PhysicsDirectBodyState3D" | "PhysicsDirectBodyState3DExtension"
|
1009 | 1031 | | "PhysicsDirectSpaceState3D" | "PhysicsDirectSpaceState3DExtension"
|
1010 | 1032 | | "PhysicsServer3D" | "PhysicsServer3DExtension"
|
1011 | 1033 | | "PhysicsServer3DManager"
|
1012 | 1034 | | "PhysicsServer3DRenderingServerHandler"
|
| 1035 | + | "RenderData" | "RenderDataExtension" |
| 1036 | + | "RenderSceneData" | "RenderSceneDataExtension" |
| 1037 | + => ClassCodegenLevel::Servers, |
| 1038 | + // Declared final (un-inheritable) in Rust, but those are still servers. |
| 1039 | + // NOTE: while these _types_ are available at Server level, the singletons themselves are actually not available until _even after_ Editor level. |
| 1040 | + | "AudioServer" | "CameraServer" | "NavigationServer2D" | "NavigationServer3D" | "RenderingServer" | "TranslationServer" | "XRServer" | "DisplayServer" |
| 1041 | + => ClassCodegenLevel::Servers, |
| 1042 | + |
| 1043 | + // Work around wrong classification in https://github.com/godotengine/godot/issues/86206. |
| 1044 | + // https://github.com/godotengine/godot/issues/103867 |
| 1045 | + "OpenXRInteractionProfileEditorBase" |
| 1046 | + | "OpenXRInteractionProfileEditor" |
| 1047 | + | "OpenXRBindingModifierEditor" if cfg!(before_api = "4.5") |
| 1048 | + => ClassCodegenLevel::Editor, |
| 1049 | + // https://github.com/godotengine/godot/issues/86206 |
| 1050 | + "ResourceImporterOggVorbis" | "ResourceImporterMP3" if cfg!(before_api = "4.3") |
| 1051 | + => ClassCodegenLevel::Editor, |
1013 | 1052 |
|
1014 |
| - => true, _ => false |
1015 |
| - } |
| 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 | + } |
| 1065 | + }; |
| 1066 | + Some(level) |
1016 | 1067 | }
|
1017 | 1068 |
|
1018 | 1069 | /// Whether a generated enum is `pub(crate)`; useful for manual re-exports.
|
|
0 commit comments