1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-18 16:32:32 +02:00
openrw/tests/test_character.cpp

92 lines
2.6 KiB
C++
Raw Normal View History

#include <boost/test/unit_test.hpp>
2014-06-06 16:22:26 +02:00
#include <objects/CharacterObject.hpp>
#include <objects/VehicleObject.hpp>
2014-06-06 18:04:00 +02:00
#include <ai/DefaultAIController.hpp>
#include "test_globals.hpp"
BOOST_AUTO_TEST_SUITE(CharacterTests)
BOOST_AUTO_TEST_CASE(test_create)
{
{
auto character = Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
BOOST_REQUIRE( character != nullptr );
2014-06-06 18:04:00 +02:00
auto controller = new DefaultAIController(character);
2014-05-29 12:12:40 +02:00
// Check the initial activity is Idle.
2014-05-29 12:12:40 +02:00
BOOST_CHECK_EQUAL( controller->getCurrentActivity(), nullptr );
// Check that Idle activities are instantly displaced.
2014-05-29 12:12:40 +02:00
controller->setNextActivity( new Activities::GoTo( glm::vec3{ 1000.f, 0.f, 0.f } ) );
BOOST_CHECK_EQUAL( controller->getCurrentActivity()->name(), "GoTo" );
BOOST_CHECK_EQUAL( controller->getNextActivity(), nullptr );
Global::get().e->destroyObject(character);
delete controller;
}
}
BOOST_AUTO_TEST_CASE(test_activities)
{
{
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
BOOST_REQUIRE( character != nullptr );
2014-06-06 18:04:00 +02:00
auto controller = new DefaultAIController(character);
controller->setNextActivity( new Activities::GoTo( glm::vec3{ 10.f, 10.f, 0.f } ) );
2014-05-29 12:12:40 +02:00
BOOST_CHECK_EQUAL( controller->getCurrentActivity()->name(), "GoTo" );
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);
}
// This check will undoubtably break in the future, please improve.
2014-08-26 23:54:26 +02:00
BOOST_CHECK_CLOSE( glm::distance(character->getPosition(), {10.f, 10.f, 0.f}), 1.0f, 100.0f );
Global::get().e->destroyObject(character);
delete controller;
}
2014-05-29 12:12:40 +02:00
{
2014-06-06 16:22:26 +02:00
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
2014-05-29 12:12:40 +02:00
BOOST_REQUIRE(vehicle != nullptr);
2014-06-06 13:18:32 +02:00
BOOST_REQUIRE(vehicle->model != nullptr);
2014-05-29 12:12:40 +02:00
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
BOOST_REQUIRE( character != nullptr );
2014-06-06 18:04:00 +02:00
auto controller = new DefaultAIController(character);
2014-05-29 12:12:40 +02:00
controller->setNextActivity( new Activities::EnterVehicle( vehicle, 0 ) );
for(float t = 0.f; t < 0.5f; t+=(1.f/60.f)) {
2014-05-29 12:12:40 +02:00
character->tick(1.f/60.f);
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
}
BOOST_CHECK_EQUAL( nullptr, character->getCurrentVehicle() );
for(float t = 0.f; t < 9.0f; t+=(1.f/60.f)) {
2014-05-29 12:12:40 +02:00
character->tick(1.f/60.f);
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
}
BOOST_CHECK_EQUAL( vehicle, character->getCurrentVehicle() );
Global::get().e->destroyObject(character);
delete controller;
2014-05-29 12:12:40 +02:00
}
}
BOOST_AUTO_TEST_SUITE_END()