From 47aac958012aa133931cbb66ed5b19ac065d5beb Mon Sep 17 00:00:00 2001 From: Bluub Date: Mon, 31 May 2021 14:54:53 +0200 Subject: [PATCH] adding unit test crashing on addEntity --- CMakeLists.txt | 1 + .../Collision/CollisionComponent.cpp | 20 +++---- .../Collision/CollisionComponent.hpp | 4 +- tests/CollisionTest.cpp | 53 +++++++++++++++++++ 4 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 tests/CollisionTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c0e8f2f..10f22238 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ add_executable(unit_tests EXCLUDE_FROM_ALL tests/MainTest.cpp tests/EngineTests.cpp tests/CallbackTest.cpp + tests/CollisionTest.cpp ) target_include_directories(unit_tests PUBLIC sources) target_link_libraries(unit_tests PUBLIC wal ray) diff --git a/sources/Component/Collision/CollisionComponent.cpp b/sources/Component/Collision/CollisionComponent.cpp index 0f14ca27..2f5b6c9d 100644 --- a/sources/Component/Collision/CollisionComponent.cpp +++ b/sources/Component/Collision/CollisionComponent.cpp @@ -17,48 +17,48 @@ namespace BBM } CollisionComponent::CollisionComponent(WAL::Entity &entity, std::function callback, Vector3f bound) - : WAL::Component(entity), onCollide(callback), _boundX(bound.x), _boundY(bound.y), _boundZ(bound.z) + : WAL::Component(entity), onCollide(callback), _bound(bound) { } CollisionComponent::CollisionComponent(WAL::Entity &entity, std::function callback, float boundSize) - : WAL::Component(entity), onCollide(callback), _boundX(boundSize), _boundY(boundSize), _boundZ(boundSize) + : WAL::Component(entity), onCollide(callback), _bound({boundSize, boundSize, boundSize}) { } CollisionComponent::CollisionComponent(WAL::Entity &entity, WAL::Callback callback, Vector3f bound) - : WAL::Component(entity), onCollide(callback), _boundX(bound.x), _boundY(bound.y), _boundZ(bound.z) + : WAL::Component(entity), onCollide(callback), _bound(bound) { } CollisionComponent::CollisionComponent(WAL::Entity &entity, WAL::Callback callback, float boundSize) - : WAL::Component(entity), onCollide(callback), _boundX(boundSize), _boundY(boundSize), _boundZ(boundSize) + : WAL::Component(entity), onCollide(callback), _bound({boundSize, boundSize, boundSize}) { } float CollisionComponent::getBoundX(void) const { - return _boundX; + return _bound.x; } float CollisionComponent::getBoundY(void) const { - return _boundY; + return _bound.y; } float CollisionComponent::getBoundZ(void) const { - return _boundZ; + return _bound.z; } void CollisionComponent::setBoundX(float value) { - _boundX = value; + _bound.x = value; } void CollisionComponent::setBoundY(float value) { - _boundY = value; + _bound.y = value; } void CollisionComponent::setBoundZ(float value) { - _boundZ = value; + _bound.z = value; } } \ No newline at end of file diff --git a/sources/Component/Collision/CollisionComponent.hpp b/sources/Component/Collision/CollisionComponent.hpp index 64ecc243..9d557f64 100644 --- a/sources/Component/Collision/CollisionComponent.hpp +++ b/sources/Component/Collision/CollisionComponent.hpp @@ -14,9 +14,7 @@ namespace BBM class CollisionComponent : public WAL::Component { private: - float _boundX; - float _boundY; - float _boundZ; + Vector3f _bound; public: //! @brief get bound size on the X axis float getBoundX(void) const; diff --git a/tests/CollisionTest.cpp b/tests/CollisionTest.cpp new file mode 100644 index 00000000..72818cef --- /dev/null +++ b/tests/CollisionTest.cpp @@ -0,0 +1,53 @@ +// +// Created by Louis Auzuret on 5/31/21. +// + +#include +#include "Entity/Entity.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "System/Collision/CollisionSystem.hpp" +#include "Wal.hpp" + +#define private public +#include "Component/Collision/CollisionComponent.hpp" + +using namespace WAL; +using namespace BBM; + + +TEST_CASE("Collsion test", "[Component][System]") +{ + Wal wal; + wal.scene->addEntity("player") + .addComponent(); + // .addComponent([](Entity &actual, const Entity &) { + // auto &pos = actual.getComponent(); + // pos.position.x = 1; + // pos.position.y = 1; + // pos.position.z = 1; + // }, 5.0); + //Entity &entity = wal.scene->getEntities()[0]; +// + //REQUIRE(entity.getComponent().position == Vector3f()); +// + //entity.getComponent()._bound.x = 5; + //entity.getComponent()._bound.y = 5; + //entity.getComponent()._bound.z = 5; +// + //CollisionSystem collision(wal); + //collision.onUpdate(entity, std::chrono::nanoseconds(1)); + //collision.onFixedUpdate(entity); + //REQUIRE(entity.getComponent().position.x == 0); + //REQUIRE(entity.getComponent().position.y == 0); + //REQUIRE(entity.getComponent().position.z == 0); +// +// + //wal.scene->addEntity("block") + // .addComponent() + // .addComponent([](Entity &, const Entity &){}, 1); + //collision.onUpdate(entity, std::chrono::nanoseconds(1)); + //collision.onFixedUpdate(entity); + //REQUIRE(entity.getComponent().position.x == 1); + //REQUIRE(entity.getComponent().position.y == 1); + //REQUIRE(entity.getComponent().position.z == 1); +} \ No newline at end of file