2015-02-17 02:31:20 +01:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2017-10-26 03:51:24 +02:00
|
|
|
#include "test_Globals.hpp"
|
2015-02-17 02:31:20 +01:00
|
|
|
|
|
|
|
#include <ai/AIGraph.hpp>
|
2018-12-10 01:51:05 +01:00
|
|
|
#include <ai/AIGraphNode.hpp>
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <ai/TrafficDirector.hpp>
|
2018-12-10 01:51:05 +01:00
|
|
|
#include <data/PathData.hpp>
|
2015-02-17 02:31:20 +01:00
|
|
|
#include <objects/CharacterObject.hpp>
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <objects/InstanceObject.hpp>
|
2016-06-26 04:55:31 +02:00
|
|
|
#include <render/ViewCamera.hpp>
|
2015-02-17 02:31:20 +01:00
|
|
|
|
2018-12-10 01:51:05 +01:00
|
|
|
bool operator!=(const ai::AIGraphNode* lhs, const glm::vec3& rhs) {
|
2016-09-09 22:13:22 +02:00
|
|
|
return lhs->position != rhs;
|
|
|
|
}
|
2018-12-10 01:51:05 +01:00
|
|
|
std::ostream& operator<<(std::ostream& os, const ai::AIGraphNode* yt) {
|
2016-09-09 22:13:22 +02:00
|
|
|
os << glm::to_string(yt->position);
|
|
|
|
return os;
|
|
|
|
}
|
2015-02-17 02:31:20 +01:00
|
|
|
|
2019-01-18 02:29:59 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE(TrafficDirectorTests, DATA_TEST_PREDICATE)
|
2015-02-17 02:31:20 +01:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_available_nodes) {
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::AIGraph graph;
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
PathData path{PathData::PATH_PED,
|
|
|
|
0,
|
|
|
|
"",
|
|
|
|
{
|
|
|
|
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
|
|
|
{PathNode::EXTERNAL, 2, {10.f, 0.f, 0.f}, 1.f, 0, 0},
|
|
|
|
{PathNode::EXTERNAL, 3, {10.f, -10.f, 0.f}, 1.f, 0, 0},
|
|
|
|
{PathNode::EXTERNAL, 4, {0.f, -10.f, 0.f}, 1.f, 0, 0},
|
|
|
|
{PathNode::EXTERNAL, 5, {-10.f, -10.f, 0.f}, 1.f, 0, 0},
|
|
|
|
{PathNode::EXTERNAL, 6, {-10.f, 0.f, 0.f}, 1.f, 0, 0},
|
|
|
|
{PathNode::EXTERNAL, -1, {-10.f, 10.f, 0.f}, 1.f, 0, 0},
|
|
|
|
}};
|
|
|
|
|
2018-02-06 20:47:31 +01:00
|
|
|
graph.createPathNodes(glm::vec3(), glm::quat{1.0f,0.0f,0.0f,0.0f}, path);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::TrafficDirector director(&graph, Global::get().e);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
ViewCamera testCamera(glm::vec3(-5.f, -5.f, 0.f));
|
|
|
|
|
|
|
|
auto open =
|
2018-12-10 01:51:05 +01:00
|
|
|
director.findAvailableNodes(ai::NodeType::Pedestrian, testCamera, 10.f);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
std::vector<glm::vec3> expected{
|
|
|
|
{0.f, -10.f, 0.f}, {-10.f, -10.f, 0.f}, {-10.f, 0.f, 0.f}};
|
|
|
|
|
|
|
|
BOOST_REQUIRE(expected.size() == 3);
|
|
|
|
BOOST_ASSERT(expected.size() == open.size());
|
|
|
|
|
|
|
|
for (auto& v : expected) {
|
2018-12-10 01:51:05 +01:00
|
|
|
BOOST_CHECK(std::find_if(open.begin(), open.end(), [v](ai::AIGraphNode* n) {
|
2016-09-09 22:13:22 +02:00
|
|
|
return n->position == v;
|
|
|
|
}) != open.end());
|
|
|
|
}
|
2015-02-17 02:31:20 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_node_not_blocking) {
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::AIGraph graph;
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
PathData path{PathData::PATH_PED,
|
|
|
|
0,
|
|
|
|
"",
|
|
|
|
{
|
|
|
|
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
|
|
|
}};
|
|
|
|
|
2018-02-06 20:47:31 +01:00
|
|
|
graph.createPathNodes(glm::vec3(), glm::quat{1.0f,0.0f,0.0f,0.0f}, path);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::TrafficDirector director(&graph, Global::get().e);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
// Create something that isn't a pedestrian
|
|
|
|
InstanceObject* box =
|
|
|
|
Global::get().e->createInstance(1337, glm::vec3(10.f, 10.f, 0.f));
|
|
|
|
|
|
|
|
{
|
2018-12-10 01:51:05 +01:00
|
|
|
auto open = director.findAvailableNodes(ai::NodeType::Pedestrian,
|
2016-09-09 22:13:22 +02:00
|
|
|
glm::vec3(5.f, 5.f, 0.f), 10.f);
|
|
|
|
BOOST_CHECK(open.size() == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Global::get().e->destroyObject(box);
|
2015-02-17 02:31:20 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_node_blocking) {
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::AIGraph graph;
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
PathData path{PathData::PATH_PED,
|
|
|
|
0,
|
|
|
|
"",
|
|
|
|
{
|
|
|
|
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
|
|
|
}};
|
|
|
|
|
2018-02-06 20:47:31 +01:00
|
|
|
graph.createPathNodes(glm::vec3(), glm::quat{1.0f,0.0f,0.0f,0.0f}, path);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::TrafficDirector director(&graph, Global::get().e);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
// create something that should block the spawn point
|
|
|
|
CharacterObject* ped =
|
|
|
|
Global::get().e->createPedestrian(1, glm::vec3(10.f, 10.f, 0.f));
|
|
|
|
|
|
|
|
{
|
2018-12-10 01:51:05 +01:00
|
|
|
auto open = director.findAvailableNodes(ai::NodeType::Pedestrian,
|
2016-09-09 22:13:22 +02:00
|
|
|
glm::vec3(5.f, 5.f, 0.f), 10.f);
|
|
|
|
BOOST_CHECK(open.size() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Global::get().e->destroyObject(ped);
|
2015-02-17 02:31:20 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_node_density) {
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::AIGraph graph;
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
PathData path{PathData::PATH_PED,
|
|
|
|
0,
|
|
|
|
"",
|
|
|
|
{
|
|
|
|
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
|
|
|
}};
|
|
|
|
|
2018-02-06 20:47:31 +01:00
|
|
|
graph.createPathNodes(glm::vec3(), glm::quat{1.0f,0.0f,0.0f,0.0f}, path);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::TrafficDirector director(&graph, Global::get().e);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
CharacterObject* ped =
|
|
|
|
Global::get().e->createPedestrian(1, glm::vec3(5.f, 5.f, 0.f));
|
|
|
|
|
|
|
|
{
|
2018-12-10 01:51:05 +01:00
|
|
|
director.setDensity(ai::NodeType::Pedestrian, 1.f);
|
|
|
|
auto open = director.findAvailableNodes(ai::NodeType::Pedestrian,
|
2016-09-09 22:13:22 +02:00
|
|
|
glm::vec3(5.f, 5.f, 0.f), 10.f);
|
|
|
|
BOOST_CHECK(open.size() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-12-10 01:51:05 +01:00
|
|
|
director.setDensity(ai::NodeType::Pedestrian, 2.f);
|
|
|
|
auto open = director.findAvailableNodes(ai::NodeType::Pedestrian,
|
2016-09-09 22:13:22 +02:00
|
|
|
glm::vec3(5.f, 5.f, 0.f), 10.f);
|
|
|
|
BOOST_CHECK(open.size() == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Global::get().e->destroyObject(ped);
|
2015-02-17 02:31:20 +01:00
|
|
|
}
|
2015-02-18 16:29:39 +01:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_create_traffic) {
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::AIGraph graph;
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
PathData path{PathData::PATH_PED,
|
|
|
|
0,
|
|
|
|
"",
|
|
|
|
{
|
|
|
|
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
|
|
|
}};
|
|
|
|
|
2018-02-06 20:47:31 +01:00
|
|
|
graph.createPathNodes(glm::vec3(), glm::quat{1.0f,0.0f,0.0f,0.0f}, path);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
2018-12-10 01:51:05 +01:00
|
|
|
ai::TrafficDirector director(&graph, Global::get().e);
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
auto created = director.populateNearby(glm::vec3(0.f, 0.f, 0.f), 20.f);
|
|
|
|
|
|
|
|
BOOST_CHECK(created.size() == 1);
|
|
|
|
|
|
|
|
// Global::get().e->destroyObject(created[0]);
|
2015-02-18 16:29:39 +01:00
|
|
|
}
|
|
|
|
|
2015-02-17 02:31:20 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|