From de0ca3b999819a99a5dcab99f0083a760277b95e Mon Sep 17 00:00:00 2001 From: reduz Date: Tue, 3 May 2022 11:56:08 +0200 Subject: 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). --- modules/text_server_adv/register_types.cpp | 19 ++++++++++++------- modules/text_server_adv/register_types.h | 12 ++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'modules/text_server_adv') diff --git a/modules/text_server_adv/register_types.cpp b/modules/text_server_adv/register_types.cpp index ed00bdfbf9..6a26584506 100644 --- a/modules/text_server_adv/register_types.cpp +++ b/modules/text_server_adv/register_types.cpp @@ -32,7 +32,11 @@ #include "text_server_adv.h" -void preregister_text_server_adv_types() { +void initialize_text_server_adv_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) { + return; + } + GDREGISTER_CLASS(TextServerAdvanced); TextServerManager *tsman = TextServerManager::get_singleton(); if (tsman) { @@ -42,10 +46,10 @@ void preregister_text_server_adv_types() { } } -void register_text_server_adv_types() { -} - -void unregister_text_server_adv_types() { +void uninitialize_text_server_adv_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) { + return; + } } #ifdef GDEXTENSION @@ -61,8 +65,9 @@ extern "C" { GDNativeBool GDN_EXPORT textserver_advanced_init(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization) { GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization); - init_obj.register_server_initializer(&preregister_text_server_adv_types); - init_obj.register_server_terminator(&unregister_text_server_adv_types); + init_obj.register_initializer(&initialize_text_server_adv_module); + init_obj.register_terminator(&uninitialize_text_server_adv_module); + init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SERVERS); return init_obj.init(); } diff --git a/modules/text_server_adv/register_types.h b/modules/text_server_adv/register_types.h index d2b49fce6e..dfe20c860c 100644 --- a/modules/text_server_adv/register_types.h +++ b/modules/text_server_adv/register_types.h @@ -31,10 +31,14 @@ #ifndef TEXT_SERVER_ADV_REGISTER_TYPES_H #define TEXT_SERVER_ADV_REGISTER_TYPES_H -#define MODULE_TEXT_SERVER_ADV_HAS_PREREGISTER +#ifdef GDEXTENSION +#include +using namespace godot; +#else +#include "modules/register_module_types.h" +#endif -void preregister_text_server_adv_types(); -void register_text_server_adv_types(); -void unregister_text_server_adv_types(); +void initialize_text_server_adv_module(ModuleInitializationLevel p_level); +void uninitialize_text_server_adv_module(ModuleInitializationLevel p_level); #endif // TEXT_SERVER_ADV_REGISTER_TYPES_H -- cgit v1.2.3