diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-05-04 19:08:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-04 19:08:43 +0200 |
commit | 84f64ddde956f5ecba4674750442df89b75556c9 (patch) | |
tree | 920e09993cd21dc3f809735a4669b6adaf7cd7cd /modules/visual_script | |
parent | 3a82b7eeef005fdc654aaccadbaa80b4520b5f13 (diff) | |
parent | de0ca3b999819a99a5dcab99f0083a760277b95e (diff) |
Merge pull request #60723 from reduz/refactor-module-initialization
Diffstat (limited to 'modules/visual_script')
-rw-r--r-- | modules/visual_script/register_types.cpp | 171 | ||||
-rw-r--r-- | modules/visual_script/register_types.h | 6 |
2 files changed, 94 insertions, 83 deletions
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index d19870921d..04a7442d0a 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -47,95 +47,104 @@ VisualScriptLanguage *visual_script_language = nullptr; static VisualScriptCustomNodes *vs_custom_nodes_singleton = nullptr; #endif -void register_visual_script_types() { - visual_script_language = memnew(VisualScriptLanguage); - //script_language_gd->init(); - ScriptServer::register_language(visual_script_language); - - GDREGISTER_CLASS(VisualScript); - GDREGISTER_ABSTRACT_CLASS(VisualScriptNode); - GDREGISTER_CLASS(VisualScriptFunctionState); - GDREGISTER_CLASS(VisualScriptFunction); - GDREGISTER_ABSTRACT_CLASS(VisualScriptLists); - GDREGISTER_CLASS(VisualScriptComposeArray); - GDREGISTER_CLASS(VisualScriptOperator); - GDREGISTER_CLASS(VisualScriptVariableSet); - GDREGISTER_CLASS(VisualScriptVariableGet); - GDREGISTER_CLASS(VisualScriptConstant); - GDREGISTER_CLASS(VisualScriptIndexGet); - GDREGISTER_CLASS(VisualScriptIndexSet); - GDREGISTER_CLASS(VisualScriptGlobalConstant); - GDREGISTER_CLASS(VisualScriptClassConstant); - GDREGISTER_CLASS(VisualScriptMathConstant); - GDREGISTER_CLASS(VisualScriptBasicTypeConstant); - GDREGISTER_CLASS(VisualScriptEngineSingleton); - GDREGISTER_CLASS(VisualScriptSceneNode); - GDREGISTER_CLASS(VisualScriptSceneTree); - GDREGISTER_CLASS(VisualScriptResourcePath); - GDREGISTER_CLASS(VisualScriptSelf); - GDREGISTER_CLASS(VisualScriptCustomNode); - GDREGISTER_CLASS(VisualScriptSubCall); - GDREGISTER_CLASS(VisualScriptComment); - GDREGISTER_CLASS(VisualScriptConstructor); - GDREGISTER_CLASS(VisualScriptLocalVar); - GDREGISTER_CLASS(VisualScriptLocalVarSet); - GDREGISTER_CLASS(VisualScriptInputAction); - GDREGISTER_CLASS(VisualScriptDeconstruct); - GDREGISTER_CLASS(VisualScriptPreload); - GDREGISTER_CLASS(VisualScriptTypeCast); - - GDREGISTER_CLASS(VisualScriptFunctionCall); - GDREGISTER_CLASS(VisualScriptPropertySet); - GDREGISTER_CLASS(VisualScriptPropertyGet); - //ClassDB::register_type<VisualScriptScriptCall>(); - GDREGISTER_CLASS(VisualScriptEmitSignal); - - GDREGISTER_CLASS(VisualScriptReturn); - GDREGISTER_CLASS(VisualScriptCondition); - GDREGISTER_CLASS(VisualScriptWhile); - GDREGISTER_CLASS(VisualScriptIterator); - GDREGISTER_CLASS(VisualScriptSequence); - //GDREGISTER_CLASS(VisualScriptInputFilter); - GDREGISTER_CLASS(VisualScriptSwitch); - GDREGISTER_CLASS(VisualScriptSelect); - - GDREGISTER_CLASS(VisualScriptYield); - GDREGISTER_CLASS(VisualScriptYieldSignal); - - GDREGISTER_CLASS(VisualScriptBuiltinFunc); - - GDREGISTER_CLASS(VisualScriptExpression); - - register_visual_script_nodes(); - register_visual_script_func_nodes(); - register_visual_script_builtin_func_node(); - register_visual_script_flow_control_nodes(); - register_visual_script_yield_nodes(); - register_visual_script_expression_node(); +void initialize_visual_script_module(ModuleInitializationLevel p_level) { + if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) { + visual_script_language = memnew(VisualScriptLanguage); + //script_language_gd->init(); + ScriptServer::register_language(visual_script_language); + + GDREGISTER_CLASS(VisualScript); + GDREGISTER_ABSTRACT_CLASS(VisualScriptNode); + GDREGISTER_CLASS(VisualScriptFunctionState); + GDREGISTER_CLASS(VisualScriptFunction); + GDREGISTER_ABSTRACT_CLASS(VisualScriptLists); + GDREGISTER_CLASS(VisualScriptComposeArray); + GDREGISTER_CLASS(VisualScriptOperator); + GDREGISTER_CLASS(VisualScriptVariableSet); + GDREGISTER_CLASS(VisualScriptVariableGet); + GDREGISTER_CLASS(VisualScriptConstant); + GDREGISTER_CLASS(VisualScriptIndexGet); + GDREGISTER_CLASS(VisualScriptIndexSet); + GDREGISTER_CLASS(VisualScriptGlobalConstant); + GDREGISTER_CLASS(VisualScriptClassConstant); + GDREGISTER_CLASS(VisualScriptMathConstant); + GDREGISTER_CLASS(VisualScriptBasicTypeConstant); + GDREGISTER_CLASS(VisualScriptEngineSingleton); + GDREGISTER_CLASS(VisualScriptSceneNode); + GDREGISTER_CLASS(VisualScriptSceneTree); + GDREGISTER_CLASS(VisualScriptResourcePath); + GDREGISTER_CLASS(VisualScriptSelf); + GDREGISTER_CLASS(VisualScriptCustomNode); + GDREGISTER_CLASS(VisualScriptSubCall); + GDREGISTER_CLASS(VisualScriptComment); + GDREGISTER_CLASS(VisualScriptConstructor); + GDREGISTER_CLASS(VisualScriptLocalVar); + GDREGISTER_CLASS(VisualScriptLocalVarSet); + GDREGISTER_CLASS(VisualScriptInputAction); + GDREGISTER_CLASS(VisualScriptDeconstruct); + GDREGISTER_CLASS(VisualScriptPreload); + GDREGISTER_CLASS(VisualScriptTypeCast); + + GDREGISTER_CLASS(VisualScriptFunctionCall); + GDREGISTER_CLASS(VisualScriptPropertySet); + GDREGISTER_CLASS(VisualScriptPropertyGet); + //ClassDB::register_type<VisualScriptScriptCall>(); + GDREGISTER_CLASS(VisualScriptEmitSignal); + + GDREGISTER_CLASS(VisualScriptReturn); + GDREGISTER_CLASS(VisualScriptCondition); + GDREGISTER_CLASS(VisualScriptWhile); + GDREGISTER_CLASS(VisualScriptIterator); + GDREGISTER_CLASS(VisualScriptSequence); + //GDREGISTER_CLASS(VisualScriptInputFilter); + GDREGISTER_CLASS(VisualScriptSwitch); + GDREGISTER_CLASS(VisualScriptSelect); + + GDREGISTER_CLASS(VisualScriptYield); + GDREGISTER_CLASS(VisualScriptYieldSignal); + + GDREGISTER_CLASS(VisualScriptBuiltinFunc); + + GDREGISTER_CLASS(VisualScriptExpression); + + register_visual_script_nodes(); + register_visual_script_func_nodes(); + register_visual_script_builtin_func_node(); + register_visual_script_flow_control_nodes(); + register_visual_script_yield_nodes(); + register_visual_script_expression_node(); + } #ifdef TOOLS_ENABLED - ClassDB::set_current_api(ClassDB::API_EDITOR); - GDREGISTER_CLASS(VisualScriptCustomNodes); - ClassDB::set_current_api(ClassDB::API_CORE); - vs_custom_nodes_singleton = memnew(VisualScriptCustomNodes); - Engine::get_singleton()->add_singleton(Engine::Singleton("VisualScriptCustomNodes", VisualScriptCustomNodes::get_singleton())); - - VisualScriptEditor::register_editor(); + if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) { + ClassDB::set_current_api(ClassDB::API_EDITOR); + GDREGISTER_CLASS(VisualScriptCustomNodes); + ClassDB::set_current_api(ClassDB::API_CORE); + vs_custom_nodes_singleton = memnew(VisualScriptCustomNodes); + Engine::get_singleton()->add_singleton(Engine::Singleton("VisualScriptCustomNodes", VisualScriptCustomNodes::get_singleton())); + + VisualScriptEditor::register_editor(); + } #endif } -void unregister_visual_script_types() { - unregister_visual_script_nodes(); +void uninitialize_visual_script_module(ModuleInitializationLevel p_level) { + if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) { + unregister_visual_script_nodes(); - ScriptServer::unregister_language(visual_script_language); + ScriptServer::unregister_language(visual_script_language); + + if (visual_script_language) { + memdelete(visual_script_language); + } + } #ifdef TOOLS_ENABLED - VisualScriptEditor::free_clipboard(); - if (vs_custom_nodes_singleton) { - memdelete(vs_custom_nodes_singleton); + if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) { + VisualScriptEditor::free_clipboard(); + if (vs_custom_nodes_singleton) { + memdelete(vs_custom_nodes_singleton); + } } #endif - if (visual_script_language) { - memdelete(visual_script_language); - } } diff --git a/modules/visual_script/register_types.h b/modules/visual_script/register_types.h index 29768da67f..90f84de11c 100644 --- a/modules/visual_script/register_types.h +++ b/modules/visual_script/register_types.h @@ -31,7 +31,9 @@ #ifndef VISUAL_SCRIPT_REGISTER_TYPES_H #define VISUAL_SCRIPT_REGISTER_TYPES_H -void register_visual_script_types(); -void unregister_visual_script_types(); +#include "modules/register_module_types.h" + +void initialize_visual_script_module(ModuleInitializationLevel p_level); +void uninitialize_visual_script_module(ModuleInitializationLevel p_level); #endif // VISUAL_SCRIPT_REGISTER_TYPES_H |