Fix issues with blackboard plan system

This commit is contained in:
Serhii Snitsaruk 2024-03-11 18:58:40 +01:00
parent 92010f19f1
commit b09006a11b
6 changed files with 22 additions and 5 deletions

View File

@ -88,7 +88,7 @@ void BlackboardPlan::_get_property_list(List<PropertyInfo> *p_list) const {
BBVariable var = p.second; BBVariable var = p.second;
// * Editor // * Editor
if (!is_derived() || !var_name.begins_with("_")) { if (var.get_type() != Variant::NIL && (!is_derived() || !var_name.begins_with("_"))) {
p_list->push_back(PropertyInfo(var.get_type(), var_name, var.get_hint(), var.get_hint_string(), PROPERTY_USAGE_EDITOR)); p_list->push_back(PropertyInfo(var.get_type(), var_name, var.get_hint(), var.get_hint_string(), PROPERTY_USAGE_EDITOR));
} }

View File

@ -193,6 +193,8 @@ void BTPlayer::_notification(int p_notification) {
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
_set_monitor_performance(monitor_performance); _set_monitor_performance(monitor_performance);
#endif #endif
} else {
_update_blackboard_plan();
} }
} break; } break;
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_ENTER_TREE: {

View File

@ -26,14 +26,13 @@ private:
StringName success_event; StringName success_event;
StringName failure_event; StringName failure_event;
void _update_blackboard_plan();
protected: protected:
static void _bind_methods(); static void _bind_methods();
void _notification(int p_notification); void _notification(int p_notification);
virtual bool _should_use_new_scope() const override { return true; } virtual bool _should_use_new_scope() const override { return true; }
virtual void _update_blackboard_plan() override;
virtual void _setup() override; virtual void _setup() override;
virtual void _exit() override; virtual void _exit() override;

View File

@ -215,7 +215,9 @@ void LimboAIEditor::_load_bt(String p_path) {
ERR_FAIL_COND_MSG(p_path.is_empty(), "Empty p_path"); ERR_FAIL_COND_MSG(p_path.is_empty(), "Empty p_path");
Ref<BehaviorTree> bt = RESOURCE_LOAD(p_path, "BehaviorTree"); Ref<BehaviorTree> bt = RESOURCE_LOAD(p_path, "BehaviorTree");
ERR_FAIL_COND(!bt.is_valid()); ERR_FAIL_COND(!bt.is_valid());
if (bt->get_blackboard_plan().is_null()) {
bt->set_blackboard_plan(memnew(BlackboardPlan));
}
if (history.find(bt) != -1) { if (history.find(bt) != -1) {
history.erase(bt); history.erase(bt);
history.push_back(bt); history.push_back(bt);

View File

@ -26,6 +26,14 @@
#ifdef LIMBOAI_GDEXTENSION #ifdef LIMBOAI_GDEXTENSION
#endif #endif
void LimboState::set_blackboard_plan(const Ref<BlackboardPlan> &p_plan) {
blackboard_plan = p_plan;
_update_blackboard_plan();
}
void LimboState::_update_blackboard_plan() {
}
LimboState *LimboState::get_root() const { LimboState *LimboState::get_root() const {
const LimboState *state = this; const LimboState *state = this;
while (state->get_parent() && IS_CLASS(state->get_parent(), LimboState)) { while (state->get_parent() && IS_CLASS(state->get_parent(), LimboState)) {
@ -159,6 +167,11 @@ void LimboState::clear_guard() {
void LimboState::_notification(int p_what) { void LimboState::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_READY: {
if (Engine::get_singleton()->is_editor_hint()) {
_update_blackboard_plan();
}
} break;
case NOTIFICATION_EXIT_TREE: { case NOTIFICATION_EXIT_TREE: {
if (active) { if (active) {
_exit(); _exit();

View File

@ -58,6 +58,7 @@ protected:
virtual bool _dispatch(const StringName &p_event, const Variant &p_cargo = Variant()); virtual bool _dispatch(const StringName &p_event, const Variant &p_cargo = Variant());
virtual bool _should_use_new_scope() const { return blackboard_plan.is_valid() || is_root(); } virtual bool _should_use_new_scope() const { return blackboard_plan.is_valid() || is_root(); }
virtual void _update_blackboard_plan();
virtual void _setup(); virtual void _setup();
virtual void _enter(); virtual void _enter();
@ -72,7 +73,7 @@ protected:
#endif // LIMBOAI_MODULE #endif // LIMBOAI_MODULE
public: public:
void set_blackboard_plan(const Ref<BlackboardPlan> &p_plan) { blackboard_plan = p_plan; } void set_blackboard_plan(const Ref<BlackboardPlan> &p_plan);
Ref<BlackboardPlan> get_blackboard_plan() const { return blackboard_plan; } Ref<BlackboardPlan> get_blackboard_plan() const { return blackboard_plan; }
Ref<Blackboard> get_blackboard() const { return blackboard; } Ref<Blackboard> get_blackboard() const { return blackboard; }