From 2612ec0855849d431b0b1a6e4a1b61f9b686084b Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sun, 28 Jan 2024 11:56:53 +0100 Subject: [PATCH] Fix LimboHSM::add_transition signature --- doc_classes/LimboHSM.xml | 4 ++-- hsm/limbo_hsm.cpp | 12 +++++------- hsm/limbo_hsm.h | 5 ++--- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/doc_classes/LimboHSM.xml b/doc_classes/LimboHSM.xml index 413d33f..53033be 100644 --- a/doc_classes/LimboHSM.xml +++ b/doc_classes/LimboHSM.xml @@ -11,8 +11,8 @@ - - + + Establishes a transition from one state to another when [param p_event] is dispatched. Both [param p_from_state] and [param p_to_state] must be immediate children of this state. diff --git a/hsm/limbo_hsm.cpp b/hsm/limbo_hsm.cpp index 8834f52..1b1a146 100644 --- a/hsm/limbo_hsm.cpp +++ b/hsm/limbo_hsm.cpp @@ -97,13 +97,11 @@ void LimboHSM::update(double p_delta) { _update(p_delta); } -void LimboHSM::add_transition(Node *p_from_state, Node *p_to_state, const String &p_event) { - ERR_FAIL_COND(p_from_state != nullptr && p_from_state->get_parent() != this); - ERR_FAIL_COND(p_from_state != nullptr && !p_from_state->is_class("LimboState")); - ERR_FAIL_COND(p_to_state == nullptr); - ERR_FAIL_COND(p_to_state->get_parent() != this); - ERR_FAIL_COND(!p_to_state->is_class("LimboState")); - ERR_FAIL_COND(p_event.is_empty()); +void LimboHSM::add_transition(LimboState *p_from_state, LimboState *p_to_state, const String &p_event) { + ERR_FAIL_COND_MSG(p_from_state != nullptr && p_from_state->get_parent() != this, "LimboHSM: Unable to add a transition from a state that is not an immediate child of mine."); + ERR_FAIL_COND_MSG(p_to_state == nullptr, "LimboHSM: Unable to add a transition to a null state."); + ERR_FAIL_COND_MSG(p_to_state->get_parent() != this, "LimboHSM: Unable to add a transition to a state that is not an immediate child of mine."); + ERR_FAIL_COND_MSG(p_event.is_empty(), "LimboHSM: Failed to add transition due to empty event string."); uint64_t key = _get_transition_key(p_from_state, p_event); transitions[key] = Object::cast_to(p_to_state); diff --git a/hsm/limbo_hsm.h b/hsm/limbo_hsm.h index 6c59083..8be57a6 100644 --- a/hsm/limbo_hsm.h +++ b/hsm/limbo_hsm.h @@ -30,7 +30,7 @@ private: LimboState *active_state; HashMap transitions; - _FORCE_INLINE_ uint64_t _get_transition_key(Node *p_from_state, const String &p_event) { + _FORCE_INLINE_ uint64_t _get_transition_key(LimboState *p_from_state, const String &p_event) { uint64_t key = hash_djb2_one_64(Variant::OBJECT); key = hash_djb2_one_64(Variant(p_from_state).hash(), key); key = hash_djb2_one_64(p_event.hash(), key); @@ -65,8 +65,7 @@ public: virtual bool dispatch(const String &p_event, const Variant &p_cargo = Variant()) override; void update(double p_delta); - void add_transition(Node *p_from_state, Node *p_to_state, const String &p_event); - // void add_transition_from_any_state(Node *p_to_state, const String &p_event); + void add_transition(LimboState *p_from_state, LimboState *p_to_state, const String &p_event); LimboState *anystate() const { return nullptr; } LimboHSM();