diff --git a/addons/beehave/libs/windows/beehave.windows.editor.x86_64.dll b/addons/beehave/libs/windows/beehave.windows.editor.x86_64.dll index 8ec5f252..374ee703 100644 Binary files a/addons/beehave/libs/windows/beehave.windows.editor.x86_64.dll and b/addons/beehave/libs/windows/beehave.windows.editor.x86_64.dll differ diff --git a/extension/src/nodes/beehave_tree_node.cpp b/extension/src/nodes/beehave_tree_node.cpp index 7bae0a3d..f280a245 100644 --- a/extension/src/nodes/beehave_tree_node.cpp +++ b/extension/src/nodes/beehave_tree_node.cpp @@ -45,6 +45,14 @@ BeehaveTickStatus BeehaveTreeNode::tick(Ref context) { return status; } +BeehaveTreeNode* BeehaveTreeNode::cast_node(Node* node) const { + BeehaveTreeNode *tree_node = cast_to(node); + if (!tree_node) { + return nullptr; + } + return tree_node; +} + void BeehaveTreeNode::_bind_methods() { GDVIRTUAL_BIND(_tick, "context"); diff --git a/extension/src/nodes/beehave_tree_node.h b/extension/src/nodes/beehave_tree_node.h index 2c87065b..0d40567d 100644 --- a/extension/src/nodes/beehave_tree_node.h +++ b/extension/src/nodes/beehave_tree_node.h @@ -57,6 +57,7 @@ class BeehaveTreeNode : public Node { protected: static void _bind_methods(); + BeehaveTreeNode *cast_node(Node* node) const; public: BeehaveTreeNode(); diff --git a/extension/src/nodes/composites/beehave_composite.cpp b/extension/src/nodes/composites/beehave_composite.cpp new file mode 100644 index 00000000..a74af03d --- /dev/null +++ b/extension/src/nodes/composites/beehave_composite.cpp @@ -0,0 +1,40 @@ +/**************************************************************************/ +/* beehave_composite.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "beehave_composite.h" + +using namespace godot; + +BeehaveComposite::BeehaveComposite() { + +} + +BeehaveComposite::~BeehaveComposite() { + +} \ No newline at end of file diff --git a/extension/src/nodes/composites/beehave_composite.h b/extension/src/nodes/composites/beehave_composite.h new file mode 100644 index 00000000..20e20acc --- /dev/null +++ b/extension/src/nodes/composites/beehave_composite.h @@ -0,0 +1,46 @@ +/**************************************************************************/ +/* beehave_composite.h */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef BEEHAVE_COMPOSITE_H +#define BEEHAVE_COMPOSITE_H + +#include "nodes/beehave_tree_node.h" + +namespace godot { + +class BeehaveComposite : public BeehaveTreeNode { +GDCLASS(BeehaveComposite, BeehaveTreeNode); + +public: + BeehaveComposite(); + ~BeehaveComposite(); +}; +} //namespace godot + +#endif //BEEHAVE_COMPOSITE_H \ No newline at end of file diff --git a/extension/src/nodes/composites/beehave_selector.cpp b/extension/src/nodes/composites/beehave_selector.cpp new file mode 100644 index 00000000..609e4266 --- /dev/null +++ b/extension/src/nodes/composites/beehave_selector.cpp @@ -0,0 +1,72 @@ +/**************************************************************************/ +/* beehave_selector.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "beehave_selector.h" + +using namespace godot; + +BeehaveSelector::BeehaveSelector() { + +} + +BeehaveSelector::~BeehaveSelector() { + +} + +void BeehaveSelector::_bind_methods() { + +} + +BeehaveTickStatus BeehaveSelector::tick(Ref context) { + TypedArray children = get_children(); + for (int i = 0; i < children.size(); ++i) { + if (i < last_execution_index) { + // skip everything that was executed already + continue; + } + BeehaveTreeNode *child = cast_node(Object::cast_to(children[i])); + if (child == nullptr) { + // skip anything that is not a valid beehave node + continue; + } + BeehaveTickStatus response = child->tick(context); + + switch (response) { + case SUCCESS: + // TODO: introduce after_run mechanism + return SUCCESS; + case FAILURE: + ++last_execution_index; + break; + case RUNNING: + return RUNNING; + } + } + return BeehaveTickStatus::FAILURE; +} \ No newline at end of file diff --git a/extension/src/nodes/composites/beehave_selector.h b/extension/src/nodes/composites/beehave_selector.h new file mode 100644 index 00000000..373f3014 --- /dev/null +++ b/extension/src/nodes/composites/beehave_selector.h @@ -0,0 +1,53 @@ +/**************************************************************************/ +/* beehave_selector.h */ +/**************************************************************************/ +/* This file is part of: */ +/* BEEHAVE */ +/* https://bitbra.in/beehave */ +/**************************************************************************/ +/* Copyright (c) 2024-present Beehave Contributors. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef BEEHAVE_SELECTOR_H +#define BEEHAVE_SELECTOR_H + +#include "nodes/composites/beehave_composite.h" + +namespace godot { + +class BeehaveSelector : public BeehaveComposite { + GDCLASS(BeehaveSelector, BeehaveComposite); + + int last_execution_index = 0; + +protected: + static void _bind_methods(); + +public: + BeehaveSelector(); + ~BeehaveSelector(); + + BeehaveTickStatus tick(Ref context); +}; +}// namespace godot + +#endif // BEEHAVE_SELECTOR_H \ No newline at end of file diff --git a/extension/src/nodes/composites/selector.cpp b/extension/src/nodes/composites/selector.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/extension/src/nodes/composites/selector.h b/extension/src/nodes/composites/selector.h deleted file mode 100644 index e69de29b..00000000 diff --git a/extension/src/nodes/decorators/beehave_decorator.cpp b/extension/src/nodes/decorators/beehave_decorator.cpp index adbaf197..51efeeab 100644 --- a/extension/src/nodes/decorators/beehave_decorator.cpp +++ b/extension/src/nodes/decorators/beehave_decorator.cpp @@ -47,11 +47,5 @@ BeehaveTreeNode* BeehaveDecorator::get_wrapped_child() const { if (get_child_count() != 1) { return nullptr; } - - BeehaveTreeNode *tree_node = cast_to(get_child(0)); - if (!tree_node) { - return nullptr; - } - - return tree_node; + return cast_node(get_child(0)); } \ No newline at end of file diff --git a/extension/src/register_types.cpp b/extension/src/register_types.cpp index 66707370..fa53f3cb 100644 --- a/extension/src/register_types.cpp +++ b/extension/src/register_types.cpp @@ -20,6 +20,8 @@ #include "nodes/decorators/beehave_delayer.h" #include "nodes/decorators/beehave_repeater.h" #include "nodes/decorators/beehave_until_fail.h" +#include "nodes/composites/beehave_composite.h" +#include "nodes/composites/beehave_selector.h" using namespace godot; @@ -50,7 +52,8 @@ void initialize_beehave_types(ModuleInitializationLevel p_level) { ClassDB::register_class(); // composites - // TODO + ClassDB::register_abstract_class(); + ClassDB::register_class(); } void uninitialize_beehave_types(ModuleInitializationLevel p_level) {