Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 nodes composites #360

Merged
merged 2 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
8 changes: 8 additions & 0 deletions extension/src/nodes/beehave_tree_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ BeehaveTickStatus BeehaveTreeNode::tick(Ref<BeehaveContext> context) {
return status;
}

BeehaveTreeNode* BeehaveTreeNode::cast_node(Node* node) const {
BeehaveTreeNode *tree_node = cast_to<BeehaveTreeNode>(node);
if (!tree_node) {
return nullptr;
}
return tree_node;
}

void BeehaveTreeNode::_bind_methods() {

GDVIRTUAL_BIND(_tick, "context");
Expand Down
1 change: 1 addition & 0 deletions extension/src/nodes/beehave_tree_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class BeehaveTreeNode : public Node {

protected:
static void _bind_methods();
BeehaveTreeNode *cast_node(Node* node) const;

public:
BeehaveTreeNode();
Expand Down
40 changes: 40 additions & 0 deletions extension/src/nodes/composites/beehave_composite.cpp
Original file line number Diff line number Diff line change
@@ -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() {

}
46 changes: 46 additions & 0 deletions extension/src/nodes/composites/beehave_composite.h
Original file line number Diff line number Diff line change
@@ -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
72 changes: 72 additions & 0 deletions extension/src/nodes/composites/beehave_selector.cpp
Original file line number Diff line number Diff line change
@@ -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<BeehaveContext> context) {
TypedArray<Node> 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<Node>(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;
}
53 changes: 53 additions & 0 deletions extension/src/nodes/composites/beehave_selector.h
Original file line number Diff line number Diff line change
@@ -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<BeehaveContext> context);
};
}// namespace godot

#endif // BEEHAVE_SELECTOR_H
Empty file.
Empty file.
8 changes: 1 addition & 7 deletions extension/src/nodes/decorators/beehave_decorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,5 @@ BeehaveTreeNode* BeehaveDecorator::get_wrapped_child() const {
if (get_child_count() != 1) {
return nullptr;
}

BeehaveTreeNode *tree_node = cast_to<BeehaveTreeNode>(get_child(0));
if (!tree_node) {
return nullptr;
}

return tree_node;
return cast_node(get_child(0));
}
5 changes: 4 additions & 1 deletion extension/src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -50,7 +52,8 @@ void initialize_beehave_types(ModuleInitializationLevel p_level) {
ClassDB::register_class<BeehaveUntilFail>();

// composites
// TODO
ClassDB::register_abstract_class<BeehaveComposite>();
ClassDB::register_class<BeehaveSelector>();
}

void uninitialize_beehave_types(ModuleInitializationLevel p_level) {
Expand Down
Loading