Fix the type of the CreateNavigationMeshGeneratorCallback.

This commit is contained in:
Relintai 2023-06-04 09:41:39 +02:00
parent e55c561075
commit 6136f0b802
2 changed files with 11 additions and 30 deletions

View File

@ -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<FuncRef> &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<FuncRef> 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<NavigationMeshGenerator>(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<FuncRef> 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<NavigationMeshGenerator>(o);
NavigationMeshGenerator *gen = navigation_mesh_generators[id].create_callback();
ERR_FAIL_COND_V(!gen, nullptr);

View File

@ -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<FuncRef> create_callback;
CreateNavigationMeshGeneratorCallback create_callback;
};
Vector<ClassInfo> navigation_mesh_generators;
@ -113,7 +115,7 @@ public:
static NavigationMeshGeneratorManager *get_singleton();
void register_server(const String &p_name, const Ref<FuncRef> &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;