Reorganize files

This commit is contained in:
Serhii Snitsaruk 2022-08-31 17:05:25 +02:00
parent a236aee22b
commit 3393ed24d7
107 changed files with 139 additions and 126 deletions

10
SCsub Normal file
View File

@ -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")

View File

@ -3,7 +3,7 @@
#ifndef BT_ACTION_H #ifndef BT_ACTION_H
#define BT_ACTION_H #define BT_ACTION_H
#include "bt_task.h" #include "../bt_task.h"
#include "core/object.h" #include "core/object.h"
class BTAction : public BTTask { class BTAction : public BTTask {

View File

@ -12,7 +12,7 @@ void BehaviorTree::init() {
BTTask *task = root_task.ptr(); BTTask *task = root_task.ptr();
while (task != nullptr) { while (task != nullptr) {
for (int i = 0; i < task->get_child_count(); i++) { 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()); stack.push_back(task->get_child(i).ptr());
} }
task = nullptr; task = nullptr;

View File

@ -2,14 +2,13 @@
#include "bt_task.h" #include "bt_task.h"
#include "../limbo_string_names.h"
#include "../limbo_utility.h"
#include "core/class_db.h" #include "core/class_db.h"
#include "core/object.h" #include "core/object.h"
#include "core/script_language.h" #include "core/script_language.h"
#include "core/variant.h" #include "core/variant.h"
#include "editor/editor_node.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 { String BTTask::_generate_name() const {
if (get_script_instance()) { if (get_script_instance()) {
@ -38,42 +37,42 @@ Array BTTask::_get_children() const {
} }
void BTTask::_set_children(Array p_children) { void BTTask::_set_children(Array p_children) {
_children.clear(); children.clear();
const int num_children = p_children.size(); const int num_children = p_children.size();
_children.resize(num_children); children.resize(num_children);
for (int i = 0; i < num_children; i++) { for (int i = 0; i < num_children; i++) {
Variant task_var = p_children[i]; Variant task_var = p_children[i];
const Ref<BTTask> task_ref = task_var; const Ref<BTTask> task_ref = task_var;
_children.set(i, task_var); children.set(i, task_var);
} }
} }
String BTTask::get_task_name() const { String BTTask::get_task_name() const {
if (_custom_name.empty()) { if (custom_name.empty()) {
return _generate_name(); return _generate_name();
} }
return _custom_name; return custom_name;
} }
Ref<BTTask> BTTask::get_root() const { Ref<BTTask> BTTask::get_root() const {
const BTTask *task = this; const BTTask *task = this;
while (!task->is_root()) { while (!task->is_root()) {
task = task->_parent; task = task->parent;
} }
return Ref<BTTask>(task); return Ref<BTTask>(task);
} }
void BTTask::set_custom_name(const String &p_name) { void BTTask::set_custom_name(const String &p_name) {
if (_custom_name != p_name) { if (custom_name != p_name) {
_custom_name = p_name; custom_name = p_name;
emit_changed(); emit_changed();
} }
}; };
void BTTask::initialize(Object *p_agent, Dictionary p_blackboard) { void BTTask::initialize(Object *p_agent, Dictionary p_blackboard) {
_agent = p_agent; agent = p_agent;
_blackboard = p_blackboard; blackboard = p_blackboard;
for (int i = 0; i < _children.size(); i++) { for (int i = 0; i < children.size(); i++) {
get_child(i)->initialize(p_agent, p_blackboard); get_child(i)->initialize(p_agent, p_blackboard);
} }
if (get_script_instance() && if (get_script_instance() &&
@ -86,18 +85,18 @@ void BTTask::initialize(Object *p_agent, Dictionary p_blackboard) {
Ref<BTTask> BTTask::clone() const { Ref<BTTask> BTTask::clone() const {
Ref<BTTask> inst = duplicate(true); Ref<BTTask> inst = duplicate(true);
inst->_parent = nullptr; inst->parent = nullptr;
CRASH_COND(inst->get_parent().is_valid()); 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(); Ref<BTTask> c = get_child(i)->clone();
c->_parent = inst.ptr(); c->parent = inst.ptr();
inst->_children.set(i, c); inst->children.set(i, c);
} }
return inst; return inst;
} }
int BTTask::execute(float p_delta) { int BTTask::execute(float p_delta) {
if (_status == RUNNING) { if (status != RUNNING) {
if (get_script_instance() && if (get_script_instance() &&
// get_script_instance()->get_script()->is_valid() && // get_script_instance()->get_script()->is_valid() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_enter)) { get_script_instance()->has_method(LimboStringNames::get_singleton()->_enter)) {
@ -106,15 +105,16 @@ int BTTask::execute(float p_delta) {
_enter(); _enter();
} }
} }
if (get_script_instance() && if (get_script_instance() &&
// get_script_instance()->get_script()->is_valid() && // get_script_instance()->get_script()->is_valid() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_tick)) { 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 { } else {
_status = _tick(p_delta); status = _tick(p_delta);
} }
if (_status != RUNNING) { if (status != RUNNING) {
if (get_script_instance() && if (get_script_instance() &&
// get_script_instance()->get_script()->is_valid() && // get_script_instance()->get_script()->is_valid() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) { get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) {
@ -123,14 +123,14 @@ int BTTask::execute(float p_delta) {
_exit(); _exit();
} }
} }
return _status; return status;
} }
void BTTask::cancel() { void BTTask::cancel() {
for (int i = 0; i < _children.size(); i++) { for (int i = 0; i < children.size(); i++) {
get_child(i)->cancel(); get_child(i)->cancel();
} }
if (_status == RUNNING) { if (status == RUNNING) {
if (get_script_instance() && if (get_script_instance() &&
// get_script_instance()->get_script()->is_valid() && // get_script_instance()->get_script()->is_valid() &&
get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) { get_script_instance()->has_method(LimboStringNames::get_singleton()->_exit)) {
@ -139,59 +139,59 @@ void BTTask::cancel() {
_exit(); _exit();
} }
} }
_status = FRESH; status = FRESH;
} }
Ref<BTTask> BTTask::get_child(int p_idx) const { Ref<BTTask> BTTask::get_child(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, _children.size(), nullptr); ERR_FAIL_INDEX_V(p_idx, children.size(), nullptr);
return _children.get(p_idx); return children.get(p_idx);
} }
int BTTask::get_child_count() const { int BTTask::get_child_count() const {
return _children.size(); return children.size();
} }
void BTTask::add_child(Ref<BTTask> p_child) { void BTTask::add_child(Ref<BTTask> p_child) {
ERR_FAIL_COND_MSG(p_child->get_parent().is_valid(), "p_child already has a parent!"); ERR_FAIL_COND_MSG(p_child->get_parent().is_valid(), "p_child already has a parent!");
p_child->_parent = this; p_child->parent = this;
_children.push_back(p_child); children.push_back(p_child);
emit_changed(); emit_changed();
} }
void BTTask::add_child_at_index(Ref<BTTask> p_child, int p_idx) { 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!"); ERR_FAIL_COND_MSG(p_child->get_parent().is_valid(), "p_child already has a parent!");
if (p_idx < 0 || p_idx > _children.size()) { if (p_idx < 0 || p_idx > children.size()) {
p_idx = _children.size(); p_idx = children.size();
} }
_children.insert(p_idx, p_child); children.insert(p_idx, p_child);
p_child->_parent = this; p_child->parent = this;
emit_changed(); emit_changed();
} }
void BTTask::remove_child(Ref<BTTask> p_child) { void BTTask::remove_child(Ref<BTTask> p_child) {
int idx = _children.find(p_child); int idx = children.find(p_child);
if (idx == -1) { if (idx == -1) {
ERR_FAIL_MSG("p_child not found!"); ERR_FAIL_MSG("p_child not found!");
} else { } else {
_children.remove(idx); children.remove(idx);
p_child->_parent = nullptr; p_child->parent = nullptr;
emit_changed(); emit_changed();
} }
} }
bool BTTask::has_child(const Ref<BTTask> &p_child) const { 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 { 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 { Ref<BTTask> BTTask::next_sibling() const {
if (_parent != nullptr) { if (parent != nullptr) {
int idx = _parent->get_child_index(Ref<BTTask>(this)); int idx = parent->get_child_index(Ref<BTTask>(this));
if (idx != -1 && _parent->get_child_count() > (idx + 1)) { if (idx != -1 && parent->get_child_count() > (idx + 1)) {
return _parent->get_child(idx + 1); return parent->get_child(idx + 1);
} }
} }
return Ref<BTTask>(); return Ref<BTTask>();
@ -202,7 +202,7 @@ String BTTask::get_configuration_warning() const {
} }
Ref<Texture> BTTask::get_icon() 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 { void BTTask::print_tree(int p_initial_tabs) const {
@ -274,18 +274,18 @@ void BTTask::_bind_methods() {
} }
BTTask::BTTask() { BTTask::BTTask() {
_custom_name = String(); custom_name = String();
_agent = nullptr; agent = nullptr;
_parent = nullptr; parent = nullptr;
_blackboard = Dictionary(); blackboard = Dictionary();
_children = Vector<Ref<BTTask>>(); children = Vector<Ref<BTTask>>();
_status = FRESH; status = FRESH;
} }
BTTask::~BTTask() { BTTask::~BTTask() {
for (int i = 0; i < get_child_count(); i++) { for (int i = 0; i < get_child_count(); i++) {
ERR_FAIL_COND(!get_child(i).is_valid()); ERR_FAIL_COND(!get_child(i).is_valid());
get_child(i)->_parent = nullptr; get_child(i)->parent = nullptr;
get_child(i).unref(); get_child(i).unref();
} }
} }

View File

@ -5,12 +5,12 @@
#include "core/array.h" #include "core/array.h"
#include "core/dictionary.h" #include "core/dictionary.h"
#include "core/object.h"
#include "core/reference.h" #include "core/reference.h"
#include "core/resource.h" #include "core/resource.h"
#include "core/ustring.h" #include "core/ustring.h"
#include "core/vector.h" #include "core/vector.h"
#include "scene/resources/texture.h" #include "scene/resources/texture.h"
#include <cstddef>
class BTTask : public Resource { class BTTask : public Resource {
GDCLASS(BTTask, Resource); GDCLASS(BTTask, Resource);
@ -26,12 +26,12 @@ public:
private: private:
friend class BehaviorTree; friend class BehaviorTree;
String _custom_name; String custom_name;
Object *_agent; Object *agent;
Dictionary _blackboard; Dictionary blackboard;
BTTask *_parent; BTTask *parent;
Vector<Ref<BTTask>> _children; Vector<Ref<BTTask>> children;
int _status; int status;
Array _get_children() const; Array _get_children() const;
void _set_children(Array children); void _set_children(Array children);
@ -40,19 +40,19 @@ protected:
static void _bind_methods(); static void _bind_methods();
virtual String _generate_name() const; virtual String _generate_name() const;
virtual void _setup(){}; virtual void _setup() {}
virtual void _enter(){}; virtual void _enter() {}
virtual void _exit(){}; virtual void _exit() {}
virtual int _tick(float p_delta) { return FAILURE; }; virtual int _tick(float p_delta) { return FAILURE; }
public: public:
Object *get_agent() const { return _agent; }; Object *get_agent() const { return agent; }
Dictionary get_blackboard() const { return _blackboard; }; Dictionary get_blackboard() const { return blackboard; }
Ref<BTTask> get_parent() const { return Ref<BTTask>(_parent); }; Ref<BTTask> get_parent() const { return Ref<BTTask>(parent); }
bool is_root() const { return _parent == nullptr; }; bool is_root() const { return parent == nullptr; }
Ref<BTTask> get_root() const; Ref<BTTask> get_root() const;
int get_status() const { return _status; }; int get_status() const { return status; }
String get_custom_name() const { return _custom_name; }; String get_custom_name() const { return custom_name; }
void set_custom_name(const String &p_name); void set_custom_name(const String &p_name);
String get_task_name() const; String get_task_name() const;

View File

@ -3,7 +3,7 @@
#ifndef BT_COMPOSITE_H #ifndef BT_COMPOSITE_H
#define BT_COMPOSITE_H #define BT_COMPOSITE_H
#include "bt_task.h" #include "../bt_task.h"
#include "core/object.h" #include "core/object.h"
class BTComposite : public BTTask { class BTComposite : public BTTask {

View File

@ -21,12 +21,21 @@ protected:
virtual int _tick(float p_delta); virtual int _tick(float p_delta);
public: public:
int get_num_successes_required() const { return num_successes_required; }; int get_num_successes_required() const { return num_successes_required; }
void set_num_successes_required(int p_value) { num_successes_required = p_value; }; void set_num_successes_required(int p_value) {
int get_num_failures_required() const { return num_failures_required; }; num_successes_required = p_value;
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; }; 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 #endif // BT_PARALLEL_H

View File

@ -3,7 +3,7 @@
#ifndef BT_CONDITION_H #ifndef BT_CONDITION_H
#define BT_CONDITION_H #define BT_CONDITION_H
#include "bt_task.h" #include "../bt_task.h"
#include "core/object.h" #include "core/object.h"
class BTCondition : public BTTask { class BTCondition : public BTTask {

View File

@ -3,7 +3,7 @@
#ifndef BT_DECORATOR_H #ifndef BT_DECORATOR_H
#define BT_DECORATOR_H #define BT_DECORATOR_H
#include "bt_task.h" #include "../bt_task.h"
#include "core/object.h" #include "core/object.h"
class BTDecorator : public BTTask { class BTDecorator : public BTTask {

View File

@ -24,8 +24,8 @@ public:
void set_seconds(float p_value) { void set_seconds(float p_value) {
seconds = p_value; seconds = p_value;
emit_changed(); emit_changed();
}; }
float get_seconds() const { return seconds; }; float get_seconds() const { return seconds; }
}; };
#endif // BT_DELAY_H #endif // BT_DELAY_H

View File

@ -25,13 +25,13 @@ public:
void set_times(int p_value) { void set_times(int p_value) {
times = p_value; times = p_value;
emit_changed(); emit_changed();
}; }
int get_times() const { return times; }; int get_times() const { return times; }
void set_abort_on_failure(bool p_value) { void set_abort_on_failure(bool p_value) {
abort_on_failure = p_value; abort_on_failure = p_value;
emit_changed(); 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 #endif // BT_REPEAT_H

View File

@ -23,8 +23,8 @@ public:
void set_run_limit(int p_value) { void set_run_limit(int p_value) {
run_limit = p_value; run_limit = p_value;
emit_changed(); emit_changed();
}; }
int get_run_limit() const { return run_limit; }; int get_run_limit() const { return run_limit; }
}; };
#endif // BT_RUN_LIMIT_H #endif // BT_RUN_LIMIT_H

View File

@ -24,8 +24,8 @@ public:
void set_time_limit(float p_value) { void set_time_limit(float p_value) {
time_limit = p_value; time_limit = p_value;
emit_changed(); emit_changed();
}; }
float get_time_limit() const { return time_limit; }; float get_time_limit() const { return time_limit; }
}; };
#endif // BT_TIME_LIMIT_H #endif // BT_TIME_LIMIT_H

View File

Before

Width:  |  Height:  |  Size: 281 B

After

Width:  |  Height:  |  Size: 281 B

View File

Before

Width:  |  Height:  |  Size: 242 B

After

Width:  |  Height:  |  Size: 242 B

View File

Before

Width:  |  Height:  |  Size: 265 B

After

Width:  |  Height:  |  Size: 265 B

View File

Before

Width:  |  Height:  |  Size: 487 B

After

Width:  |  Height:  |  Size: 487 B

View File

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 421 B

View File

Before

Width:  |  Height:  |  Size: 268 B

After

Width:  |  Height:  |  Size: 268 B

View File

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 421 B

View File

Before

Width:  |  Height:  |  Size: 661 B

After

Width:  |  Height:  |  Size: 661 B

View File

Before

Width:  |  Height:  |  Size: 296 B

After

Width:  |  Height:  |  Size: 296 B

View File

Before

Width:  |  Height:  |  Size: 242 B

After

Width:  |  Height:  |  Size: 242 B

View File

Before

Width:  |  Height:  |  Size: 230 B

After

Width:  |  Height:  |  Size: 230 B

View File

Before

Width:  |  Height:  |  Size: 415 B

After

Width:  |  Height:  |  Size: 415 B

View File

Before

Width:  |  Height:  |  Size: 301 B

After

Width:  |  Height:  |  Size: 301 B

View File

Before

Width:  |  Height:  |  Size: 686 B

After

Width:  |  Height:  |  Size: 686 B

View File

Before

Width:  |  Height:  |  Size: 774 B

After

Width:  |  Height:  |  Size: 774 B

View File

Before

Width:  |  Height:  |  Size: 750 B

After

Width:  |  Height:  |  Size: 750 B

View File

Before

Width:  |  Height:  |  Size: 377 B

After

Width:  |  Height:  |  Size: 377 B

View File

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 421 B

View File

Before

Width:  |  Height:  |  Size: 561 B

After

Width:  |  Height:  |  Size: 561 B

View File

Before

Width:  |  Height:  |  Size: 561 B

After

Width:  |  Height:  |  Size: 561 B

View File

Before

Width:  |  Height:  |  Size: 561 B

After

Width:  |  Height:  |  Size: 561 B

View File

Before

Width:  |  Height:  |  Size: 520 B

After

Width:  |  Height:  |  Size: 520 B

View File

Before

Width:  |  Height:  |  Size: 449 B

After

Width:  |  Height:  |  Size: 449 B

View File

Before

Width:  |  Height:  |  Size: 215 B

After

Width:  |  Height:  |  Size: 215 B

View File

Before

Width:  |  Height:  |  Size: 520 B

After

Width:  |  Height:  |  Size: 520 B

View File

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 421 B

View File

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 421 B

View File

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 225 B

View File

Before

Width:  |  Height:  |  Size: 510 B

After

Width:  |  Height:  |  Size: 510 B

View File

Before

Width:  |  Height:  |  Size: 776 B

After

Width:  |  Height:  |  Size: 776 B

View File

Before

Width:  |  Height:  |  Size: 508 B

After

Width:  |  Height:  |  Size: 508 B

View File

Before

Width:  |  Height:  |  Size: 572 B

After

Width:  |  Height:  |  Size: 572 B

View File

Before

Width:  |  Height:  |  Size: 284 B

After

Width:  |  Height:  |  Size: 284 B

View File

Before

Width:  |  Height:  |  Size: 340 B

After

Width:  |  Height:  |  Size: 340 B

View File

Before

Width:  |  Height:  |  Size: 141 B

After

Width:  |  Height:  |  Size: 141 B

View File

Before

Width:  |  Height:  |  Size: 375 B

After

Width:  |  Height:  |  Size: 375 B

View File

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 225 B

View File

Before

Width:  |  Height:  |  Size: 600 B

After

Width:  |  Height:  |  Size: 600 B

View File

Before

Width:  |  Height:  |  Size: 301 B

After

Width:  |  Height:  |  Size: 301 B

View File

Before

Width:  |  Height:  |  Size: 565 B

After

Width:  |  Height:  |  Size: 565 B

Some files were not shown because too many files have changed in this diff Show More