From a2dae24b999c8340650dd53f096a1cb075fddf8d Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 2 May 2024 12:11:59 +0200 Subject: [PATCH] Rename BTPlayer's agent => agent_node --- bt/bt_player.cpp | 14 +++++++------- bt/bt_player.h | 6 +++--- bt/bt_state.cpp | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/bt/bt_player.cpp b/bt/bt_player.cpp index d3d3bc3..bd00b44 100644 --- a/bt/bt_player.cpp +++ b/bt/bt_player.cpp @@ -52,11 +52,11 @@ void BTPlayer::_load_tree() { tree_instance.unref(); ERR_FAIL_COND_MSG(!behavior_tree.is_valid(), "BTPlayer: Initialization failed - needs a valid behavior tree."); ERR_FAIL_COND_MSG(!behavior_tree->get_root_task().is_valid(), "BTPlayer: Initialization failed - behavior tree has no valid root task."); - Node *agent_node = GET_NODE(this, agent); - ERR_FAIL_NULL_MSG(agent_node, vformat("BTPlayer: Initialization failed - can't get agent by provided path '%s'.", agent)); + Node *agent = GET_NODE(this, agent_node); + ERR_FAIL_NULL_MSG(agent, vformat("BTPlayer: Initialization failed - can't get agent with path '%s'.", agent_node)); Node *scene_root = get_owner(); ERR_FAIL_NULL_MSG(scene_root, "BTPlayer: Initialization failed - can't get scene root (make sure the BTPlayer.owner is set)."); - tree_instance = behavior_tree->instantiate(agent_node, blackboard, scene_root); + tree_instance = behavior_tree->instantiate(agent, blackboard, scene_root); #ifdef DEBUG_ENABLED if (IS_DEBUGGER_ACTIVE()) { LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path()); @@ -232,8 +232,8 @@ void BTPlayer::_notification(int p_notification) { void BTPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_behavior_tree", "behavior_tree"), &BTPlayer::set_behavior_tree); ClassDB::bind_method(D_METHOD("get_behavior_tree"), &BTPlayer::get_behavior_tree); - ClassDB::bind_method(D_METHOD("set_agent", "agent"), &BTPlayer::set_agent); - ClassDB::bind_method(D_METHOD("get_agent"), &BTPlayer::get_agent); + ClassDB::bind_method(D_METHOD("set_agent_node", "agent_node"), &BTPlayer::set_agent_node); + ClassDB::bind_method(D_METHOD("get_agent_node"), &BTPlayer::get_agent_node); ClassDB::bind_method(D_METHOD("set_update_mode", "update_mode"), &BTPlayer::set_update_mode); ClassDB::bind_method(D_METHOD("get_update_mode"), &BTPlayer::get_update_mode); ClassDB::bind_method(D_METHOD("set_active", "active"), &BTPlayer::set_active); @@ -251,7 +251,7 @@ void BTPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_tree_instance"), &BTPlayer::get_tree_instance); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "behavior_tree", PROPERTY_HINT_RESOURCE_TYPE, "BehaviorTree"), "set_behavior_tree", "get_behavior_tree"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "agent"), "set_agent", "get_agent"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "agent_node"), "set_agent_node", "get_agent_node"); ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "Idle,Physics,Manual"), "set_update_mode", "get_update_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "get_active"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard", PROPERTY_HINT_NONE, "Blackboard", 0), "set_blackboard", "get_blackboard"); @@ -273,7 +273,7 @@ void BTPlayer::_bind_methods() { BTPlayer::BTPlayer() { blackboard = Ref(memnew(Blackboard)); - agent = LW_NAME(node_pp); + agent_node = LW_NAME(node_pp); } BTPlayer::~BTPlayer() { diff --git a/bt/bt_player.h b/bt/bt_player.h index dffa913..74b72e2 100644 --- a/bt/bt_player.h +++ b/bt/bt_player.h @@ -37,7 +37,7 @@ public: private: Ref behavior_tree; - NodePath agent; + NodePath agent_node; Ref blackboard_plan; UpdateMode update_mode = UpdateMode::PHYSICS; bool active = true; @@ -58,8 +58,8 @@ public: void set_behavior_tree(const Ref &p_tree); Ref get_behavior_tree() const { return behavior_tree; }; - void set_agent(const NodePath &p_agent) { agent = p_agent; } - NodePath get_agent() const { return agent; } + void set_agent_node(const NodePath &p_agent_node) { agent_node = p_agent_node; } + NodePath get_agent_node() const { return agent_node; } void set_blackboard_plan(const Ref &p_plan); Ref get_blackboard_plan() const { return blackboard_plan; } diff --git a/bt/bt_state.cpp b/bt/bt_state.cpp index d362479..08c40a6 100644 --- a/bt/bt_state.cpp +++ b/bt/bt_state.cpp @@ -52,7 +52,6 @@ void BTState::_update_blackboard_plan() { void BTState::_setup() { LimboState::_setup(); ERR_FAIL_COND_MSG(behavior_tree.is_null(), "BTState: BehaviorTree is not assigned."); - // TODO: BBNode relies on agent to be scene owner, so if the user provides anything else, the behavior tree can break. tree_instance = behavior_tree->instantiate(get_agent(), get_blackboard(), get_owner()); #ifdef DEBUG_ENABLED