2014-06-13 22:54:17 +02:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <objects/VehicleObject.hpp>
|
2017-10-26 03:51:24 +02:00
|
|
|
#include "test_Globals.hpp"
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2019-01-18 02:29:59 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE(BuoyancyTests, DATA_TEST_PREDICATE)
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_vehicle_buoyancy) {
|
|
|
|
glm::vec2 tpos(-WATER_WORLD_SIZE / 2.f + 10.f);
|
|
|
|
{
|
|
|
|
VehicleObject* vehicle = Global::get().e->createVehicle(
|
2018-02-06 20:47:31 +01:00
|
|
|
90u, glm::vec3(tpos, 100.f), glm::quat{1.0f,0.0f,0.0f,0.0f});
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_REQUIRE(vehicle != nullptr);
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_REQUIRE(vehicle->info != nullptr);
|
2016-09-11 03:58:00 +02:00
|
|
|
BOOST_REQUIRE(vehicle->getVehicle() != nullptr);
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Relies on tile 0,0 being watered...
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(!vehicle->isInWater());
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Move it under the water
|
|
|
|
vehicle->setPosition(glm::vec3(tpos, -5.f));
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Allow the object to update
|
|
|
|
vehicle->tickPhysics(0.0016f);
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(vehicle->isInWater());
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Ensure that the in water state sticks
|
|
|
|
vehicle->tickPhysics(0.0016f);
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(vehicle->isInWater());
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
vehicle->setPosition(glm::vec3(tpos, 5.f));
|
|
|
|
vehicle->tickPhysics(0.0016f);
|
|
|
|
BOOST_CHECK(!vehicle->isInWater());
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// TODO: fix magic numbers
|
|
|
|
auto orgval = Global::get().e->data->realWater[0];
|
|
|
|
Global::get().e->data->realWater[0] = NO_WATER_INDEX;
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
vehicle->tickPhysics(0.0016f);
|
|
|
|
BOOST_CHECK(!vehicle->isInWater());
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
vehicle->setPosition(glm::vec3(tpos, -5.f));
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
vehicle->tickPhysics(0.0016f);
|
|
|
|
BOOST_CHECK(!vehicle->isInWater());
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->data->realWater[0] = orgval;
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
vehicle->tickPhysics(0.0016f);
|
|
|
|
BOOST_CHECK(!vehicle->isInWater());
|
2014-06-13 22:54:17 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObject(vehicle);
|
|
|
|
}
|
2014-06-13 22:54:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|