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/navigation | |
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/navigation')
-rw-r--r-- | modules/navigation/register_types.cpp | 22 | ||||
-rw-r--r-- | modules/navigation/register_types.h | 6 |
2 files changed, 19 insertions, 9 deletions
diff --git a/modules/navigation/register_types.cpp b/modules/navigation/register_types.cpp index 218f2c2937..62ae2c7f02 100644 --- a/modules/navigation/register_types.cpp +++ b/modules/navigation/register_types.cpp @@ -51,21 +51,29 @@ NavigationServer3D *new_server() { return memnew(GodotNavigationServer); } -void register_navigation_types() { - NavigationServer3DManager::set_default_server(new_server); +void initialize_navigation_module(ModuleInitializationLevel p_level) { + if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) { + NavigationServer3DManager::set_default_server(new_server); #ifndef _3D_DISABLED - _nav_mesh_generator = memnew(NavigationMeshGenerator); - GDREGISTER_CLASS(NavigationMeshGenerator); - Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationMeshGenerator", NavigationMeshGenerator::get_singleton())); + _nav_mesh_generator = memnew(NavigationMeshGenerator); + GDREGISTER_CLASS(NavigationMeshGenerator); + Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationMeshGenerator", NavigationMeshGenerator::get_singleton())); #endif + } #ifdef TOOLS_ENABLED - EditorPlugins::add_by_type<NavigationMeshEditorPlugin>(); + if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) { + EditorPlugins::add_by_type<NavigationMeshEditorPlugin>(); + } #endif } -void unregister_navigation_types() { +void uninitialize_navigation_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) { + return; + } + #ifndef _3D_DISABLED if (_nav_mesh_generator) { memdelete(_nav_mesh_generator); diff --git a/modules/navigation/register_types.h b/modules/navigation/register_types.h index 11fa5769d7..c4dbd19ed3 100644 --- a/modules/navigation/register_types.h +++ b/modules/navigation/register_types.h @@ -31,7 +31,9 @@ #ifndef NAVIGATION_REGISTER_TYPES_H #define NAVIGATION_REGISTER_TYPES_H -void register_navigation_types(); -void unregister_navigation_types(); +#include "modules/register_module_types.h" + +void initialize_navigation_module(ModuleInitializationLevel p_level); +void uninitialize_navigation_module(ModuleInitializationLevel p_level); #endif // NAVIGATION_REGISTER_TYPES_H |