2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* bt_player.h
|
|
|
|
* =============================================================================
|
2024-03-04 20:36:16 +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-08-30 16:48:49 +00:00
|
|
|
|
|
|
|
#ifndef BT_PLAYER_H
|
|
|
|
#define BT_PLAYER_H
|
|
|
|
|
2024-01-13 16:10:42 +00:00
|
|
|
#include "../blackboard/blackboard.h"
|
2024-01-23 19:02:23 +00:00
|
|
|
#include "../blackboard/blackboard_plan.h"
|
2024-01-13 16:10:42 +00:00
|
|
|
#include "behavior_tree.h"
|
2024-08-03 09:07:06 +00:00
|
|
|
#include "bt_instance.h"
|
2024-01-13 16:10:42 +00:00
|
|
|
#include "tasks/bt_task.h"
|
|
|
|
|
2024-01-07 01:40:51 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2023-08-15 15:49:13 +00:00
|
|
|
#include "scene/main/node.h"
|
2024-01-07 01:40:51 +00:00
|
|
|
#endif
|
2023-08-15 15:49:13 +00:00
|
|
|
|
2024-01-07 01:40:51 +00:00
|
|
|
#ifdef LIMBOAI_GDEXTENSION
|
|
|
|
#include <godot_cpp/classes/node.hpp>
|
|
|
|
#endif
|
|
|
|
|
2022-08-30 16:48:49 +00:00
|
|
|
class BTPlayer : public Node {
|
|
|
|
GDCLASS(BTPlayer, Node);
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum UpdateMode : unsigned int {
|
|
|
|
IDLE, // automatically call update() during NOTIFICATION_PROCESS
|
2024-01-13 16:10:42 +00:00
|
|
|
PHYSICS, // automatically call update() during NOTIFICATION_PHYSICS
|
2022-08-30 16:48:49 +00:00
|
|
|
MANUAL, // manually update state machine, user must call update(delta)
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
Ref<BehaviorTree> behavior_tree;
|
2024-05-02 10:11:59 +00:00
|
|
|
NodePath agent_node;
|
2024-01-23 19:02:23 +00:00
|
|
|
Ref<BlackboardPlan> blackboard_plan;
|
2022-12-16 14:29:36 +00:00
|
|
|
UpdateMode update_mode = UpdateMode::PHYSICS;
|
|
|
|
bool active = true;
|
2022-09-08 13:56:51 +00:00
|
|
|
Ref<Blackboard> blackboard;
|
2024-08-05 11:21:57 +00:00
|
|
|
Node *scene_root_hint = nullptr;
|
2022-08-30 16:48:49 +00:00
|
|
|
|
2024-08-03 09:07:06 +00:00
|
|
|
Ref<BTInstance> bt_instance;
|
2022-08-30 16:48:49 +00:00
|
|
|
|
|
|
|
void _load_tree();
|
2024-01-23 19:02:23 +00:00
|
|
|
void _update_blackboard_plan();
|
2022-08-30 16:48:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
void _notification(int p_notification);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_behavior_tree(const Ref<BehaviorTree> &p_tree);
|
|
|
|
Ref<BehaviorTree> get_behavior_tree() const { return behavior_tree; };
|
2024-01-23 11:05:54 +00:00
|
|
|
|
2024-05-02 10:49:32 +00:00
|
|
|
void set_agent_node(const NodePath &p_agent_node);
|
2024-05-02 10:11:59 +00:00
|
|
|
NodePath get_agent_node() const { return agent_node; }
|
2024-05-01 21:20:17 +00:00
|
|
|
|
2024-01-23 19:02:23 +00:00
|
|
|
void set_blackboard_plan(const Ref<BlackboardPlan> &p_plan);
|
|
|
|
Ref<BlackboardPlan> get_blackboard_plan() const { return blackboard_plan; }
|
2022-08-30 16:48:49 +00:00
|
|
|
|
|
|
|
void set_update_mode(UpdateMode p_mode);
|
|
|
|
UpdateMode get_update_mode() const { return update_mode; }
|
|
|
|
|
|
|
|
void set_active(bool p_active);
|
|
|
|
bool get_active() const { return active; }
|
|
|
|
|
2022-09-08 13:56:51 +00:00
|
|
|
Ref<Blackboard> get_blackboard() const { return blackboard; }
|
|
|
|
void set_blackboard(const Ref<Blackboard> &p_blackboard) { blackboard = p_blackboard; }
|
2022-09-05 14:30:41 +00:00
|
|
|
|
2023-04-10 08:08:11 +00:00
|
|
|
void update(double p_delta);
|
2022-08-30 16:48:49 +00:00
|
|
|
void restart();
|
2022-09-08 13:56:51 +00:00
|
|
|
|
2024-08-03 09:07:06 +00:00
|
|
|
Ref<BTInstance> get_bt_instance() { return bt_instance; }
|
2024-08-04 10:36:44 +00:00
|
|
|
void set_bt_instance(const Ref<BTInstance> &p_bt_instance);
|
2024-02-03 15:31:21 +00:00
|
|
|
|
2024-08-05 10:49:58 +00:00
|
|
|
void set_scene_root_hint(Node *p_scene_root);
|
|
|
|
|
2022-09-08 13:56:51 +00:00
|
|
|
BTPlayer();
|
|
|
|
~BTPlayer();
|
2023-04-15 13:49:34 +00:00
|
|
|
|
2024-01-13 16:10:42 +00:00
|
|
|
#ifdef DEBUG_ENABLED // Performance monitoring
|
|
|
|
|
2023-04-15 13:49:34 +00:00
|
|
|
private:
|
|
|
|
bool monitor_performance = false;
|
|
|
|
|
|
|
|
void _set_monitor_performance(bool p_monitor_performance);
|
|
|
|
bool _get_monitor_performance() const { return monitor_performance; }
|
2024-06-04 07:30:42 +00:00
|
|
|
|
2024-08-03 09:07:06 +00:00
|
|
|
#endif // * DEBUG_ENABLED
|
2022-08-30 16:48:49 +00:00
|
|
|
};
|
|
|
|
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif // BT_PLAYER_H
|