aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crepe/system/CollisionSystem.cpp100
-rw-r--r--src/crepe/system/CollisionSystem.h41
-rw-r--r--src/test/CMakeLists.txt4
-rw-r--r--src/test/CollisionTest.cpp124
-rw-r--r--src/test/Profiling.cpp2
5 files changed, 134 insertions, 137 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp
index 6f2c39d..362378d 100644
--- a/src/crepe/system/CollisionSystem.cpp
+++ b/src/crepe/system/CollisionSystem.cpp
@@ -28,19 +28,19 @@ void CollisionSystem::update() {
std::vector<std::reference_wrapper<BoxCollider>> boxcolliders = mgr.get_components_by_type<BoxCollider>();
std::vector<std::reference_wrapper<CircleCollider>> circlecolliders = mgr.get_components_by_type<CircleCollider>();
- std::vector<collider_stor> all_colliders;
+ std::vector<collider_variant> all_colliders;
// Add BoxCollider references
for (auto& box : boxcolliders) {
- all_colliders.push_back(collider_stor{box});
+ all_colliders.push_back(collider_variant{box});
}
// Add CircleCollider references
for (auto& circle : circlecolliders) {
- all_colliders.push_back(collider_stor{circle});
+ all_colliders.push_back(collider_variant{circle});
}
// Check between all colliders if there is a collision
- std::vector<std::pair<CollidedInfoStor,CollidedInfoStor>> collided = check_collisions(all_colliders);
+ std::vector<std::pair<CollisionInternal,CollisionInternal>> collided = check_collisions(all_colliders);
// For both objects call the collision handler
for (auto& collision_pair : collided) {
@@ -49,30 +49,30 @@ void CollisionSystem::update() {
}
}
-void CollisionSystem::collision_handler_request(CollidedInfoStor& data1,CollidedInfoStor& data2){
+void CollisionSystem::collision_handler_request(CollisionInternal& data1,CollisionInternal& data2){
- ColliderStorType type = check_collider_type(data1.collider,data2.collider);
- std::pair<vec2,CollisionSystem::Direction> move_back_data = collision_handler(data1,data2,type);
+ CollisionInternalType type = check_collider_type(data1.collider,data2.collider);
+ std::pair<vec2,CollisionSystem::Direction> resolution_data = collision_handler(data1,data2,type);
OptionalRef<Collider> collider1;
OptionalRef<Collider> collider2;
switch (type) {
- case ColliderStorType::BOX_BOX:{
+ case CollisionInternalType::BOX_BOX:{
collider1 = std::get<std::reference_wrapper<BoxCollider>>(data1.collider);
collider2 = std::get<std::reference_wrapper<BoxCollider>>(data2.collider);
break;
}
- case ColliderStorType::BOX_CIRCLE:{
+ case CollisionInternalType::BOX_CIRCLE:{
collider1 = std::get<std::reference_wrapper<BoxCollider>>(data1.collider);
collider2 = std::get<std::reference_wrapper<CircleCollider>>(data2.collider);
break;
}
- case ColliderStorType::CIRCLE_BOX:{
+ case CollisionInternalType::CIRCLE_BOX:{
collider1 = std::get<std::reference_wrapper<CircleCollider>>(data1.collider);
collider2 = std::get<std::reference_wrapper<BoxCollider>>(data2.collider);
break;
}
- case ColliderStorType::CIRCLE_CIRCLE:{
+ case CollisionInternalType::CIRCLE_CIRCLE:{
collider1 = std::get<std::reference_wrapper<CircleCollider>>(data1.collider);
collider2 = std::get<std::reference_wrapper<CircleCollider>>(data2.collider);
break;
@@ -81,10 +81,14 @@ void CollisionSystem::collision_handler_request(CollidedInfoStor& data1,Collided
// collision info
crepe::CollisionSystem::CollisionInfo collision_info{
- .first={ collider1, data1.transform, data1.rigidbody },
- .second={ collider2, data2.transform, data2.rigidbody },
- .move_back_value = move_back_data.first,
- .move_back_direction = move_back_data.second,
+ .first_collider = collider1,
+ .first_transform = data1.transform,
+ .first_rigidbody = data1.rigidbody,
+ .second_collider = collider2,
+ .second_transform = data2.transform,
+ .second_rigidbody = data2.rigidbody,
+ .resolution = resolution_data.first,
+ .resolution_direction = resolution_data.second,
};
// Determine if static needs to be called
@@ -92,23 +96,23 @@ void CollisionSystem::collision_handler_request(CollidedInfoStor& data1,Collided
}
-std::pair<vec2,CollisionSystem::Direction> CollisionSystem::collision_handler(CollidedInfoStor& data1,CollidedInfoStor& data2,ColliderStorType type) {
+std::pair<vec2,CollisionSystem::Direction> CollisionSystem::collision_handler(CollisionInternal& data1,CollisionInternal& data2,CollisionInternalType type) {
vec2 move_back;
switch (type) {
- case ColliderStorType::BOX_BOX: {
+ case CollisionInternalType::BOX_BOX: {
const BoxCollider & collider1 = std::get<std::reference_wrapper<BoxCollider>>(data1.collider);
const BoxCollider & collider2 = std::get<std::reference_wrapper<BoxCollider>>(data2.collider);
vec2 collider_pos1 = current_position(collider1.offset, data1.transform, data1.rigidbody);
vec2 collider_pos2 = current_position(collider2.offset, data2.transform, data2.rigidbody);
move_back = box_box_move_back(collider1,collider2,collider_pos1,collider_pos2);
}
- case ColliderStorType::BOX_CIRCLE: {
+ case CollisionInternalType::BOX_CIRCLE: {
}
- case ColliderStorType::CIRCLE_CIRCLE: {
+ case CollisionInternalType::CIRCLE_CIRCLE: {
}
- case ColliderStorType::CIRCLE_BOX: {
+ case CollisionInternalType::CIRCLE_BOX: {
}
}
@@ -165,43 +169,43 @@ vec2 CollisionSystem::box_box_move_back(const BoxCollider& box_collider1,const B
void CollisionSystem::determine_collision_handler(CollisionInfo& info){
// Check rigidbody type for static
- if(info.first.rigidbody.data.body_type != Rigidbody::BodyType::STATIC)
+ if(info.first_rigidbody.data.body_type != Rigidbody::BodyType::STATIC)
{
// If second body is static perform the static collision handler in this system
- if(info.second.rigidbody.data.body_type == Rigidbody::BodyType::STATIC){
+ if(info.second_rigidbody.data.body_type == Rigidbody::BodyType::STATIC){
static_collision_handler(info);
};
// Call collision event for user
CollisionEvent data(info);
- EventManager::get_instance().trigger_event<CollisionEvent>(data, info.first.collider.game_object_id);
+ EventManager::get_instance().trigger_event<CollisionEvent>(data, info.first_collider.game_object_id);
}
}
void CollisionSystem::static_collision_handler(CollisionInfo& info){
// Move object back using calculate move back value
- info.first.transform.position += info.move_back_value;
+ info.first_transform.position += info.resolution;
// If bounce is enabled mirror velocity
- if(info.first.rigidbody.data.bounce) {
- if(info.move_back_direction == Direction::BOTH)
+ if(info.first_rigidbody.data.bounce) {
+ if(info.resolution_direction == Direction::BOTH)
{
- info.first.rigidbody.data.linear_velocity.y = -info.first.rigidbody.data.linear_velocity.y * info.first.rigidbody.data.elastisity;
- info.first.rigidbody.data.linear_velocity.x = -info.first.rigidbody.data.linear_velocity.x * info.first.rigidbody.data.elastisity;
+ info.first_rigidbody.data.linear_velocity.y = -info.first_rigidbody.data.linear_velocity.y * info.first_rigidbody.data.elastisity;
+ info.first_rigidbody.data.linear_velocity.x = -info.first_rigidbody.data.linear_velocity.x * info.first_rigidbody.data.elastisity;
}
- else if(info.move_back_direction == Direction::Y_DIRECTION) {
- info.first.rigidbody.data.linear_velocity.y = -info.first.rigidbody.data.linear_velocity.y * info.first.rigidbody.data.elastisity;
+ else if(info.resolution_direction == Direction::Y_DIRECTION) {
+ info.first_rigidbody.data.linear_velocity.y = -info.first_rigidbody.data.linear_velocity.y * info.first_rigidbody.data.elastisity;
}
- else if(info.move_back_direction == Direction::X_DIRECTION){
- info.first.rigidbody.data.linear_velocity.x = -info.first.rigidbody.data.linear_velocity.x * info.first.rigidbody.data.elastisity;
+ else if(info.resolution_direction == Direction::X_DIRECTION){
+ info.first_rigidbody.data.linear_velocity.x = -info.first_rigidbody.data.linear_velocity.x * info.first_rigidbody.data.elastisity;
}
}
// Stop movement if bounce is disabled
else {
- info.first.rigidbody.data.linear_velocity = {0,0};
+ info.first_rigidbody.data.linear_velocity = {0,0};
}
}
-std::vector<std::pair<CollisionSystem::CollidedInfoStor,CollisionSystem::CollidedInfoStor>> CollisionSystem::check_collisions(std::vector<collider_stor> & colliders) {
+std::vector<std::pair<CollisionSystem::CollisionInternal,CollisionSystem::CollisionInternal>> CollisionSystem::check_collisions(std::vector<collider_variant> & colliders) {
// TODO:
@@ -233,7 +237,7 @@ std::vector<std::pair<CollisionSystem::CollidedInfoStor,CollisionSystem::Collide
};
- std::vector<std::pair<CollidedInfoStor,CollidedInfoStor>> collisions_ret;
+ std::vector<std::pair<CollisionInternal,CollisionInternal>> collisions_ret;
for (size_t i = 0; i < colliders.size(); ++i) {
std::visit([&](auto& inner_collider_ref) {
if (!inner_collider_ref.get().active) return;
@@ -245,11 +249,11 @@ std::vector<std::pair<CollisionSystem::CollidedInfoStor,CollisionSystem::Collide
if (inner_collider_ref.get().game_object_id == outer_collider_ref.get().game_object_id) return;
auto outer_components = get_active_transform_and_rigidbody(outer_collider_ref.get().game_object_id);
if (!outer_components) return;
- ColliderStorType type = check_collider_type(colliders[i],colliders[j]);
+ CollisionInternalType type = check_collider_type(colliders[i],colliders[j]);
if(!check_collision(colliders[i],*inner_components,colliders[j],*outer_components,type)) return;
collisions_ret.emplace_back(
- CollidedInfoStor{colliders[i], inner_components->first.get(), inner_components->second.get()},
- CollidedInfoStor{colliders[j], outer_components->first.get(), outer_components->second.get()}
+ CollisionInternal{colliders[i], inner_components->first.get(), inner_components->second.get()},
+ CollisionInternal{colliders[j], outer_components->first.get(), outer_components->second.get()}
);
}, colliders[j]);
}
@@ -259,45 +263,45 @@ std::vector<std::pair<CollisionSystem::CollidedInfoStor,CollisionSystem::Collide
return collisions_ret;
}
-CollisionSystem::ColliderStorType CollisionSystem::check_collider_type(const collider_stor& collider1,const collider_stor& collider2){
+CollisionSystem::CollisionInternalType CollisionSystem::check_collider_type(const collider_variant& collider1,const collider_variant& collider2){
if(std::holds_alternative<std::reference_wrapper<CircleCollider>>(collider1)){
if(std::holds_alternative<std::reference_wrapper<CircleCollider>>(collider2))
{
- return ColliderStorType::CIRCLE_CIRCLE;
+ return CollisionInternalType::CIRCLE_CIRCLE;
}
else {
- return ColliderStorType::CIRCLE_BOX;
+ return CollisionInternalType::CIRCLE_BOX;
}
}
else {
if(std::holds_alternative<std::reference_wrapper<CircleCollider>>(collider2))
{
- return ColliderStorType::BOX_CIRCLE;
+ return CollisionInternalType::BOX_CIRCLE;
}
else {
- return ColliderStorType::BOX_BOX;
+ return CollisionInternalType::BOX_BOX;
}
}
}
-bool CollisionSystem::check_collision(const collider_stor& collider1,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> components1,const collider_stor& collider2,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> components2, ColliderStorType type){
+bool CollisionSystem::check_collision(const collider_variant& collider1,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> components1,const collider_variant& collider2,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> components2, CollisionInternalType type){
switch (type) {
- case ColliderStorType::BOX_BOX: {
+ case CollisionInternalType::BOX_BOX: {
const BoxCollider & box_collider1 = std::get<std::reference_wrapper<BoxCollider>>(collider1);
const BoxCollider & box_collider2 = std::get<std::reference_wrapper<BoxCollider>>(collider2);
return check_box_box_collision(box_collider1,box_collider2,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get());
}
- case ColliderStorType::BOX_CIRCLE: {
+ case CollisionInternalType::BOX_CIRCLE: {
const BoxCollider & box_collider = std::get<std::reference_wrapper<BoxCollider>>(collider1);
const CircleCollider & circle_collider = std::get<std::reference_wrapper<CircleCollider>>(collider2);
return check_box_circle_collision(box_collider,circle_collider,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get());
}
- case ColliderStorType::CIRCLE_CIRCLE: {
+ case CollisionInternalType::CIRCLE_CIRCLE: {
const CircleCollider & circle_collider1 = std::get<std::reference_wrapper<CircleCollider>>(collider1);
const CircleCollider & circle_collider2 = std::get<std::reference_wrapper<CircleCollider>>(collider2);
return check_circle_circle_collision(circle_collider1,circle_collider2,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get());
}
- case ColliderStorType::CIRCLE_BOX: {
+ case CollisionInternalType::CIRCLE_BOX: {
const CircleCollider & circle_collider = std::get<std::reference_wrapper<CircleCollider>>(collider1);
const BoxCollider & box_collider = std::get<std::reference_wrapper<BoxCollider>>(collider2);
return check_box_circle_collision(box_collider,circle_collider,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get());
diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h
index 6334ba1..f8c7633 100644
--- a/src/crepe/system/CollisionSystem.h
+++ b/src/crepe/system/CollisionSystem.h
@@ -23,10 +23,10 @@ private:
//! A variant type that can hold either a BoxCollider or a CircleCollider.
// using collider_stor = std::variant<BoxCollider, CircleCollider>;
- using collider_stor = std::variant<std::reference_wrapper<BoxCollider>, std::reference_wrapper<CircleCollider>>;
+ using collider_variant = std::variant<std::reference_wrapper<BoxCollider>, std::reference_wrapper<CircleCollider>>;
//! A enum that is used to tell the pair of the collider stor in a std::pair.
- enum class ColliderStorType {
+ enum class CollisionInternalType {
BOX_BOX,
CIRCLE_CIRCLE,
BOX_CIRCLE,
@@ -38,9 +38,9 @@ private:
*
* This structure stores the collider type, its associated transform, and its rigidbody.
*/
- struct CollidedInfoStor {
+ struct CollisionInternal {
//! Store either BoxCollider or CircleCollider
- collider_stor& collider;
+ collider_variant& collider;
Transform& transform;
Rigidbody& rigidbody;
};
@@ -55,26 +55,19 @@ private:
public:
/**
- * \brief A structure representing the collision information between two colliders.
- *
- * This structure contains both colliders, their associated transforms and rigidbodies,
- * as well as the movement vector to resolve the collision.
- */
- struct ColliderInfo {
- const Collider& collider;
- Transform& transform;
- Rigidbody& rigidbody;
- };
- /**
* \brief A structure representing detailed collision information between two colliders.
*
* This includes the movement data required to resolve the collision.
*/
struct CollisionInfo{
- ColliderInfo first;
- ColliderInfo second;
- vec2 move_back_value;
- Direction move_back_direction = Direction::NONE;
+ Collider& first_collider;
+ Transform& first_transform;
+ Rigidbody& first_rigidbody;
+ Collider& second_collider;
+ Transform& second_transform;
+ Rigidbody& second_rigidbody;
+ vec2 resolution;
+ Direction resolution_direction = Direction::NONE;
};
public:
@@ -94,7 +87,7 @@ private: //generic
*
* \return collider pair type.
*/
- ColliderStorType check_collider_type(const collider_stor& collider1,const collider_stor& collider2);
+ CollisionInternalType check_collider_type(const collider_variant& collider1,const collider_variant& collider2);
/**
* \brief Calculates the position of the Collider
@@ -122,7 +115,7 @@ private:// handeling
*
* \return Postion of collider.
*/
- void collision_handler_request(CollidedInfoStor& data1,CollidedInfoStor& data2);
+ void collision_handler_request(CollisionInternal& data1,CollisionInternal& data2);
/**
* \brief Calculates the move back value and direction of the Collision
@@ -135,7 +128,7 @@ private:// handeling
*
* \return Move back value and direction for first gameobject
*/
- std::pair<vec2,Direction> collision_handler(CollidedInfoStor& data1,CollidedInfoStor& data2 ,ColliderStorType type);
+ std::pair<vec2,Direction> collision_handler(CollisionInternal& data1,CollisionInternal& data2 ,CollisionInternalType type);
/**
* \brief Calculates the move back value for box box collision
@@ -183,7 +176,7 @@ private: // detection
*
* \return Move back value and direction for first gameobject
*/
- std::vector<std::pair<CollidedInfoStor,CollidedInfoStor>> check_collisions(std::vector<collider_stor> & colliders);
+ std::vector<std::pair<CollisionInternal,CollisionInternal>> check_collisions(std::vector<collider_variant> & colliders);
/**
* \brief Calls the correct check collision function.
@@ -198,7 +191,7 @@ private: // detection
*
* \return status of collision
*/
- bool check_collision(const collider_stor& collider1,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> components1,const collider_stor& collider2,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> components2,CollisionSystem::ColliderStorType type);
+ bool check_collision(const collider_variant& collider1,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> components1,const collider_variant& collider2,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> components2,CollisionSystem::CollisionInternalType type);
/**
* \brief Check collision for box on box collider
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
index 68fa01c..616e238 100644
--- a/src/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -1,5 +1,5 @@
target_sources(test_main PUBLIC
- # CollisionTest.cpp
+ CollisionTest.cpp
main.cpp
# PhysicsTest.cpp
# ScriptTest.cpp
@@ -13,5 +13,5 @@ target_sources(test_main PUBLIC
# ValueBrokerTest.cpp
# DBTest.cpp
# Vector2Test.cpp
- Profiling.cpp
+ # Profiling.cpp
)
diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp
index 245cced..8daf77f 100644
--- a/src/test/CollisionTest.cpp
+++ b/src/test/CollisionTest.cpp
@@ -114,11 +114,11 @@ TEST_F(CollisionTest, collision_example) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 2);
};
EXPECT_FALSE(collision_happend);
collision_sys.update();
@@ -129,17 +129,17 @@ TEST_F(CollisionTest, collision_box_box_dynamic_both_no_velocity) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
- EXPECT_EQ(ev.info.move_back_value.x, 10);
- EXPECT_EQ(ev.info.move_back_value.y, 10);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.resolution.x, 10);
+ EXPECT_EQ(ev.info.resolution.y, 10);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 2);
- EXPECT_EQ(ev.info.move_back_value.x, 10);
- EXPECT_EQ(ev.info.move_back_value.y, 10);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.resolution.x, 10);
+ EXPECT_EQ(ev.info.resolution.y, 10);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
@@ -152,17 +152,17 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
- EXPECT_EQ(ev.info.move_back_value.x, -5);
- EXPECT_EQ(ev.info.move_back_value.y, 0);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.resolution.x, -5);
+ EXPECT_EQ(ev.info.resolution.y, 0);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 2);
- EXPECT_EQ(ev.info.move_back_value.x, 5);
- EXPECT_EQ(ev.info.move_back_value.y, 0);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.resolution.x, 5);
+ EXPECT_EQ(ev.info.resolution.y, 0);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
};
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
@@ -175,17 +175,17 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
- EXPECT_EQ(ev.info.move_back_value.x, 0);
- EXPECT_EQ(ev.info.move_back_value.y, -5);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.resolution.x, 0);
+ EXPECT_EQ(ev.info.resolution.y, -5);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 2);
- EXPECT_EQ(ev.info.move_back_value.x, 0);
- EXPECT_EQ(ev.info.move_back_value.y, 5);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.resolution.x, 0);
+ EXPECT_EQ(ev.info.resolution.y, 5);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
};
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
@@ -198,17 +198,17 @@ TEST_F(CollisionTest, collision_box_box_dynamic_both) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
- EXPECT_EQ(ev.info.move_back_value.x, 10);
- EXPECT_EQ(ev.info.move_back_value.y, 10);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.resolution.x, 10);
+ EXPECT_EQ(ev.info.resolution.y, 10);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 2);
- EXPECT_EQ(ev.info.move_back_value.x, 10);
- EXPECT_EQ(ev.info.move_back_value.y, 10);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.resolution.x, 10);
+ EXPECT_EQ(ev.info.resolution.y, 10);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
@@ -225,17 +225,17 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
- EXPECT_EQ(ev.info.move_back_value.x, -5);
- EXPECT_EQ(ev.info.move_back_value.y, -5);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.resolution.x, -5);
+ EXPECT_EQ(ev.info.resolution.y, -5);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 2);
- EXPECT_EQ(ev.info.move_back_value.x, 5);
- EXPECT_EQ(ev.info.move_back_value.y, 5);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.resolution.x, 5);
+ EXPECT_EQ(ev.info.resolution.y, 5);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
};
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
@@ -252,17 +252,17 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
- EXPECT_EQ(ev.info.move_back_value.x, -5);
- EXPECT_EQ(ev.info.move_back_value.y, -5);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.resolution.x, -5);
+ EXPECT_EQ(ev.info.resolution.y, -5);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 2);
- EXPECT_EQ(ev.info.move_back_value.x, 5);
- EXPECT_EQ(ev.info.move_back_value.y, 5);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 2);
+ EXPECT_EQ(ev.info.resolution.x, 5);
+ EXPECT_EQ(ev.info.resolution.y, 5);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
};
EXPECT_FALSE(collision_happend);
Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get();
@@ -280,10 +280,10 @@ TEST_F(CollisionTest, collision_box_box_static_both) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
- EXPECT_EQ(ev.info.move_back_value.x, 10);
- EXPECT_EQ(ev.info.move_back_value.y, 10);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.resolution.x, 10);
+ EXPECT_EQ(ev.info.resolution.y, 10);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
// is static should not be called
@@ -302,10 +302,10 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
- EXPECT_EQ(ev.info.move_back_value.x, -5);
- EXPECT_EQ(ev.info.move_back_value.y, -5);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.resolution.x, -5);
+ EXPECT_EQ(ev.info.resolution.y, -5);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
// is static should not be called
@@ -326,10 +326,10 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) {
bool collision_happend = false;
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
- EXPECT_EQ(ev.info.first.collider.game_object_id, 1);
- EXPECT_EQ(ev.info.move_back_value.x, -5);
- EXPECT_EQ(ev.info.move_back_value.y, -5);
- EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
+ EXPECT_EQ(ev.info.first_collider.game_object_id, 1);
+ EXPECT_EQ(ev.info.resolution.x, -5);
+ EXPECT_EQ(ev.info.resolution.y, -5);
+ EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION);
};
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
// is static should not be called
diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp
index 2b03102..2549c57 100644
--- a/src/test/Profiling.cpp
+++ b/src/test/Profiling.cpp
@@ -36,7 +36,7 @@ List of test cases with component settings/details
class TestScript : public Script {
bool oncollision(const CollisionEvent& test) {
- Log::logf("Box {} script on_collision()", test.info.first.collider.game_object_id);
+ Log::logf("Box {} script on_collision()", test.info.first_collider.game_object_id);
return true;
}
void init() {