ephysics: avoid many unecessary allocs / free on
authorBruno Dilly <bdilly@profusion.mobi>
Wed, 31 Oct 2012 21:02:43 +0000 (21:02 +0000)
committerBruno Dilly <bdilly@profusion.mobi>
Wed, 31 Oct 2012 21:02:43 +0000 (21:02 +0000)
 collision detection

Only allocates data when it has a callback registered.

SVN revision: 78725

legacy/ephysics/src/lib/ephysics_body.cpp
legacy/ephysics/src/lib/ephysics_private.h

index 7cc3652..d7c25ee 100644 (file)
@@ -1347,7 +1347,7 @@ ephysics_body_contact_processed(EPhysics_Body *body, EPhysics_Body *contact_body
    double rate;
    int wy, wh;
 
-   if ((!body) || (!contact_body))
+   if ((!body) || (!contact_body) || (body->collision_cb < 1))
      return;
 
    collision = (EPhysics_Body_Collision *)calloc(
@@ -2845,6 +2845,8 @@ ephysics_body_event_callback_add(EPhysics_Body *body, EPhysics_Callback_Body_Typ
    cb->data = (void *)data;
 
    body->callbacks = eina_inlist_append(body->callbacks, EINA_INLIST_GET(cb));
+   if (type == EPHYSICS_CALLBACK_BODY_COLLISION)
+       body->collision_cb++;
 }
 
 EAPI void *
@@ -2866,8 +2868,9 @@ ephysics_body_event_callback_del(EPhysics_Body *body, EPhysics_Callback_Body_Typ
 
         cb_data = cb->data;
         _ephysics_body_event_callback_del(body, cb);
+        if (type == EPHYSICS_CALLBACK_BODY_COLLISION)
+            body->collision_cb--;
         break;
-
      }
 
    return cb_data;
index 2114a2b..4f070a1 100644 (file)
@@ -114,6 +114,7 @@ struct _EPhysics_Body {
      int cloth_columns;
      int cloth_rows;
      int material_index;
+     int collision_cb;
      EPhysics_Body_Soft_Body_Data *soft_data;
      struct {
        int triangle;