// // Created by Louis Auzuret on 5/31/21. // #include #include "Entity/Entity.hpp" #include "Component/Position/PositionComponent.hpp" #include "Wal.hpp" #define private public #include "System/Collision/CollisionSystem.hpp" #include "System/Movable/MovableSystem.hpp" #include "Component/Movable/MovableComponent.hpp" #include "Component/Collision/CollisionComponent.hpp" using namespace WAL; using namespace BBM; TEST_CASE("Collision test", "[Component][System]") { Wal wal; CollisionSystem collision(wal); wal.scene = std::make_shared(); wal.scene->addEntity("player") .addComponent() .addComponent([](Entity &actual, const Entity &) { try { auto &pos = actual.getComponent(); pos.position.x = 1; pos.position.y = 1; pos.position.z = 1; } catch (std::exception &e) {}; }, [](Entity &, const Entity &){}, 5.0); Entity &entity = wal.scene->getEntities().front(); REQUIRE(entity.getComponent().position == Vector3f()); entity.getComponent().bound.x = 5; entity.getComponent().bound.y = 5; entity.getComponent().bound.z = 5; collision.update(std::chrono::nanoseconds(1)); collision.fixedUpdate(); REQUIRE(entity.getComponent().position.x == 0.0); REQUIRE(entity.getComponent().position.y == 0.0); REQUIRE(entity.getComponent().position.z == 0.0); wal.scene->addEntity("block") .addComponent(2,2,2) .addComponent(1); Entity &player = wal.scene->getEntities().front(); collision.update(std::chrono::nanoseconds(1)); REQUIRE(player.hasComponent(typeid(PositionComponent))); collision.fixedUpdate(); REQUIRE(wal.scene->getEntities().size() == 2); REQUIRE(player.hasComponent(typeid(PositionComponent))); REQUIRE(player.getComponent().position.x == 1.0); REQUIRE(player.getComponent().position.y == 1); REQUIRE(player.getComponent().position.z == 1); } TEST_CASE("Collsion test with movable", "[Component][System]") { Wal wal; CollisionSystem collision(wal); MovableSystem movable(wal); wal.scene = std::make_shared(); wal.scene->addEntity("player") .addComponent() .addComponent([](Entity &actual, const Entity &) {}, [](Entity &actual, const Entity &) {}, 5.0) .addComponent(); wal.scene->addEntity("block") .addComponent(0, 0, 0) .addComponent([](Entity &actual, const Entity &){}, [](Entity &actual, const Entity &) { try { auto &mov = actual.getComponent(); mov._velocity = Vector3f(); } catch (std::exception &e) {}; }, 1); Entity &entity = wal.scene->getEntities().front(); REQUIRE(entity.getComponent().position == Vector3f()); entity.getComponent().bound.x = 5; entity.getComponent().bound.y = 5; entity.getComponent().bound.z = 5; entity.getComponent().addForce({1, 1, 1}); collision.update(std::chrono::nanoseconds(1)); collision.fixedUpdate(); movable.update(std::chrono::nanoseconds(1)); movable.fixedUpdate(); REQUIRE(entity.getComponent().position.x == 0.0); REQUIRE(entity.getComponent().position.y == 0.0); REQUIRE(entity.getComponent().position.z == 0.0); }