2016-09-09 22:13:22 +02:00
|
|
|
#include <ai/DefaultAIController.hpp>
|
2014-05-29 10:10:08 +02:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <engine/Animator.hpp>
|
2014-06-06 16:22:26 +02:00
|
|
|
#include <objects/CharacterObject.hpp>
|
|
|
|
#include <objects/VehicleObject.hpp>
|
2017-10-26 03:51:24 +02:00
|
|
|
#include "test_Globals.hpp"
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2019-01-18 02:29:59 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE(CharacterTests, DATA_TEST_PREDICATE)
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_create) {
|
|
|
|
{
|
|
|
|
auto character =
|
|
|
|
Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
rwengine: Pass CharacterController to the CharacterObject constructor
The CharacterObject should remove the CharacterController upon
destruction.
Should fix this memory leak:
==31441== 480 (360 direct, 120 indirect) bytes in 5 blocks are definitely lost in loss record 2,038 of 2,723
==31441== at 0x4C2F1CA: operator new(unsigned long) (vg_replace_malloc.c:334)
==31441== by 0x7E2370: GameWorld::createPedestrian(unsigned short, glm::tvec3<float, (glm::precision)0> const&, glm::tquat<float, (glm::precision)0> const&, unsigned int) (GameWorld.cpp:334)
==31441== by 0x8E2F01: TrafficDirector::populateNearby(ViewCamera const&, float, int) (TrafficDirector.cpp:164)
==31441== by 0x7E1170: GameWorld::createTraffic(ViewCamera const&) (GameWorld.cpp:176)
==31441== by 0x75C616: RWGame::tick(float) (RWGame.cpp:531)
==31441== by 0x75BF18: RWGame::run() (RWGame.cpp:420)
==31441== by 0x749184: main (main.cpp:15)
2017-09-13 03:05:42 +02:00
|
|
|
auto controller = character->controller;
|
|
|
|
BOOST_REQUIRE(controller != nullptr);
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Check the initial activity is Idle.
|
|
|
|
BOOST_CHECK_EQUAL(controller->getCurrentActivity(), nullptr);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Check that Idle activities are instantly displaced.
|
|
|
|
controller->setNextActivity(
|
2018-12-10 01:51:05 +01:00
|
|
|
std::make_unique<ai::Activities::GoTo>(glm::vec3{1000.f, 0.f, 0.f}));
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(controller->getCurrentActivity()->name(), "GoTo");
|
|
|
|
BOOST_CHECK_EQUAL(controller->getNextActivity(), nullptr);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
2014-05-29 10:10:08 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_activities) {
|
|
|
|
{
|
|
|
|
auto character =
|
|
|
|
Global::get().e->createPedestrian(1, {0.f, 0.f, 225.6f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
rwengine: Pass CharacterController to the CharacterObject constructor
The CharacterObject should remove the CharacterController upon
destruction.
Should fix this memory leak:
==31441== 480 (360 direct, 120 indirect) bytes in 5 blocks are definitely lost in loss record 2,038 of 2,723
==31441== at 0x4C2F1CA: operator new(unsigned long) (vg_replace_malloc.c:334)
==31441== by 0x7E2370: GameWorld::createPedestrian(unsigned short, glm::tvec3<float, (glm::precision)0> const&, glm::tquat<float, (glm::precision)0> const&, unsigned int) (GameWorld.cpp:334)
==31441== by 0x8E2F01: TrafficDirector::populateNearby(ViewCamera const&, float, int) (TrafficDirector.cpp:164)
==31441== by 0x7E1170: GameWorld::createTraffic(ViewCamera const&) (GameWorld.cpp:176)
==31441== by 0x75C616: RWGame::tick(float) (RWGame.cpp:531)
==31441== by 0x75BF18: RWGame::run() (RWGame.cpp:420)
==31441== by 0x749184: main (main.cpp:15)
2017-09-13 03:05:42 +02:00
|
|
|
auto controller = character->controller;
|
|
|
|
BOOST_REQUIRE(controller != nullptr);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
controller->setNextActivity(
|
2018-12-10 01:51:05 +01:00
|
|
|
std::make_unique<ai::Activities::GoTo>(glm::vec3{10.f, 10.f, 0.f}));
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(controller->getCurrentActivity()->name(), "GoTo");
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
for (float t = 0.f; t < 11.5f; t += (1.f / 60.f)) {
|
|
|
|
controller->update(1.f / 60.f);
|
|
|
|
character->tick(1.f / 60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
|
|
|
}
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2018-07-13 18:52:10 +02:00
|
|
|
// Actually GoTo ignores z axis (up)
|
|
|
|
BOOST_CHECK_LT(glm::distance(glm::vec2{character->getPosition()},
|
|
|
|
{10.f, 10.f}),
|
|
|
|
0.1f);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
VehicleObject* vehicle = Global::get().e->createVehicle(
|
2018-02-06 20:47:31 +01:00
|
|
|
90u, glm::vec3(10.f, 0.f, 0.f), glm::quat{1.0f,0.0f,0.0f,0.0f});
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_REQUIRE(vehicle != nullptr);
|
2019-05-11 21:33:23 +02:00
|
|
|
BOOST_REQUIRE(vehicle->getClump() != nullptr);
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2014-05-29 12:12:40 +02:00
|
|
|
|
rwengine: Pass CharacterController to the CharacterObject constructor
The CharacterObject should remove the CharacterController upon
destruction.
Should fix this memory leak:
==31441== 480 (360 direct, 120 indirect) bytes in 5 blocks are definitely lost in loss record 2,038 of 2,723
==31441== at 0x4C2F1CA: operator new(unsigned long) (vg_replace_malloc.c:334)
==31441== by 0x7E2370: GameWorld::createPedestrian(unsigned short, glm::tvec3<float, (glm::precision)0> const&, glm::tquat<float, (glm::precision)0> const&, unsigned int) (GameWorld.cpp:334)
==31441== by 0x8E2F01: TrafficDirector::populateNearby(ViewCamera const&, float, int) (TrafficDirector.cpp:164)
==31441== by 0x7E1170: GameWorld::createTraffic(ViewCamera const&) (GameWorld.cpp:176)
==31441== by 0x75C616: RWGame::tick(float) (RWGame.cpp:531)
==31441== by 0x75BF18: RWGame::run() (RWGame.cpp:420)
==31441== by 0x749184: main (main.cpp:15)
2017-09-13 03:05:42 +02:00
|
|
|
auto controller = character->controller;
|
|
|
|
BOOST_REQUIRE(controller != nullptr);
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2017-09-13 18:14:34 +02:00
|
|
|
controller->setNextActivity(
|
2018-12-10 01:51:05 +01:00
|
|
|
std::make_unique<ai::Activities::EnterVehicle>(vehicle, 0));
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
for (float t = 0.f; t < 0.5f; t += (1.f / 60.f)) {
|
|
|
|
character->tick(1.f / 60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
|
|
|
}
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(nullptr, character->getCurrentVehicle());
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
for (float t = 0.f; t < 9.0f; t += (1.f / 60.f)) {
|
|
|
|
character->tick(1.f / 60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
|
|
|
}
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(vehicle, character->getCurrentVehicle());
|
2014-05-31 09:18:50 +02:00
|
|
|
|
2017-09-13 18:14:34 +02:00
|
|
|
controller->setNextActivity(
|
2018-12-10 01:51:05 +01:00
|
|
|
std::make_unique<ai::Activities::ExitVehicle>());
|
2016-05-25 00:49:01 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
for (float t = 0.f; t < 9.0f; t += (1.f / 60.f)) {
|
|
|
|
character->tick(1.f / 60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
|
|
|
}
|
2016-05-25 00:49:01 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(nullptr, character->getCurrentVehicle());
|
2016-05-25 00:49:01 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
character->setPosition(glm::vec3(5.f, 0.f, 0.f));
|
2017-09-13 18:14:34 +02:00
|
|
|
controller->setNextActivity(
|
2018-12-10 01:51:05 +01:00
|
|
|
std::make_unique<ai::Activities::EnterVehicle>(vehicle, 0));
|
2016-05-25 00:49:01 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
for (float t = 0.f; t < 0.5f; t += (1.f / 60.f)) {
|
|
|
|
character->tick(1.f / 60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
|
|
|
}
|
2016-05-25 00:49:01 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(nullptr, character->getCurrentVehicle());
|
|
|
|
controller->skipActivity();
|
2016-05-25 00:49:01 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
for (float t = 0.f; t < 5.0f; t += (1.f / 60.f)) {
|
|
|
|
character->tick(1.f / 60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
|
|
|
}
|
2016-05-25 00:49:01 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(nullptr, character->getCurrentVehicle());
|
2016-05-25 00:49:01 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
2014-05-29 10:10:08 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_death) {
|
|
|
|
{
|
|
|
|
auto character =
|
|
|
|
Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2016-04-17 05:54:19 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_EQUAL(character->getCurrentState().health, 100.f);
|
|
|
|
BOOST_CHECK(character->isAlive());
|
2016-04-17 05:54:19 +02:00
|
|
|
|
2019-01-05 03:22:38 +01:00
|
|
|
GameObject::DamageInfo dmg {
|
|
|
|
GameObject::DamageInfo::DamageType::Bullet,
|
|
|
|
{}, {},
|
|
|
|
character->getCurrentState().health + 1.f
|
|
|
|
};
|
2016-04-17 05:54:19 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Do some damage
|
|
|
|
BOOST_CHECK(character->takeDamage(dmg));
|
2016-04-17 05:54:19 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(!character->isAlive());
|
2016-04-17 05:54:19 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
character->tick(0.16f);
|
2016-04-17 05:54:19 +02:00
|
|
|
|
2017-02-12 01:25:26 +01:00
|
|
|
BOOST_CHECK_EQUAL(
|
|
|
|
character->animator->getAnimation(0),
|
|
|
|
character->animations->animation(AnimCycle::KnockOutShotFront0));
|
2016-04-17 05:54:19 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
2016-04-17 05:54:19 +02:00
|
|
|
}
|
2017-02-18 00:45:20 +01:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_cycle_animating) {
|
|
|
|
{
|
|
|
|
auto character =
|
|
|
|
Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
|
|
|
|
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
|
|
|
|
|
|
|
// Set the character cycle
|
|
|
|
character->playCycle(AnimCycle::ArrestGun);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(static_cast<uint32_t>(character->getCurrentCycle()),
|
|
|
|
static_cast<uint32_t>(AnimCycle::ArrestGun));
|
|
|
|
}
|
|
|
|
}
|
2016-04-17 05:54:19 +02:00
|
|
|
|
2014-05-29 10:10:08 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|