Change initialization to allow custom level callbacks

Now it needs a callback for each level so custom logic (like loading
singletons) can be performed.
This commit is contained in:
George Marques
2021-09-09 21:47:45 -03:00
committed by Bastiaan Olij
parent dfa526ce16
commit aef0f1e248
5 changed files with 153 additions and 12 deletions

View File

@@ -63,6 +63,10 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, Args... args)
}
class ClassDB {
static GDNativeInitializationLevel current_level;
friend class godot::GDExtensionBinding;
public:
struct PropertySetGet {
int index;
@@ -98,7 +102,7 @@ private:
public:
template <class T>
static void register_class(GDNativeInitializationLevel p_level = GDNATIVE_INITIALIZATION_SCENE);
static void register_class();
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method);
@@ -132,11 +136,11 @@ public:
}
template <class T>
void ClassDB::register_class(GDNativeInitializationLevel p_level) {
void ClassDB::register_class() {
ClassInfo cl;
cl.name = T::get_class_static();
cl.parent_name = T::get_parent_class_static();
cl.level = p_level;
cl.level = current_level;
cl.constructor = T::create;
cl.destructor = T::free;
cl.object_instance = T::set_object_instance;

View File

@@ -45,12 +45,47 @@ extern "C" void *token;
class GDExtensionBinding {
public:
using Callback = void (*)();
static Callback core_init;
static Callback server_init;
static Callback scene_init;
static Callback editor_init;
static Callback core_terminate;
static Callback server_terminate;
static Callback scene_terminate;
static Callback editor_terminate;
static GDNativeBool init(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization);
public:
static void initialize_level(void *userdata, GDNativeInitializationLevel p_level);
static void deinitialize_level(void *userdata, GDNativeInitializationLevel p_level);
static void *create_instance_callback(void *p_token, void *p_instance);
static void free_instance_callback(void *p_token, void *p_instance, void *p_binding);
class InitObject {
const GDNativeInterface *interface;
const GDNativeExtensionClassLibraryPtr library;
GDNativeInitialization *initialization;
public:
InitObject(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization) :
interface(p_interface),
library(p_library),
initialization(r_initialization) {}
void register_core_initializer(Callback p_core_init) const;
void register_server_initializer(Callback p_server_init) const;
void register_scene_initializer(Callback p_scene_init) const;
void register_editor_initializer(Callback p_editor_init) const;
void register_core_terminator(Callback p_core_terminate) const;
void register_server_terminator(Callback p_server_terminate) const;
void register_scene_terminator(Callback p_scene_terminate) const;
void register_editor_terminator(Callback p_editor_terminate) const;
GDNativeBool init() const;
};
};
} // namespace godot