| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | #define SG_BUILD_MODULE |
| 16 | #include <siege/physics/collision.h> |
| 17 | #include <siege/core/entity.h> |
| 18 | |
| 19 | #include <stdlib.h> |
| 20 | |
| 21 | #include <chipmunk/chipmunk.h> |
| 22 | |
| 23 | |
| 24 | void SG_CALL__cdecl _sg_cbPhysicsCollisionBegin(SGPhysicsShape* shape1, SGPhysicsShape* shape2, void* handle) |
| 25 | { |
| 26 | SGPhysicsCollision coll; |
| 27 | coll.handle = handle; |
| 28 | coll.shape1 = shape1; |
| 29 | coll.shape2 = shape2; |
| 30 | |
| 31 | if(shape1 && shape1->body->entity) |
| 1 | Assuming pointer value is null | |
|
| 32 | { |
| 33 | if(shape1->body->entity->lcCollisionBegin) |
| 34 | shape1->body->entity->lcCollisionBegin(shape1->body->entity, shape2->body->entity, &coll); |
| 35 | if(shape1->body->entity->lcCollisionOneBegin) |
| 36 | shape1->body->entity->lcCollisionOneBegin(shape1->body->entity, shape2->body->entity, &coll); |
| 37 | } |
| 38 | if(shape2 && shape2->body->entity) |
| |
| 39 | { |
| 40 | if(shape2->body->entity->lcCollisionBegin) |
| |
| 41 | shape2->body->entity->lcCollisionBegin(shape2->body->entity, shape1->body->entity, &coll); |
| 4 | | Access to field 'body' results in a dereference of a null pointer (loaded from variable 'shape1') |
|
| 42 | if(shape2->body->entity->lcCollisionTwoBegin) |
| 43 | shape2->body->entity->lcCollisionTwoBegin(shape2->body->entity, shape1->body->entity, &coll); |
| 44 | } |
| 45 | } |
| 46 | void SG_CALL__cdecl _sg_cbPhysicsCollisionPreSolve(SGPhysicsShape* shape1, SGPhysicsShape* shape2, void* handle) |
| 47 | { |
| 48 | SGPhysicsCollision coll; |
| 49 | coll.handle = handle; |
| 50 | coll.shape1 = shape1; |
| 51 | coll.shape2 = shape2; |
| 52 | |
| 53 | if(shape1 && shape1->body->entity) |
| 54 | { |
| 55 | if(shape1->body->entity->lcCollision) |
| 56 | shape1->body->entity->lcCollision(shape1->body->entity, shape2->body->entity, &coll); |
| 57 | if(shape1->body->entity->lcCollisionOne) |
| 58 | shape1->body->entity->lcCollisionOne(shape1->body->entity, shape2->body->entity, &coll); |
| 59 | } |
| 60 | if(shape2 && shape2->body->entity) |
| 61 | { |
| 62 | if(shape2->body->entity->lcCollision) |
| 63 | shape2->body->entity->lcCollision(shape2->body->entity, shape1->body->entity, &coll); |
| 64 | if(shape2->body->entity->lcCollisionTwo) |
| 65 | shape2->body->entity->lcCollisionTwo(shape2->body->entity, shape1->body->entity, &coll); |
| 66 | } |
| 67 | } |
| 68 | void SG_CALL__cdecl _sg_cbPhysicsCollisionPostSolve(SGPhysicsShape* shape1, SGPhysicsShape* shape2, void* handle) |
| 69 | { |
| 70 | } |
| 71 | void SG_CALL__cdecl _sg_cbPhysicsCollisionSeparate(SGPhysicsShape* shape1, SGPhysicsShape* shape2, void* handle) |
| 72 | { |
| 73 | SGPhysicsCollision coll; |
| 74 | coll.handle = handle; |
| 75 | coll.shape1 = shape1; |
| 76 | coll.shape2 = shape2; |
| 77 | |
| 78 | if(shape1 && shape1->body->entity) |
| 79 | { |
| 80 | if(shape1->body->entity->lcCollisionEnd) |
| 81 | shape1->body->entity->lcCollisionEnd(shape1->body->entity, shape2->body->entity, &coll); |
| 82 | if(shape1->body->entity->lcCollisionOneEnd) |
| 83 | shape1->body->entity->lcCollisionOneEnd(shape1->body->entity, shape2->body->entity, &coll); |
| 84 | } |
| 85 | if(shape2 && shape2->body->entity) |
| 86 | { |
| 87 | if(shape2->body->entity->lcCollisionEnd) |
| 88 | shape2->body->entity->lcCollisionEnd(shape2->body->entity, shape1->body->entity, &coll); |
| 89 | if(shape2->body->entity->lcCollisionTwoEnd) |
| 90 | shape2->body->entity->lcCollisionTwoEnd(shape2->body->entity, shape1->body->entity, &coll); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void SG_CALL__cdecl sgPhysicsCollisionIgnore(SGPhysicsCollision* coll) |
| 95 | { |
| 96 | cpArbiterIgnore(coll->handle); |
| 97 | } |
| 98 | |
| 99 | size_t SG_CALL__cdecl sgPhysicsCollisionGetNumContacts(SGPhysicsCollision* coll) |
| 100 | { |
| 101 | return cpArbiterGetCount(coll->handle); |
| 102 | } |
| 103 | void SG_CALL__cdecl sgPhysicsCollisionGetPoint(SGPhysicsCollision* coll, size_t index, float* x, float* y) |
| 104 | { |
| 105 | float t; |
| 106 | if(!x) x = &t; |
| 107 | if(!y) y = &t; |
| 108 | |
| 109 | cpVect v = cpArbiterGetPoint(coll->handle, index); |
| 110 | *x = v.x; |
| 111 | *y = v.y; |
| 112 | } |
| 113 | void SG_CALL__cdecl sgPhysicsCollisionGetNormal(SGPhysicsCollision* coll, size_t index, float* x, float* y) |
| 114 | { |
| 115 | float t; |
| 116 | if(!x) x = &t; |
| 117 | if(!y) y = &t; |
| 118 | |
| 119 | cpVect v = cpArbiterGetNormal(coll->handle, index); |
| 120 | *x = v.x; |
| 121 | *y = v.y; |
| 122 | } |
| 123 | float SG_CALL__cdecl sgPhysicsCollisionGetDepth(SGPhysicsCollision* coll, size_t index) |
| 124 | { |
| 125 | return cpArbiterGetDepth(coll->handle, index); |
| 126 | } |
| 127 | void SG_CALL__cdecl sgPhysicsCollisionGetImpulse(SGPhysicsCollision* coll, float* x, float* y, SGbool friction) |
| 128 | { |
| 129 | float t; |
| 130 | if(!x) x = &t; |
| 131 | if(!y) y = &t; |
| 132 | |
| 133 | cpVect v; |
| 134 | if(friction) |
| 135 | v = cpArbiterTotalImpulseWithFriction(coll->handle); |
| 136 | else |
| 137 | v = cpArbiterTotalImpulse(coll->handle); |
| 138 | *x = v.x; |
| 139 | *y = v.y; |
| 140 | } |
| 141 | SGPhysicsShape* SG_CALL__cdecl sgPhysicsCollisionGetShapeOne(SGPhysicsCollision* coll) |
| 142 | { |
| 143 | return coll->shape1; |
| 144 | } |
| 145 | SGPhysicsShape* SG_CALL__cdecl sgPhysicsCollisionGetShapeTwo(SGPhysicsCollision* coll) |
| 146 | { |
| 147 | return coll->shape2; |
| 148 | } |