forked from enlightenment/efl
EPhysics: use inlist for world's bodies list
SVN revision: 75139
This commit is contained in:
parent
595e8c8195
commit
4d800075e7
|
@ -14,7 +14,7 @@ struct _Ball_Props {
|
||||||
static void
|
static void
|
||||||
_jump(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
_jump(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||||
{
|
{
|
||||||
const Eina_List *l, *bodies;
|
Eina_List *l, *bodies;
|
||||||
EPhysics_Body *body;
|
EPhysics_Body *body;
|
||||||
Test_Data *test_data = data;
|
Test_Data *test_data = data;
|
||||||
EPhysics_World *world = test_data->world;
|
EPhysics_World *world = test_data->world;
|
||||||
|
@ -24,6 +24,7 @@ _jump(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||||
bodies = ephysics_world_bodies_get(world);
|
bodies = ephysics_world_bodies_get(world);
|
||||||
EINA_LIST_FOREACH(bodies, l, body)
|
EINA_LIST_FOREACH(bodies, l, body)
|
||||||
ephysics_body_central_impulse_apply(body, 0, 10);
|
ephysics_body_central_impulse_apply(body, 0, 10);
|
||||||
|
eina_list_free(bodies);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -684,13 +684,15 @@ EAPI double ephysics_world_rate_get(const EPhysics_World *world);
|
||||||
* @param world The world object.
|
* @param world The world object.
|
||||||
* @return The list of bodies that belongs to this @p world.
|
* @return The list of bodies that belongs to this @p world.
|
||||||
*
|
*
|
||||||
|
* @note The list should be freed after usage.
|
||||||
|
*
|
||||||
* @see ephysics_body_circle_add().
|
* @see ephysics_body_circle_add().
|
||||||
* @see ephysics_body_box_add().
|
* @see ephysics_body_box_add().
|
||||||
* @see ephysics_body_del().
|
* @see ephysics_body_del().
|
||||||
*
|
*
|
||||||
* @ingroup EPhysics_World
|
* @ingroup EPhysics_World
|
||||||
*/
|
*/
|
||||||
EAPI const Eina_List *ephysics_world_bodies_get(const EPhysics_World *world);
|
EAPI Eina_List *ephysics_world_bodies_get(const EPhysics_World *world);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
|
|
|
@ -19,18 +19,6 @@ struct _EPhysics_Body_Callback {
|
||||||
EPhysics_Callback_Body_Type type;
|
EPhysics_Callback_Body_Type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _EPhysics_Body {
|
|
||||||
btCollisionShape *collision_shape;
|
|
||||||
btRigidBody *rigid_body;
|
|
||||||
Evas_Object *evas_obj;
|
|
||||||
EPhysics_World *world;
|
|
||||||
void *data;
|
|
||||||
Eina_Inlist *callbacks;
|
|
||||||
double mass;
|
|
||||||
Eina_Bool active:1;
|
|
||||||
Eina_List *collision_groups;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _EPhysics_Body_Collision {
|
struct _EPhysics_Body_Collision {
|
||||||
EPhysics_Body *contact_body;
|
EPhysics_Body *contact_body;
|
||||||
Evas_Coord x;
|
Evas_Coord x;
|
||||||
|
|
|
@ -53,12 +53,25 @@ typedef enum _EPhysics_World_Boundary
|
||||||
EPHYSICS_WORLD_BOUNDARY_LAST
|
EPHYSICS_WORLD_BOUNDARY_LAST
|
||||||
} EPhysics_World_Boundary;
|
} EPhysics_World_Boundary;
|
||||||
|
|
||||||
|
struct _EPhysics_Body {
|
||||||
|
EINA_INLIST;
|
||||||
|
btCollisionShape *collision_shape;
|
||||||
|
btRigidBody *rigid_body;
|
||||||
|
Evas_Object *evas_obj;
|
||||||
|
EPhysics_World *world;
|
||||||
|
void *data;
|
||||||
|
Eina_Inlist *callbacks;
|
||||||
|
double mass;
|
||||||
|
Eina_Bool active:1;
|
||||||
|
Eina_List *collision_groups;
|
||||||
|
};
|
||||||
|
|
||||||
extern int _ephysics_log_dom;
|
extern int _ephysics_log_dom;
|
||||||
|
|
||||||
int ephysics_world_init(void);
|
int ephysics_world_init(void);
|
||||||
int ephysics_world_shutdown(void);
|
int ephysics_world_shutdown(void);
|
||||||
Eina_Bool ephysics_world_body_add(EPhysics_World *world, const EPhysics_Body *body, btRigidBody *rigid_body);
|
Eina_Bool ephysics_world_body_add(EPhysics_World *world, EPhysics_Body *body, btRigidBody *rigid_body);
|
||||||
void ephysics_world_body_del(EPhysics_World *world, const EPhysics_Body *body, btRigidBody *rigid_body);
|
void ephysics_world_body_del(EPhysics_World *world, EPhysics_Body *body, btRigidBody *rigid_body);
|
||||||
void ephysics_world_constraint_add(EPhysics_World *world, btTypedConstraint *bt_constraint);
|
void ephysics_world_constraint_add(EPhysics_World *world, btTypedConstraint *bt_constraint);
|
||||||
void ephysics_world_constraint_del(EPhysics_World *world, btTypedConstraint *bt_constraint);
|
void ephysics_world_constraint_del(EPhysics_World *world, btTypedConstraint *bt_constraint);
|
||||||
void ephysics_body_world_boundaries_resize(EPhysics_World *world);
|
void ephysics_body_world_boundaries_resize(EPhysics_World *world);
|
||||||
|
|
|
@ -31,7 +31,7 @@ struct _EPhysics_World {
|
||||||
EPhysics_Camera *camera;
|
EPhysics_Camera *camera;
|
||||||
Evas_Coord x, y, w, h;
|
Evas_Coord x, y, w, h;
|
||||||
Eina_Inlist *callbacks;
|
Eina_Inlist *callbacks;
|
||||||
Eina_List *bodies;
|
Eina_Inlist *bodies;
|
||||||
int max_sub_steps;
|
int max_sub_steps;
|
||||||
double last_update;
|
double last_update;
|
||||||
double rate;
|
double rate;
|
||||||
|
@ -185,9 +185,10 @@ _ephysics_world_boundary_del_cb(void *data, EPhysics_Body *body, void *event_inf
|
||||||
}
|
}
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
ephysics_world_body_add(EPhysics_World *world, const EPhysics_Body *body, btRigidBody *rigid_body)
|
ephysics_world_body_add(EPhysics_World *world, EPhysics_Body *body, btRigidBody *rigid_body)
|
||||||
{
|
{
|
||||||
world->bodies = eina_list_append(world->bodies, body);
|
world->bodies = eina_inlist_append(world->bodies,
|
||||||
|
EINA_INLIST_GET(body));
|
||||||
if (eina_error_get())
|
if (eina_error_get())
|
||||||
{
|
{
|
||||||
ERR("Couldn't add body to bodies list.");
|
ERR("Couldn't add body to bodies list.");
|
||||||
|
@ -198,10 +199,11 @@ ephysics_world_body_add(EPhysics_World *world, const EPhysics_Body *body, btRigi
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ephysics_world_body_del(EPhysics_World *world, const EPhysics_Body *body, btRigidBody *rigid_body)
|
ephysics_world_body_del(EPhysics_World *world, EPhysics_Body *body, btRigidBody *rigid_body)
|
||||||
{
|
{
|
||||||
world->dynamics_world->removeRigidBody(rigid_body);
|
world->dynamics_world->removeRigidBody(rigid_body);
|
||||||
world->bodies = eina_list_remove(world->bodies, body);
|
world->bodies = eina_inlist_remove(world->bodies,
|
||||||
|
EINA_INLIST_GET(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -420,7 +422,7 @@ EAPI void
|
||||||
ephysics_world_del(EPhysics_World *world)
|
ephysics_world_del(EPhysics_World *world)
|
||||||
{
|
{
|
||||||
EPhysics_World_Callback *cb;
|
EPhysics_World_Callback *cb;
|
||||||
void *data;
|
EPhysics_Body *body;
|
||||||
|
|
||||||
if (!world)
|
if (!world)
|
||||||
{
|
{
|
||||||
|
@ -446,8 +448,12 @@ ephysics_world_del(EPhysics_World *world)
|
||||||
free(cb);
|
free(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
EINA_LIST_FREE(world->bodies, data)
|
while (world->bodies)
|
||||||
ephysics_orphan_body_del((EPhysics_Body *) data);
|
{
|
||||||
|
body = EINA_INLIST_CONTAINER_GET(world->bodies, EPhysics_Body);
|
||||||
|
world->bodies = eina_inlist_remove(world->bodies, world->bodies);
|
||||||
|
ephysics_orphan_body_del(body);
|
||||||
|
}
|
||||||
|
|
||||||
ephysics_camera_del(world->camera);
|
ephysics_camera_del(world->camera);
|
||||||
delete world->dynamics_world;
|
delete world->dynamics_world;
|
||||||
|
@ -753,16 +759,22 @@ ephysics_world_event_callback_del_full(EPhysics_World *world, EPhysics_Callback_
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI const Eina_List *
|
EAPI Eina_List *
|
||||||
ephysics_world_bodies_get(const EPhysics_World *world)
|
ephysics_world_bodies_get(const EPhysics_World *world)
|
||||||
{
|
{
|
||||||
|
Eina_List *list = NULL;
|
||||||
|
EPhysics_Body *body;
|
||||||
|
|
||||||
if (!world)
|
if (!world)
|
||||||
{
|
{
|
||||||
ERR("Couldn't get the bodies list, no world provided.");
|
ERR("Couldn't get the bodies list, no world provided.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return world->bodies;
|
EINA_INLIST_FOREACH(world->bodies, body)
|
||||||
|
list = eina_list_append(list, body);
|
||||||
|
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
|
|
Loading…
Reference in New Issue