diff --git a/SCsub b/SCsub index 136a438..9c5b70d 100644 --- a/SCsub +++ b/SCsub @@ -5,6 +5,8 @@ Import("env_modules") module_env = env.Clone() +module_env.Append(CPPDEFINES = ['LIMBOAI_MODULE']) + module_env.add_source_files(env.modules_sources, "*.cpp") module_env.add_source_files(env.modules_sources, "blackboard/*.cpp") module_env.add_source_files(env.modules_sources, "blackboard/bb_param/*.cpp") diff --git a/blackboard/bb_param/bb_param.cpp b/blackboard/bb_param/bb_param.cpp index b68ef68..5a2310d 100644 --- a/blackboard/bb_param/bb_param.cpp +++ b/blackboard/bb_param/bb_param.cpp @@ -111,7 +111,6 @@ void BBParam::_bind_methods() { ClassDB::bind_method(D_METHOD("get_variable"), &BBParam::get_variable); ClassDB::bind_method(D_METHOD("get_type"), &BBParam::get_type); ClassDB::bind_method(D_METHOD("get_value", "p_agent", "p_blackboard", "p_default"), &BBParam::get_value, Variant()); - ClassDB::bind_method(D_METHOD("_to_string"), &BBParam::_to_string); ADD_PROPERTY(PropertyInfo(Variant::INT, "value_source", PROPERTY_HINT_ENUM, "Saved Value,Blackboard Var"), "set_value_source", "get_value_source"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable", PROPERTY_HINT_NONE, "", 0), "set_variable", "get_variable"); diff --git a/bt/behavior_tree.cpp b/bt/behavior_tree.cpp index d1e4246..b3300b5 100644 --- a/bt/behavior_tree.cpp +++ b/bt/behavior_tree.cpp @@ -31,7 +31,7 @@ Ref BehaviorTree::clone() const { return copy; } -void BehaviorTree::copy_from(const Ref &p_other) { +void BehaviorTree::copy_other(const Ref &p_other) { ERR_FAIL_COND(p_other.is_null()); description = p_other->get_description(); root_task = p_other->get_root_task(); @@ -50,7 +50,7 @@ void BehaviorTree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_root_task", "p_value"), &BehaviorTree::set_root_task); ClassDB::bind_method(D_METHOD("get_root_task"), &BehaviorTree::get_root_task); ClassDB::bind_method(D_METHOD("clone"), &BehaviorTree::clone); - ClassDB::bind_method(D_METHOD("copy_from", "p_other"), &BehaviorTree::copy_from); + ClassDB::bind_method(D_METHOD("copy_other", "p_other"), &BehaviorTree::copy_other); ClassDB::bind_method(D_METHOD("instantiate", "p_agent", "p_blackboard"), &BehaviorTree::instantiate); ADD_PROPERTY(PropertyInfo(Variant::STRING, "description", PROPERTY_HINT_MULTILINE_TEXT), "set_description", "get_description"); diff --git a/bt/behavior_tree.h b/bt/behavior_tree.h index 5ede279..ab1d57f 100644 --- a/bt/behavior_tree.h +++ b/bt/behavior_tree.h @@ -52,7 +52,7 @@ public: Ref get_root_task() const { return root_task; } Ref clone() const; - void copy_from(const Ref &p_other); + void copy_other(const Ref &p_other); Ref instantiate(Node *p_agent, const Ref &p_blackboard) const; }; diff --git a/bt/bt_player.cpp b/bt/bt_player.cpp index cd48cd0..80a7e6d 100644 --- a/bt/bt_player.cpp +++ b/bt/bt_player.cpp @@ -12,6 +12,7 @@ #include "bt_player.h" #include "../editor/debugger/limbo_debugger.h" +#include "../util/limbo_compat.h" #include "../util/limbo_string_names.h" #ifdef LIMBOAI_MODULE @@ -130,7 +131,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)); + PERFORMANCE_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); diff --git a/bt/tasks/bt_task.h b/bt/tasks/bt_task.h index 11be49b..8950686 100644 --- a/bt/tasks/bt_task.h +++ b/bt/tasks/bt_task.h @@ -12,11 +12,12 @@ #ifndef BTTASK_H #define BTTASK_H -#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 "../../blackboard/blackboard.h" +#include "../../util/limbo_compat.h" +#include "../../util/limbo_string_names.h" +#include "../../util/limbo_task_db.h" +#ifdef LIMBOAI_MODULE #include "core/config/engine.h" #include "core/error/error_macros.h" #include "core/io/resource.h" @@ -31,21 +32,16 @@ #include "core/variant/binder_common.h" #include "core/variant/dictionary.h" #include "scene/resources/texture.h" -#endif // LIMBOAI_MODULE +#endif // ! LIMBOAI_MODULE #ifdef LIMBOAI_GDEXTENSION -#include "blackboard/blackboard.h" -#include "util/limbo_compat.h" -#include "util/limbo_string_names.h" -#include "util/limbo_task_db.h" - #include #include #include #include using namespace godot; -#endif // LIMBOAI_GDEXTENSION +#endif // ! LIMBOAI_GDEXTENSION /** * Base class for BTTask. diff --git a/bt/tasks/composites/bt_probability_selector.cpp b/bt/tasks/composites/bt_probability_selector.cpp index 826dd42..4b8eb14 100644 --- a/bt/tasks/composites/bt_probability_selector.cpp +++ b/bt/tasks/composites/bt_probability_selector.cpp @@ -10,7 +10,8 @@ */ #include "bt_probability_selector.h" -#include "godot_cpp/variant/utility_functions.hpp" + +#include "../../../util/limbo_compat.h" double BTProbabilitySelector::get_weight(int p_index) const { ERR_FAIL_INDEX_V(p_index, get_child_count(), 0.0); diff --git a/bt/tasks/composites/bt_probability_selector.h b/bt/tasks/composites/bt_probability_selector.h index 47754c2..c20507b 100644 --- a/bt/tasks/composites/bt_probability_selector.h +++ b/bt/tasks/composites/bt_probability_selector.h @@ -12,6 +12,7 @@ #ifndef BT_PROBABILITY_SELECTOR_H #define BT_PROBABILITY_SELECTOR_H +#include "../../../util/limbo_compat.h" #include "../bt_comment.h" #include "../bt_composite.h" diff --git a/bt/tasks/decorators/bt_probability.cpp b/bt/tasks/decorators/bt_probability.cpp index 6aa4dbd..847143b 100644 --- a/bt/tasks/decorators/bt_probability.cpp +++ b/bt/tasks/decorators/bt_probability.cpp @@ -11,6 +11,8 @@ #include "bt_probability.h" +#include "../../../util/limbo_compat.h" + void BTProbability::set_run_chance(float p_value) { run_chance = p_value; emit_changed(); diff --git a/bt/tasks/decorators/bt_repeat.cpp b/bt/tasks/decorators/bt_repeat.cpp index 0bcf983..202d07f 100644 --- a/bt/tasks/decorators/bt_repeat.cpp +++ b/bt/tasks/decorators/bt_repeat.cpp @@ -10,7 +10,8 @@ */ #include "bt_repeat.h" -#include "util/limbo_string_names.h" + +#include "../../../util/limbo_string_names.h" String BTRepeat::_generate_name() { if (forever) { diff --git a/bt/tasks/utility/bt_call_method.cpp b/bt/tasks/utility/bt_call_method.cpp index c0af443..7c3bb22 100644 --- a/bt/tasks/utility/bt_call_method.cpp +++ b/bt/tasks/utility/bt_call_method.cpp @@ -11,6 +11,8 @@ #include "bt_call_method.h" +#include "../../../util/limbo_compat.h" + //**** Setters / Getters void BTCallMethod::set_method(StringName p_method_name) { diff --git a/bt/tasks/utility/bt_call_method.h b/bt/tasks/utility/bt_call_method.h index e32e116..5c3cae3 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 "../../limboai/blackboard/bb_param/bb_node.h" +#include "../../../limboai/blackboard/bb_param/bb_node.h" class BTCallMethod : public BTAction { GDCLASS(BTCallMethod, BTAction); diff --git a/bt/tasks/utility/bt_console_print.cpp b/bt/tasks/utility/bt_console_print.cpp index 6447641..ae866b0 100644 --- a/bt/tasks/utility/bt_console_print.cpp +++ b/bt/tasks/utility/bt_console_print.cpp @@ -11,6 +11,8 @@ #include "bt_console_print.h" +#include "../../../util/limbo_compat.h" + String BTConsolePrint::_generate_name() { String tx = text; if (text.length() > 30) { diff --git a/bt/tasks/utility/bt_random_wait.cpp b/bt/tasks/utility/bt_random_wait.cpp index ae2e102..c2bf74b 100644 --- a/bt/tasks/utility/bt_random_wait.cpp +++ b/bt/tasks/utility/bt_random_wait.cpp @@ -11,6 +11,8 @@ #include "bt_random_wait.h" +#include "../../../util/limbo_compat.h" + String BTRandomWait::_generate_name() { return vformat("Wait %s to %s sec", Math::snapped(min_duration, 0.001), diff --git a/editor/action_banner.cpp b/editor/action_banner.cpp index dc21de4..207ab94 100644 --- a/editor/action_banner.cpp +++ b/editor/action_banner.cpp @@ -11,16 +11,15 @@ #include "action_banner.h" +#include "../util/limbo_compat.h" +#include "../util/limbo_string_names.h" + #ifdef LIMBOAI_MODULE #include "scene/gui/button.h" #endif // LIMBOAI_MODULE #ifdef LIMBOAI_GDEXTENSION -#include "../util/limbo_compat.h" -#include "../util/limbo_string_names.h" - #include - #endif // ! LIMBOAI_GDEXTENSION void ActionBanner::set_text(const String &p_text) { diff --git a/editor/debugger/limbo_debugger.cpp b/editor/debugger/limbo_debugger.cpp index 45ea87c..bfad1cc 100644 --- a/editor/debugger/limbo_debugger.cpp +++ b/editor/debugger/limbo_debugger.cpp @@ -12,6 +12,7 @@ #include "limbo_debugger.h" #include "../../bt/tasks/bt_task.h" +#include "../../util/limbo_compat.h" #include "behavior_tree_data.h" #ifdef LIMBOAI_MODULE @@ -88,11 +89,13 @@ Error LimboDebugger::parse_message(void *p_user, const String &p_msg, const Arra return OK; } +#ifdef LIMBOAI_GDEXTENSION bool LimboDebugger::parse_message_gdext(const String &p_msg, const Array &p_args) { bool r_captured; LimboDebugger::parse_message(nullptr, p_msg, p_args, r_captured); return r_captured; } +#endif // LIMBOAI_MODULE void LimboDebugger::register_bt_instance(Ref p_instance, NodePath p_player_path) { ERR_FAIL_COND(p_instance.is_null()); diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 3291121..8e96c55 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -191,7 +191,11 @@ void LimboAIEditor::_new_bt() { void LimboAIEditor::_save_bt(String p_path) { ERR_FAIL_COND_MSG(p_path.is_empty(), "Empty p_path"); ERR_FAIL_COND_MSG(task_tree->get_bt().is_null(), "Behavior Tree is null."); +#ifdef LIMBOAI_MODULE + task_tree->get_bt()->set_path(p_path, true); +#else // LIMBOAI_GDEXTENSION task_tree->get_bt()->take_over_path(p_path); +#endif // LIMBOAI_MODULE RESOURCE_SAVE(task_tree->get_bt(), p_path, ResourceSaver::FLAG_CHANGE_PATH); _update_header(); _mark_as_dirty(false); @@ -760,7 +764,7 @@ void LimboAIEditor::_on_resources_reload(const PackedStringArray &p_resources) { disk_changed_files.insert(res_path); } else { Ref reloaded = RESOURCE_LOAD_NO_CACHE(res_path, "BehaviorTree"); - res->copy_from(reloaded); + res->copy_other(reloaded); } } } @@ -849,7 +853,7 @@ void LimboAIEditor::_reload_modified() { Ref res = RESOURCE_LOAD(res_path, "BehaviorTree"); if (res.is_valid()) { Ref reloaded = RESOURCE_LOAD_NO_CACHE(res_path, "BehaviorTree"); - res->copy_from(reloaded); + res->copy_other(reloaded); if (idx_history >= 0 && history.get(idx_history) == res) { edit_bt(res, true); } diff --git a/editor/mode_switch_button.h b/editor/mode_switch_button.h index d5072f4..c2a3ec4 100644 --- a/editor/mode_switch_button.h +++ b/editor/mode_switch_button.h @@ -12,6 +12,8 @@ #ifndef MODE_SWITCH_BUTTON #define MODE_SWITCH_BUTTON +#include "../util/limbo_compat.h" + #ifdef LIMBOAI_MODULE #include "scene/gui/button.h" @@ -28,8 +30,6 @@ using namespace godot; -#define SET_BUTTON_ICON(m_tex) set_button_icon(m_tex) - #endif // LIMBOAI_GDEXTENSION class ModeSwitchButton : public Button { @@ -47,7 +47,7 @@ private: _FORCE_INLINE_ void _set_mode_by_index(int p_index) { current_mode_index = p_index; - SET_BUTTON_ICON(modes[current_mode_index].icon); + BUTTON_SET_ICON(this, modes[current_mode_index].icon); if (!modes[current_mode_index].tooltip.is_empty()) { set_tooltip_text(modes[current_mode_index].tooltip); } diff --git a/editor/task_palette.cpp b/editor/task_palette.cpp index 5a923cd..346d019 100644 --- a/editor/task_palette.cpp +++ b/editor/task_palette.cpp @@ -16,7 +16,7 @@ #include "../util/limbo_task_db.h" #include "../util/limbo_utility.h" -#ifdef LIMBO_MODULE +#ifdef LIMBOAI_MODULE #include "core/config/project_settings.h" #include "core/error/error_macros.h" #include "editor/editor_help.h" @@ -29,7 +29,6 @@ #endif // LIMBO_MODULE #ifdef LIMBOAI_GDEXTENSION -#include "godot_cpp/core/error_macros.hpp" #include #include #include @@ -48,6 +47,7 @@ #include #include #include +#include using namespace godot; #endif // LIMBOAI_GDEXTENSION diff --git a/gdextension/window_wrapper.h b/gdextension/window_wrapper.h index 5aed1d5..2bce17e 100644 --- a/gdextension/window_wrapper.h +++ b/gdextension/window_wrapper.h @@ -30,13 +30,22 @@ // * This is a port of a WindowWrapper from the Godot Engine to use with godot-cpp. -#ifdef LIMBOAI_GDEXTENSION - #ifndef COMPAT_WINDOW_WRAPPER_H #define COMPAT_WINDOW_WRAPPER_H +#ifdef LIMBOAI_MODULE +#include "editor/window_wrapper.h" + +#define CompatWindowWrapper WindowWrapper +#define CompatShortcutBin ShortcutBin +#define CompatScreenSelect ScreenSelect + +#endif // ! LIMBOAI_MODULE + // TODO: Need to compile this as module too!!! +#ifdef LIMBOAI_GDEXTENSION + #include #include #include @@ -133,6 +142,6 @@ public: CompatScreenSelect(); }; -#endif // ! COMPAT_WINDOW_WRAPPER_H - #endif // ! LIMBOAI_GDEXTENSION + +#endif // ! COMPAT_WINDOW_WRAPPER_H diff --git a/register_types.cpp b/register_types.cpp index 64bb980..421beff 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -279,5 +279,5 @@ GDExtensionBool GDE_EXPORT limboai_init(GDExtensionInterfaceGetProcAddress p_get return init_obj.init(); } -#endif // ! LIMBOAI_GDEXTENSION } +#endif // ! LIMBOAI_GDEXTENSION diff --git a/util/limbo_compat.cpp b/util/limbo_compat.cpp index 5bc78c8..2fbb11e 100644 --- a/util/limbo_compat.cpp +++ b/util/limbo_compat.cpp @@ -13,13 +13,11 @@ #ifdef LIMBOAI_MODULE -void EDIT_SCRIPT(const String &p_path) { - Ref res = ScriptEditor::get_singleton()->open_file(p_path); - ERR_FAIL_COND_MSG(res.is_null(), "Failed to load script: " + p_path); - EditorNode::get_singleton()->edit_resource(res); -} +#include "core/io/resource.h" +#include "editor/editor_node.h" +#include "editor/plugins/script_editor_plugin.h" -#endif // LIMBOAI_MODULE +#endif // ! LIMBOAI_MODULE #ifdef LIMBOAI_GDEXTENSION @@ -51,10 +49,6 @@ String TTR(const String &p_text, const String &p_context) { } void EDIT_SCRIPT(const String &p_path) { - Ref