您当前的位置: 首页 > 

开发游戏的老王

暂无认证

  • 1浏览

    0关注

    803博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Object::has_method时间复杂度

开发游戏的老王 发布时间:2020-01-14 22:21:30 ,浏览量:1

GDScript中Object的has_method方法对应着 C++中的Object::has_method方法,之前想在每一帧都判断一下has_method,方法很优雅不过时间复杂度至少是O(n)还是算了吧,附上该方法C++的实现:

Object::has_method
bool Object::has_method(const StringName &p_method) const {

	if (p_method == CoreStringNames::get_singleton()->_free) {
		return true;
	}

	if (script_instance && script_instance->has_method(p_method)) {
		return true;
	}

	MethodBind *method = ClassDB::get_method(get_class_name(), p_method);

	return method != NULL;
}
ClassDB::get_method
MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {

	OBJTYPE_RLOCK;

	ClassInfo *type = classes.getptr(p_class);

	while (type) {

		MethodBind **method = type->method_map.getptr(p_name);
		if (method && *method)
			return *method;
		type = type->inherits_ptr;
	}
	return NULL;
}
关注
打赏
1656935939
查看更多评论
立即登录/注册

微信扫码登录

0.0416s