Reorganize files
|
@ -0,0 +1,10 @@
|
|||
# SCsub
|
||||
|
||||
Import('env')
|
||||
|
||||
env.add_source_files(env.modules_sources, "*.cpp")
|
||||
env.add_source_files(env.modules_sources, "bt/*.cpp")
|
||||
env.add_source_files(env.modules_sources, "bt/composites/*.cpp")
|
||||
env.add_source_files(env.modules_sources, "bt/actions/*.cpp")
|
||||
env.add_source_files(env.modules_sources, "bt/decorators/*.cpp")
|
||||
env.add_source_files(env.modules_sources, "bt/conditions/*.cpp")
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef BT_ACTION_H
|
||||
#define BT_ACTION_H
|
||||
|
||||
#include "bt_task.h"
|
||||
#include "../bt_task.h"
|
||||
#include "core/object.h"
|
||||
|
||||
class BTAction : public BTTask {
|
|
@ -12,7 +12,7 @@ void BehaviorTree::init() {
|
|||
BTTask *task = root_task.ptr();
|
||||
while (task != nullptr) {
|
||||
for (int i = 0; i < task->get_child_count(); i++) {
|
||||
task->get_child(i)->_parent = task;
|
||||
task->get_child(i)->parent = task;
|
||||
stack.push_back(task->get_child(i).ptr());
|
||||
}
|
||||
task = nullptr;
|
|
@ -2,14 +2,13 @@
|
|||
|
||||
#include "bt_task.h"
|
||||
|
||||
#include "../limbo_string_names.h"
|
||||
#include "../limbo_utility.h"
|
||||
#include "core/class_db.h"
|
||||
#include "core/object.h"
|
||||
#include "core/script_language.h"
|
||||
#include "core/variant.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include <cstddef>
|
||||
#include "modules/limboai/limbo_string_names.h"
|
||||
#include "modules/limboai/limbo_utility.h"
|
||||
|
||||
String BTTask::_generate_name() const {
|
||||
if (get_script_instance()) {
|
||||
|
@ -38,42 +37,42 @@ Array BTTask::_get_children() const {
|
|||
}
|
||||
|
||||
void BTTask::_set_children(Array p_children) {
|
||||
_children.clear();
|
||||
children.clear();
|
||||
const int num_children = p_children.size();
|
||||
_children.resize(num_children);
|
||||
children.resize(num_children);
|
||||
for (int i = 0; i < num_children; i++) {
|
||||
Variant task_var = p_children[i];
|
||||
const Ref<BTTask> task_ref = task_var;
|
||||
_children.set(i, task_var);
|
||||
children.set(i, task_var);
|
||||
}
|
||||
}
|
||||
|
||||
String BTTask::get_task_name() const {
|
||||
if (_custom_name.empty()) {
|
||||
if (custom_name.empty()) {
|
||||
return _generate_name();
|
||||
}
|
||||
return _custom_name;
|
||||
return custom_name;
|
||||
}
|
||||
|
||||
Ref<BTTask> BTTask::get_root() const {
|
||||
const BTTask *task = this;
|
||||
while (!task->is_root()) {
|
||||
task = task->_parent;
|
||||
task = task->parent;
|
||||
}
|
||||
return Ref<BTTask>(task);
|
||||
}
|
||||
|
||||
void BTTask::set_custom_name(const String &p_name) {
|
||||
if (_custom_name != p_name) {
|
||||
_custom_name = p_name;
|
||||
if (custom_name != p_name) {
|
||||
custom_name = p_name;
|
||||
emit_changed();
|
||||
}
|
||||
};
|
||||
|
||||
void BTTask::initialize(Object *p_agent, Dictionary p_blackboard) {
|
||||
_agent = p_agent;
|
||||
_blackboard = p_blackboard;
|
||||
for (int i = 0; i < _children.size(); i++) {
|
||||
agent = p_agent;
|
||||
blackboard = p_blackboard;
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
get_child(i)->initialize(p_agent, p_blackboard);
|
||||
}
|
||||
if (get_script_instance() &&
|
||||
|
@ -86,18 +85,18 @@ void BTTask::initialize(Object *p_agent, Dictionary p_blackboard) {
|
|||
|
||||
Ref<BTTask> BTTask::clone() const {
|
||||
Ref<BTTask> inst = duplicate(true);
|
||||
inst->_parent = nullptr;
|
||||
inst->parent = nullptr;
|
||||
CRASH_COND(inst->get_parent().is_valid());
|
||||
for (int i = 0; i < _children.size(); i++) {
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
Ref<BTTask> c = get_child(i)->clone();
|
||||
c->_parent = inst.ptr();
|
||||
inst->_children.set(i, c);
|
||||
c->parent = inst.ptr();
|
||||
inst->children.set(i, c);
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
||||
int BTTask::execute(float p_delta) {
|
||||
if (_status == RUNNING) {
|
||||
if (status != RUNNING) {
|
||||
if (get_script_instance() &&
|
||||
// get_script_instance()->get_script()->is_valid() &&
|
||||
get_script_instance()->has_method(LimboStringNames::get_singleton()->_enter)) {
|
||||
|
@ -106,15 +105,16 @@ int BTTask::execute(float p_delta) {
|
|||
_enter();
|
||||
}
|
||||
}
|
||||
|
||||
if (get_script_instance() &&
|
||||
// get_script_instance()->get_script()->is_valid() &&
|
||||
get_script_instance()->has_method(LimboStringNames::get_singleton()->_tick)) {
|
||||
_status = get_script_instance()->call(LimboStringNames::get_singleton()->_tick, Variant(p_delta));
|
||||
status = get_script_instance()->call(LimboStringNames::get_singleton()->_tick, Variant(p_delta));
|
||||
} else {
|
||||
_status = _tick(p_delta);
|
||||
status = _tick(p_delta);
|
||||
}
|
||||
|
||||
if (_status != RUNNING) {
|
||||
if (status != RUNNING) {
|
||||
if (get_script_instance() &&
|
||||
// get_script_instance()->get_script()->is_valid() &&
|
||||
get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) {
|
||||
|
@ -123,14 +123,14 @@ int BTTask::execute(float p_delta) {
|
|||
_exit();
|
||||
}
|
||||
}
|
||||
return _status;
|
||||
return status;
|
||||
}
|
||||
|
||||
void BTTask::cancel() {
|
||||
for (int i = 0; i < _children.size(); i++) {
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
get_child(i)->cancel();
|
||||
}
|
||||
if (_status == RUNNING) {
|
||||
if (status == RUNNING) {
|
||||
if (get_script_instance() &&
|
||||
// get_script_instance()->get_script()->is_valid() &&
|
||||
get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) {
|
||||
|
@ -139,59 +139,59 @@ void BTTask::cancel() {
|
|||
_exit();
|
||||
}
|
||||
}
|
||||
_status = FRESH;
|
||||
status = FRESH;
|
||||
}
|
||||
|
||||
Ref<BTTask> BTTask::get_child(int p_idx) const {
|
||||
ERR_FAIL_INDEX_V(p_idx, _children.size(), nullptr);
|
||||
return _children.get(p_idx);
|
||||
ERR_FAIL_INDEX_V(p_idx, children.size(), nullptr);
|
||||
return children.get(p_idx);
|
||||
}
|
||||
|
||||
int BTTask::get_child_count() const {
|
||||
return _children.size();
|
||||
return children.size();
|
||||
}
|
||||
|
||||
void BTTask::add_child(Ref<BTTask> p_child) {
|
||||
ERR_FAIL_COND_MSG(p_child->get_parent().is_valid(), "p_child already has a parent!");
|
||||
p_child->_parent = this;
|
||||
_children.push_back(p_child);
|
||||
p_child->parent = this;
|
||||
children.push_back(p_child);
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
void BTTask::add_child_at_index(Ref<BTTask> p_child, int p_idx) {
|
||||
ERR_FAIL_COND_MSG(p_child->get_parent().is_valid(), "p_child already has a parent!");
|
||||
if (p_idx < 0 || p_idx > _children.size()) {
|
||||
p_idx = _children.size();
|
||||
if (p_idx < 0 || p_idx > children.size()) {
|
||||
p_idx = children.size();
|
||||
}
|
||||
_children.insert(p_idx, p_child);
|
||||
p_child->_parent = this;
|
||||
children.insert(p_idx, p_child);
|
||||
p_child->parent = this;
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
void BTTask::remove_child(Ref<BTTask> p_child) {
|
||||
int idx = _children.find(p_child);
|
||||
int idx = children.find(p_child);
|
||||
if (idx == -1) {
|
||||
ERR_FAIL_MSG("p_child not found!");
|
||||
} else {
|
||||
_children.remove(idx);
|
||||
p_child->_parent = nullptr;
|
||||
children.remove(idx);
|
||||
p_child->parent = nullptr;
|
||||
emit_changed();
|
||||
}
|
||||
}
|
||||
|
||||
bool BTTask::has_child(const Ref<BTTask> &p_child) const {
|
||||
return _children.find(p_child) != -1;
|
||||
return children.find(p_child) != -1;
|
||||
}
|
||||
|
||||
int BTTask::get_child_index(const Ref<BTTask> &p_child) const {
|
||||
return _children.find(p_child);
|
||||
return children.find(p_child);
|
||||
}
|
||||
|
||||
Ref<BTTask> BTTask::next_sibling() const {
|
||||
if (_parent != nullptr) {
|
||||
int idx = _parent->get_child_index(Ref<BTTask>(this));
|
||||
if (idx != -1 && _parent->get_child_count() > (idx + 1)) {
|
||||
return _parent->get_child(idx + 1);
|
||||
if (parent != nullptr) {
|
||||
int idx = parent->get_child_index(Ref<BTTask>(this));
|
||||
if (idx != -1 && parent->get_child_count() > (idx + 1)) {
|
||||
return parent->get_child(idx + 1);
|
||||
}
|
||||
}
|
||||
return Ref<BTTask>();
|
||||
|
@ -202,7 +202,7 @@ String BTTask::get_configuration_warning() const {
|
|||
}
|
||||
|
||||
Ref<Texture> BTTask::get_icon() const {
|
||||
return EditorNode::get_singleton()->get_class_icon("BTAction", "Object");
|
||||
return EditorNode::get_singleton()->get_class_icon(_class_name, "Object");
|
||||
}
|
||||
|
||||
void BTTask::print_tree(int p_initial_tabs) const {
|
||||
|
@ -274,18 +274,18 @@ void BTTask::_bind_methods() {
|
|||
}
|
||||
|
||||
BTTask::BTTask() {
|
||||
_custom_name = String();
|
||||
_agent = nullptr;
|
||||
_parent = nullptr;
|
||||
_blackboard = Dictionary();
|
||||
_children = Vector<Ref<BTTask>>();
|
||||
_status = FRESH;
|
||||
custom_name = String();
|
||||
agent = nullptr;
|
||||
parent = nullptr;
|
||||
blackboard = Dictionary();
|
||||
children = Vector<Ref<BTTask>>();
|
||||
status = FRESH;
|
||||
}
|
||||
|
||||
BTTask::~BTTask() {
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
ERR_FAIL_COND(!get_child(i).is_valid());
|
||||
get_child(i)->_parent = nullptr;
|
||||
get_child(i)->parent = nullptr;
|
||||
get_child(i).unref();
|
||||
}
|
||||
}
|
|
@ -5,12 +5,12 @@
|
|||
|
||||
#include "core/array.h"
|
||||
#include "core/dictionary.h"
|
||||
#include "core/object.h"
|
||||
#include "core/reference.h"
|
||||
#include "core/resource.h"
|
||||
#include "core/ustring.h"
|
||||
#include "core/vector.h"
|
||||
#include "scene/resources/texture.h"
|
||||
#include <cstddef>
|
||||
|
||||
class BTTask : public Resource {
|
||||
GDCLASS(BTTask, Resource);
|
||||
|
@ -26,12 +26,12 @@ public:
|
|||
private:
|
||||
friend class BehaviorTree;
|
||||
|
||||
String _custom_name;
|
||||
Object *_agent;
|
||||
Dictionary _blackboard;
|
||||
BTTask *_parent;
|
||||
Vector<Ref<BTTask>> _children;
|
||||
int _status;
|
||||
String custom_name;
|
||||
Object *agent;
|
||||
Dictionary blackboard;
|
||||
BTTask *parent;
|
||||
Vector<Ref<BTTask>> children;
|
||||
int status;
|
||||
|
||||
Array _get_children() const;
|
||||
void _set_children(Array children);
|
||||
|
@ -40,19 +40,19 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
virtual String _generate_name() const;
|
||||
virtual void _setup(){};
|
||||
virtual void _enter(){};
|
||||
virtual void _exit(){};
|
||||
virtual int _tick(float p_delta) { return FAILURE; };
|
||||
virtual void _setup() {}
|
||||
virtual void _enter() {}
|
||||
virtual void _exit() {}
|
||||
virtual int _tick(float p_delta) { return FAILURE; }
|
||||
|
||||
public:
|
||||
Object *get_agent() const { return _agent; };
|
||||
Dictionary get_blackboard() const { return _blackboard; };
|
||||
Ref<BTTask> get_parent() const { return Ref<BTTask>(_parent); };
|
||||
bool is_root() const { return _parent == nullptr; };
|
||||
Object *get_agent() const { return agent; }
|
||||
Dictionary get_blackboard() const { return blackboard; }
|
||||
Ref<BTTask> get_parent() const { return Ref<BTTask>(parent); }
|
||||
bool is_root() const { return parent == nullptr; }
|
||||
Ref<BTTask> get_root() const;
|
||||
int get_status() const { return _status; };
|
||||
String get_custom_name() const { return _custom_name; };
|
||||
int get_status() const { return status; }
|
||||
String get_custom_name() const { return custom_name; }
|
||||
void set_custom_name(const String &p_name);
|
||||
String get_task_name() const;
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef BT_COMPOSITE_H
|
||||
#define BT_COMPOSITE_H
|
||||
|
||||
#include "bt_task.h"
|
||||
#include "../bt_task.h"
|
||||
#include "core/object.h"
|
||||
|
||||
class BTComposite : public BTTask {
|
|
@ -21,12 +21,21 @@ protected:
|
|||
virtual int _tick(float p_delta);
|
||||
|
||||
public:
|
||||
int get_num_successes_required() const { return num_successes_required; };
|
||||
void set_num_successes_required(int p_value) { num_successes_required = p_value; };
|
||||
int get_num_failures_required() const { return num_failures_required; };
|
||||
void set_num_failures_required(int p_value) { num_failures_required = p_value; };
|
||||
bool get_repeat() const { return repeat; };
|
||||
void set_repeat(bool p_value) { repeat = p_value; };
|
||||
int get_num_successes_required() const { return num_successes_required; }
|
||||
void set_num_successes_required(int p_value) {
|
||||
num_successes_required = p_value;
|
||||
emit_changed();
|
||||
}
|
||||
int get_num_failures_required() const { return num_failures_required; }
|
||||
void set_num_failures_required(int p_value) {
|
||||
num_failures_required = p_value;
|
||||
emit_changed();
|
||||
}
|
||||
bool get_repeat() const { return repeat; }
|
||||
void set_repeat(bool p_value) {
|
||||
repeat = p_value;
|
||||
emit_changed();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // BT_PARALLEL_H
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef BT_CONDITION_H
|
||||
#define BT_CONDITION_H
|
||||
|
||||
#include "bt_task.h"
|
||||
#include "../bt_task.h"
|
||||
#include "core/object.h"
|
||||
|
||||
class BTCondition : public BTTask {
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef BT_DECORATOR_H
|
||||
#define BT_DECORATOR_H
|
||||
|
||||
#include "bt_task.h"
|
||||
#include "../bt_task.h"
|
||||
#include "core/object.h"
|
||||
|
||||
class BTDecorator : public BTTask {
|
|
@ -24,8 +24,8 @@ public:
|
|||
void set_seconds(float p_value) {
|
||||
seconds = p_value;
|
||||
emit_changed();
|
||||
};
|
||||
float get_seconds() const { return seconds; };
|
||||
}
|
||||
float get_seconds() const { return seconds; }
|
||||
};
|
||||
|
||||
#endif // BT_DELAY_H
|
|
@ -25,13 +25,13 @@ public:
|
|||
void set_times(int p_value) {
|
||||
times = p_value;
|
||||
emit_changed();
|
||||
};
|
||||
int get_times() const { return times; };
|
||||
}
|
||||
int get_times() const { return times; }
|
||||
void set_abort_on_failure(bool p_value) {
|
||||
abort_on_failure = p_value;
|
||||
emit_changed();
|
||||
};
|
||||
bool get_abort_on_failure() const { return abort_on_failure; };
|
||||
}
|
||||
bool get_abort_on_failure() const { return abort_on_failure; }
|
||||
};
|
||||
|
||||
#endif // BT_REPEAT_H
|
|
@ -23,8 +23,8 @@ public:
|
|||
void set_run_limit(int p_value) {
|
||||
run_limit = p_value;
|
||||
emit_changed();
|
||||
};
|
||||
int get_run_limit() const { return run_limit; };
|
||||
}
|
||||
int get_run_limit() const { return run_limit; }
|
||||
};
|
||||
|
||||
#endif // BT_RUN_LIMIT_H
|
|
@ -24,8 +24,8 @@ public:
|
|||
void set_time_limit(float p_value) {
|
||||
time_limit = p_value;
|
||||
emit_changed();
|
||||
};
|
||||
float get_time_limit() const { return time_limit; };
|
||||
}
|
||||
float get_time_limit() const { return time_limit; }
|
||||
};
|
||||
|
||||
#endif // BT_TIME_LIMIT_H
|
Before Width: | Height: | Size: 281 B After Width: | Height: | Size: 281 B |
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B |
Before Width: | Height: | Size: 265 B After Width: | Height: | Size: 265 B |
Before Width: | Height: | Size: 487 B After Width: | Height: | Size: 487 B |
Before Width: | Height: | Size: 421 B After Width: | Height: | Size: 421 B |
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 268 B |
Before Width: | Height: | Size: 421 B After Width: | Height: | Size: 421 B |
Before Width: | Height: | Size: 661 B After Width: | Height: | Size: 661 B |
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 296 B |
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B |
Before Width: | Height: | Size: 230 B After Width: | Height: | Size: 230 B |
Before Width: | Height: | Size: 415 B After Width: | Height: | Size: 415 B |
Before Width: | Height: | Size: 301 B After Width: | Height: | Size: 301 B |
Before Width: | Height: | Size: 686 B After Width: | Height: | Size: 686 B |
Before Width: | Height: | Size: 774 B After Width: | Height: | Size: 774 B |
Before Width: | Height: | Size: 750 B After Width: | Height: | Size: 750 B |
Before Width: | Height: | Size: 377 B After Width: | Height: | Size: 377 B |
Before Width: | Height: | Size: 421 B After Width: | Height: | Size: 421 B |
Before Width: | Height: | Size: 561 B After Width: | Height: | Size: 561 B |
Before Width: | Height: | Size: 561 B After Width: | Height: | Size: 561 B |
Before Width: | Height: | Size: 561 B After Width: | Height: | Size: 561 B |
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 520 B |
Before Width: | Height: | Size: 449 B After Width: | Height: | Size: 449 B |
Before Width: | Height: | Size: 215 B After Width: | Height: | Size: 215 B |
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 520 B |
Before Width: | Height: | Size: 421 B After Width: | Height: | Size: 421 B |
Before Width: | Height: | Size: 421 B After Width: | Height: | Size: 421 B |
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
Before Width: | Height: | Size: 510 B After Width: | Height: | Size: 510 B |
Before Width: | Height: | Size: 776 B After Width: | Height: | Size: 776 B |
Before Width: | Height: | Size: 508 B After Width: | Height: | Size: 508 B |
Before Width: | Height: | Size: 572 B After Width: | Height: | Size: 572 B |
Before Width: | Height: | Size: 284 B After Width: | Height: | Size: 284 B |
Before Width: | Height: | Size: 340 B After Width: | Height: | Size: 340 B |
Before Width: | Height: | Size: 141 B After Width: | Height: | Size: 141 B |
Before Width: | Height: | Size: 375 B After Width: | Height: | Size: 375 B |
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
Before Width: | Height: | Size: 600 B After Width: | Height: | Size: 600 B |
Before Width: | Height: | Size: 301 B After Width: | Height: | Size: 301 B |
Before Width: | Height: | Size: 565 B After Width: | Height: | Size: 565 B |