diff --git a/.github/actions/init-version-gdext/action.yml b/.github/actions/init-version-gdext/action.yml new file mode 100644 index 0000000..6a2a805 --- /dev/null +++ b/.github/actions/init-version-gdext/action.yml @@ -0,0 +1,24 @@ +name: Setup version + +runs: + using: "composite" + steps: + - name: Set GDEXTENSION_VERSION & LIMBOAI_VERSION + shell: bash + run: | + cd godot-cpp + GDEXTENSION_VERSION=$( (git describe --tags --exact-match HEAD || git rev-parse --short HEAD) | sed 's/\(.*\)-\(.*\)/\1/g' ) + + if [[ ${GDEXTENSION_VERSION} == godot-* ]]; then + GDEXTENSION_VERSION=${GDEXTENSION_VERSION#"godot-"} + fi + + echo "GDEXTENSION_VERSION=${GDEXTENSION_VERSION}" >> "$GITHUB_ENV" + + cd ../limboai + echo "LIMBOAI_VERSION=$( (git describe --tags --exact-match HEAD || git rev-parse --short HEAD) | sed 's/\(.*\)-\(.*\)/\1/g' )" >> "$GITHUB_ENV" + + - name: Set NAME_PREFIX + shell: bash + run: echo "NAME_PREFIX=gdextension-${GDEXTENSION_VERSION}.limboai+${LIMBOAI_VERSION}" >> "$GITHUB_ENV" + diff --git a/.github/workflows/gdextension.yml b/.github/workflows/gdextension.yml new file mode 100644 index 0000000..bb82542 --- /dev/null +++ b/.github/workflows/gdextension.yml @@ -0,0 +1,209 @@ +name: 🔌 GDExtension +on: + workflow_call: + inputs: + godot-cpp-treeish: + description: A tag, branch or commit hash in the godot-cpp repository. + type: string + default: 4.2 + limboai-treeish: + description: A tag, branch or commit hash in the LimboAI repository. + type: string + default: master + test-build: + description: Should we perform only a limited number of test builds? + type: boolean + default: false + + workflow_dispatch: + inputs: + godot-cpp-treeish: + description: A tag, branch or commit hash in the godot-cpp repository. + type: string + default: 4.2 + limboai-treeish: + description: A tag, branch or commit hash in the LimboAI repository. + type: string + default: master + test-build: + description: Should we perform only a limited number of test builds? + type: boolean + default: false + +# Global Settings +env: + SCONS_CACHE_LIMIT: 4096 + SCONSFLAGS: dev_build=no debug_symbols=no + +jobs: + gdextension: + runs-on: ${{ matrix.opts.runner }} + name: ${{ matrix.opts.name }} + strategy: + fail-fast: false + matrix: + opts: + - name: 🐧 Linux (x86_64, release) + runner: ubuntu-20.04 + platform: linux + target: template_release + arch: x86_64 + should-build: true + + - name: 🐧 Linux (x86_64, debug) + runner: ubuntu-20.04 + platform: linux + target: editor + arch: x86_64 + should-build: true + + - name: 🪟 Windows (x86_64, release) + runner: windows-latest + platform: windows + target: template_release + arch: x86_64 + should-build: true + + - name: 🪟 Windows (x86_64, debug) + runner: windows-latest + platform: windows + target: editor + arch: x86_64 + should-build: true + + - name: 🍎 macOS (universal, release) + runner: macos-latest + platform: macos + target: template_release + arch: universal + should-build: true + + - name: 🍎 macOS (universal, debug) + runner: macos-latest + platform: macos + target: editor + arch: universal + should-build: true + + exclude: + - { opts: {should-build: false }} + + env: + BIN: liblimboai.${{matrix.opts.platform}}.${{matrix.opts.target}}.${{matrix.opts.arch}} + + steps: + - name: Clone godot-cpp + uses: actions/checkout@v4 + with: + repository: godotengine/godot-cpp + fetch-tags: true + path: godot-cpp + ref: ${{ inputs.godot-cpp-treeish }} + + - name: Clone LimboAI module + uses: actions/checkout@v4 + with: + path: limboai + fetch-tags: true + ref: ${{ inputs.limboai-treeish }} + + # Inits GDEXTENSION_VERSION, LIMBOAI_VERSION and NAME_PREFIX environment variables. + - uses: ./limboai/.github/actions/init-version-gdext + + - name: Set up Linux buildroot x86_64 + if: matrix.opts.platform == 'linux' && matrix.opts.arch == 'x86_64' + run: | + wget https://download.tuxfamily.org/godotengine/toolchains/linux/x86_64-godot-linux-gnu_sdk-buildroot.tar.bz2 + tar -xjf x86_64-godot-linux-gnu_sdk-buildroot.tar.bz2 + mv x86_64-godot-linux-gnu_sdk-buildroot buildroot + cd buildroot + ./relocate-sdk.sh + cd .. + + - name: Set up Linux buildroot x86_32 + if: matrix.opts.platform == 'linux' && matrix.opts.arch == 'x86_32' + run: | + wget https://download.tuxfamily.org/godotengine/toolchains/linux/i686-godot-linux-gnu_sdk-buildroot.tar.bz2 + tar -xjf i686-godot-linux-gnu_sdk-buildroot.tar.bz2 + mv i686-godot-linux-gnu_sdk-buildroot buildroot + cd buildroot + ./relocate-sdk.sh + cd .. + + - name: Set up Python 3.x + if: matrix.opts.platform == 'windows' || matrix.opts.platform == 'macos' + uses: actions/setup-python@v4 + with: + python-version: '3.x' + architecture: 'x64' + + - name: Set up scons + if: matrix.opts.platform == 'windows' || matrix.opts.platform == 'macos' + run: | + python -c "import sys; print(sys.version)" + python -m pip install scons==4.4.0 + python --version + scons --version + + - name: Set up MSVC problem matcher on Windows + if: matrix.opts.platform == 'windows' + uses: ammaraskar/msvc-problem-matcher@master + + - name: Set up scons cache + uses: actions/cache@v3 + with: + path: ${{github.workspace}}/.scons_cache/ + key: ${{env.BIN}}-${{inputs.godot-cpp-treeish}}-${{inputs.limboai-treeish}}-${{env.LIMBOAI_VERSION}} + restore-keys: | + ${{env.BIN}}-${{inputs.godot-cpp-treeish}}-${{inputs.limboai-treeish}}-${{env.LIMBOAI_VERSION}} + ${{env.BIN}}-${{inputs.godot-cpp-treeish}}-${{inputs.limboai-treeish}} + ${{env.BIN}}-${{inputs.godot-cpp-treeish}} + + - name: Setup project structure for GDExtension + shell: bash + run: | + python ./limboai/gdextension/update_icons.py + mkdir -p demo/addons/limboai/bin + mv limboai/icons demo/addons/limboai/ + cp limboai/gdextension/SConstruct SConstruct + cp limboai/gdextension/limboai.gdextension demo/addons/limboai/bin + echo "---" + ls -l + ls -l -R ./demo/ + + - name: Compilation + shell: bash + env: + SCONS_CACHE: ${{github.workspace}}/.scons_cache/ + run: | + PATH=${GITHUB_WORKSPACE}/buildroot/bin:$PATH + scons platform=${{matrix.opts.platform}} target=${{matrix.opts.target}} arch=${{matrix.opts.arch}} ${{env.SCONSFLAGS}} + + - name: Prepare artifact + shell: bash + run: | + mkdir out + mv demo/addons/ out/ + rm -f out/addons/limboai/bin/*.{exp,lib,pdb} + ls -R out/ + + - name: Strip lib + if: matrix.opts.platform != 'windows' + run: | + ls -l -R out/addons/limboai/bin/ + echo "---" + if [ "$RUNNER_OS" == "macOS" ]; then + strip -u out/addons/limboai/bin/liblimboai*/liblimboai* + else + strip out/addons/limboai/bin/liblimboai* + fi + echo "---" + ls -l -R out/addons/limboai/bin/ + + - name: Upload artifact + uses: actions/upload-artifact@v3 + env: + NAME: ${{env.NAME_PREFIX}} + with: + name: ${{ env.NAME }} + path: out/* diff --git a/.github/workflows/test_builds.yml b/.github/workflows/test_builds.yml index 1ae3d0f..c0cf874 100644 --- a/.github/workflows/test_builds.yml +++ b/.github/workflows/test_builds.yml @@ -10,11 +10,6 @@ on: - "**/*.png" - "demo/*" - "doc/*" - inputs: - godot-treeish: - description: A tag, branch or commit hash in the Godot repository. - type: string - default: 4.2.1-stable pull_request: branches: [ master ] @@ -23,11 +18,12 @@ on: - "LICENSE" - "**/*.png" - "demo/*" - inputs: - godot-treeish: - description: A tag, branch or commit hash in the Godot repository. - type: string - default: 4.2.1-stable + - "doc/*" + +# Global Settings. +env: + GODOT_REF: "4.2.1-stable" + GODOT_CPP_REF: "4.2" jobs: unit-tests: @@ -45,7 +41,7 @@ jobs: uses: actions/checkout@v4 with: repository: godotengine/godot - ref: ${{ inputs.godot-treeish }} + ref: ${{ env.GODOT_REF }} - name: Clone LimboAI module uses: actions/checkout@v4 @@ -67,11 +63,11 @@ jobs: uses: actions/cache@v3 with: path: ${{github.workspace}}/.scons_cache/ - key: ${{env.BIN}}-${{inputs.godot-treeish}}-${{github.ref}}-${{github.sha}} + key: ${{env.BIN}}-${{env.GODOT_REF}}-${{github.ref}}-${{github.sha}} restore-keys: | - ${{env.BIN}}-${{inputs.godot-treeish}}-${{github.ref}}-${{github.sha}} - ${{env.BIN}}-${{inputs.godot-treeish}}-${{github.ref}} - ${{env.BIN}}-${{inputs.godot-treeish}} + ${{env.BIN}}-${{env.GODOT_REF}}-${{github.ref}}-${{github.sha}} + ${{env.BIN}}-${{env.GODOT_REF}}-${{github.ref}} + ${{env.BIN}}-${{env.GODOT_REF}} continue-on-error: true - name: Set up Python 3.x @@ -107,26 +103,50 @@ jobs: run: | bin/${{ env.BIN }} --test --headless + cache-env: + runs-on: ubuntu-latest + outputs: + godot-ref: ${{ steps.cache-env.outputs.godot-ref }} + godot-cpp-ref: ${{ steps.cache-env.outputs.godot-cpp-ref }} + steps: + - name: Cache env + id: cache-env + run: | + echo "godot-ref=${GODOT_REF}" >> "$GITHUB_OUTPUT" + echo "godot-cpp-ref=${GODOT_CPP_REF}" >> "$GITHUB_OUTPUT" + linux-test-build: - name: 🐧 Linux test build + name: 🐧 Linux + needs: cache-env uses: ./.github/workflows/linux.yml with: - godot-treeish: ${{ inputs.godot-treeish }} + godot-treeish: ${{ needs.cache-env.outputs.godot-ref }} limboai-treeish: ${{ github.sha }} test-build: true windows-test-build: - name: 🪟 Windows test build + name: 🪟 Windows + needs: cache-env uses: ./.github/workflows/windows.yml with: - godot-treeish: ${{ inputs.godot-treeish }} + godot-treeish: ${{ needs.cache-env.outputs.godot-ref }} limboai-treeish: ${{ github.sha }} test-build: true macos-test-build: - name: 🍎 macOS test build + name: 🍎 macOS + needs: cache-env uses: ./.github/workflows/macos.yml with: - godot-treeish: ${{ inputs.godot-treeish }} + godot-treeish: ${{ needs.cache-env.outputs.godot-ref }} + limboai-treeish: ${{ github.sha }} + test-build: true + + gdextension: + name: 🔌 GDExtension + needs: cache-env + uses: ./.github/workflows/gdextension.yml + with: + godot-cpp-treeish: ${{ needs.cache-env.outputs.godot-cpp-ref }} limboai-treeish: ${{ github.sha }} test-build: true diff --git a/.gitignore b/.gitignore index 79fcb11..025e52f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# LimboAI-specific +demo/addons/ +icons/*.import + # Godot auto generated files *.gen.* .import/ 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_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..8e45004 100644 --- a/blackboard/bb_param/bb_node.cpp +++ b/blackboard/bb_param/bb_node.cpp @@ -10,9 +10,15 @@ */ #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 +34,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..465e374 100644 --- a/blackboard/bb_param/bb_param.cpp +++ b/blackboard/bb_param/bb_param.cpp @@ -11,14 +11,20 @@ #include "bb_param.h" -#include "modules/limboai/util/limbo_utility.h" +#include "../../util/limbo_utility.h" +#ifdef LIMBOAI_MODULE #include "core/core_bind.h" #include "core/error/error_macros.h" #include "core/object/class_db.h" #include "core/object/object.h" #include "core/variant/variant.h" #include "core/variant/variant_utility.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +using namespace godot; +#endif // LIMBOAI_GDEXTENSION VARIANT_ENUM_CAST(BBParam::ValueSource); @@ -49,18 +55,22 @@ void BBParam::set_variable(const String &p_value) { emit_changed(); } +#ifdef LIMBOAI_MODULE String BBParam::to_string() { +#elif LIMBOAI_GDEXTENSION +String BBParam::_to_string() { +#endif if (value_source == SAVED_VALUE) { String s = saved_value.stringify(); switch (get_type()) { case Variant::STRING: { - s = s.c_escape().quote(); + s = "\"" + s.c_escape() + "\""; } break; case Variant::STRING_NAME: { - s = "&" + s.c_escape().quote(); + s = "&\"" + s.c_escape() + "\""; } break; case Variant::NODE_PATH: { - s = "^" + s.c_escape().quote(); + s = "^\"" + s.c_escape() + "\""; } break; default: { } break; diff --git a/blackboard/bb_param/bb_param.h b/blackboard/bb_param/bb_param.h index 65e32cf..96044c5 100644 --- a/blackboard/bb_param/bb_param.h +++ b/blackboard/bb_param/bb_param.h @@ -12,13 +12,22 @@ #ifndef BB_PARAM_H #define BB_PARAM_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/io/resource.h" #include "core/object/object.h" #include "core/typedefs.h" #include "core/variant/variant.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include +#include +#include +#include +#endif // LIMBOAI_GDEXTENSION class BBParam : public Resource { GDCLASS(BBParam, Resource); @@ -42,8 +51,12 @@ 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); +#elif LIMBOAI_GDEXTENSION + saved_value.clear(); +#endif } void _get_property_list(List *p_list) const; @@ -60,7 +73,11 @@ public: void set_variable(const String &p_value); String get_variable() const { return variable; } +#ifdef LIMBOAI_MODULE virtual String to_string() override; +#elif LIMBOAI_GDEXTENSION + virtual String _to_string(); +#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); diff --git a/blackboard/blackboard.cpp b/blackboard/blackboard.cpp index 6f45ed1..cfd6973 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 { @@ -57,7 +68,7 @@ void Blackboard::prefetch_nodepath_vars(Node *p_node) { } } } -}; +} void Blackboard::_bind_methods() { ClassDB::bind_method(D_METHOD("get_data"), &Blackboard::get_data); @@ -70,4 +81,4 @@ void Blackboard::_bind_methods() { ClassDB::bind_method(D_METHOD("erase_var", "p_key"), &Blackboard::erase_var); ClassDB::bind_method(D_METHOD("prefetch_nodepath_vars", "p_node"), &Blackboard::prefetch_nodepath_vars); ClassDB::bind_method(D_METHOD("top"), &Blackboard::top); -} \ No newline at end of file +} diff --git a/blackboard/blackboard.h b/blackboard/blackboard.h index 6b2838b..893bd89 100644 --- a/blackboard/blackboard.h +++ b/blackboard/blackboard.h @@ -12,11 +12,22 @@ #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/behavior_tree.cpp b/bt/behavior_tree.cpp index b761843..b6fc0d9 100644 --- a/bt/behavior_tree.cpp +++ b/bt/behavior_tree.cpp @@ -11,10 +11,16 @@ #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 +#include "godot_cpp/core/error_macros.hpp" +#endif // ! LIMBOAI_GDEXTENSION Ref BehaviorTree::clone() const { Ref copy = duplicate(false); @@ -25,6 +31,12 @@ Ref BehaviorTree::clone() const { return copy; } +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(); +} + Ref BehaviorTree::instantiate(Node *p_agent, const Ref &p_blackboard) const { ERR_FAIL_COND_V_MSG(root_task == nullptr, memnew(BTTask), "Trying to instance a behavior tree with no valid root task."); Ref inst = root_task->clone(); @@ -38,8 +50,9 @@ 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_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"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "root_task", PROPERTY_HINT_RESOURCE_TYPE, "BTTask", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_root_task", "get_root_task"); -} \ No newline at end of file +} diff --git a/bt/behavior_tree.h b/bt/behavior_tree.h index cb35c96..ffd6f53 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; @@ -43,7 +52,8 @@ public: Ref get_root_task() const { return root_task; } Ref clone() const; + void copy_other(const Ref &p_other); Ref instantiate(Node *p_agent, const Ref &p_blackboard) const; }; -#endif // BEHAVIOR_TREE_H \ No newline at end of file +#endif // BEHAVIOR_TREE_H diff --git a/bt/bt_player.cpp b/bt/bt_player.cpp index 669cc83..25d8004 100644 --- a/bt/bt_player.cpp +++ b/bt/bt_player.cpp @@ -11,10 +11,11 @@ #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_compat.h" +#include "../util/limbo_string_names.h" +#ifdef LIMBOAI_MODULE #include "core/config/engine.h" #include "core/debugger/engine_debugger.h" #include "core/error/error_macros.h" @@ -25,11 +26,26 @@ #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 // ! LIMBOAI_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 +57,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 +90,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 +102,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 +129,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()); + 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); @@ -130,7 +146,7 @@ double BTPlayer::_get_mean_update_time_msec() { return 0.0; } -#endif // DEBUG_ENABLED +#endif // ! DEBUG_ENABLED void BTPlayer::_notification(int p_notification) { switch (p_notification) { @@ -155,16 +171,16 @@ 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; -#endif +#endif // DEBUG_ENABLED } } @@ -205,7 +221,6 @@ 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); #endif // DEBUG_ENABLED } diff --git a/bt/bt_player.h b/bt/bt_player.h index 63bdd61..175fafc 100644 --- a/bt/bt_player.h +++ b/bt/bt_player.h @@ -12,19 +12,25 @@ #ifndef BT_PLAYER_H #define BT_PLAYER_H -#include "scene/main/node.h" - +#include "../blackboard/blackboard.h" #include "behavior_tree.h" -#include "modules/limboai/blackboard/blackboard.h" #include "tasks/bt_task.h" +#ifdef LIMBOAI_MODULE +#include "scene/main/node.h" +#endif + +#ifdef LIMBOAI_GDEXTENSION +#include +#endif + class BTPlayer : public Node { GDCLASS(BTPlayer, Node); public: enum UpdateMode : unsigned int { IDLE, // automatically call update() during NOTIFICATION_PROCESS - PHYSICS, //# automatically call update() during NOTIFICATION_PHYSICS + PHYSICS, // automatically call update() during NOTIFICATION_PHYSICS MANUAL, // manually update state machine, user must call update(delta) }; @@ -71,8 +77,8 @@ public: BTPlayer(); ~BTPlayer(); -#ifdef DEBUG_ENABLED - // Performace monitoring. +#ifdef DEBUG_ENABLED // Performance monitoring + private: bool monitor_performance = false; StringName monitor_id; @@ -86,4 +92,4 @@ private: #endif // DEBUG_ENABLED }; -#endif // BT_PLAYER_H \ No newline at end of file +#endif // BT_PLAYER_H diff --git a/bt/bt_state.cpp b/bt/bt_state.cpp index e185909..2a18104 100644 --- a/bt/bt_state.cpp +++ b/bt/bt_state.cpp @@ -11,21 +11,27 @@ #include "bt_state.h" -#include "modules/limboai/editor/debugger/limbo_debugger.h" -#include "modules/limboai/hsm/limbo_state.h" -#include "modules/limboai/util/limbo_string_names.h" +#include "../editor/debugger/limbo_debugger.h" +#include "../util/limbo_compat.h" +#include "../util/limbo_string_names.h" +#ifdef LIMBOAI_MODULE #include "core/debugger/engine_debugger.h" #include "core/error/error_macros.h" #include "core/object/class_db.h" #include "core/variant/variant.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include +#endif // LIMBOAI_GDEXTENSION void BTState::_setup() { ERR_FAIL_COND_MSG(behavior_tree.is_null(), "BTState: BehaviorTree is not assigned."); tree_instance = behavior_tree->instantiate(get_agent(), get_blackboard()); #ifdef DEBUG_ENABLED - 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()); } #endif @@ -51,12 +57,12 @@ void BTState::_update(double p_delta) { void BTState::_notification(int p_notification) { switch (p_notification) { 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; diff --git a/bt/bt_state.h b/bt/bt_state.h index 497ba4e..b3baa74 100644 --- a/bt/bt_state.h +++ b/bt/bt_state.h @@ -12,10 +12,10 @@ #ifndef BT_STATE_H #define BT_STATE_H -#include "modules/limboai/hsm/limbo_state.h" +#include "../hsm/limbo_state.h" -#include "modules/limboai/bt/behavior_tree.h" -#include "modules/limboai/bt/tasks/bt_task.h" +#include "../bt/behavior_tree.h" +#include "../bt/tasks/bt_task.h" class BTState : public LimboState { GDCLASS(BTState, LimboState); @@ -30,7 +30,6 @@ protected: static void _bind_methods(); virtual void _setup() override; - // virtual void _enter() override {} virtual void _exit() override; virtual void _update(double p_delta) override; @@ -53,4 +52,4 @@ protected: #endif }; -#endif // BT_STATE_H \ No newline at end of file +#endif // BT_STATE_H 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..5415312 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(LW_NAME(changed), Callable(this, LW_NAME(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..2809ee3 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 "../../../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..9c165b9 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 = LW_NAME(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(LW_NAME(changed), Callable(this, LW_NAME(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..a8c61e4 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 "../../../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_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..a685d25 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 +#endif // BT_ACTION_H 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..78cc0e0 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 +#endif // BT_COMMENT_H 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..d747fca 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 +#endif // BT_COMPOSITE_H 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..f1ab6a3 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 +#endif // BT_CONDITION_H 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..f3a2cbc 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 +#endif // BT_DECORATOR_H diff --git a/bt/tasks/bt_task.cpp b/bt/tasks/bt_task.cpp index 3cdad3f..e563ba9 100644 --- a/bt/tasks/bt_task.cpp +++ b/bt/tasks/bt_task.cpp @@ -11,11 +11,12 @@ #include "bt_task.h" +#include "../../blackboard/blackboard.h" +#include "../../util/limbo_string_names.h" +#include "../../util/limbo_utility.h" #include "bt_comment.h" -#include "modules/limboai/blackboard/blackboard.h" -#include "modules/limboai/util/limbo_string_names.h" -#include "modules/limboai/util/limbo_utility.h" +#ifdef LIMBOAI_MODULE #include "core/error/error_macros.h" #include "core/io/resource.h" #include "core/object/class_db.h" @@ -25,6 +26,19 @@ #include "core/string/ustring.h" #include "core/templates/hash_map.h" #include "core/variant/variant.h" +#endif // LIMBOAI_MODULE + +#ifdef LIMBOAI_GDEXTENSION +#include "godot_cpp/classes/global_constants.hpp" +#include "godot_cpp/core/class_db.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" +#include +#include +#endif // LIMBOAI_GDEXTENSION void BT::_bind_methods() { BIND_ENUM_CONSTANT(FRESH); @@ -33,19 +47,21 @@ void BT::_bind_methods() { BIND_ENUM_CONSTANT(SUCCESS); } -String BTTask::_generate_name() const { - 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!"); - return get_script_instance()->call(LimboStringNames::get_singleton()->_generate_name); - } - String script_path = get_script_instance()->get_script()->get_path(); - if (!script_path.is_empty()) { - // Generate name based on script file - return script_path.get_basename().get_file().trim_prefix("BT").to_pascal_case(); - } +String BTTask::_generate_name() { + String ret; + + // Generate name based on script path. + Ref