2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* bt_player.h
|
|
|
|
* =============================================================================
|
|
|
|
* Copyright 2021-2023 Serhii Snitsaruk
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2023-08-15 15:49:13 +00:00
|
|
|
#include "scene/main/node.h"
|
|
|
|
|
2022-08-30 16:48:49 +00:00
|
|
|
#include "behavior_tree.h"
|
2023-07-20 16:35:36 +00:00
|
|
|
#include "modules/limboai/blackboard/blackboard.h"
|
2023-08-15 15:49:13 +00:00
|
|
|
#include "tasks/bt_task.h"
|
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
|
|
|
|
PHYSICS, //# automatically call update() during NOTIFICATION_PHYSICS
|
|
|
|
MANUAL, // manually update state machine, user must call update(delta)
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
Ref<BehaviorTree> behavior_tree;
|
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;
|
2022-10-19 14:01:16 +00:00
|
|
|
bool prefetch_nodepath_vars = true;
|
2022-12-16 14:29:36 +00:00
|
|
|
int last_status = -1;
|
2022-08-30 16:48:49 +00:00
|
|
|
|
2022-12-16 14:29:36 +00:00
|
|
|
Ref<BTTask> tree_instance;
|
2022-08-30 16:48:49 +00:00
|
|
|
|
|
|
|
void _load_tree();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-10-26 23:51:29 +00:00
|
|
|
void _set_blackboard_data(Dictionary p_value) { blackboard->set_data(p_value.duplicate()); }
|
2022-09-08 13:56:51 +00:00
|
|
|
Dictionary _get_blackboard_data() const { return blackboard->get_data(); }
|
|
|
|
|
2022-08-30 16:48:49 +00:00
|
|
|
void _notification(int p_notification);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_behavior_tree(const Ref<BehaviorTree> &p_tree);
|
|
|
|
Ref<BehaviorTree> get_behavior_tree() const { return behavior_tree; };
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-10-19 14:01:16 +00:00
|
|
|
void set_prefetch_nodepath_vars(bool p_value) { prefetch_nodepath_vars = p_value; }
|
|
|
|
bool get_prefetch_nodepath_vars() const { return prefetch_nodepath_vars; }
|
|
|
|
|
2023-04-10 08:08:11 +00:00
|
|
|
void update(double p_delta);
|
2022-08-30 16:48:49 +00:00
|
|
|
void restart();
|
2022-12-16 14:29:36 +00:00
|
|
|
int get_last_status() const { return last_status; }
|
2022-09-08 13:56:51 +00:00
|
|
|
|
|
|
|
BTPlayer();
|
|
|
|
~BTPlayer();
|
2023-04-15 13:49:34 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
// Performace monitoring.
|
|
|
|
private:
|
|
|
|
bool monitor_performance = false;
|
|
|
|
StringName monitor_id;
|
|
|
|
double update_time_acc = 0.0;
|
|
|
|
double update_time_n = 0.0;
|
|
|
|
|
|
|
|
void _set_monitor_performance(bool p_monitor_performance);
|
|
|
|
bool _get_monitor_performance() const { return monitor_performance; }
|
|
|
|
double _get_mean_update_time_msec();
|
|
|
|
|
|
|
|
#endif // DEBUG_ENABLED
|
2022-08-30 16:48:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BT_PLAYER_H
|