From 2c4e343a484cebc283caf431a837271ae31ef989 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 6 Jan 2024 21:04:34 +0100 Subject: [PATCH 01/42] Port the first core classes to get started Ported: Blackboard, BTTask, BTAction, BTComment, BTDecorator, BTComposite, BTDecorator, LimboStringNames, LimboTaskDB, LimboUtility --- blackboard/blackboard.cpp | 13 +++- blackboard/blackboard.h | 14 ++++ bt/tasks/bt_action.cpp | 2 +- bt/tasks/bt_action.h | 2 +- bt/tasks/bt_comment.cpp | 7 +- bt/tasks/bt_comment.h | 2 +- bt/tasks/bt_composite.cpp | 2 +- bt/tasks/bt_composite.h | 2 +- bt/tasks/bt_condition.cpp | 2 +- bt/tasks/bt_condition.h | 2 +- bt/tasks/bt_decorator.cpp | 2 +- bt/tasks/bt_decorator.h | 2 +- bt/tasks/bt_task.cpp | 125 ++++++++++++++++++++++++++++++++++-- bt/tasks/bt_task.h | 27 ++++++-- util/limbo_string_names.cpp | 29 ++++----- util/limbo_string_names.h | 10 ++- util/limbo_task_db.cpp | 24 ++++++- util/limbo_task_db.h | 16 +++++ util/limbo_utility.cpp | 124 +++++++++++++++++++++++++++++------ util/limbo_utility.h | 11 ++++ 20 files changed, 362 insertions(+), 56 deletions(-) diff --git a/blackboard/blackboard.cpp b/blackboard/blackboard.cpp index 6f45ed1..09d1209 100644 --- a/blackboard/blackboard.cpp +++ b/blackboard/blackboard.cpp @@ -11,9 +11,20 @@ #include "blackboard.h" +#ifdef LIMBOAI_MODULE #include "core/error/error_macros.h" #include "core/variant/variant.h" #include "scene/main/node.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include +#include +#include +#include +#include +using namespace godot; +#endif Ref Blackboard::top() const { Ref bb(this); @@ -25,7 +36,7 @@ Ref Blackboard::top() const { Variant Blackboard::get_var(const Variant &p_key, const Variant &p_default) const { if (data.has(p_key)) { - return data.get_valid(p_key); + return data.get(p_key, Variant()); } else if (parent.is_valid()) { return parent->get_var(p_key, p_default); } else { diff --git a/blackboard/blackboard.h b/blackboard/blackboard.h index 6b2838b..e22c8d7 100644 --- a/blackboard/blackboard.h +++ b/blackboard/blackboard.h @@ -12,11 +12,25 @@ #ifndef BLACKBOARD_H #define BLACKBOARD_H +#ifdef LIMBOAI_MODULE #include "core/object/object.h" #include "core/object/ref_counted.h" #include "core/variant/dictionary.h" #include "core/variant/variant.h" #include "scene/main/node.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION + +#include +#include +#include +#include +#include + +using namespace godot; + +#endif // LIMBOAI_GDEXTENSION class Blackboard : public RefCounted { GDCLASS(Blackboard, RefCounted); diff --git a/bt/tasks/bt_action.cpp b/bt/tasks/bt_action.cpp index 9719a4e..0735006 100644 --- a/bt/tasks/bt_action.cpp +++ b/bt/tasks/bt_action.cpp @@ -11,7 +11,7 @@ #include "bt_action.h" -PackedStringArray BTAction::get_configuration_warnings() const { +PackedStringArray BTAction::get_configuration_warnings() { PackedStringArray warnings = BTTask::get_configuration_warnings(); if (get_child_count_excluding_comments() != 0) { warnings.append("Action can't have child tasks."); diff --git a/bt/tasks/bt_action.h b/bt/tasks/bt_action.h index cc7749f..49c4b6f 100644 --- a/bt/tasks/bt_action.h +++ b/bt/tasks/bt_action.h @@ -18,7 +18,7 @@ class BTAction : public BTTask { GDCLASS(BTAction, BTTask); public: - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_ACTION_H \ No newline at end of file diff --git a/bt/tasks/bt_comment.cpp b/bt/tasks/bt_comment.cpp index c57a8d3..56d28e9 100644 --- a/bt/tasks/bt_comment.cpp +++ b/bt/tasks/bt_comment.cpp @@ -13,6 +13,11 @@ #include "bt_task.h" +#ifdef LIMBOAI_GDEXTENSION +#include +using namespace godot; +#endif + Ref BTComment::clone() const { if (Engine::get_singleton()->is_editor_hint()) { return BTTask::clone(); @@ -20,7 +25,7 @@ Ref BTComment::clone() const { return nullptr; } -PackedStringArray BTComment::get_configuration_warnings() const { +PackedStringArray BTComment::get_configuration_warnings() { PackedStringArray warnings = BTTask::get_configuration_warnings(); if (get_child_count_excluding_comments() > 0) { warnings.append("Can only have other comment tasks as children."); diff --git a/bt/tasks/bt_comment.h b/bt/tasks/bt_comment.h index 3bb59f2..cfe6173 100644 --- a/bt/tasks/bt_comment.h +++ b/bt/tasks/bt_comment.h @@ -20,7 +20,7 @@ class BTComment : public BTTask { public: virtual Ref clone() const override; - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_COMMENT \ No newline at end of file diff --git a/bt/tasks/bt_composite.cpp b/bt/tasks/bt_composite.cpp index 364e483..43b9186 100644 --- a/bt/tasks/bt_composite.cpp +++ b/bt/tasks/bt_composite.cpp @@ -11,7 +11,7 @@ #include "bt_composite.h" -PackedStringArray BTComposite::get_configuration_warnings() const { +PackedStringArray BTComposite::get_configuration_warnings() { PackedStringArray warnings = BTTask::get_configuration_warnings(); if (get_child_count_excluding_comments() < 1) { warnings.append("Composite should have at least one child task."); diff --git a/bt/tasks/bt_composite.h b/bt/tasks/bt_composite.h index 56cd376..e8b8205 100644 --- a/bt/tasks/bt_composite.h +++ b/bt/tasks/bt_composite.h @@ -18,7 +18,7 @@ class BTComposite : public BTTask { GDCLASS(BTComposite, BTTask); public: - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_COMPOSITE_H \ No newline at end of file diff --git a/bt/tasks/bt_condition.cpp b/bt/tasks/bt_condition.cpp index 73bf254..376dae2 100644 --- a/bt/tasks/bt_condition.cpp +++ b/bt/tasks/bt_condition.cpp @@ -11,7 +11,7 @@ #include "bt_condition.h" -PackedStringArray BTCondition::get_configuration_warnings() const { +PackedStringArray BTCondition::get_configuration_warnings() { PackedStringArray warnings = BTTask::get_configuration_warnings(); if (get_child_count_excluding_comments() != 0) { warnings.append("Condition task can't have child tasks."); diff --git a/bt/tasks/bt_condition.h b/bt/tasks/bt_condition.h index 19efda1..ac01df5 100644 --- a/bt/tasks/bt_condition.h +++ b/bt/tasks/bt_condition.h @@ -18,7 +18,7 @@ class BTCondition : public BTTask { GDCLASS(BTCondition, BTTask); public: - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_CONDITION_H \ No newline at end of file diff --git a/bt/tasks/bt_decorator.cpp b/bt/tasks/bt_decorator.cpp index 8ac2de1..1e683fb 100644 --- a/bt/tasks/bt_decorator.cpp +++ b/bt/tasks/bt_decorator.cpp @@ -11,7 +11,7 @@ #include "bt_decorator.h" -PackedStringArray BTDecorator::get_configuration_warnings() const { +PackedStringArray BTDecorator::get_configuration_warnings() { PackedStringArray warnings = BTTask::get_configuration_warnings(); if (get_child_count_excluding_comments() != 1) { warnings.append("Decorator should have a single child task."); diff --git a/bt/tasks/bt_decorator.h b/bt/tasks/bt_decorator.h index 249122d..ae5177e 100644 --- a/bt/tasks/bt_decorator.h +++ b/bt/tasks/bt_decorator.h @@ -18,7 +18,7 @@ class BTDecorator : public BTTask { GDCLASS(BTDecorator, BTTask) public: - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_DECORATOR_H \ No newline at end of file diff --git a/bt/tasks/bt_task.cpp b/bt/tasks/bt_task.cpp index 3cdad3f..de7420a 100644 --- a/bt/tasks/bt_task.cpp +++ b/bt/tasks/bt_task.cpp @@ -10,7 +10,14 @@ */ #include "bt_task.h" +#include "godot_cpp/classes/global_constants.hpp" +#include "godot_cpp/variant/dictionary.hpp" +#include "godot_cpp/variant/string_name.hpp" +#include "godot_cpp/variant/typed_array.hpp" +#include "godot_cpp/variant/utility_functions.hpp" +#include "godot_cpp/variant/variant.hpp" +#ifdef LIMBOAI_MODULE #include "bt_comment.h" #include "modules/limboai/blackboard/blackboard.h" #include "modules/limboai/util/limbo_string_names.h" @@ -25,6 +32,15 @@ #include "core/string/ustring.h" #include "core/templates/hash_map.h" #include "core/variant/variant.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include "blackboard/blackboard.h" +#include "bt/tasks/bt_comment.h" +#include "util/limbo_string_names.h" + +#include +#endif // LIMBOAI_GDEXTENSION void BT::_bind_methods() { BIND_ENUM_CONSTANT(FRESH); @@ -33,7 +49,8 @@ void BT::_bind_methods() { BIND_ENUM_CONSTANT(SUCCESS); } -String BTTask::_generate_name() const { +String BTTask::_generate_name() { +#ifdef LIMBOAI_MODULE if (get_script_instance()) { if (get_script_instance()->has_method(LimboStringNames::get_singleton()->_generate_name)) { ERR_FAIL_COND_V_MSG(!get_script_instance()->get_script()->is_tool(), "ERROR: not a tool script", "Task script should be a \"tool\" script!"); @@ -46,6 +63,14 @@ String BTTask::_generate_name() const { } } return get_class().trim_prefix("BT"); +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION + if (!get_path().is_empty()) { + return get_path().get_basename().get_file().trim_prefix("BT").to_pascal_case(); + } + return get_class().trim_prefix("BT"); +#endif // LIMBOAI_GDEXTENSION } Array BTTask::_get_children() const { @@ -72,9 +97,9 @@ void BTTask::_set_children(Array p_children) { } } -String BTTask::get_task_name() const { +String BTTask::get_task_name() { if (data.custom_name.is_empty()) { - return _generate_name(); + return call(LimboStringNames::get_singleton()->_generate_name); } return data.custom_name; } @@ -103,9 +128,15 @@ void BTTask::initialize(Node *p_agent, const Ref &p_blackboard) { get_child(i)->initialize(p_agent, p_blackboard); } +#ifdef LIMBOAI_MODULE if (!GDVIRTUAL_CALL(_setup)) { _setup(); } +#endif + +#ifdef LIMBOAI_GDEXTENSION + call(LimboStringNames::get_singleton()->_setup); +#endif } Ref BTTask::clone() const { @@ -129,6 +160,7 @@ Ref BTTask::clone() const { inst->data.children.resize(data.children.size() - num_null); } +#ifdef LIMBOAI_MODULE // Make BBParam properties unique. List props; inst->get_property_list(&props); @@ -154,6 +186,37 @@ Ref BTTask::clone() const { } } } +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION + // Make BBParam properties unique. + TypedArray props = inst->get_property_list(); + HashMap, Ref> duplicates; + for (int i = 0; i < props.size(); i++) { + Dictionary prop = props[i]; + if (!(int(prop["usage"]) & PROPERTY_USAGE_STORAGE)) { + continue; + } + + StringName prop_name = prop["name"]; + Variant v = inst->get(prop_name); + + if (v.get_type() == Variant::OBJECT && int(prop["hint"]) == PROPERTY_HINT_RESOURCE_TYPE) { + Ref ref = v; + if (ref.is_valid()) { + Ref res = ref; + if (res.is_valid() && res->is_class("BBParam")) { + if (!duplicates.has(res)) { + duplicates[res] = res->duplicate(); + } + res = duplicates[res]; + inst->set(prop_name, res); + } + } + } + } + +#endif // LIMBOAI_GDEXTENSION return inst; } @@ -166,21 +229,38 @@ BT::Status BTTask::execute(double p_delta) { data.children.get(i)->abort(); } } + +#ifdef LIMBOAI_MODULE if (!GDVIRTUAL_CALL(_enter)) { _enter(); } +#endif +#ifdef LIMBOAI_GDEXTENSION + call(LimboStringNames::get_singleton()->_enter); +#endif + } else { data.elapsed += p_delta; } +#ifdef LIMBOAI_MODULE if (!GDVIRTUAL_CALL(_tick, p_delta, data.status)) { data.status = _tick(p_delta); } +#endif +#ifdef LIMBOAI_GDEXTENSION + data.status = (Status)(int)call(LimboStringNames::get_singleton()->_tick, p_delta); +#endif if (data.status != RUNNING) { +#ifdef LIMBOAI_MODULE if (!GDVIRTUAL_CALL(_exit)) { _exit(); } +#endif +#ifdef LIMBOAI_GDEXTENSION + call(LimboStringNames::get_singleton()->_exit); +#endif data.elapsed = 0.0; } return data.status; @@ -191,9 +271,14 @@ void BTTask::abort() { get_child(i)->abort(); } if (data.status == RUNNING) { +#ifdef LIMBOAI_MODULE if (!GDVIRTUAL_CALL(_exit)) { _exit(); } +#endif +#ifdef LIMBOAI_GDEXTENSION + call(LimboStringNames::get_singleton()->_exit); +#endif } data.status = FRESH; data.elapsed = 0.0; @@ -202,9 +287,16 @@ void BTTask::abort() { int BTTask::get_child_count_excluding_comments() const { int count = 0; for (int i = 0; i < data.children.size(); i++) { +#ifdef LIMBOAI_MODULE if (!data.children[i]->is_class_ptr(BTComment::get_class_ptr_static())) { count += 1; } +#endif +#ifdef LIMBOAI_GDEXTENSION + if (data.children[i]->get_class_static() != BTComment::get_class_static()) { + count += 1; + } +#endif } return count; } @@ -274,23 +366,36 @@ Ref BTTask::next_sibling() const { return Ref(); } -PackedStringArray BTTask::get_configuration_warnings() const { +PackedStringArray BTTask::get_configuration_warnings() { PackedStringArray ret; PackedStringArray warnings; +#ifdef LIMBOAI_MODULE if (GDVIRTUAL_CALL(_get_configuration_warning, warnings)) { ret.append_array(warnings); } +#endif +#ifdef LIMBOAI_GDEXTENSION + warnings = call(LimboStringNames::get_singleton()->_get_configuration_warning); + ret.append_array(warnings); +#endif return ret; } -void BTTask::print_tree(int p_initial_tabs) const { +void BTTask::print_tree(int p_initial_tabs) { String tabs = "--"; for (int i = 0; i < p_initial_tabs; i++) { tabs += "--"; } + +#ifdef LIMBOAI_MODULE print_line(vformat("%s Name: %s Instance: %s", tabs, get_task_name(), Ref(this))); +#endif +#ifdef LIMBOAI_GDEXTENSION + UtilityFunctions::print(vformat("%s Name: %s Instance: %s", tabs, get_task_name(), Ref(this))); +#endif + for (int i = 0; i < get_child_count(); i++) { get_child(i)->print_tree(p_initial_tabs + 1); } @@ -338,12 +443,22 @@ void BTTask::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "status", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_status"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "elapsed_time", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_elapsed_time"); +#ifdef LIMBOAI_MODULE GDVIRTUAL_BIND(_setup); GDVIRTUAL_BIND(_enter); GDVIRTUAL_BIND(_exit); GDVIRTUAL_BIND(_tick, "p_delta"); GDVIRTUAL_BIND(_generate_name); GDVIRTUAL_BIND(_get_configuration_warning); +#endif // LIMBOAI_MODULE +#ifdef LIMBOAI_GDEXTENSION + ClassDB::bind_method(D_METHOD("_setup"), &BTTask::_setup); + ClassDB::bind_method(D_METHOD("_enter"), &BTTask::_enter); + ClassDB::bind_method(D_METHOD("_exit"), &BTTask::_exit); + ClassDB::bind_method(D_METHOD("_tick", "p_delta"), &BTTask::_tick); + ClassDB::bind_method(D_METHOD("_generate_name"), &BTTask::_generate_name); + ClassDB::bind_method(D_METHOD("_get_configuration_warnings"), &BTTask::get_configuration_warnings); +#endif } BTTask::BTTask() { diff --git a/bt/tasks/bt_task.h b/bt/tasks/bt_task.h index 15f3d80..83c1c92 100644 --- a/bt/tasks/bt_task.h +++ b/bt/tasks/bt_task.h @@ -12,6 +12,7 @@ #ifndef BTTASK_H #define BTTASK_H +#ifdef LIMBOAI_MODULE #include "modules/limboai/blackboard/blackboard.h" #include "modules/limboai/util/limbo_task_db.h" @@ -25,6 +26,18 @@ #include "core/variant/binder_common.h" #include "core/variant/dictionary.h" #include "scene/resources/texture.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include "blackboard/blackboard.h" +#include "util/limbo_task_db.h" + +#include +#include +#include + +using namespace godot; +#endif // LIMBOAI_GDEXTENSION /** * Base class for BTTask. @@ -72,34 +85,40 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const; + virtual String _generate_name(); virtual void _setup() {} virtual void _enter() {} virtual void _exit() {} virtual Status _tick(double p_delta) { return FAILURE; } +#ifdef LIMBOAI_MODULE GDVIRTUAL0RC(String, _generate_name); GDVIRTUAL0(_setup); GDVIRTUAL0(_enter); GDVIRTUAL0(_exit); GDVIRTUAL1R(Status, _tick, double); GDVIRTUAL0RC(PackedStringArray, _get_configuration_warning); +#endif // LIMBOAI_MODULE public: + // TODO: GDExtension doesn't have this method hmm... + +#ifdef LIMBOAI_MODULE virtual bool editor_can_reload_from_file() override { return false; } +#endif // LIMBOAI_MODULE _FORCE_INLINE_ Node *get_agent() const { return data.agent; } void set_agent(Node *p_agent) { data.agent = p_agent; } String get_custom_name() const { return data.custom_name; } void set_custom_name(const String &p_name); - String get_task_name() const; + String get_task_name(); Ref get_root() const; virtual Ref clone() const; virtual void initialize(Node *p_agent, const Ref &p_blackboard); - virtual PackedStringArray get_configuration_warnings() const; + virtual PackedStringArray get_configuration_warnings(); Status execute(double p_delta); void abort(); @@ -129,7 +148,7 @@ public: bool is_descendant_of(const Ref &p_task) const; Ref next_sibling() const; - void print_tree(int p_initial_tabs = 0) const; + void print_tree(int p_initial_tabs = 0); BTTask(); ~BTTask(); diff --git a/util/limbo_string_names.cpp b/util/limbo_string_names.cpp index b18137f..adc6057 100644 --- a/util/limbo_string_names.cpp +++ b/util/limbo_string_names.cpp @@ -10,23 +10,22 @@ */ #include "limbo_string_names.h" - -#include "core/string/string_name.h" +#include "godot_cpp/variant/string_name.hpp" LimboStringNames *LimboStringNames::singleton = nullptr; LimboStringNames::LimboStringNames() { - _generate_name = StaticCString::create("_generate_name"); - _setup = StaticCString::create("_setup"); - _enter = StaticCString::create("_enter"); - _exit = StaticCString::create("_exit"); - _tick = StaticCString::create("_tick"); - behavior_tree_finished = StaticCString::create("behavior_tree_finished"); - setup = StaticCString::create("setup"); - entered = StaticCString::create("entered"); - exited = StaticCString::create("exited"); - updated = StaticCString::create("updated"); - _update = StaticCString::create("_update"); - state_changed = StaticCString::create("state_changed"); - _get_configuration_warning = StaticCString::create("_get_configuration_warning"); + _generate_name = StringName("_generate_name"); + _setup = StringName("_setup"); + _enter = StringName("_enter"); + _exit = StringName("_exit"); + _tick = StringName("_tick"); + behavior_tree_finished = StringName("behavior_tree_finished"); + setup = StringName("setup"); + entered = StringName("entered"); + exited = StringName("exited"); + updated = StringName("updated"); + _update = StringName("_update"); + state_changed = StringName("state_changed"); + _get_configuration_warning = StringName("_get_configuration_warning"); } \ No newline at end of file diff --git a/util/limbo_string_names.h b/util/limbo_string_names.h index 6fa6ca3..e5802c8 100644 --- a/util/limbo_string_names.h +++ b/util/limbo_string_names.h @@ -12,10 +12,16 @@ #ifndef LIMBO_STRING_NAMES_H #define LIMBO_STRING_NAMES_H -#include "modules/register_module_types.h" - +#ifdef LIMBOAI_MODULE #include "core/string/string_name.h" #include "core/typedefs.h" +#include "modules/register_module_types.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include +using namespace godot; +#endif // LIMBOAI_GDEXTENSION class LimboStringNames { friend void initialize_limboai_module(ModuleInitializationLevel p_level); diff --git a/util/limbo_task_db.cpp b/util/limbo_task_db.cpp index 5dc99e2..6c38465 100644 --- a/util/limbo_task_db.cpp +++ b/util/limbo_task_db.cpp @@ -11,8 +11,16 @@ #include "limbo_task_db.h" +#ifdef LIMBOAI_MODULE #include "core/config/project_settings.h" #include "core/io/dir_access.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include +#include +using namespace godot; +#endif // LIMBOAI_GDEXTENSION HashMap> LimboTaskDB::core_tasks; HashMap> LimboTaskDB::tasks_cache; @@ -21,7 +29,14 @@ _FORCE_INLINE_ void _populate_scripted_tasks_from_dir(String p_path, List dir = DirAccess::create(DirAccess::ACCESS_RESOURCES); +#endif +#ifdef LIMBOAI_GDEXTENSION + Ref dir = memnew(DirAccess); +#endif + if (dir->change_dir(p_path) == OK) { dir->list_dir_begin(); String fn = dir->get_next(); @@ -42,7 +57,14 @@ _FORCE_INLINE_ void _populate_from_user_dir(String p_path, HashMap dir = DirAccess::create(DirAccess::ACCESS_RESOURCES); +#endif +#ifdef LIMBOAI_GDEXTENSION + Ref dir = memnew(DirAccess); +#endif + if (dir->change_dir(p_path) == OK) { dir->list_dir_begin(); String fn = dir->get_next(); @@ -80,7 +102,7 @@ void LimboTaskDB::scan_user_tasks() { } for (int i = 1; i < 4; i++) { - String dir1 = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_" + itos(i)); + String dir1 = ProjectSettings::get_singleton()->get_setting_with_override("limbo_ai/behavior_tree/user_task_dir_" + itos(i)); _populate_from_user_dir(dir1, &tasks_cache); } diff --git a/util/limbo_task_db.h b/util/limbo_task_db.h index 6ac587a..b55a3fd 100644 --- a/util/limbo_task_db.h +++ b/util/limbo_task_db.h @@ -12,9 +12,19 @@ #ifndef LIMBO_TASK_DB_H #define LIMBO_TASK_DB_H +#ifdef LIMBOAI_MODULE #include "core/object/class_db.h" #include "core/templates/hash_map.h" #include "core/templates/list.h" +#endif + +#ifdef LIMBOAI_GDEXTENSION +#include +#include +#include +#include +using namespace godot; +#endif class LimboTaskDB { private: @@ -54,10 +64,16 @@ public: } }; +#ifdef LIMBOAI_MODULE #define LIMBO_REGISTER_TASK(m_class) \ if (m_class::_class_is_enabled) { \ ::LimboTaskDB::register_task(); \ } +#endif + +#ifdef LIMBOAI_GDEXTENSION +#define LIMBO_REGISTER_TASK(m_class) LimboTaskDB::register_task(); +#endif #define TASK_CATEGORY(m_cat) \ public: \ diff --git a/util/limbo_utility.cpp b/util/limbo_utility.cpp index 11b3fac..37e5f5e 100644 --- a/util/limbo_utility.cpp +++ b/util/limbo_utility.cpp @@ -11,6 +11,8 @@ #include "limbo_utility.h" +#ifdef LIMBOAI_MODULE + #include "modules/limboai/bt/tasks/bt_task.h" #include "core/error/error_macros.h" @@ -22,6 +24,14 @@ #include "editor/editor_node.h" #endif // TOOLS_ENABLED +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include "bt/tasks/bt_task.h" + +#include +#endif + LimboUtility *LimboUtility::singleton = nullptr; LimboUtility *LimboUtility::get_singleton() { @@ -124,29 +134,60 @@ String LimboUtility::get_check_operator_string(CheckType p_check_type) const { } bool LimboUtility::perform_check(CheckType p_check_type, const Variant &left_value, const Variant &right_value) { + Variant ret; +#ifdef LIMBOAI_MODULE switch (p_check_type) { case LimboUtility::CheckType::CHECK_EQUAL: { - return Variant::evaluate(Variant::OP_EQUAL, left_value, right_value); + ret = Variant::evaluate(Variant::OP_EQUAL, left_value, right_value); } break; case LimboUtility::CheckType::CHECK_LESS_THAN: { - return Variant::evaluate(Variant::OP_LESS, left_value, right_value); + ret = Variant::evaluate(Variant::OP_LESS, left_value, right_value); } break; case LimboUtility::CheckType::CHECK_LESS_THAN_OR_EQUAL: { - return Variant::evaluate(Variant::OP_LESS_EQUAL, left_value, right_value); + ret = Variant::evaluate(Variant::OP_LESS_EQUAL, left_value, right_value); } break; case LimboUtility::CheckType::CHECK_GREATER_THAN: { - return Variant::evaluate(Variant::OP_GREATER, left_value, right_value); + ret = Variant::evaluate(Variant::OP_GREATER, left_value, right_value); } break; case LimboUtility::CheckType::CHECK_GREATER_THAN_OR_EQUAL: { - return Variant::evaluate(Variant::OP_GREATER_EQUAL, left_value, right_value); + ret = Variant::evaluate(Variant::OP_GREATER_EQUAL, left_value, right_value); } break; case LimboUtility::CheckType::CHECK_NOT_EQUAL: { - return Variant::evaluate(Variant::OP_NOT_EQUAL, left_value, right_value); + ret = Variant::evaluate(Variant::OP_NOT_EQUAL, left_value, right_value); + } break; + default: { + ret = false; + } break; + } +#endif +#ifdef LIMBOAI_GDEXTENSION + bool valid; + switch (p_check_type) { + case LimboUtility::CheckType::CHECK_EQUAL: { + Variant::evaluate(Variant::OP_LESS, left_value, right_value, ret, valid); + } break; + case LimboUtility::CheckType::CHECK_LESS_THAN: { + Variant::evaluate(Variant::OP_LESS, left_value, right_value, ret, valid); + } break; + case LimboUtility::CheckType::CHECK_LESS_THAN_OR_EQUAL: { + Variant::evaluate(Variant::OP_LESS_EQUAL, left_value, right_value, ret, valid); + } break; + case LimboUtility::CheckType::CHECK_GREATER_THAN: { + Variant::evaluate(Variant::OP_GREATER, left_value, right_value, ret, valid); + } break; + case LimboUtility::CheckType::CHECK_GREATER_THAN_OR_EQUAL: { + Variant::evaluate(Variant::OP_GREATER_EQUAL, left_value, right_value, ret, valid); + } break; + case LimboUtility::CheckType::CHECK_NOT_EQUAL: { + Variant::evaluate(Variant::OP_NOT_EQUAL, left_value, right_value, ret, valid); } break; default: { return false; } break; } +#endif + + return ret; } String LimboUtility::get_operation_string(Operation p_operation) const { @@ -192,44 +233,91 @@ String LimboUtility::get_operation_string(Operation p_operation) const { } Variant LimboUtility::perform_operation(Operation p_operation, const Variant &left_value, const Variant &right_value) { + Variant ret; +#ifdef LIMBOAI_MODULE switch (p_operation) { case OPERATION_NONE: { - return right_value; + ret = right_value; } break; case OPERATION_ADDITION: { - return Variant::evaluate(Variant::OP_ADD, left_value, right_value); + ret = Variant::evaluate(Variant::OP_ADD, left_value, right_value); } break; case OPERATION_SUBTRACTION: { - return Variant::evaluate(Variant::OP_SUBTRACT, left_value, right_value); + ret = Variant::evaluate(Variant::OP_SUBTRACT, left_value, right_value); } break; case OPERATION_MULTIPLICATION: { - return Variant::evaluate(Variant::OP_MULTIPLY, left_value, right_value); + ret = Variant::evaluate(Variant::OP_MULTIPLY, left_value, right_value); } break; case OPERATION_DIVISION: { - return Variant::evaluate(Variant::OP_DIVIDE, left_value, right_value); + ret = Variant::evaluate(Variant::OP_DIVIDE, left_value, right_value); } break; case OPERATION_MODULO: { - return Variant::evaluate(Variant::OP_MODULE, left_value, right_value); + ret = Variant::evaluate(Variant::OP_MODULE, left_value, right_value); } break; case OPERATION_POWER: { - return Variant::evaluate(Variant::OP_POWER, left_value, right_value); + ret = Variant::evaluate(Variant::OP_POWER, left_value, right_value); } break; case OPERATION_BIT_SHIFT_LEFT: { - return Variant::evaluate(Variant::OP_SHIFT_LEFT, left_value, right_value); + ret = Variant::evaluate(Variant::OP_SHIFT_LEFT, left_value, right_value); } break; case OPERATION_BIT_SHIFT_RIGHT: { - return Variant::evaluate(Variant::OP_SHIFT_RIGHT, left_value, right_value); + ret = Variant::evaluate(Variant::OP_SHIFT_RIGHT, left_value, right_value); } break; case OPERATION_BIT_AND: { - return Variant::evaluate(Variant::OP_BIT_AND, left_value, right_value); + ret = Variant::evaluate(Variant::OP_BIT_AND, left_value, right_value); } break; case OPERATION_BIT_OR: { - return Variant::evaluate(Variant::OP_BIT_OR, left_value, right_value); + ret = Variant::evaluate(Variant::OP_BIT_OR, left_value, right_value); } break; case OPERATION_BIT_XOR: { - return Variant::evaluate(Variant::OP_BIT_XOR, left_value, right_value); + ret = Variant::evaluate(Variant::OP_BIT_XOR, left_value, right_value); } break; } +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION + bool valid; + switch (p_operation) { + case OPERATION_NONE: { + ret = right_value; + } break; + case OPERATION_ADDITION: { + Variant::evaluate(Variant::OP_ADD, left_value, right_value, ret, valid); + } break; + case OPERATION_SUBTRACTION: { + Variant::evaluate(Variant::OP_SUBTRACT, left_value, right_value, ret, valid); + } break; + case OPERATION_MULTIPLICATION: { + Variant::evaluate(Variant::OP_MULTIPLY, left_value, right_value, ret, valid); + } break; + case OPERATION_DIVISION: { + Variant::evaluate(Variant::OP_DIVIDE, left_value, right_value, ret, valid); + } break; + case OPERATION_MODULO: { + Variant::evaluate(Variant::OP_MODULE, left_value, right_value, ret, valid); + } break; + // TODO: Uncomment when https://github.com/godotengine/godot-cpp/issues/1348 is fixed. + // case OPERATION_POWER: { + // Variant::evaluate(Variant::OP_POWER, left_value, right_value, ret, valid); + // } break; + case OPERATION_BIT_SHIFT_LEFT: { + Variant::evaluate(Variant::OP_SHIFT_LEFT, left_value, right_value, ret, valid); + } break; + case OPERATION_BIT_SHIFT_RIGHT: { + Variant::evaluate(Variant::OP_SHIFT_RIGHT, left_value, right_value, ret, valid); + } break; + case OPERATION_BIT_AND: { + Variant::evaluate(Variant::OP_BIT_AND, left_value, right_value, ret, valid); + } break; + case OPERATION_BIT_OR: { + Variant::evaluate(Variant::OP_BIT_OR, left_value, right_value, ret, valid); + } break; + case OPERATION_BIT_XOR: { + Variant::evaluate(Variant::OP_BIT_XOR, left_value, right_value, ret, valid); + } break; + } +#endif // LIMBOAI_GDEXTENSION + return Variant(); } diff --git a/util/limbo_utility.h b/util/limbo_utility.h index 8c84be0..8a3cb58 100644 --- a/util/limbo_utility.h +++ b/util/limbo_utility.h @@ -12,12 +12,23 @@ #ifndef LIMBO_UTILITY_H #define LIMBO_UTILITY_H +#ifdef LIMBOAI_MODULE #include "core/object/object.h" #include "core/object/class_db.h" #include "core/variant/binder_common.h" #include "core/variant/variant.h" #include "scene/resources/texture.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include + +#include +#include +#include +using namespace godot; +#endif // LIMBOAI_GDEXTENSION #define LOGICAL_XOR(a, b) (a) ? !(b) : (b) From 8eed672213547252abdc3d7358716a74337750a4 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 6 Jan 2024 21:05:08 +0100 Subject: [PATCH 02/42] Port BBParam classes --- blackboard/bb_param/bb_aabb.h | 1 - blackboard/bb_param/bb_array.h | 1 - blackboard/bb_param/bb_basis.h | 1 - blackboard/bb_param/bb_bool.h | 1 - blackboard/bb_param/bb_byte_array.h | 1 - blackboard/bb_param/bb_color.h | 1 - blackboard/bb_param/bb_color_array.h | 1 - blackboard/bb_param/bb_dictionary.h | 1 - blackboard/bb_param/bb_float.h | 1 - blackboard/bb_param/bb_float_array.h | 1 - blackboard/bb_param/bb_int.h | 1 - blackboard/bb_param/bb_int_array.h | 1 - blackboard/bb_param/bb_node.cpp | 9 +++++++-- blackboard/bb_param/bb_node.h | 1 - blackboard/bb_param/bb_param.cpp | 10 ++++++++++ blackboard/bb_param/bb_param.h | 19 +++++++++++++++++++ blackboard/bb_param/bb_plane.h | 1 - blackboard/bb_param/bb_quaternion.h | 1 - blackboard/bb_param/bb_rect2.h | 1 - blackboard/bb_param/bb_rect2i.h | 1 - blackboard/bb_param/bb_string.h | 1 - blackboard/bb_param/bb_string_array.h | 1 - blackboard/bb_param/bb_string_name.h | 1 - blackboard/bb_param/bb_transform2d.h | 1 - blackboard/bb_param/bb_transform3d.h | 1 - blackboard/bb_param/bb_variant.cpp | 2 -- blackboard/bb_param/bb_variant.h | 2 -- blackboard/bb_param/bb_vector2.h | 1 - blackboard/bb_param/bb_vector2_array.h | 1 - blackboard/bb_param/bb_vector2i.h | 1 - blackboard/bb_param/bb_vector3.h | 1 - blackboard/bb_param/bb_vector3_array.h | 1 - blackboard/bb_param/bb_vector3i.h | 1 - blackboard/bb_param/bb_vector4.h | 1 - blackboard/bb_param/bb_vector4i.h | 1 - 35 files changed, 36 insertions(+), 36 deletions(-) diff --git a/blackboard/bb_param/bb_aabb.h b/blackboard/bb_param/bb_aabb.h index 727065f..17fe311 100644 --- a/blackboard/bb_param/bb_aabb.h +++ b/blackboard/bb_param/bb_aabb.h @@ -13,7 +13,6 @@ #define BB_AABB_H #include "bb_param.h" -#include "core/object/object.h" class BBAabb : public BBParam { GDCLASS(BBAabb, BBParam); diff --git a/blackboard/bb_param/bb_array.h b/blackboard/bb_param/bb_array.h index 4f5b467..3f97fc9 100644 --- a/blackboard/bb_param/bb_array.h +++ b/blackboard/bb_param/bb_array.h @@ -13,7 +13,6 @@ #define BB_ARRAY_H #include "bb_param.h" -#include "core/object/object.h" class BBArray : public BBParam { GDCLASS(BBArray, BBParam); diff --git a/blackboard/bb_param/bb_basis.h b/blackboard/bb_param/bb_basis.h index ce8923f..ba7af05 100644 --- a/blackboard/bb_param/bb_basis.h +++ b/blackboard/bb_param/bb_basis.h @@ -13,7 +13,6 @@ #define BB_BASIS_H #include "bb_param.h" -#include "core/object/object.h" class BBBasis : public BBParam { GDCLASS(BBBasis, BBParam); diff --git a/blackboard/bb_param/bb_bool.h b/blackboard/bb_param/bb_bool.h index f6bf7be..e9a08a7 100644 --- a/blackboard/bb_param/bb_bool.h +++ b/blackboard/bb_param/bb_bool.h @@ -13,7 +13,6 @@ #define BB_BOOL_H #include "bb_param.h" -#include "core/object/object.h" class BBBool : public BBParam { GDCLASS(BBBool, BBParam); diff --git a/blackboard/bb_param/bb_byte_array.h b/blackboard/bb_param/bb_byte_array.h index ff49002..48b0b07 100644 --- a/blackboard/bb_param/bb_byte_array.h +++ b/blackboard/bb_param/bb_byte_array.h @@ -13,7 +13,6 @@ #define BB_BYTE_ARRAY_H #include "bb_param.h" -#include "core/object/object.h" class BBByteArray : public BBParam { GDCLASS(BBByteArray, BBParam); diff --git a/blackboard/bb_param/bb_color.h b/blackboard/bb_param/bb_color.h index 047f313..3cf9dd6 100644 --- a/blackboard/bb_param/bb_color.h +++ b/blackboard/bb_param/bb_color.h @@ -13,7 +13,6 @@ #define BB_COLOR_H #include "bb_param.h" -#include "core/object/object.h" class BBColor : public BBParam { GDCLASS(BBColor, BBParam); diff --git a/blackboard/bb_param/bb_color_array.h b/blackboard/bb_param/bb_color_array.h index 2f60177..4d167c9 100644 --- a/blackboard/bb_param/bb_color_array.h +++ b/blackboard/bb_param/bb_color_array.h @@ -13,7 +13,6 @@ #define BB_COLOR_ARRAY_H #include "bb_param.h" -#include "core/object/object.h" class BBColorArray : public BBParam { GDCLASS(BBColorArray, BBParam); diff --git a/blackboard/bb_param/bb_dictionary.h b/blackboard/bb_param/bb_dictionary.h index 762875f..e598c86 100644 --- a/blackboard/bb_param/bb_dictionary.h +++ b/blackboard/bb_param/bb_dictionary.h @@ -13,7 +13,6 @@ #define BB_DICTIONARY_H #include "bb_param.h" -#include "core/object/object.h" class BBDictionary : public BBParam { GDCLASS(BBDictionary, BBParam); diff --git a/blackboard/bb_param/bb_float.h b/blackboard/bb_param/bb_float.h index 3b65327..799c16e 100644 --- a/blackboard/bb_param/bb_float.h +++ b/blackboard/bb_param/bb_float.h @@ -13,7 +13,6 @@ #define BB_FLOAT_H #include "bb_param.h" -#include "core/object/object.h" class BBFloat : public BBParam { GDCLASS(BBFloat, BBParam); diff --git a/blackboard/bb_param/bb_float_array.h b/blackboard/bb_param/bb_float_array.h index ec6609b..f5c0838 100644 --- a/blackboard/bb_param/bb_float_array.h +++ b/blackboard/bb_param/bb_float_array.h @@ -13,7 +13,6 @@ #define BB_FLOAT_ARRAY_H #include "bb_param.h" -#include "core/object/object.h" class BBFloatArray : public BBParam { GDCLASS(BBFloatArray, BBParam); diff --git a/blackboard/bb_param/bb_int.h b/blackboard/bb_param/bb_int.h index 26ee495..eeb0509 100644 --- a/blackboard/bb_param/bb_int.h +++ b/blackboard/bb_param/bb_int.h @@ -13,7 +13,6 @@ #define BB_INT_H #include "bb_param.h" -#include "core/object/object.h" class BBInt : public BBParam { GDCLASS(BBInt, BBParam); diff --git a/blackboard/bb_param/bb_int_array.h b/blackboard/bb_param/bb_int_array.h index 9980218..15981ad 100644 --- a/blackboard/bb_param/bb_int_array.h +++ b/blackboard/bb_param/bb_int_array.h @@ -13,7 +13,6 @@ #define BB_INT_ARRAY_H #include "bb_param.h" -#include "core/object/object.h" class BBIntArray : public BBParam { GDCLASS(BBIntArray, BBParam); diff --git a/blackboard/bb_param/bb_node.cpp b/blackboard/bb_param/bb_node.cpp index 59994ef..088788b 100644 --- a/blackboard/bb_param/bb_node.cpp +++ b/blackboard/bb_param/bb_node.cpp @@ -10,9 +10,14 @@ */ #include "bb_node.h" + +#ifdef LIMBOAI_MODULE #include "core/error/error_macros.h" -#include "core/variant/variant.h" #include "scene/main/node.h" +#endif // LIMBOAI_MODULE +#ifdef LIMBOAI_GDEXTENSION +#include +#endif // LIMBOAI_GDEXTENSION Variant BBNode::get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default) { ERR_FAIL_COND_V(p_agent == nullptr, Variant()); @@ -28,7 +33,7 @@ Variant BBNode::get_value(Object *p_agent, const Ref &p_blackboard, if (val.get_type() == Variant::NODE_PATH) { Node *agent = Object::cast_to(p_agent); ERR_FAIL_COND_V_MSG(agent == nullptr, Variant(), "BBNode: p_agent must be a Node."); - return agent->get_node(val); + return agent->get_node_or_null(val); } else { Object *obj = val; if (unlikely(obj == nullptr && val.get_type() != Variant::NIL)) { diff --git a/blackboard/bb_param/bb_node.h b/blackboard/bb_param/bb_node.h index 38d46ad..931818f 100644 --- a/blackboard/bb_param/bb_node.h +++ b/blackboard/bb_param/bb_node.h @@ -13,7 +13,6 @@ #define BB_NODE_H #include "bb_param.h" -#include "core/object/object.h" class BBNode : public BBParam { GDCLASS(BBNode, BBParam); diff --git a/blackboard/bb_param/bb_param.cpp b/blackboard/bb_param/bb_param.cpp index e73e070..e1e47d7 100644 --- a/blackboard/bb_param/bb_param.cpp +++ b/blackboard/bb_param/bb_param.cpp @@ -11,6 +11,7 @@ #include "bb_param.h" +#ifdef LIMBOAI_MODULE #include "modules/limboai/util/limbo_utility.h" #include "core/core_bind.h" @@ -19,6 +20,13 @@ #include "core/object/object.h" #include "core/variant/variant.h" #include "core/variant/variant_utility.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include "util/limbo_utility.h" + +using namespace godot; +#endif // LIMBOAI_GDEXTENSION VARIANT_ENUM_CAST(BBParam::ValueSource); @@ -49,6 +57,7 @@ void BBParam::set_variable(const String &p_value) { emit_changed(); } +#ifdef LIMBOAI_MODULE String BBParam::to_string() { if (value_source == SAVED_VALUE) { String s = saved_value.stringify(); @@ -70,6 +79,7 @@ String BBParam::to_string() { return LimboUtility::get_singleton()->decorate_var(variable); } } +#endif // LIMBOAI_MODULE Variant BBParam::get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default) { ERR_FAIL_COND_V(!p_blackboard.is_valid(), p_default); diff --git a/blackboard/bb_param/bb_param.h b/blackboard/bb_param/bb_param.h index 65e32cf..e92b289 100644 --- a/blackboard/bb_param/bb_param.h +++ b/blackboard/bb_param/bb_param.h @@ -12,6 +12,7 @@ #ifndef BB_PARAM_H #define BB_PARAM_H +#ifdef LIMBOAI_MODULE #include "modules/limboai/blackboard/blackboard.h" #include "modules/limboai/util/limbo_utility.h" @@ -19,6 +20,17 @@ #include "core/object/object.h" #include "core/typedefs.h" #include "core/variant/variant.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include "blackboard/blackboard.h" +#include "util/limbo_utility.h" + +#include +#include +#include +#include +#endif class BBParam : public Resource { GDCLASS(BBParam, Resource); @@ -42,8 +54,13 @@ protected: static void _bind_methods(); _FORCE_INLINE_ void _assign_default_value() { +#ifdef LIMBOAI_MODULE Callable::CallError err; Variant::construct(get_type(), saved_value, nullptr, 0, err); +#endif +#ifdef LIMBOAI_GDEXTENSION + saved_value.clear(); +#endif } void _get_property_list(List *p_list) const; @@ -60,7 +77,9 @@ public: void set_variable(const String &p_value); String get_variable() const { return variable; } +#ifdef LIMBOAI_MODULE virtual String to_string() override; +#endif virtual Variant get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default = Variant()); diff --git a/blackboard/bb_param/bb_plane.h b/blackboard/bb_param/bb_plane.h index 36ecead..a2c2745 100644 --- a/blackboard/bb_param/bb_plane.h +++ b/blackboard/bb_param/bb_plane.h @@ -13,7 +13,6 @@ #define BB_PLANE_H #include "bb_param.h" -#include "core/object/object.h" class BBPlane : public BBParam { GDCLASS(BBPlane, BBParam); diff --git a/blackboard/bb_param/bb_quaternion.h b/blackboard/bb_param/bb_quaternion.h index 81d1ad7..838b711 100644 --- a/blackboard/bb_param/bb_quaternion.h +++ b/blackboard/bb_param/bb_quaternion.h @@ -13,7 +13,6 @@ #define BB_QUATERNION_H #include "bb_param.h" -#include "core/object/object.h" class BBQuaternion : public BBParam { GDCLASS(BBQuaternion, BBParam); diff --git a/blackboard/bb_param/bb_rect2.h b/blackboard/bb_param/bb_rect2.h index c67aa1a..ff7dd3a 100644 --- a/blackboard/bb_param/bb_rect2.h +++ b/blackboard/bb_param/bb_rect2.h @@ -13,7 +13,6 @@ #define BB_RECT2_H #include "bb_param.h" -#include "core/object/object.h" class BBRect2 : public BBParam { GDCLASS(BBRect2, BBParam); diff --git a/blackboard/bb_param/bb_rect2i.h b/blackboard/bb_param/bb_rect2i.h index 0659809..c74108a 100644 --- a/blackboard/bb_param/bb_rect2i.h +++ b/blackboard/bb_param/bb_rect2i.h @@ -13,7 +13,6 @@ #define BB_RECT2I_H #include "bb_param.h" -#include "core/object/object.h" class BBRect2i : public BBParam { GDCLASS(BBRect2i, BBParam); diff --git a/blackboard/bb_param/bb_string.h b/blackboard/bb_param/bb_string.h index 510a5c1..11bb1cb 100644 --- a/blackboard/bb_param/bb_string.h +++ b/blackboard/bb_param/bb_string.h @@ -13,7 +13,6 @@ #define BB_STRING_H #include "bb_param.h" -#include "core/object/object.h" class BBString : public BBParam { GDCLASS(BBString, BBParam); diff --git a/blackboard/bb_param/bb_string_array.h b/blackboard/bb_param/bb_string_array.h index c07e957..6aeef84 100644 --- a/blackboard/bb_param/bb_string_array.h +++ b/blackboard/bb_param/bb_string_array.h @@ -13,7 +13,6 @@ #define BB_STRING_ARRAY_H #include "bb_param.h" -#include "core/object/object.h" class BBStringArray : public BBParam { GDCLASS(BBStringArray, BBParam); diff --git a/blackboard/bb_param/bb_string_name.h b/blackboard/bb_param/bb_string_name.h index 8d1cdec..fd96856 100644 --- a/blackboard/bb_param/bb_string_name.h +++ b/blackboard/bb_param/bb_string_name.h @@ -13,7 +13,6 @@ #define BB_STRING_NAME_H #include "bb_param.h" -#include "core/object/object.h" class BBStringName : public BBParam { GDCLASS(BBStringName, BBParam); diff --git a/blackboard/bb_param/bb_transform2d.h b/blackboard/bb_param/bb_transform2d.h index ceeaa27..33101d8 100644 --- a/blackboard/bb_param/bb_transform2d.h +++ b/blackboard/bb_param/bb_transform2d.h @@ -13,7 +13,6 @@ #define BB_TRANSFORM2D_H #include "bb_param.h" -#include "core/object/object.h" class BBTransform2D : public BBParam { GDCLASS(BBTransform2D, BBParam); diff --git a/blackboard/bb_param/bb_transform3d.h b/blackboard/bb_param/bb_transform3d.h index d539f5e..c203c31 100644 --- a/blackboard/bb_param/bb_transform3d.h +++ b/blackboard/bb_param/bb_transform3d.h @@ -13,7 +13,6 @@ #define BB_TRANSFORM3D_H #include "bb_param.h" -#include "core/object/object.h" class BBTransform3D : public BBParam { GDCLASS(BBTransform3D, BBParam); diff --git a/blackboard/bb_param/bb_variant.cpp b/blackboard/bb_param/bb_variant.cpp index 2e92dc6..cec0cf4 100644 --- a/blackboard/bb_param/bb_variant.cpp +++ b/blackboard/bb_param/bb_variant.cpp @@ -10,8 +10,6 @@ */ #include "bb_variant.h" -#include "core/object/object.h" -#include "core/variant/variant.h" void BBVariant::set_type(Variant::Type p_type) { if (type != p_type) { diff --git a/blackboard/bb_param/bb_variant.h b/blackboard/bb_param/bb_variant.h index 1eb95bc..5634206 100644 --- a/blackboard/bb_param/bb_variant.h +++ b/blackboard/bb_param/bb_variant.h @@ -13,8 +13,6 @@ #define BB_VARIANT_H #include "bb_param.h" -#include "core/object/object.h" -#include "core/variant/variant.h" class BBVariant : public BBParam { GDCLASS(BBVariant, BBParam); diff --git a/blackboard/bb_param/bb_vector2.h b/blackboard/bb_param/bb_vector2.h index 7131019..2777d5c 100644 --- a/blackboard/bb_param/bb_vector2.h +++ b/blackboard/bb_param/bb_vector2.h @@ -13,7 +13,6 @@ #define BB_VECTOR2_H #include "bb_param.h" -#include "core/object/object.h" class BBVector2 : public BBParam { GDCLASS(BBVector2, BBParam); diff --git a/blackboard/bb_param/bb_vector2_array.h b/blackboard/bb_param/bb_vector2_array.h index fa45357..15486bb 100644 --- a/blackboard/bb_param/bb_vector2_array.h +++ b/blackboard/bb_param/bb_vector2_array.h @@ -13,7 +13,6 @@ #define BB_VECTOR2_ARRAY_H #include "bb_param.h" -#include "core/object/object.h" class BBVector2Array : public BBParam { GDCLASS(BBVector2Array, BBParam); diff --git a/blackboard/bb_param/bb_vector2i.h b/blackboard/bb_param/bb_vector2i.h index b80b99e..45f9ade 100644 --- a/blackboard/bb_param/bb_vector2i.h +++ b/blackboard/bb_param/bb_vector2i.h @@ -13,7 +13,6 @@ #define BB_VECTOR2I_H #include "bb_param.h" -#include "core/object/object.h" class BBVector2i : public BBParam { GDCLASS(BBVector2i, BBParam); diff --git a/blackboard/bb_param/bb_vector3.h b/blackboard/bb_param/bb_vector3.h index 7aab869..e31c502 100644 --- a/blackboard/bb_param/bb_vector3.h +++ b/blackboard/bb_param/bb_vector3.h @@ -13,7 +13,6 @@ #define BB_VECTOR3_H #include "bb_param.h" -#include "core/object/object.h" class BBVector3 : public BBParam { GDCLASS(BBVector3, BBParam); diff --git a/blackboard/bb_param/bb_vector3_array.h b/blackboard/bb_param/bb_vector3_array.h index 60ecae1..f70e6be 100644 --- a/blackboard/bb_param/bb_vector3_array.h +++ b/blackboard/bb_param/bb_vector3_array.h @@ -13,7 +13,6 @@ #define BB_VECTOR3_ARRAY_H #include "bb_param.h" -#include "core/object/object.h" class BBVector3Array : public BBParam { GDCLASS(BBVector3Array, BBParam); diff --git a/blackboard/bb_param/bb_vector3i.h b/blackboard/bb_param/bb_vector3i.h index 7cf07d6..65896c0 100644 --- a/blackboard/bb_param/bb_vector3i.h +++ b/blackboard/bb_param/bb_vector3i.h @@ -13,7 +13,6 @@ #define BB_VECTOR3I_H #include "bb_param.h" -#include "core/object/object.h" class BBVector3i : public BBParam { GDCLASS(BBVector3i, BBParam); diff --git a/blackboard/bb_param/bb_vector4.h b/blackboard/bb_param/bb_vector4.h index d0e9487..4172a36 100644 --- a/blackboard/bb_param/bb_vector4.h +++ b/blackboard/bb_param/bb_vector4.h @@ -13,7 +13,6 @@ #define BB_VECTOR4_H #include "bb_param.h" -#include "core/object/object.h" class BBVector4 : public BBParam { GDCLASS(BBVector4, BBParam); diff --git a/blackboard/bb_param/bb_vector4i.h b/blackboard/bb_param/bb_vector4i.h index f29851d..63a47d1 100644 --- a/blackboard/bb_param/bb_vector4i.h +++ b/blackboard/bb_param/bb_vector4i.h @@ -13,7 +13,6 @@ #define BB_VECTOR4I_H #include "bb_param.h" -#include "core/object/object.h" class BBVector4i : public BBParam { GDCLASS(BBVector4i, BBParam); From 4f97c1bd24c13e9581eaaa44ebd55155400e9954 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sun, 7 Jan 2024 00:47:46 +0100 Subject: [PATCH 03/42] Post the rest of the BT tasks (massive changes) --- bt/behavior_tree.cpp | 4 +++ bt/behavior_tree.h | 15 +++++++-- bt/tasks/blackboard/bt_check_trigger.cpp | 8 ++--- bt/tasks/blackboard/bt_check_trigger.h | 6 ++-- bt/tasks/blackboard/bt_check_var.cpp | 10 ++---- bt/tasks/blackboard/bt_check_var.h | 8 ++--- bt/tasks/blackboard/bt_set_var.cpp | 14 +++----- bt/tasks/blackboard/bt_set_var.h | 10 +++--- bt/tasks/bt_task.cpp | 9 +----- bt/tasks/bt_task.h | 8 +++++ bt/tasks/composites/bt_parallel.cpp | 2 -- .../composites/bt_probability_selector.cpp | 17 ++++------ bt/tasks/composites/bt_probability_selector.h | 21 +++++++----- bt/tasks/composites/bt_random_selector.cpp | 2 +- bt/tasks/composites/bt_random_selector.h | 2 -- bt/tasks/composites/bt_random_sequence.cpp | 4 +-- bt/tasks/composites/bt_random_sequence.h | 2 -- bt/tasks/decorators/bt_cooldown.cpp | 16 +++++++--- bt/tasks/decorators/bt_cooldown.h | 7 +++- bt/tasks/decorators/bt_delay.cpp | 9 +----- bt/tasks/decorators/bt_delay.h | 2 +- bt/tasks/decorators/bt_for_each.cpp | 12 +++---- bt/tasks/decorators/bt_for_each.h | 2 +- bt/tasks/decorators/bt_new_scope.cpp | 6 ---- bt/tasks/decorators/bt_probability.cpp | 4 +-- bt/tasks/decorators/bt_probability.h | 2 +- bt/tasks/decorators/bt_repeat.cpp | 17 ++++------ bt/tasks/decorators/bt_repeat.h | 4 ++- bt/tasks/decorators/bt_run_limit.cpp | 2 +- bt/tasks/decorators/bt_run_limit.h | 2 +- bt/tasks/decorators/bt_subtree.cpp | 12 ++----- bt/tasks/decorators/bt_subtree.h | 6 ++-- bt/tasks/decorators/bt_time_limit.cpp | 4 +-- bt/tasks/decorators/bt_time_limit.h | 2 +- bt/tasks/scene/bt_await_animation.cpp | 8 ++--- bt/tasks/scene/bt_await_animation.h | 12 +++++-- bt/tasks/scene/bt_check_agent_property.cpp | 15 +++++---- bt/tasks/scene/bt_check_agent_property.h | 10 +++--- bt/tasks/scene/bt_pause_animation.cpp | 8 ++--- bt/tasks/scene/bt_pause_animation.h | 12 +++++-- bt/tasks/scene/bt_play_animation.cpp | 10 +++--- bt/tasks/scene/bt_play_animation.h | 12 +++++-- bt/tasks/scene/bt_set_agent_property.cpp | 18 ++++++++--- bt/tasks/scene/bt_set_agent_property.h | 8 ++--- bt/tasks/scene/bt_stop_animation.cpp | 8 ++--- bt/tasks/scene/bt_stop_animation.h | 12 +++++-- bt/tasks/utility/bt_call_method.cpp | 26 +++++++++++---- bt/tasks/utility/bt_call_method.h | 6 ++-- bt/tasks/utility/bt_console_print.cpp | 19 +++++------ bt/tasks/utility/bt_console_print.h | 6 ++-- bt/tasks/utility/bt_random_wait.cpp | 6 ++-- bt/tasks/utility/bt_random_wait.h | 2 +- bt/tasks/utility/bt_wait.cpp | 7 +--- bt/tasks/utility/bt_wait.h | 2 +- bt/tasks/utility/bt_wait_ticks.cpp | 5 +-- bt/tasks/utility/bt_wait_ticks.h | 2 +- util/limbo_def.h | 32 +++++++++++++++++++ util/limbo_string_names.cpp | 6 ++++ util/limbo_string_names.h | 8 +++++ 59 files changed, 284 insertions(+), 227 deletions(-) create mode 100644 util/limbo_def.h diff --git a/bt/behavior_tree.cpp b/bt/behavior_tree.cpp index b761843..e3dec62 100644 --- a/bt/behavior_tree.cpp +++ b/bt/behavior_tree.cpp @@ -11,10 +11,14 @@ #include "behavior_tree.h" +#ifdef LIMBOAI_MODULE #include "core/error/error_macros.h" #include "core/object/class_db.h" #include "core/templates/list.h" #include "core/variant/variant.h" +#endif // LIMBOAI_MODULE +#ifdef LIMBOAI_GDEXTENSION +#endif // LIMBOAI_GDEXTENSION Ref BehaviorTree::clone() const { Ref copy = duplicate(false); diff --git a/bt/behavior_tree.h b/bt/behavior_tree.h index cb35c96..ca30924 100644 --- a/bt/behavior_tree.h +++ b/bt/behavior_tree.h @@ -12,11 +12,18 @@ #ifndef BEHAVIOR_TREE_H #define BEHAVIOR_TREE_H -#include "core/io/resource.h" - -#include "modules/limboai/blackboard/blackboard.h" #include "tasks/bt_task.h" +#ifdef LIMBOAI_MODULE +#include "core/io/resource.h" +#include "modules/limboai/blackboard/blackboard.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include +using namespace godot; +#endif // LIMBOAI_GDEXTENSION + class BehaviorTree : public Resource { GDCLASS(BehaviorTree, Resource); @@ -28,7 +35,9 @@ protected: static void _bind_methods(); public: +#ifdef LIMBOAI_MODULE virtual bool editor_can_reload_from_file() override { return false; } +#endif void set_description(String p_value) { description = p_value; diff --git a/bt/tasks/blackboard/bt_check_trigger.cpp b/bt/tasks/blackboard/bt_check_trigger.cpp index 7762d8b..d50c5f2 100644 --- a/bt/tasks/blackboard/bt_check_trigger.cpp +++ b/bt/tasks/blackboard/bt_check_trigger.cpp @@ -11,16 +11,14 @@ #include "bt_check_trigger.h" -#include "modules/limboai/util/limbo_utility.h" - -#include "core/variant/variant.h" +#include "../../../util/limbo_utility.h" void BTCheckTrigger::set_variable(String p_variable) { variable = p_variable; emit_changed(); } -PackedStringArray BTCheckTrigger::get_configuration_warnings() const { +PackedStringArray BTCheckTrigger::get_configuration_warnings() { PackedStringArray warnings = BTCondition::get_configuration_warnings(); if (variable.is_empty()) { warnings.append("Variable is not set."); @@ -28,7 +26,7 @@ PackedStringArray BTCheckTrigger::get_configuration_warnings() const { return warnings; } -String BTCheckTrigger::_generate_name() const { +String BTCheckTrigger::_generate_name() { if (variable.is_empty()) { return "CheckTrigger ???"; } diff --git a/bt/tasks/blackboard/bt_check_trigger.h b/bt/tasks/blackboard/bt_check_trigger.h index fafd296..6f8a01a 100644 --- a/bt/tasks/blackboard/bt_check_trigger.h +++ b/bt/tasks/blackboard/bt_check_trigger.h @@ -14,8 +14,6 @@ #include "../bt_condition.h" -#include "core/string/ustring.h" - class BTCheckTrigger : public BTCondition { GDCLASS(BTCheckTrigger, BTCondition); TASK_CATEGORY(Blackboard); @@ -26,14 +24,14 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: void set_variable(String p_variable); String get_variable() const { return variable; } - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_CHECK_TRIGGER \ No newline at end of file diff --git a/bt/tasks/blackboard/bt_check_var.cpp b/bt/tasks/blackboard/bt_check_var.cpp index 28139f9..2aac926 100644 --- a/bt/tasks/blackboard/bt_check_var.cpp +++ b/bt/tasks/blackboard/bt_check_var.cpp @@ -11,10 +11,6 @@ #include "bt_check_var.h" -#include "modules/limboai/util/limbo_utility.h" - -#include "core/variant/callable.h" - void BTCheckVar::set_variable(String p_variable) { variable = p_variable; emit_changed(); @@ -29,11 +25,11 @@ void BTCheckVar::set_value(Ref p_value) { value = p_value; emit_changed(); if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) { - value->connect(SNAME("changed"), Callable(this, SNAME("emit_changed"))); + value->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed))); } } -PackedStringArray BTCheckVar::get_configuration_warnings() const { +PackedStringArray BTCheckVar::get_configuration_warnings() { PackedStringArray warnings = BTCondition::get_configuration_warnings(); if (variable.is_empty()) { warnings.append("`variable` should be assigned."); @@ -44,7 +40,7 @@ PackedStringArray BTCheckVar::get_configuration_warnings() const { return warnings; } -String BTCheckVar::_generate_name() const { +String BTCheckVar::_generate_name() { if (variable.is_empty()) { return "CheckVar ???"; } diff --git a/bt/tasks/blackboard/bt_check_var.h b/bt/tasks/blackboard/bt_check_var.h index b84717e..bb215ec 100644 --- a/bt/tasks/blackboard/bt_check_var.h +++ b/bt/tasks/blackboard/bt_check_var.h @@ -14,8 +14,8 @@ #include "../bt_condition.h" -#include "modules/limboai/blackboard/bb_param/bb_variant.h" -#include "modules/limboai/util/limbo_utility.h" +#include "../../../blackboard/bb_param/bb_variant.h" +#include "../../../limboai/util/limbo_utility.h" class BTCheckVar : public BTCondition { GDCLASS(BTCheckVar, BTCondition); @@ -29,11 +29,11 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; void set_variable(String p_variable); String get_variable() const { return variable; } diff --git a/bt/tasks/blackboard/bt_set_var.cpp b/bt/tasks/blackboard/bt_set_var.cpp index 51b84ae..50b3826 100644 --- a/bt/tasks/blackboard/bt_set_var.cpp +++ b/bt/tasks/blackboard/bt_set_var.cpp @@ -11,13 +11,7 @@ #include "bt_set_var.h" -#include "modules/limboai/blackboard/bb_param/bb_param.h" -#include "modules/limboai/util/limbo_utility.h" - -#include "core/variant/callable.h" -#include "core/variant/variant.h" - -String BTSetVar::_generate_name() const { +String BTSetVar::_generate_name() { if (variable.is_empty()) { return "SetVar ???"; } @@ -31,7 +25,7 @@ BT::Status BTSetVar::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BTSetVar: `variable` is not set."); ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetVar: `value` is not set."); Variant result; - Variant error_result = SNAME("Error: BTSetVar failed to get value!"); + Variant error_result = LSNAME(error_value); Variant right_value = value->get_value(get_agent(), get_blackboard(), error_result); ERR_FAIL_COND_V_MSG(right_value == error_result, FAILURE, "BTSetVar: Failed to get parameter value. Returning FAILURE."); if (operation == LimboUtility::OPERATION_NONE) { @@ -55,7 +49,7 @@ void BTSetVar::set_value(Ref p_value) { value = p_value; emit_changed(); if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) { - value->connect(SNAME("changed"), Callable(this, SNAME("emit_changed"))); + value->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed))); } } @@ -64,7 +58,7 @@ void BTSetVar::set_operation(LimboUtility::Operation p_operation) { emit_changed(); } -PackedStringArray BTSetVar::get_configuration_warnings() const { +PackedStringArray BTSetVar::get_configuration_warnings() { PackedStringArray warnings = BTAction::get_configuration_warnings(); if (variable.is_empty()) { warnings.append("`variable` should be assigned."); diff --git a/bt/tasks/blackboard/bt_set_var.h b/bt/tasks/blackboard/bt_set_var.h index f4c5692..8b7d5ee 100644 --- a/bt/tasks/blackboard/bt_set_var.h +++ b/bt/tasks/blackboard/bt_set_var.h @@ -14,10 +14,8 @@ #include "../bt_action.h" -#include "modules/limboai/blackboard/bb_param/bb_variant.h" -#include "modules/limboai/util/limbo_utility.h" - -#include "core/string/ustring.h" +#include "../../../blackboard/bb_param/bb_variant.h" +#include "../../../limboai/util/limbo_utility.h" class BTSetVar : public BTAction { GDCLASS(BTSetVar, BTAction); @@ -31,11 +29,11 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; void set_variable(const String &p_variable); String get_variable() const { return variable; } diff --git a/bt/tasks/bt_task.cpp b/bt/tasks/bt_task.cpp index de7420a..1f103b5 100644 --- a/bt/tasks/bt_task.cpp +++ b/bt/tasks/bt_task.cpp @@ -287,16 +287,9 @@ void BTTask::abort() { int BTTask::get_child_count_excluding_comments() const { int count = 0; for (int i = 0; i < data.children.size(); i++) { -#ifdef LIMBOAI_MODULE - if (!data.children[i]->is_class_ptr(BTComment::get_class_ptr_static())) { + if (!IS_CLASS(data.children[i], BTComment)) { count += 1; } -#endif -#ifdef LIMBOAI_GDEXTENSION - if (data.children[i]->get_class_static() != BTComment::get_class_static()) { - count += 1; - } -#endif } return count; } diff --git a/bt/tasks/bt_task.h b/bt/tasks/bt_task.h index 83c1c92..a5341cf 100644 --- a/bt/tasks/bt_task.h +++ b/bt/tasks/bt_task.h @@ -14,11 +14,16 @@ #ifdef LIMBOAI_MODULE #include "modules/limboai/blackboard/blackboard.h" +#include "modules/limboai/util/limbo_string_names.h" #include "modules/limboai/util/limbo_task_db.h" +#include "core/config/engine.h" +#include "core/error/error_macros.h" #include "core/io/resource.h" +#include "core/math/math_funcs.h" #include "core/object/object.h" #include "core/object/ref_counted.h" +#include "core/os/memory.h" #include "core/string/ustring.h" #include "core/templates/vector.h" #include "core/typedefs.h" @@ -30,8 +35,11 @@ #ifdef LIMBOAI_GDEXTENSION #include "blackboard/blackboard.h" +#include "util/limbo_def.h" +#include "util/limbo_string_names.h" #include "util/limbo_task_db.h" +#include #include #include #include diff --git a/bt/tasks/composites/bt_parallel.cpp b/bt/tasks/composites/bt_parallel.cpp index 8afee63..6e3a50e 100644 --- a/bt/tasks/composites/bt_parallel.cpp +++ b/bt/tasks/composites/bt_parallel.cpp @@ -11,8 +11,6 @@ #include "bt_parallel.h" -#include "core/object/class_db.h" - void BTParallel::_enter() { for (int i = 0; i < get_child_count(); i++) { get_child(i)->abort(); diff --git a/bt/tasks/composites/bt_probability_selector.cpp b/bt/tasks/composites/bt_probability_selector.cpp index 096c5b9..826dd42 100644 --- a/bt/tasks/composites/bt_probability_selector.cpp +++ b/bt/tasks/composites/bt_probability_selector.cpp @@ -10,26 +10,23 @@ */ #include "bt_probability_selector.h" - -#include "modules/limboai/bt/tasks/bt_task.h" - -#include "core/error/error_macros.h" +#include "godot_cpp/variant/utility_functions.hpp" double BTProbabilitySelector::get_weight(int p_index) const { ERR_FAIL_INDEX_V(p_index, get_child_count(), 0.0); - ERR_FAIL_COND_V(get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static()), 0.0); + ERR_FAIL_COND_V(IS_CLASS(get_child(p_index), BTComment), 0.0); return _get_weight(p_index); } void BTProbabilitySelector::set_weight(int p_index, double p_weight) { ERR_FAIL_INDEX(p_index, get_child_count()); - ERR_FAIL_COND(get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static())); + ERR_FAIL_COND(IS_CLASS(get_child(p_index), BTComment)); _set_weight(p_index, p_weight); } double BTProbabilitySelector::get_probability(int p_index) const { ERR_FAIL_INDEX_V(p_index, get_child_count(), 0.0); - ERR_FAIL_COND_V(get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static()), 0.0); + ERR_FAIL_COND_V(IS_CLASS(get_child(p_index), BTComment), 0.0); double total = _get_total_weight(); return total == 0.0 ? 0.0 : _get_weight(p_index) / total; } @@ -38,7 +35,7 @@ void BTProbabilitySelector::set_probability(int p_index, double p_probability) { ERR_FAIL_INDEX(p_index, get_child_count()); ERR_FAIL_COND(p_probability < 0.0); ERR_FAIL_COND(p_probability >= 1.0); - ERR_FAIL_COND(get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static())); + ERR_FAIL_COND(IS_CLASS(get_child(p_index), BTComment)); double others_total = _get_total_weight() - _get_weight(p_index); double others_probability = 1.0 - p_probability; @@ -52,7 +49,7 @@ void BTProbabilitySelector::set_probability(int p_index, double p_probability) { bool BTProbabilitySelector::has_probability(int p_index) const { ERR_FAIL_INDEX_V(p_index, get_child_count(), false); - return !get_child(p_index)->is_class_ptr(BTComment::get_class_ptr_static()); + return !IS_CLASS(get_child(p_index), BTComment); } void BTProbabilitySelector::set_abort_on_failure(bool p_abort_on_failure) { @@ -98,7 +95,7 @@ void BTProbabilitySelector::_select_task() { remaining_tasks_weight -= _get_weight(task); } - double roll = Math::random(0.0, remaining_tasks_weight); + double roll = RAND_RANGE(0.0, remaining_tasks_weight); for (int i = 0; i < get_child_count(); i++) { Ref task = get_child(i); if (failed_tasks.has(task)) { diff --git a/bt/tasks/composites/bt_probability_selector.h b/bt/tasks/composites/bt_probability_selector.h index 12b1c25..54d504a 100644 --- a/bt/tasks/composites/bt_probability_selector.h +++ b/bt/tasks/composites/bt_probability_selector.h @@ -12,11 +12,16 @@ #ifndef BT_PROBABILITY_SELECTOR_H #define BT_PROBABILITY_SELECTOR_H -#include "modules/limboai/bt/tasks/bt_comment.h" -#include "modules/limboai/bt/tasks/bt_composite.h" +#include "../bt_comment.h" +#include "../bt_composite.h" +#ifdef LIMBOAI_MODULE #include "core/core_string_names.h" #include "core/typedefs.h" +#endif // LIMBOAI_MODULE +#ifdef LIMBOAI_GDEXTENSION +#include +#endif // LIMBOAI_GDEXTENSION class BTProbabilitySelector : public BTComposite { GDCLASS(BTProbabilitySelector, BTComposite); @@ -28,17 +33,17 @@ private: bool abort_on_failure = false; void _select_task(); - - _FORCE_INLINE_ double _get_weight(int p_index) const { return get_child(p_index)->get_meta(SNAME("_weight_"), 1.0); } - _FORCE_INLINE_ double _get_weight(Ref p_task) const { return p_task->get_meta(SNAME("_weight_"), 1.0); } +#define SNAME(m_arg) ([]() -> const StringName & { static StringName sname = _scs_create(m_arg, true); return sname; })() + _FORCE_INLINE_ double _get_weight(int p_index) const { return get_child(p_index)->get_meta(LSNAME(_weight_), 1.0); } + _FORCE_INLINE_ double _get_weight(Ref p_task) const { return p_task->get_meta(LSNAME(_weight_), 1.0); } _FORCE_INLINE_ void _set_weight(int p_index, double p_weight) { - get_child(p_index)->set_meta(SNAME("_weight_"), Variant(p_weight)); - get_child(p_index)->emit_signal(CoreStringNames::get_singleton()->changed); + get_child(p_index)->set_meta(LSNAME(_weight_), Variant(p_weight)); + get_child(p_index)->emit_signal(LSNAME(changed)); } _FORCE_INLINE_ double _get_total_weight() const { double total = 0.0; for (int i = 0; i < get_child_count(); i++) { - if (!get_child(i)->is_class_ptr(BTComment::get_class_ptr_static())) { + if (!IS_CLASS(get_child(i), BTComment)) { total += _get_weight(i); } } diff --git a/bt/tasks/composites/bt_random_selector.cpp b/bt/tasks/composites/bt_random_selector.cpp index ffbf75a..5ac2c6a 100644 --- a/bt/tasks/composites/bt_random_selector.cpp +++ b/bt/tasks/composites/bt_random_selector.cpp @@ -16,7 +16,7 @@ void BTRandomSelector::_enter() { if (indicies.size() != get_child_count()) { indicies.resize(get_child_count()); for (int i = 0; i < get_child_count(); i++) { - indicies.set(i, i); + indicies[i] = i; } } indicies.shuffle(); diff --git a/bt/tasks/composites/bt_random_selector.h b/bt/tasks/composites/bt_random_selector.h index 54337e2..627f93a 100644 --- a/bt/tasks/composites/bt_random_selector.h +++ b/bt/tasks/composites/bt_random_selector.h @@ -14,8 +14,6 @@ #include "../bt_composite.h" -#include "core/templates/vector.h" - class BTRandomSelector : public BTComposite { GDCLASS(BTRandomSelector, BTComposite); TASK_CATEGORY(Composites); diff --git a/bt/tasks/composites/bt_random_sequence.cpp b/bt/tasks/composites/bt_random_sequence.cpp index a6ddeba..2b19674 100644 --- a/bt/tasks/composites/bt_random_sequence.cpp +++ b/bt/tasks/composites/bt_random_sequence.cpp @@ -1,7 +1,7 @@ /** * bt_random_sequence.cpp * ============================================================================= - * Copyright 2021-2023 Serhii Snitsaruk + * Copyright 2021-2024 Serhii Snitsaruk * * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at @@ -16,7 +16,7 @@ void BTRandomSequence::_enter() { if (indicies.size() != get_child_count()) { indicies.resize(get_child_count()); for (int i = 0; i < get_child_count(); i++) { - indicies.set(i, i); + indicies[i] = i; } } indicies.shuffle(); diff --git a/bt/tasks/composites/bt_random_sequence.h b/bt/tasks/composites/bt_random_sequence.h index caba87b..0e1c244 100644 --- a/bt/tasks/composites/bt_random_sequence.h +++ b/bt/tasks/composites/bt_random_sequence.h @@ -14,8 +14,6 @@ #include "../bt_composite.h" -#include "core/templates/vector.h" - class BTRandomSequence : public BTComposite { GDCLASS(BTRandomSequence, BTComposite); TASK_CATEGORY(Composites); diff --git a/bt/tasks/decorators/bt_cooldown.cpp b/bt/tasks/decorators/bt_cooldown.cpp index 8c450e0..422a528 100644 --- a/bt/tasks/decorators/bt_cooldown.cpp +++ b/bt/tasks/decorators/bt_cooldown.cpp @@ -11,10 +11,12 @@ #include "bt_cooldown.h" -#include "core/math/math_funcs.h" -#include "core/object/class_db.h" -#include "core/variant/array.h" +#ifdef LIMBOAI_MODULE #include "scene/main/scene_tree.h" +#endif +#ifdef LIMBOAI_GDEXTENSION +#include +#endif //**** Setters / Getters @@ -45,7 +47,7 @@ void BTCooldown::set_cooldown_state_var(String p_value) { //**** Task Implementation -String BTCooldown::_generate_name() const { +String BTCooldown::_generate_name() { return vformat("Cooldown %s sec", Math::snapped(duration, 0.001)); } @@ -76,7 +78,13 @@ void BTCooldown::_chill() { if (timer.is_valid()) { timer->set_time_left(duration); } else { +#ifdef LIMBOAI_MODULE timer = SceneTree::get_singleton()->create_timer(duration, process_pause); +#endif +#ifdef LIMBOAI_GDEXTENSION + SceneTree *st = (SceneTree *)Engine::get_singleton()->get_main_loop(); + timer = st->create_timer(duration, process_pause); +#endif timer->connect("timeout", callable_mp(this, &BTCooldown::_on_timeout), CONNECT_ONE_SHOT); } } diff --git a/bt/tasks/decorators/bt_cooldown.h b/bt/tasks/decorators/bt_cooldown.h index f7a9773..be52b6b 100644 --- a/bt/tasks/decorators/bt_cooldown.h +++ b/bt/tasks/decorators/bt_cooldown.h @@ -14,7 +14,12 @@ #include "../bt_decorator.h" +#ifdef LIMBOAI_MODULE #include "scene/main/scene_tree.h" +#endif +#ifdef LIMBOAI_GDEXTENSION +#include +#endif class BTCooldown : public BTDecorator { GDCLASS(BTCooldown, BTDecorator); @@ -35,7 +40,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual void _setup() override; virtual Status _tick(double p_delta) override; diff --git a/bt/tasks/decorators/bt_delay.cpp b/bt/tasks/decorators/bt_delay.cpp index 4e6aacd..4f127e2 100644 --- a/bt/tasks/decorators/bt_delay.cpp +++ b/bt/tasks/decorators/bt_delay.cpp @@ -11,19 +11,12 @@ #include "bt_delay.h" -#include "core/error/error_macros.h" -#include "core/math/math_funcs.h" -#include "core/object/class_db.h" -#include "core/object/object.h" -#include "core/variant/array.h" -#include "core/variant/variant.h" - void BTDelay::set_seconds(double p_value) { seconds = p_value; emit_changed(); } -String BTDelay::_generate_name() const { +String BTDelay::_generate_name() { return vformat("Delay %s sec", Math::snapped(seconds, 0.001)); } diff --git a/bt/tasks/decorators/bt_delay.h b/bt/tasks/decorators/bt_delay.h index 067b8ea..a3dccab 100644 --- a/bt/tasks/decorators/bt_delay.h +++ b/bt/tasks/decorators/bt_delay.h @@ -24,7 +24,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: diff --git a/bt/tasks/decorators/bt_for_each.cpp b/bt/tasks/decorators/bt_for_each.cpp index 35df0fb..0c0e94a 100644 --- a/bt/tasks/decorators/bt_for_each.cpp +++ b/bt/tasks/decorators/bt_for_each.cpp @@ -11,12 +11,12 @@ #include "bt_for_each.h" -#include "modules/limboai/blackboard/blackboard.h" -#include "modules/limboai/util/limbo_utility.h" +#include "../../../blackboard/blackboard.h" +#include "../../../util/limbo_utility.h" +#ifdef LIMBOAI_MODULE #include "core/error/error_list.h" -#include "core/error/error_macros.h" -#include "core/variant/variant.h" +#endif //**** Setters / Getters @@ -32,7 +32,7 @@ void BTForEach::set_save_var(String p_value) { //**** Task Implementation -String BTForEach::_generate_name() const { +String BTForEach::_generate_name() { return vformat("ForEach %s in %s", LimboUtility::get_singleton()->decorate_var(save_var), LimboUtility::get_singleton()->decorate_var(array_var)); @@ -51,7 +51,7 @@ BT::Status BTForEach::_tick(double p_delta) { if (arr.size() == 0) { return SUCCESS; } - Variant elem = arr.get(current_idx); + Variant elem = arr[current_idx]; get_blackboard()->set_var(save_var, elem); Status status = get_child(0)->execute(p_delta); diff --git a/bt/tasks/decorators/bt_for_each.h b/bt/tasks/decorators/bt_for_each.h index 2efd5a1..b9abf99 100644 --- a/bt/tasks/decorators/bt_for_each.h +++ b/bt/tasks/decorators/bt_for_each.h @@ -27,7 +27,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual void _enter() override; virtual Status _tick(double p_delta) override; diff --git a/bt/tasks/decorators/bt_new_scope.cpp b/bt/tasks/decorators/bt_new_scope.cpp index e3ef6c0..4f12b21 100644 --- a/bt/tasks/decorators/bt_new_scope.cpp +++ b/bt/tasks/decorators/bt_new_scope.cpp @@ -11,12 +11,6 @@ #include "bt_new_scope.h" -#include "modules/limboai/blackboard/blackboard.h" - -#include "core/error/error_macros.h" -#include "core/os/memory.h" -#include "core/string/ustring.h" - void BTNewScope::initialize(Node *p_agent, const Ref &p_blackboard) { ERR_FAIL_COND(p_agent == nullptr); ERR_FAIL_COND(p_blackboard == nullptr); diff --git a/bt/tasks/decorators/bt_probability.cpp b/bt/tasks/decorators/bt_probability.cpp index 890bef7..6aa4dbd 100644 --- a/bt/tasks/decorators/bt_probability.cpp +++ b/bt/tasks/decorators/bt_probability.cpp @@ -16,13 +16,13 @@ void BTProbability::set_run_chance(float p_value) { emit_changed(); } -String BTProbability::_generate_name() const { +String BTProbability::_generate_name() { return vformat("Probability %.1f%%", run_chance); } BT::Status BTProbability::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(get_child_count() == 0, FAILURE, "BT decorator has no child."); - if (get_child(0)->get_status() == RUNNING || Math::randf() <= run_chance) { + if (get_child(0)->get_status() == RUNNING || RANDF() <= run_chance) { return get_child(0)->execute(p_delta); } return FAILURE; diff --git a/bt/tasks/decorators/bt_probability.h b/bt/tasks/decorators/bt_probability.h index e4bf09b..94ccb72 100644 --- a/bt/tasks/decorators/bt_probability.h +++ b/bt/tasks/decorators/bt_probability.h @@ -24,7 +24,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: diff --git a/bt/tasks/decorators/bt_repeat.cpp b/bt/tasks/decorators/bt_repeat.cpp index a4947b1..18d0e1f 100644 --- a/bt/tasks/decorators/bt_repeat.cpp +++ b/bt/tasks/decorators/bt_repeat.cpp @@ -10,19 +10,11 @@ */ #include "bt_repeat.h" +#include "util/limbo_string_names.h" -#include "core/object/object.h" -#include "core/string/ustring.h" -#include "core/variant/variant.h" - -static String repeat_forever_str; - -String BTRepeat::_generate_name() const { +String BTRepeat::_generate_name() { if (forever) { - if (repeat_forever_str.is_empty()) { - repeat_forever_str.parse_utf8("Repeat ∞"); - } - return repeat_forever_str; + return LSNAME(repeat_forever); } return vformat("Repeat x%s", times); } @@ -81,3 +73,6 @@ void BTRepeat::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "times", PROPERTY_HINT_RANGE, "1,65535", PROPERTY_USAGE_NONE), "set_times", "get_times"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "abort_on_failure", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_abort_on_failure", "get_abort_on_failure"); } + +BTRepeat::BTRepeat() { +} diff --git a/bt/tasks/decorators/bt_repeat.h b/bt/tasks/decorators/bt_repeat.h index 37e1866..1cfd112 100644 --- a/bt/tasks/decorators/bt_repeat.h +++ b/bt/tasks/decorators/bt_repeat.h @@ -29,7 +29,7 @@ protected: void _get_property_list(List *p_list) const; - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual void _enter() override; virtual Status _tick(double p_delta) override; @@ -42,6 +42,8 @@ public: void set_abort_on_failure(bool p_value); bool get_abort_on_failure() const { return abort_on_failure; } + + BTRepeat(); }; #endif // BT_REPEAT_H \ No newline at end of file diff --git a/bt/tasks/decorators/bt_run_limit.cpp b/bt/tasks/decorators/bt_run_limit.cpp index 4b8ffa2..8fed369 100644 --- a/bt/tasks/decorators/bt_run_limit.cpp +++ b/bt/tasks/decorators/bt_run_limit.cpp @@ -16,7 +16,7 @@ void BTRunLimit::set_run_limit(int p_value) { emit_changed(); } -String BTRunLimit::_generate_name() const { +String BTRunLimit::_generate_name() { return vformat("RunLimit x%d", run_limit); } diff --git a/bt/tasks/decorators/bt_run_limit.h b/bt/tasks/decorators/bt_run_limit.h index 9ae93a0..40f9126 100644 --- a/bt/tasks/decorators/bt_run_limit.h +++ b/bt/tasks/decorators/bt_run_limit.h @@ -25,7 +25,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: diff --git a/bt/tasks/decorators/bt_subtree.cpp b/bt/tasks/decorators/bt_subtree.cpp index aacaf4c..0510920 100644 --- a/bt/tasks/decorators/bt_subtree.cpp +++ b/bt/tasks/decorators/bt_subtree.cpp @@ -11,20 +11,12 @@ #include "bt_subtree.h" -#include "bt_new_scope.h" -#include "modules/limboai/blackboard/blackboard.h" - -#include "core/config/engine.h" -#include "core/error/error_macros.h" -#include "core/typedefs.h" -#include "core/variant/variant.h" - void BTSubtree::set_subtree(const Ref &p_value) { subtree = p_value; emit_changed(); } -String BTSubtree::_generate_name() const { +String BTSubtree::_generate_name() { String s; if (subtree.is_null()) { s = "(unassigned)"; @@ -51,7 +43,7 @@ BT::Status BTSubtree::_tick(double p_delta) { return get_child(0)->execute(p_delta); } -PackedStringArray BTSubtree::get_configuration_warnings() const { +PackedStringArray BTSubtree::get_configuration_warnings() { PackedStringArray warnings = BTTask::get_configuration_warnings(); // ! BTDecorator skipped intentionally if (subtree.is_null()) { warnings.append("Subtree needs to be assigned."); diff --git a/bt/tasks/decorators/bt_subtree.h b/bt/tasks/decorators/bt_subtree.h index dae6e79..3cd7c65 100644 --- a/bt/tasks/decorators/bt_subtree.h +++ b/bt/tasks/decorators/bt_subtree.h @@ -14,7 +14,7 @@ #include "bt_new_scope.h" -#include "modules/limboai/bt/behavior_tree.h" +#include "../../../bt/behavior_tree.h" class BTSubtree : public BTNewScope { GDCLASS(BTSubtree, BTNewScope); @@ -26,7 +26,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: @@ -34,7 +34,7 @@ public: Ref get_subtree() const { return subtree; } virtual void initialize(Node *p_agent, const Ref &p_blackboard) override; - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_SUBTREE_H \ No newline at end of file diff --git a/bt/tasks/decorators/bt_time_limit.cpp b/bt/tasks/decorators/bt_time_limit.cpp index 1ea3693..912695e 100644 --- a/bt/tasks/decorators/bt_time_limit.cpp +++ b/bt/tasks/decorators/bt_time_limit.cpp @@ -11,14 +11,12 @@ #include "bt_time_limit.h" -#include "core/math/math_funcs.h" - void BTTimeLimit::set_time_limit(double p_value) { time_limit = p_value; emit_changed(); } -String BTTimeLimit::_generate_name() const { +String BTTimeLimit::_generate_name() { return vformat("TimeLimit %s sec", Math::snapped(time_limit, 0.001)); } diff --git a/bt/tasks/decorators/bt_time_limit.h b/bt/tasks/decorators/bt_time_limit.h index c6bd855..dea420a 100644 --- a/bt/tasks/decorators/bt_time_limit.h +++ b/bt/tasks/decorators/bt_time_limit.h @@ -24,7 +24,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: diff --git a/bt/tasks/scene/bt_await_animation.cpp b/bt/tasks/scene/bt_await_animation.cpp index 5c9e882..62d611f 100644 --- a/bt/tasks/scene/bt_await_animation.cpp +++ b/bt/tasks/scene/bt_await_animation.cpp @@ -17,7 +17,7 @@ void BTAwaitAnimation::set_animation_player(Ref p_animation_player) { animation_player_param = p_animation_player; emit_changed(); if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) { - animation_player_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed"))); + animation_player_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed))); } } @@ -33,12 +33,12 @@ void BTAwaitAnimation::set_max_time(double p_max_time) { //**** Task Implementation -PackedStringArray BTAwaitAnimation::get_configuration_warnings() const { +PackedStringArray BTAwaitAnimation::get_configuration_warnings() { PackedStringArray warnings = BTAction::get_configuration_warnings(); if (animation_player_param.is_null()) { warnings.append("Animation Player parameter is not set."); } else { - if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) { + if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value() == Variant()) { warnings.append("Path to AnimationPlayer node is not set."); } else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) { warnings.append("AnimationPlayer blackboard variable is not set."); @@ -53,7 +53,7 @@ PackedStringArray BTAwaitAnimation::get_configuration_warnings() const { return warnings; } -String BTAwaitAnimation::_generate_name() const { +String BTAwaitAnimation::_generate_name() { return "AwaitAnimation" + (animation_name != StringName() ? vformat(" \"%s\"", animation_name) : " ???") + vformat(" max_time: %ss", Math::snapped(max_time, 0.001)); diff --git a/bt/tasks/scene/bt_await_animation.h b/bt/tasks/scene/bt_await_animation.h index 88a2508..923d542 100644 --- a/bt/tasks/scene/bt_await_animation.h +++ b/bt/tasks/scene/bt_await_animation.h @@ -14,9 +14,15 @@ #include "../bt_action.h" -#include "modules/limboai/blackboard/bb_param/bb_node.h" +#include "../../../blackboard/bb_param/bb_node.h" +#ifdef LIMBOAI_MODULE #include "scene/animation/animation_player.h" +#endif + +#ifdef LIMBOAI_GDEXTENSION +#include +#endif class BTAwaitAnimation : public BTAction { GDCLASS(BTAwaitAnimation, BTAction); @@ -33,7 +39,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual void _setup() override; virtual Status _tick(double p_delta) override; @@ -47,7 +53,7 @@ public: void set_max_time(double p_max_time); double get_max_time() const { return max_time; } - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_AWAIT_ANIMATION \ No newline at end of file diff --git a/bt/tasks/scene/bt_check_agent_property.cpp b/bt/tasks/scene/bt_check_agent_property.cpp index 0befedd..83da21c 100644 --- a/bt/tasks/scene/bt_check_agent_property.cpp +++ b/bt/tasks/scene/bt_check_agent_property.cpp @@ -11,10 +11,6 @@ #include "bt_check_agent_property.h" -#include "modules/limboai/util/limbo_utility.h" - -#include "core/variant/callable.h" - void BTCheckAgentProperty::set_property(StringName p_prop) { property = p_prop; emit_changed(); @@ -29,11 +25,11 @@ void BTCheckAgentProperty::set_value(Ref p_value) { value = p_value; emit_changed(); if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) { - value->connect(SNAME("changed"), Callable(this, SNAME("emit_changed"))); + value->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed))); } } -PackedStringArray BTCheckAgentProperty::get_configuration_warnings() const { +PackedStringArray BTCheckAgentProperty::get_configuration_warnings() { PackedStringArray warnings = BTCondition::get_configuration_warnings(); if (property == StringName()) { warnings.append("`property` should be assigned."); @@ -44,7 +40,7 @@ PackedStringArray BTCheckAgentProperty::get_configuration_warnings() const { return warnings; } -String BTCheckAgentProperty::_generate_name() const { +String BTCheckAgentProperty::_generate_name() { if (property == StringName()) { return "CheckAgentProperty ???"; } @@ -58,9 +54,14 @@ BT::Status BTCheckAgentProperty::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(property == StringName(), FAILURE, "BTCheckAgentProperty: `property` is not set."); ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTCheckAgentProperty: `value` is not set."); +#ifdef LIMBOAI_MODULE bool r_valid; Variant left_value = get_agent()->get(property, &r_valid); ERR_FAIL_COND_V_MSG(r_valid == false, FAILURE, vformat("BTCheckAgentProperty: Agent has no property named \"%s\"", property)); +#endif +#ifdef LIMBOAI_GDEXTENSION + Variant left_value = get_agent()->get(property); +#endif Variant right_value = value->get_value(get_agent(), get_blackboard()); diff --git a/bt/tasks/scene/bt_check_agent_property.h b/bt/tasks/scene/bt_check_agent_property.h index 905346a..76065a3 100644 --- a/bt/tasks/scene/bt_check_agent_property.h +++ b/bt/tasks/scene/bt_check_agent_property.h @@ -14,10 +14,8 @@ #include "../bt_condition.h" -#include "modules/limboai/blackboard/bb_param/bb_variant.h" -#include "modules/limboai/util/limbo_utility.h" - -#include "core/string/string_name.h" +#include "../../../blackboard/bb_param/bb_variant.h" +#include "../../../util/limbo_utility.h" class BTCheckAgentProperty : public BTCondition { GDCLASS(BTCheckAgentProperty, BTCondition); @@ -31,7 +29,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: @@ -44,7 +42,7 @@ public: void set_value(Ref p_value); Ref get_value() const { return value; } - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_CHECK_AGENT_PROPERTY \ No newline at end of file diff --git a/bt/tasks/scene/bt_pause_animation.cpp b/bt/tasks/scene/bt_pause_animation.cpp index 3208ca3..5598bb1 100644 --- a/bt/tasks/scene/bt_pause_animation.cpp +++ b/bt/tasks/scene/bt_pause_animation.cpp @@ -17,18 +17,18 @@ void BTPauseAnimation::set_animation_player(Ref p_animation_player) { animation_player_param = p_animation_player; emit_changed(); if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) { - animation_player_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed"))); + animation_player_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed))); } } //**** Task Implementation -PackedStringArray BTPauseAnimation::get_configuration_warnings() const { +PackedStringArray BTPauseAnimation::get_configuration_warnings() { PackedStringArray warnings = BTAction::get_configuration_warnings(); if (animation_player_param.is_null()) { warnings.append("Animation Player parameter is not set."); } else { - if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) { + if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value() == Variant()) { warnings.append("Path to AnimationPlayer node is not set."); } else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) { warnings.append("AnimationPlayer blackboard variable is not set."); @@ -37,7 +37,7 @@ PackedStringArray BTPauseAnimation::get_configuration_warnings() const { return warnings; } -String BTPauseAnimation::_generate_name() const { +String BTPauseAnimation::_generate_name() { return "PauseAnimation"; } diff --git a/bt/tasks/scene/bt_pause_animation.h b/bt/tasks/scene/bt_pause_animation.h index 385d87b..b58b993 100644 --- a/bt/tasks/scene/bt_pause_animation.h +++ b/bt/tasks/scene/bt_pause_animation.h @@ -14,9 +14,15 @@ #include "../bt_action.h" -#include "modules/limboai/blackboard/bb_param/bb_node.h" +#include "../../../blackboard/bb_param/bb_node.h" +#ifdef LIMBOAI_MODULE #include "scene/animation/animation_player.h" +#endif + +#ifdef LIMBOAI_GDEXTENSION +#include +#endif class BTPauseAnimation : public BTAction { GDCLASS(BTPauseAnimation, BTAction); @@ -31,7 +37,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual void _setup() override; virtual Status _tick(double p_delta) override; @@ -39,7 +45,7 @@ public: void set_animation_player(Ref p_animation_player); Ref get_animation_player() const { return animation_player_param; } - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_PAUSE_ANIMATION diff --git a/bt/tasks/scene/bt_play_animation.cpp b/bt/tasks/scene/bt_play_animation.cpp index 5fc224e..0ed5d8a 100644 --- a/bt/tasks/scene/bt_play_animation.cpp +++ b/bt/tasks/scene/bt_play_animation.cpp @@ -11,15 +11,13 @@ #include "bt_play_animation.h" -#include "core/math/math_funcs.h" - //**** Setters / Getters void BTPlayAnimation::set_animation_player(Ref p_animation_player) { animation_player_param = p_animation_player; emit_changed(); if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) { - animation_player_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed"))); + animation_player_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed))); } } @@ -50,12 +48,12 @@ void BTPlayAnimation::set_from_end(bool p_from_end) { //**** Task Implementation -PackedStringArray BTPlayAnimation::get_configuration_warnings() const { +PackedStringArray BTPlayAnimation::get_configuration_warnings() { PackedStringArray warnings = BTAction::get_configuration_warnings(); if (animation_player_param.is_null()) { warnings.append("Animation Player parameter is not set."); } else { - if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) { + if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value() == Variant()) { warnings.append("Path to AnimationPlayer node is not set."); } else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) { warnings.append("AnimationPlayer blackboard variable is not set."); @@ -67,7 +65,7 @@ PackedStringArray BTPlayAnimation::get_configuration_warnings() const { return warnings; } -String BTPlayAnimation::_generate_name() const { +String BTPlayAnimation::_generate_name() { return "PlayAnimation" + (animation_name != StringName() ? vformat(" \"%s\"", animation_name) : "") + (blend >= 0.0 ? vformat(" blend: %ss", Math::snapped(blend, 0.001)) : "") + diff --git a/bt/tasks/scene/bt_play_animation.h b/bt/tasks/scene/bt_play_animation.h index 331a1b6..10042fa 100644 --- a/bt/tasks/scene/bt_play_animation.h +++ b/bt/tasks/scene/bt_play_animation.h @@ -14,9 +14,15 @@ #include "../bt_action.h" -#include "modules/limboai/blackboard/bb_param/bb_node.h" +#include "../../../blackboard/bb_param/bb_node.h" +#ifdef LIMBOAI_MODULE #include "scene/animation/animation_player.h" +#endif + +#ifdef LIMBOAI_GDEXTENSION +#include +#endif class BTPlayAnimation : public BTAction { GDCLASS(BTPlayAnimation, BTAction); @@ -36,7 +42,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual void _setup() override; virtual void _enter() override; virtual Status _tick(double p_delta) override; @@ -60,7 +66,7 @@ public: void set_from_end(bool p_from_end); bool get_from_end() const { return from_end; } - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_PLAY_ANIMATION \ No newline at end of file diff --git a/bt/tasks/scene/bt_set_agent_property.cpp b/bt/tasks/scene/bt_set_agent_property.cpp index dc3c87a..0e5bb45 100644 --- a/bt/tasks/scene/bt_set_agent_property.cpp +++ b/bt/tasks/scene/bt_set_agent_property.cpp @@ -20,7 +20,7 @@ void BTSetAgentProperty::set_value(Ref p_value) { value = p_value; emit_changed(); if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) { - value->connect(SNAME("changed"), Callable(this, SNAME("emit_changed"))); + value->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed))); } } @@ -29,7 +29,7 @@ void BTSetAgentProperty::set_operation(LimboUtility::Operation p_operation) { emit_changed(); } -PackedStringArray BTSetAgentProperty::get_configuration_warnings() const { +PackedStringArray BTSetAgentProperty::get_configuration_warnings() { PackedStringArray warnings = BTAction::get_configuration_warnings(); if (property == StringName()) { warnings.append("`property` should be assigned."); @@ -40,7 +40,7 @@ PackedStringArray BTSetAgentProperty::get_configuration_warnings() const { return warnings; } -String BTSetAgentProperty::_generate_name() const { +String BTSetAgentProperty::_generate_name() { if (property == StringName()) { return "SetAgentProperty ???"; } @@ -54,21 +54,31 @@ BT::Status BTSetAgentProperty::_tick(double p_delta) { ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetAgentProperty: `value` is not set."); Variant result; - StringName error_value = SNAME("ErrorGettingValue"); + StringName error_value = LSNAME(error_value); Variant right_value = value->get_value(get_agent(), get_blackboard(), error_value); ERR_FAIL_COND_V_MSG(right_value == Variant(error_value), FAILURE, "BTSetAgentProperty: Couldn't get value of value-parameter."); bool r_valid; if (operation == LimboUtility::OPERATION_NONE) { result = right_value; } else { +#ifdef LIMBOAI_MODULE Variant left_value = get_agent()->get(property, &r_valid); ERR_FAIL_COND_V_MSG(!r_valid, FAILURE, vformat("BTSetAgentProperty: Failed to get agent's \"%s\" property. Returning FAILURE.", property)); +#endif +#ifdef LIMBOAI_GDEXTENSION + Variant left_value = get_agent()->get(property); +#endif result = LimboUtility::get_singleton()->perform_operation(operation, left_value, right_value); ERR_FAIL_COND_V_MSG(result == Variant(), FAILURE, "BTSetAgentProperty: Operation not valid. Returning FAILURE."); } +#ifdef LIMBOAI_MODULE get_agent()->set(property, result, &r_valid); ERR_FAIL_COND_V_MSG(!r_valid, FAILURE, vformat("BTSetAgentProperty: Couldn't set property \"%s\" with value \"%s\"", property, result)); +#endif +#ifdef LIMBOAI_GDEXTENSION + get_agent()->set(property, result); +#endif return SUCCESS; } diff --git a/bt/tasks/scene/bt_set_agent_property.h b/bt/tasks/scene/bt_set_agent_property.h index e5a4b12..e3e936e 100644 --- a/bt/tasks/scene/bt_set_agent_property.h +++ b/bt/tasks/scene/bt_set_agent_property.h @@ -14,8 +14,8 @@ #include "../bt_action.h" -#include "modules/limboai/blackboard/bb_param/bb_variant.h" -#include "modules/limboai/util/limbo_utility.h" +#include "../../../blackboard/bb_param/bb_variant.h" +#include "../../../util/limbo_utility.h" class BTSetAgentProperty : public BTAction { GDCLASS(BTSetAgentProperty, BTAction); @@ -29,11 +29,11 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; void set_property(StringName p_prop); StringName get_property() const { return property; } diff --git a/bt/tasks/scene/bt_stop_animation.cpp b/bt/tasks/scene/bt_stop_animation.cpp index 02a4ab7..5d83c2e 100644 --- a/bt/tasks/scene/bt_stop_animation.cpp +++ b/bt/tasks/scene/bt_stop_animation.cpp @@ -17,7 +17,7 @@ void BTStopAnimation::set_animation_player(Ref p_animation_player) { animation_player_param = p_animation_player; emit_changed(); if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) { - animation_player_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed"))); + animation_player_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed))); } } @@ -33,12 +33,12 @@ void BTStopAnimation::set_keep_state(bool p_keep_state) { //**** Task Implementation -PackedStringArray BTStopAnimation::get_configuration_warnings() const { +PackedStringArray BTStopAnimation::get_configuration_warnings() { PackedStringArray warnings = BTAction::get_configuration_warnings(); if (animation_player_param.is_null()) { warnings.append("Animation Player parameter is not set."); } else { - if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value().is_zero()) { + if (animation_player_param->get_value_source() == BBParam::SAVED_VALUE && animation_player_param->get_saved_value() == Variant()) { warnings.append("Path to AnimationPlayer node is not set."); } else if (animation_player_param->get_value_source() == BBParam::BLACKBOARD_VAR && animation_player_param->get_variable().is_empty()) { warnings.append("AnimationPlayer blackboard variable is not set."); @@ -47,7 +47,7 @@ PackedStringArray BTStopAnimation::get_configuration_warnings() const { return warnings; } -String BTStopAnimation::_generate_name() const { +String BTStopAnimation::_generate_name() { return "StopAnimation" + (animation_name != StringName() ? vformat(" \"%s\"", animation_name) : "") + (keep_state ? " keep_state: true" : ""); diff --git a/bt/tasks/scene/bt_stop_animation.h b/bt/tasks/scene/bt_stop_animation.h index d971415..6432ada 100644 --- a/bt/tasks/scene/bt_stop_animation.h +++ b/bt/tasks/scene/bt_stop_animation.h @@ -14,9 +14,15 @@ #include "../bt_action.h" -#include "modules/limboai/blackboard/bb_param/bb_node.h" +#include "../../../blackboard/bb_param/bb_node.h" +#ifdef LIMBOAI_MODULE #include "scene/animation/animation_player.h" +#endif + +#ifdef LIMBOAI_GDEXTENSION +#include +#endif class BTStopAnimation : public BTAction { GDCLASS(BTStopAnimation, BTAction); @@ -33,7 +39,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual void _setup() override; virtual Status _tick(double p_delta) override; @@ -47,7 +53,7 @@ public: void set_keep_state(bool p_keep_state); bool get_keep_state() const { return keep_state; } - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_STOP_ANIMATION \ No newline at end of file diff --git a/bt/tasks/utility/bt_call_method.cpp b/bt/tasks/utility/bt_call_method.cpp index 3640685..5865010 100644 --- a/bt/tasks/utility/bt_call_method.cpp +++ b/bt/tasks/utility/bt_call_method.cpp @@ -22,7 +22,7 @@ void BTCallMethod::set_node_param(Ref p_object) { node_param = p_object; emit_changed(); if (Engine::get_singleton()->is_editor_hint() && node_param.is_valid()) { - node_param->connect(SNAME("changed"), Callable(this, SNAME("emit_changed"))); + node_param->connect(LSNAME(changed), Callable(this, LSNAME(emit_changed))); } } @@ -38,14 +38,14 @@ void BTCallMethod::set_args(Array p_args) { //**** Task Implementation -PackedStringArray BTCallMethod::get_configuration_warnings() const { +PackedStringArray BTCallMethod::get_configuration_warnings() { PackedStringArray warnings = BTAction::get_configuration_warnings(); if (method == StringName()) { warnings.append("Method Name is not set."); } if (node_param.is_null()) { warnings.append("Node parameter is not set."); - } else if (node_param->get_value_source() == BBParam::SAVED_VALUE && node_param->get_saved_value().is_zero()) { + } else if (node_param->get_value_source() == BBParam::SAVED_VALUE && node_param->get_saved_value() == Variant()) { warnings.append("Path to node is not set."); } else if (node_param->get_value_source() == BBParam::BLACKBOARD_VAR && node_param->get_variable() == StringName()) { warnings.append("Node blackboard variable is not set."); @@ -53,13 +53,13 @@ PackedStringArray BTCallMethod::get_configuration_warnings() const { return warnings; } -String BTCallMethod::_generate_name() const { +String BTCallMethod::_generate_name() { String args_str = include_delta ? "delta" : ""; if (args.size() > 0) { if (!args_str.is_empty()) { args_str += ", "; } - args_str += Variant(args).get_construct_string().trim_prefix("[").trim_suffix("]"); + args_str += vformat("%s", args).trim_prefix("[").trim_suffix("]"); } return vformat("CallMethod %s(%s) node: %s", (method != StringName() ? method : "???"), @@ -73,6 +73,7 @@ BT::Status BTCallMethod::_tick(double p_delta) { Object *obj = node_param->get_value(get_agent(), get_blackboard()); ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTCallMethod: Failed to get object: " + node_param->to_string()); +#ifdef LIMBOAI_MODULE const Variant delta = include_delta ? Variant(p_delta) : Variant(); const Variant **argptrs = nullptr; @@ -92,6 +93,19 @@ BT::Status BTCallMethod::_tick(double p_delta) { if (ce.error != Callable::CallError::CALL_OK) { ERR_FAIL_V_MSG(FAILURE, "BTCallMethod: Error calling method: " + Variant::get_call_error_text(obj, method, argptrs, argument_count, ce) + "."); } +#endif // LIMBOAI_MODULE +#ifdef LIMBOAI_GDEXTENSION + Array call_args; + if (include_delta) { + call_args.push_back(Variant(p_delta)); + call_args.append_array(args); + } else { + call_args = args; + } + + // TODO: Unsure how to detect call error, so we return SUCCESS for now... + obj->callv(method, call_args); +#endif // LIMBOAI_GDEXTENSION return SUCCESS; } @@ -114,7 +128,7 @@ void BTCallMethod::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "args_include_delta"), "set_include_delta", "is_delta_included"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "args"), "set_args", "get_args"); - ADD_PROPERTY_DEFAULT("args_include_delta", false); + // ADD_PROPERTY_DEFAULT("args_include_delta", false); } BTCallMethod::BTCallMethod() { diff --git a/bt/tasks/utility/bt_call_method.h b/bt/tasks/utility/bt_call_method.h index a73cac4..e32e116 100644 --- a/bt/tasks/utility/bt_call_method.h +++ b/bt/tasks/utility/bt_call_method.h @@ -14,7 +14,7 @@ #include "../bt_action.h" -#include "modules/limboai/blackboard/bb_param/bb_node.h" +#include "../../limboai/blackboard/bb_param/bb_node.h" class BTCallMethod : public BTAction { GDCLASS(BTCallMethod, BTAction); @@ -29,7 +29,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: @@ -45,7 +45,7 @@ public: void set_include_delta(bool p_include_delta); bool is_delta_included() const { return include_delta; } - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; BTCallMethod(); }; diff --git a/bt/tasks/utility/bt_console_print.cpp b/bt/tasks/utility/bt_console_print.cpp index c74605e..6447641 100644 --- a/bt/tasks/utility/bt_console_print.cpp +++ b/bt/tasks/utility/bt_console_print.cpp @@ -11,10 +11,7 @@ #include "bt_console_print.h" -#include "core/object/object.h" -#include "core/string/print_string.h" - -String BTConsolePrint::_generate_name() const { +String BTConsolePrint::_generate_name() { String tx = text; if (text.length() > 30) { tx = text.substr(0, 30) + "..."; @@ -32,29 +29,29 @@ String BTConsolePrint::_generate_name() const { BT::Status BTConsolePrint::_tick(double p_delta) { switch (bb_format_parameters.size()) { case 0: { - print_line(text); + PRINT_LINE(text); } break; case 1: { - print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""))); + PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""))); } break; case 2: { - print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""), + PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""), get_blackboard()->get_var(bb_format_parameters[1], ""))); } break; case 3: { - print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""), + PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""), get_blackboard()->get_var(bb_format_parameters[1], ""), get_blackboard()->get_var(bb_format_parameters[2], ""))); } break; case 4: { - print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""), + PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""), get_blackboard()->get_var(bb_format_parameters[1], ""), get_blackboard()->get_var(bb_format_parameters[2], ""), get_blackboard()->get_var(bb_format_parameters[3], ""))); } break; case 5: default: { - print_line(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""), + PRINT_LINE(vformat(text, get_blackboard()->get_var(bb_format_parameters[0], ""), get_blackboard()->get_var(bb_format_parameters[1], ""), get_blackboard()->get_var(bb_format_parameters[2], ""), get_blackboard()->get_var(bb_format_parameters[3], ""), @@ -64,7 +61,7 @@ BT::Status BTConsolePrint::_tick(double p_delta) { return SUCCESS; } -PackedStringArray BTConsolePrint::get_configuration_warnings() const { +PackedStringArray BTConsolePrint::get_configuration_warnings() { PackedStringArray warnings = BTAction::get_configuration_warnings(); if (bb_format_parameters.size() > 5) { warnings.append("ConsolePrint supports up to 5 format arguments."); diff --git a/bt/tasks/utility/bt_console_print.h b/bt/tasks/utility/bt_console_print.h index 1ebc281..bbde225 100644 --- a/bt/tasks/utility/bt_console_print.h +++ b/bt/tasks/utility/bt_console_print.h @@ -14,8 +14,6 @@ #include "../bt_action.h" -#include "core/variant/variant.h" - class BTConsolePrint : public BTAction { GDCLASS(BTConsolePrint, BTAction); TASK_CATEGORY(Utility); @@ -27,7 +25,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: @@ -43,7 +41,7 @@ public: } PackedStringArray get_bb_format_parameters() const { return bb_format_parameters; } - virtual PackedStringArray get_configuration_warnings() const override; + virtual PackedStringArray get_configuration_warnings() override; }; #endif // BT_CONSOLE_PRINT_H \ No newline at end of file diff --git a/bt/tasks/utility/bt_random_wait.cpp b/bt/tasks/utility/bt_random_wait.cpp index 90d2727..ae2e102 100644 --- a/bt/tasks/utility/bt_random_wait.cpp +++ b/bt/tasks/utility/bt_random_wait.cpp @@ -11,16 +11,14 @@ #include "bt_random_wait.h" -#include "core/math/math_funcs.h" - -String BTRandomWait::_generate_name() const { +String BTRandomWait::_generate_name() { return vformat("Wait %s to %s sec", Math::snapped(min_duration, 0.001), Math::snapped(max_duration, 0.001)); } void BTRandomWait::_enter() { - duration = Math::random(min_duration, max_duration); + duration = RAND_RANGE(min_duration, max_duration); } BT::Status BTRandomWait::_tick(double p_delta) { diff --git a/bt/tasks/utility/bt_random_wait.h b/bt/tasks/utility/bt_random_wait.h index af47902..c6ddca5 100644 --- a/bt/tasks/utility/bt_random_wait.h +++ b/bt/tasks/utility/bt_random_wait.h @@ -27,7 +27,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual void _enter() override; virtual Status _tick(double p_delta) override; diff --git a/bt/tasks/utility/bt_wait.cpp b/bt/tasks/utility/bt_wait.cpp index 5dd1776..585b584 100644 --- a/bt/tasks/utility/bt_wait.cpp +++ b/bt/tasks/utility/bt_wait.cpp @@ -11,12 +11,7 @@ #include "bt_wait.h" -#include "core/math/math_funcs.h" -#include "core/object/class_db.h" -#include "core/object/object.h" -#include "core/variant/variant.h" - -String BTWait::_generate_name() const { +String BTWait::_generate_name() { return vformat("Wait %s sec", Math::snapped(duration, 0.001)); } diff --git a/bt/tasks/utility/bt_wait.h b/bt/tasks/utility/bt_wait.h index 462be07..e749518 100644 --- a/bt/tasks/utility/bt_wait.h +++ b/bt/tasks/utility/bt_wait.h @@ -24,7 +24,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual Status _tick(double p_delta) override; public: diff --git a/bt/tasks/utility/bt_wait_ticks.cpp b/bt/tasks/utility/bt_wait_ticks.cpp index 6d78aca..3ff04a2 100644 --- a/bt/tasks/utility/bt_wait_ticks.cpp +++ b/bt/tasks/utility/bt_wait_ticks.cpp @@ -11,10 +11,7 @@ #include "bt_wait_ticks.h" -#include "core/object/object.h" -#include "core/variant/variant.h" - -String BTWaitTicks::_generate_name() const { +String BTWaitTicks::_generate_name() { return vformat("WaitTicks x%d", num_ticks); } diff --git a/bt/tasks/utility/bt_wait_ticks.h b/bt/tasks/utility/bt_wait_ticks.h index 9682eb8..92ec093 100644 --- a/bt/tasks/utility/bt_wait_ticks.h +++ b/bt/tasks/utility/bt_wait_ticks.h @@ -26,7 +26,7 @@ private: protected: static void _bind_methods(); - virtual String _generate_name() const override; + virtual String _generate_name() override; virtual void _enter() override; virtual Status _tick(double p_delta) override; diff --git a/util/limbo_def.h b/util/limbo_def.h new file mode 100644 index 0000000..ab34413 --- /dev/null +++ b/util/limbo_def.h @@ -0,0 +1,32 @@ +#/** + * limbo_def.h + * ============================================================================= + * Copyright 2021-2024 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. + * ============================================================================= + */ + +#ifdef LIMBOAI_MODULE + +#include "core/string/print_string.h" + +#define IS_CLASS(m_obj, m_class) (m_obj->is_class_ptr(m_class::get_class_ptr_static())) +#define RAND_RANGE(m_from, m_to) (Math::random(m_from, m_to)) +#define RANDF() (Math::randf()) +#define PRINT_LINE(...) (print_line(__VA_ARGS__)) + +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION + +#include + +#define IS_CLASS(m_obj, m_class) (m_obj->get_class_static() == m_class::get_class_static()) +#define RAND_RANGE(m_from, m_to) (UtilityFunctions::randf_range(m_from, m_to)) +#define RANDF() (UtilityFunctions::randf()) +#define PRINT_LINE(...) (UtilityFunctions::print(__VA_ARGS__)) + +#endif // LIMBOAI_GDEXTENSION \ No newline at end of file diff --git a/util/limbo_string_names.cpp b/util/limbo_string_names.cpp index adc6057..2536020 100644 --- a/util/limbo_string_names.cpp +++ b/util/limbo_string_names.cpp @@ -28,4 +28,10 @@ LimboStringNames::LimboStringNames() { _update = StringName("_update"); state_changed = StringName("state_changed"); _get_configuration_warning = StringName("_get_configuration_warning"); + changed = StringName("changed"); + changed = StringName("emit_changed"); + _weight_ = StringName("_weight_"); + error_value = StringName("error_value"); + + repeat_forever.parse_utf8("Repeat ∞"); } \ No newline at end of file diff --git a/util/limbo_string_names.h b/util/limbo_string_names.h index e5802c8..7dc2eb3 100644 --- a/util/limbo_string_names.h +++ b/util/limbo_string_names.h @@ -53,6 +53,14 @@ public: StringName _update; StringName state_changed; StringName _get_configuration_warning; + StringName changed; + StringName emit_changed; + StringName _weight_; + StringName error_value; + + String repeat_forever; }; +#define LSNAME(m_arg) LimboStringNames::get_singleton()->m_arg + #endif // LIMBO_STRING_NAMES_H \ No newline at end of file From 0767c0eee148e4a46f43c5c6047c2b8a911f368d Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sun, 7 Jan 2024 02:40:51 +0100 Subject: [PATCH 04/42] Port BTPlayer and LimboDebugger (game-side part) --- bt/bt_player.cpp | 39 +++++++++++++------ bt/bt_player.h | 8 +++- editor/debugger/behavior_tree_data.cpp | 5 ++- editor/debugger/behavior_tree_data.h | 2 +- editor/debugger/limbo_debugger.cpp | 52 +++++++++++++++++++++----- editor/debugger/limbo_debugger.h | 16 +++++++- util/limbo_def.h | 4 ++ util/limbo_string_names.cpp | 1 + util/limbo_string_names.h | 1 + 9 files changed, 102 insertions(+), 26 deletions(-) diff --git a/bt/bt_player.cpp b/bt/bt_player.cpp index 669cc83..cd48cd0 100644 --- a/bt/bt_player.cpp +++ b/bt/bt_player.cpp @@ -11,9 +11,10 @@ #include "bt_player.h" -#include "modules/limboai/blackboard/blackboard.h" -#include "modules/limboai/editor/debugger/limbo_debugger.h" -#include "modules/limboai/util/limbo_string_names.h" +#include "../editor/debugger/limbo_debugger.h" +#include "../util/limbo_string_names.h" + +#ifdef LIMBOAI_MODULE #include "core/config/engine.h" #include "core/debugger/engine_debugger.h" @@ -25,11 +26,27 @@ #include "core/variant/variant.h" #include "main/performance.h" +#define IS_DEBUGGER_ACTIVE() (EngineDebugger::is_active()) +#define GET_TICKS_USEC() (OS::get_singleton()->get_ticks_usec()) + +#endif // LIMBO_MODULE + +#ifdef LIMBOAI_GDEXTENSION + +#include +#include +#include + +#define IS_DEBUGGER_ACTIVE() (EngineDebugger::get_singleton()->is_active()) +#define GET_TICKS_USEC() (Time::get_singleton()->get_ticks_usec()) + +#endif // LIMBOAI_GDEXTENSION + VARIANT_ENUM_CAST(BTPlayer::UpdateMode); void BTPlayer::_load_tree() { #ifdef DEBUG_ENABLED - if (tree_instance.is_valid() && EngineDebugger::is_active()) { + if (tree_instance.is_valid() && IS_DEBUGGER_ACTIVE()) { LimboDebugger::get_singleton()->unregister_bt_instance(tree_instance, get_path()); } #endif @@ -41,7 +58,7 @@ void BTPlayer::_load_tree() { } tree_instance = behavior_tree->instantiate(get_owner(), blackboard); #ifdef DEBUG_ENABLED - if (EngineDebugger::is_active()) { + if (IS_DEBUGGER_ACTIVE()) { LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path()); } #endif @@ -74,7 +91,7 @@ void BTPlayer::update(double p_delta) { } #ifdef DEBUG_ENABLED - double start = OS::get_singleton()->get_ticks_usec(); + double start = GET_TICKS_USEC(); #endif if (active) { @@ -86,7 +103,7 @@ void BTPlayer::update(double p_delta) { } #ifdef DEBUG_ENABLED - double end = OS::get_singleton()->get_ticks_usec(); + double end = GET_TICKS_USEC(); update_time_acc += (end - start); update_time_n += 1.0; #endif @@ -113,7 +130,7 @@ void BTPlayer::_set_monitor_performance(bool p_monitor_performance) { String(itos(get_instance_id())).md5_text().substr(0, 4)); } if (!perf->has_custom_monitor(monitor_id)) { - perf->add_custom_monitor(monitor_id, callable_mp(this, &BTPlayer::_get_mean_update_time_msec), Vector()); + perf->add_custom_monitor(monitor_id, callable_mp(this, &BTPlayer::_get_mean_update_time_msec)); } } else if (monitor_id != StringName() && perf->has_custom_monitor(monitor_id)) { perf->remove_custom_monitor(monitor_id); @@ -155,12 +172,12 @@ void BTPlayer::_notification(int p_notification) { } break; #ifdef DEBUG_ENABLED case NOTIFICATION_ENTER_TREE: { - if (tree_instance.is_valid() && EngineDebugger::is_active()) { + if (tree_instance.is_valid() && IS_DEBUGGER_ACTIVE()) { LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path()); } } break; case NOTIFICATION_EXIT_TREE: { - if (tree_instance.is_valid() && EngineDebugger::is_active()) { + if (tree_instance.is_valid() && IS_DEBUGGER_ACTIVE()) { LimboDebugger::get_singleton()->unregister_bt_instance(tree_instance, get_path()); } } break; @@ -205,7 +222,7 @@ void BTPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_monitor_performance", "p_value"), &BTPlayer::_set_monitor_performance); ClassDB::bind_method(D_METHOD("_get_monitor_performance"), &BTPlayer::_get_monitor_performance); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitor_performance"), "_set_monitor_performance", "_get_monitor_performance"); - ADD_PROPERTY_DEFAULT("monitor_performance", false); + // ADD_PROPERTY_DEFAULT("monitor_performance", false); #endif // DEBUG_ENABLED } diff --git a/bt/bt_player.h b/bt/bt_player.h index 63bdd61..4c45438 100644 --- a/bt/bt_player.h +++ b/bt/bt_player.h @@ -12,10 +12,16 @@ #ifndef BT_PLAYER_H #define BT_PLAYER_H +#ifdef LIMBOAI_MODULE #include "scene/main/node.h" +#endif +#ifdef LIMBOAI_GDEXTENSION +#include +#endif + +#include "../blackboard/blackboard.h" #include "behavior_tree.h" -#include "modules/limboai/blackboard/blackboard.h" #include "tasks/bt_task.h" class BTPlayer : public Node { diff --git a/editor/debugger/behavior_tree_data.cpp b/editor/debugger/behavior_tree_data.cpp index 2aeae1f..932bcec 100644 --- a/editor/debugger/behavior_tree_data.cpp +++ b/editor/debugger/behavior_tree_data.cpp @@ -11,8 +11,9 @@ #include "behavior_tree_data.h" -#include "core/object/script_language.h" +#ifdef LIMBOAI_MODULE #include "core/templates/list.h" +#endif //// BehaviorTreeData @@ -76,7 +77,7 @@ BehaviorTreeData::BehaviorTreeData(const Ref &p_instance, const NodePath String script_path; if (task->get_script()) { - Ref