Fix circular ref & non-tools compilation errors
This commit is contained in:
parent
3b12288ae0
commit
ef1c1e5192
|
@ -52,9 +52,13 @@ void BehaviorTree::set_blackboard_plan(const Ref<BlackboardPlan> &p_plan) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BehaviorTree::set_root_task(const Ref<BTTask> &p_value) {
|
void BehaviorTree::set_root_task(const Ref<BTTask> &p_value) {
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
_unset_editor_behavior_tree_hint();
|
_unset_editor_behavior_tree_hint();
|
||||||
|
#endif // TOOLS_ENABLED
|
||||||
root_task = p_value;
|
root_task = p_value;
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
_set_editor_behavior_tree_hint();
|
_set_editor_behavior_tree_hint();
|
||||||
|
#endif // TOOLS_ENABLED
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,18 +91,22 @@ void BehaviorTree::_plan_changed() {
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
|
||||||
void BehaviorTree::_set_editor_behavior_tree_hint() {
|
void BehaviorTree::_set_editor_behavior_tree_hint() {
|
||||||
if (root_task.is_valid()) {
|
if (root_task.is_valid()) {
|
||||||
root_task->data.behavior_tree = Ref<BehaviorTree>(this);
|
root_task->data.behavior_tree_id = this->get_instance_id();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BehaviorTree::_unset_editor_behavior_tree_hint() {
|
void BehaviorTree::_unset_editor_behavior_tree_hint() {
|
||||||
if (root_task.is_valid()) {
|
if (root_task.is_valid()) {
|
||||||
root_task->data.behavior_tree.unref();
|
root_task->data.behavior_tree_id = ObjectID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // TOOLS_ENABLED
|
||||||
|
|
||||||
void BehaviorTree::_bind_methods() {
|
void BehaviorTree::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_description", "description"), &BehaviorTree::set_description);
|
ClassDB::bind_method(D_METHOD("set_description", "description"), &BehaviorTree::set_description);
|
||||||
ClassDB::bind_method(D_METHOD("get_description"), &BehaviorTree::get_description);
|
ClassDB::bind_method(D_METHOD("get_description"), &BehaviorTree::get_description);
|
||||||
|
|
|
@ -33,8 +33,11 @@ private:
|
||||||
Ref<BTTask> root_task;
|
Ref<BTTask> root_task;
|
||||||
|
|
||||||
void _plan_changed();
|
void _plan_changed();
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
void _set_editor_behavior_tree_hint();
|
void _set_editor_behavior_tree_hint();
|
||||||
void _unset_editor_behavior_tree_hint();
|
void _unset_editor_behavior_tree_hint();
|
||||||
|
#endif // TOOLS_ENABLED
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
|
@ -377,18 +377,22 @@ void BTTask::print_tree(int p_initial_tabs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
|
||||||
Ref<BehaviorTree> BTTask::editor_get_behavior_tree() {
|
Ref<BehaviorTree> BTTask::editor_get_behavior_tree() {
|
||||||
BTTask *task = this;
|
BTTask *task = this;
|
||||||
while (task->data.behavior_tree.is_null() && task->get_parent().is_valid()) {
|
while (task->data.behavior_tree_id.is_null() && task->get_parent().is_valid()) {
|
||||||
task = task->data.parent;
|
task = task->data.parent;
|
||||||
}
|
}
|
||||||
return task->data.behavior_tree;
|
return Object::cast_to<BehaviorTree>(ObjectDB::get_instance(task->data.behavior_tree_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTTask::editor_set_behavior_tree(const Ref<BehaviorTree> &p_bt) {
|
void BTTask::editor_set_behavior_tree(const Ref<BehaviorTree> &p_bt) {
|
||||||
data.behavior_tree = p_bt;
|
data.behavior_tree_id = p_bt->get_instance_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // TOOLS_ENABLED
|
||||||
|
|
||||||
void BTTask::_bind_methods() {
|
void BTTask::_bind_methods() {
|
||||||
// Public Methods.
|
// Public Methods.
|
||||||
ClassDB::bind_method(D_METHOD("is_root"), &BTTask::is_root);
|
ClassDB::bind_method(D_METHOD("is_root"), &BTTask::is_root);
|
||||||
|
@ -410,7 +414,9 @@ void BTTask::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("print_tree", "initial_tabs"), &BTTask::print_tree, Variant(0));
|
ClassDB::bind_method(D_METHOD("print_tree", "initial_tabs"), &BTTask::print_tree, Variant(0));
|
||||||
ClassDB::bind_method(D_METHOD("get_task_name"), &BTTask::get_task_name);
|
ClassDB::bind_method(D_METHOD("get_task_name"), &BTTask::get_task_name);
|
||||||
ClassDB::bind_method(D_METHOD("abort"), &BTTask::abort);
|
ClassDB::bind_method(D_METHOD("abort"), &BTTask::abort);
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
ClassDB::bind_method(D_METHOD("editor_get_behavior_tree"), &BTTask::editor_get_behavior_tree);
|
ClassDB::bind_method(D_METHOD("editor_get_behavior_tree"), &BTTask::editor_get_behavior_tree);
|
||||||
|
#endif // TOOLS_ENABLED
|
||||||
|
|
||||||
// Properties, setters and getters.
|
// Properties, setters and getters.
|
||||||
ClassDB::bind_method(D_METHOD("get_agent"), &BTTask::get_agent);
|
ClassDB::bind_method(D_METHOD("get_agent"), &BTTask::get_agent);
|
||||||
|
|
|
@ -85,7 +85,7 @@ private:
|
||||||
double elapsed = 0.0;
|
double elapsed = 0.0;
|
||||||
bool display_collapsed = false;
|
bool display_collapsed = false;
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
Ref<BehaviorTree> behavior_tree;
|
ObjectID behavior_tree_id;
|
||||||
#endif
|
#endif
|
||||||
} data;
|
} data;
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,14 @@ void BTNewScope::set_blackboard_plan(const Ref<BlackboardPlan> &p_plan) {
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
void BTNewScope::_set_parent_scope_plan_from_bt() {
|
void BTNewScope::_set_parent_scope_plan_from_bt() {
|
||||||
ERR_FAIL_NULL(get_blackboard_plan());
|
ERR_FAIL_NULL(get_blackboard_plan());
|
||||||
Ref<BehaviorTree> bt = get_root()->editor_get_behavior_tree();
|
Ref<BehaviorTree> bt = get_root()->editor_get_behavior_tree();
|
||||||
ERR_FAIL_NULL(bt);
|
ERR_FAIL_NULL(bt);
|
||||||
get_blackboard_plan()->set_parent_scope_plan(bt->get_blackboard_plan());
|
get_blackboard_plan()->set_parent_scope_plan(bt->get_blackboard_plan());
|
||||||
}
|
}
|
||||||
|
#endif // TOOLS_ENABLED
|
||||||
|
|
||||||
void BTNewScope::initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard, Node *p_scene_root) {
|
void BTNewScope::initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard, Node *p_scene_root) {
|
||||||
ERR_FAIL_COND(p_agent == nullptr);
|
ERR_FAIL_COND(p_agent == nullptr);
|
||||||
|
|
|
@ -23,7 +23,9 @@ class BTNewScope : public BTDecorator {
|
||||||
private:
|
private:
|
||||||
Ref<BlackboardPlan> blackboard_plan;
|
Ref<BlackboardPlan> blackboard_plan;
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
void _set_parent_scope_plan_from_bt();
|
void _set_parent_scope_plan_from_bt();
|
||||||
|
#endif // TOOLS_ENABLED
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
Loading…
Reference in New Issue