diff options
author | reduz <reduzio@gmail.com> | 2022-05-03 11:56:08 +0200 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2022-05-04 17:34:51 +0200 |
commit | de0ca3b999819a99a5dcab99f0083a760277b95e (patch) | |
tree | 3078cc65c19bdedfb25c977c48b50e44003a2802 /modules/visual_script | |
parent | 0a9d31a7eb9debe30cd5078688e895d2ce3f2efa (diff) |
Refactor module initialization
* Changed to use the same stages as extensions.
* Makes the initialization more coherent, helping solve problems due to lack of stages.
* Makes it easier to port between module and extension.
* removed the DRIVER initialization level (no longer needed).
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 |