diff --git a/servers/navigation/navigation_mesh_generator.cpp b/servers/navigation/navigation_mesh_generator.cpp index 96b44126c..25048122b 100644 --- a/servers/navigation/navigation_mesh_generator.cpp +++ b/servers/navigation/navigation_mesh_generator.cpp @@ -97,17 +97,16 @@ void NavigationMeshGeneratorManager::on_servers_changed() { } void NavigationMeshGeneratorManager::_bind_methods() { - ClassDB::bind_method(D_METHOD("register_server", "name", "create_callback"), &NavigationMeshGeneratorManager::register_server); - ClassDB::bind_method(D_METHOD("set_default_server", "name", "priority"), &NavigationMeshGeneratorManager::set_default_server); + //ClassDB::bind_method(D_METHOD("register_server", "name", "create_callback"), &NavigationMeshGeneratorManager::register_server); + //ClassDB::bind_method(D_METHOD("set_default_server", "name", "priority"), &NavigationMeshGeneratorManager::set_default_server); } NavigationMeshGeneratorManager *NavigationMeshGeneratorManager::get_singleton() { return singleton; } -void NavigationMeshGeneratorManager::register_server(const String &p_name, const Ref &p_create_callback) { - // TODO: Enable check when is_valid() is fixed for static functions. - //ERR_FAIL_COND(!p_create_callback.is_valid()); +void NavigationMeshGeneratorManager::register_server(const String &p_name, CreateNavigationMeshGeneratorCallback p_create_callback) { + ERR_FAIL_COND(!p_create_callback); ERR_FAIL_COND_MSG(find_server_id(p_name) != -1, "NavigationMeshGenerator with the same name was already registered."); navigation_mesh_generators.push_back(ClassInfo{ p_name, p_create_callback }); @@ -138,17 +137,7 @@ int NavigationMeshGeneratorManager::find_server_id(const String &p_name) const { NavigationMeshGenerator *NavigationMeshGeneratorManager::new_default_server() const { ERR_FAIL_COND_V(default_server_id == -1, nullptr); - Ref fr = navigation_mesh_generators[default_server_id].create_callback; - - ERR_FAIL_COND_V(!fr.is_valid(), nullptr); - Array arr; - Variant ret = fr->call_funcv(arr); - - ERR_FAIL_COND_V(ret.is_invalid_object(), nullptr); - - Object *o = ObjectDB::get_instance(ret.get_object_instance_id()); - - NavigationMeshGenerator *gen = Object::cast_to(o); + NavigationMeshGenerator *gen = navigation_mesh_generators[default_server_id].create_callback(); ERR_FAIL_COND_V(!gen, nullptr); @@ -162,17 +151,7 @@ NavigationMeshGenerator *NavigationMeshGeneratorManager::new_server(const String return nullptr; } - Ref fr = navigation_mesh_generators[id].create_callback; - - ERR_FAIL_COND_V(!fr.is_valid(), nullptr); - Array arr; - Variant ret = fr->call_funcv(arr); - - ERR_FAIL_COND_V(ret.is_invalid_object(), nullptr); - - Object *o = ObjectDB::get_instance(ret.get_object_instance_id()); - - NavigationMeshGenerator *gen = Object::cast_to(o); + NavigationMeshGenerator *gen = navigation_mesh_generators[id].create_callback(); ERR_FAIL_COND_V(!gen, nullptr); diff --git a/servers/navigation/navigation_mesh_generator.h b/servers/navigation/navigation_mesh_generator.h index ec5391e76..940dc3f1e 100644 --- a/servers/navigation/navigation_mesh_generator.h +++ b/servers/navigation/navigation_mesh_generator.h @@ -33,8 +33,8 @@ #include "core/containers/rid.h" #include "core/object/class_db.h" -#include "core/object/reference.h" #include "core/object/func_ref.h" +#include "core/object/reference.h" class Node; class NavigationGeometryParser2D; @@ -89,6 +89,8 @@ public: /// NavigationMeshGeneratorManager //////////////////////////////////////////////////// +typedef NavigationMeshGenerator *(*CreateNavigationMeshGeneratorCallback)(); + class NavigationMeshGeneratorManager : public Object { GDCLASS(NavigationMeshGeneratorManager, Object); @@ -96,7 +98,7 @@ class NavigationMeshGeneratorManager : public Object { struct ClassInfo { String name; - Ref create_callback; + CreateNavigationMeshGeneratorCallback create_callback; }; Vector navigation_mesh_generators; @@ -113,7 +115,7 @@ public: static NavigationMeshGeneratorManager *get_singleton(); - void register_server(const String &p_name, const Ref &p_create_callback); + void register_server(const String &p_name, CreateNavigationMeshGeneratorCallback p_create_callback); void set_default_server(const String &p_name, int p_priority = 0); int find_server_id(const String &p_name) const;