Make blackboard data exposed at state level
This commit is contained in:
parent
86dba63db6
commit
a91a9ef9ed
|
@ -186,23 +186,14 @@ void LimboHSM::_initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard)
|
||||||
ERR_FAIL_COND_MSG(initial_state == nullptr, "LimboHSM: Child at index 0 is not a LimboState.");
|
ERR_FAIL_COND_MSG(initial_state == nullptr, "LimboHSM: Child at index 0 is not a LimboState.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Blackboard> bb = blackboard;
|
LimboState::_initialize(p_agent, p_blackboard);
|
||||||
if (!blackboard->get_data().empty()) {
|
|
||||||
if (!p_blackboard.is_null()) {
|
|
||||||
bb->set_parent_scope(p_blackboard);
|
|
||||||
}
|
|
||||||
} else if (!p_blackboard.is_null()) {
|
|
||||||
bb = p_blackboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
LimboState::_initialize(p_agent, bb);
|
|
||||||
|
|
||||||
for (int i = 0; i < get_child_count(); i++) {
|
for (int i = 0; i < get_child_count(); i++) {
|
||||||
LimboState *c = Object::cast_to<LimboState>(get_child(i));
|
LimboState *c = Object::cast_to<LimboState>(get_child(i));
|
||||||
if (unlikely(c == nullptr)) {
|
if (unlikely(c == nullptr)) {
|
||||||
ERR_PRINT(vformat("LimboHSM: Child at index %d is not a LimboState.", i));
|
ERR_PRINT(vformat("LimboHSM: Child at index %d is not a LimboState.", i));
|
||||||
} else {
|
} else {
|
||||||
c->_initialize(p_agent, bb);
|
c->_initialize(agent, blackboard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,9 +226,6 @@ void LimboHSM::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_initial_state", "p_state"), &LimboHSM::set_initial_state);
|
ClassDB::bind_method(D_METHOD("set_initial_state", "p_state"), &LimboHSM::set_initial_state);
|
||||||
ClassDB::bind_method(D_METHOD("get_initial_state"), &LimboHSM::get_initial_state);
|
ClassDB::bind_method(D_METHOD("get_initial_state"), &LimboHSM::get_initial_state);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_set_blackboard_data", "p_blackboard"), &LimboHSM::_set_blackboard_data);
|
|
||||||
ClassDB::bind_method(D_METHOD("_get_blackboard_data"), &LimboHSM::_get_blackboard_data);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_active_state"), &LimboHSM::get_active_state);
|
ClassDB::bind_method(D_METHOD("get_active_state"), &LimboHSM::get_active_state);
|
||||||
ClassDB::bind_method(D_METHOD("get_leaf_state"), &LimboHSM::get_leaf_state);
|
ClassDB::bind_method(D_METHOD("get_leaf_state"), &LimboHSM::get_leaf_state);
|
||||||
ClassDB::bind_method(D_METHOD("set_active", "p_active"), &LimboHSM::set_active);
|
ClassDB::bind_method(D_METHOD("set_active", "p_active"), &LimboHSM::set_active);
|
||||||
|
@ -254,7 +242,6 @@ void LimboHSM::_bind_methods() {
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "Idle, Physics, Manual"), "set_update_mode", "get_update_mode");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "Idle, Physics, Manual"), "set_update_mode", "get_update_mode");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ANYSTATE", PROPERTY_HINT_NONE, "", 0), "", "anystate");
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ANYSTATE", PROPERTY_HINT_NONE, "", 0), "", "anystate");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "initial_state", PROPERTY_HINT_RESOURCE_TYPE, "LimboState", 0), "set_initial_state", "get_initial_state");
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "initial_state", PROPERTY_HINT_RESOURCE_TYPE, "LimboState", 0), "set_initial_state", "get_initial_state");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_blackboard_data"), "_set_blackboard_data", "_get_blackboard_data");
|
|
||||||
|
|
||||||
ADD_SIGNAL(MethodInfo("state_changed", PropertyInfo(Variant::OBJECT, "p_state", PROPERTY_HINT_NONE, "", 0, "LimboState")));
|
ADD_SIGNAL(MethodInfo("state_changed", PropertyInfo(Variant::OBJECT, "p_state", PROPERTY_HINT_NONE, "", 0, "LimboState")));
|
||||||
}
|
}
|
||||||
|
@ -263,5 +250,4 @@ LimboHSM::LimboHSM() {
|
||||||
update_mode = UpdateMode::IDLE;
|
update_mode = UpdateMode::IDLE;
|
||||||
active_state = nullptr;
|
active_state = nullptr;
|
||||||
initial_state = nullptr;
|
initial_state = nullptr;
|
||||||
blackboard = Ref<Blackboard>(memnew(Blackboard));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,6 @@ protected:
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
||||||
void _set_blackboard_data(Dictionary p_value) { blackboard->set_data(p_value.duplicate()); }
|
|
||||||
Dictionary _get_blackboard_data() const { return blackboard->get_data(); }
|
|
||||||
|
|
||||||
virtual void _initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard);
|
virtual void _initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard);
|
||||||
virtual void _enter();
|
virtual void _enter();
|
||||||
virtual void _exit();
|
virtual void _exit();
|
||||||
|
|
|
@ -63,9 +63,17 @@ void LimboState::_update(float p_delta) {
|
||||||
|
|
||||||
void LimboState::_initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard) {
|
void LimboState::_initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard) {
|
||||||
ERR_FAIL_COND(p_agent == nullptr);
|
ERR_FAIL_COND(p_agent == nullptr);
|
||||||
ERR_FAIL_COND(!p_blackboard.is_valid());
|
|
||||||
agent = p_agent;
|
agent = p_agent;
|
||||||
|
|
||||||
|
if (!p_blackboard.is_null()) {
|
||||||
|
if (!blackboard->get_data().empty()) {
|
||||||
|
blackboard->set_parent_scope(p_blackboard);
|
||||||
|
} else {
|
||||||
blackboard = p_blackboard;
|
blackboard = p_blackboard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_setup();
|
_setup();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -155,6 +163,9 @@ void LimboState::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("clear_guard_func"), &LimboState::clear_guard_func);
|
ClassDB::bind_method(D_METHOD("clear_guard_func"), &LimboState::clear_guard_func);
|
||||||
ClassDB::bind_method(D_METHOD("get_blackboard"), &LimboState::get_blackboard);
|
ClassDB::bind_method(D_METHOD("get_blackboard"), &LimboState::get_blackboard);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("_set_blackboard_data", "p_blackboard"), &LimboState::_set_blackboard_data);
|
||||||
|
ClassDB::bind_method(D_METHOD("_get_blackboard_data"), &LimboState::_get_blackboard_data);
|
||||||
|
|
||||||
BIND_VMETHOD(MethodInfo("_setup"));
|
BIND_VMETHOD(MethodInfo("_setup"));
|
||||||
BIND_VMETHOD(MethodInfo("_enter"));
|
BIND_VMETHOD(MethodInfo("_enter"));
|
||||||
BIND_VMETHOD(MethodInfo("_exit"));
|
BIND_VMETHOD(MethodInfo("_exit"));
|
||||||
|
@ -163,6 +174,7 @@ void LimboState::_bind_methods() {
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "EVENT_FINISHED", PROPERTY_HINT_NONE, "", 0), "", "event_finished");
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "EVENT_FINISHED", PROPERTY_HINT_NONE, "", 0), "", "event_finished");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "agent", PROPERTY_HINT_RESOURCE_TYPE, "Object", 0), "set_agent", "get_agent");
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "agent", PROPERTY_HINT_RESOURCE_TYPE, "Object", 0), "set_agent", "get_agent");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard", PROPERTY_HINT_RESOURCE_TYPE, "Blackboard", 0), "", "get_blackboard");
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard", PROPERTY_HINT_RESOURCE_TYPE, "Blackboard", 0), "", "get_blackboard");
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_blackboard_data"), "_set_blackboard_data", "_get_blackboard_data");
|
||||||
|
|
||||||
ADD_SIGNAL(MethodInfo("setup"));
|
ADD_SIGNAL(MethodInfo("setup"));
|
||||||
ADD_SIGNAL(MethodInfo("entered"));
|
ADD_SIGNAL(MethodInfo("entered"));
|
||||||
|
@ -173,6 +185,7 @@ void LimboState::_bind_methods() {
|
||||||
LimboState::LimboState() {
|
LimboState::LimboState() {
|
||||||
agent = nullptr;
|
agent = nullptr;
|
||||||
active = false;
|
active = false;
|
||||||
|
blackboard = Ref<Blackboard>(memnew(Blackboard));
|
||||||
|
|
||||||
guard.obj = nullptr;
|
guard.obj = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,9 @@ protected:
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
||||||
|
void _set_blackboard_data(Dictionary p_value) { blackboard->set_data(p_value.duplicate()); }
|
||||||
|
Dictionary _get_blackboard_data() const { return blackboard->get_data(); }
|
||||||
|
|
||||||
virtual void _initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard);
|
virtual void _initialize(Object *p_agent, const Ref<Blackboard> &p_blackboard);
|
||||||
virtual void _setup();
|
virtual void _setup();
|
||||||
virtual void _enter();
|
virtual void _enter();
|
||||||
|
|
Loading…
Reference in New Issue