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

[pull] master from BehaviorTree:master #54

Merged
merged 2 commits into from
Dec 13, 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
2 changes: 1 addition & 1 deletion examples/t09_scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static const char* xml_text = R"(
<Sequence>
<Script code=" msg:='hello world' " />
<Script code=" A:=THE_ANSWER; B:=3.14; color:=RED " />
<Precondition if="A>B && color != BLUE" else="FAILURE">
<Precondition if="A>-B && color != BLUE" else="FAILURE">
<Sequence>
<SaySomething message="{A}"/>
<SaySomething message="{B}"/>
Expand Down
6 changes: 3 additions & 3 deletions include/behaviortree_cpp/scripting/operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,9 @@ struct Expression : lexy::expression_production
dsl::op<Ast::ExprComparison::greater_equal>(LEXY_LIT(">"
"="));

// The use of dsl::groups ensures that an expression can either contain math or bit
// The use of dsl::groups ensures that an expression can either contain math or bit or string
// operators. Mixing requires parenthesis.
using operand = dsl::groups<math_sum, bit_or>;
using operand = dsl::groups<math_sum, bit_or, string_concat>;
};

// Logical operators, || and &&
Expand All @@ -808,7 +808,7 @@ struct Expression : lexy::expression_production
dsl::op<Ast::ExprBinaryArithmetic::logic_or>(LEXY_LIT("||")) /
dsl::op<Ast::ExprBinaryArithmetic::logic_and>(LEXY_LIT("&&"));

using operand = dsl::groups<string_concat, comparison>;
using operand = comparison;
};

// x ? y : z
Expand Down
23 changes: 23 additions & 0 deletions src/xml_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,29 @@ void VerifyXML(const std::string& xml_text,
ThrowError(line_number,
std::string("The node <") + name + "> must have 1 or more children");
}
if(name == "ReactiveSequence")
{
size_t async_count = 0;
for(auto child = node->FirstChildElement(); child != nullptr;
child = child->NextSiblingElement())
{
const std::string child_name = node->FirstChildElement()->Name();
const auto child_search = registered_nodes.find(child_name);
const auto child_type = child_search->second;
if(child_type == NodeType::CONTROL &&
((child_name == "ThreadedAction") ||
(child_name == "StatefulActionNode") ||
(child_name == "CoroActionNode") || (child_name == "AsyncSequence")))
{
++async_count;
if(async_count > 1)
{
ThrowError(line_number, std::string("A ReactiveSequence cannot have more "
"than one async child."));
}
}
}
}
}
}
//recursion
Expand Down
28 changes: 28 additions & 0 deletions tests/gtest_reactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,31 @@ TEST(Reactive, TestLogging)
ASSERT_EQ(observer.getStatistics("testA").success_count, num_ticks);
ASSERT_EQ(observer.getStatistics("success").success_count, num_ticks);
}

TEST(Reactive, TwoAsyncNodesInReactiveSequence)
{
static const char* reactive_xml_text = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="MainTree">
<ReactiveSequence>
<AsyncSequence name="first">
<TestA/>
<TestB/>
<TestC/>
</AsyncSequence>
<AsyncSequence name="second">
<TestD/>
<TestE/>
<TestF/>
</AsyncSequence>
</ReactiveSequence>
</BehaviorTree>
</root>
)";

BT::BehaviorTreeFactory factory;
std::array<int, 6> counters;
RegisterTestTick(factory, "Test", counters);

EXPECT_ANY_THROW(auto tree = factory.createTreeFromText(reactive_xml_text));
}
Loading