From 564c23a80f9552255928cb29d432c29c214a1d1b Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Fri, 27 Jul 2012 14:47:46 +0000 Subject: [PATCH] EPhysics: add data setter / getter for bodies Useful when you need structures per bodies to be updated on collision callbacks. SVN revision: 74495 --- legacy/ephysics/src/lib/EPhysics.h | 33 +++++++++++++++++++++++ legacy/ephysics/src/lib/ephysics_body.cpp | 25 +++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index eeb191682f..35b36d5a7a 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -1669,6 +1669,39 @@ EAPI void ephysics_body_linear_movement_enable_get(const EPhysics_Body *body, Ei */ EAPI double ephysics_body_rotation_get(const EPhysics_Body *body); +/** + * @brief + * Set data to @p body. + * + * If a previous data was set, it's reference will be lost and body + * will point to the new data. + * + * It can be useful when you need to store a structure per body. For example, + * some values that must to be updated when a collision occurs between two + * bodies. + * + * @param body The physics body. + * @param data The data to be set. + * + * @see ephysics_body_data_get() + * + * @ingroup EPhysics_Body + */ +EAPI void ephysics_body_data_set(EPhysics_Body *body, void *data); + +/** + * @brief + * Return data previously set to body. + * + * @param body The physics body. + * @return The data set or @c NULL on error. + * + * @see ephysics_body_data_get() for more details + * + * @ingroup EPhysics_Body + */ +EAPI void *ephysics_body_data_get(const EPhysics_Body *body); + /** * @} */ diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index a18f3d9b5f..ce9b5d90af 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -26,6 +26,7 @@ struct _EPhysics_Body { btRigidBody *rigid_body; Evas_Object *evas_obj; EPhysics_World *world; + void *data; Eina_Inlist *callbacks; double mass; Eina_Bool active:1; @@ -934,6 +935,30 @@ ephysics_body_rotation_get(const EPhysics_Body *body) return rot; } +EAPI void +ephysics_body_data_set(EPhysics_Body *body, void *data) +{ + if (!body) + { + ERR("Can't set data, body is null."); + return; + } + + body->data = data; +} + +EAPI void * +ephysics_body_data_get(const EPhysics_Body *body) +{ + if (!body) + { + ERR("Can't get data, body is null."); + return NULL; + } + + return body->data; +} + #ifdef __cplusplus } #endif