2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* bt_state.h
|
|
|
|
* =============================================================================
|
2024-03-04 14:53:39 +00:00
|
|
|
* Copyright 2021-2024 Serhii Snitsaruk
|
2023-07-21 09:50:06 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2022-10-19 18:54:21 +00:00
|
|
|
|
|
|
|
#ifndef BT_STATE_H
|
|
|
|
#define BT_STATE_H
|
|
|
|
|
2024-01-07 04:54:17 +00:00
|
|
|
#include "../hsm/limbo_state.h"
|
2023-07-20 16:35:36 +00:00
|
|
|
|
2024-01-07 04:54:17 +00:00
|
|
|
#include "../bt/behavior_tree.h"
|
|
|
|
#include "../bt/tasks/bt_task.h"
|
2022-10-19 18:54:21 +00:00
|
|
|
|
|
|
|
class BTState : public LimboState {
|
|
|
|
GDCLASS(BTState, LimboState);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Ref<BehaviorTree> behavior_tree;
|
2024-08-03 09:39:23 +00:00
|
|
|
Ref<BTInstance> bt_instance;
|
2024-03-04 14:53:39 +00:00
|
|
|
StringName success_event;
|
|
|
|
StringName failure_event;
|
2024-08-05 11:21:57 +00:00
|
|
|
Node *scene_root_hint = nullptr;
|
2024-08-11 10:37:37 +00:00
|
|
|
bool monitor_performance = false;
|
2022-10-19 18:54:21 +00:00
|
|
|
|
2024-09-15 12:29:23 +00:00
|
|
|
_FORCE_INLINE_ Node *_get_scene_root() const { return scene_root_hint ? scene_root_hint : get_owner(); }
|
|
|
|
|
2022-10-19 18:54:21 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2024-03-04 14:53:39 +00:00
|
|
|
void _notification(int p_notification);
|
|
|
|
|
2024-03-06 19:17:23 +00:00
|
|
|
virtual bool _should_use_new_scope() const override { return true; }
|
2024-03-11 17:58:40 +00:00
|
|
|
virtual void _update_blackboard_plan() override;
|
2024-09-15 12:29:23 +00:00
|
|
|
virtual Node *_get_prefetch_root_for_base_plan() override;
|
2024-03-06 19:17:23 +00:00
|
|
|
|
2022-12-15 07:26:52 +00:00
|
|
|
virtual void _setup() override;
|
|
|
|
virtual void _exit() override;
|
2023-04-10 08:08:11 +00:00
|
|
|
virtual void _update(double p_delta) override;
|
2022-10-19 18:54:21 +00:00
|
|
|
|
|
|
|
public:
|
2024-01-24 23:23:34 +00:00
|
|
|
void set_behavior_tree(const Ref<BehaviorTree> &p_value);
|
2022-10-19 18:54:21 +00:00
|
|
|
Ref<BehaviorTree> get_behavior_tree() const { return behavior_tree; }
|
2022-10-19 21:41:56 +00:00
|
|
|
|
2024-08-03 09:39:23 +00:00
|
|
|
Ref<BTInstance> get_bt_instance() const { return bt_instance; }
|
2024-02-03 15:31:21 +00:00
|
|
|
|
2024-03-04 14:53:39 +00:00
|
|
|
void set_success_event(const StringName &p_success_event) { success_event = p_success_event; }
|
|
|
|
StringName get_success_event() const { return success_event; }
|
2022-11-04 12:26:49 +00:00
|
|
|
|
2024-03-04 14:53:39 +00:00
|
|
|
void set_failure_event(const StringName &p_failure_event) { failure_event = p_failure_event; }
|
|
|
|
StringName get_failure_event() const { return failure_event; }
|
2022-11-04 12:26:49 +00:00
|
|
|
|
2024-08-11 10:37:37 +00:00
|
|
|
void set_monitor_performance(bool p_monitor);
|
|
|
|
bool get_monitor_performance() const { return monitor_performance; }
|
|
|
|
|
2024-08-05 11:21:57 +00:00
|
|
|
void set_scene_root_hint(Node *p_node);
|
|
|
|
|
2022-10-19 21:41:56 +00:00
|
|
|
BTState();
|
2022-10-19 18:54:21 +00:00
|
|
|
};
|
|
|
|
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif // BT_STATE_H
|