diff --git a/src/api/l_physics_joints.c b/src/api/l_physics_joints.c index 58e6c7b0..349f4fe0 100644 --- a/src/api/l_physics_joints.c +++ b/src/api/l_physics_joints.c @@ -5,7 +5,7 @@ #include void luax_pushjoint(lua_State* L, Joint* joint) { - switch (joint->type) { + switch (lovrJointGetType(joint)) { case JOINT_BALL: luax_pushtype(L, BallJoint, joint); break; case JOINT_DISTANCE: luax_pushtype(L, DistanceJoint, joint); break; case JOINT_HINGE: luax_pushtype(L, HingeJoint, joint); break; diff --git a/src/api/l_physics_shapes.c b/src/api/l_physics_shapes.c index 01493e6a..d84601bc 100644 --- a/src/api/l_physics_shapes.c +++ b/src/api/l_physics_shapes.c @@ -5,7 +5,7 @@ #include void luax_pushshape(lua_State* L, Shape* shape) { - switch (shape->type) { + switch (lovrShapeGetType(shape)) { case SHAPE_SPHERE: luax_pushtype(L, SphereShape, shape); break; case SHAPE_BOX: luax_pushtype(L, BoxShape, shape); break; case SHAPE_CAPSULE: luax_pushtype(L, CapsuleShape, shape); break; diff --git a/src/api/l_physics_world.c b/src/api/l_physics_world.c index fb580c99..ba592c63 100644 --- a/src/api/l_physics_world.c +++ b/src/api/l_physics_world.c @@ -161,7 +161,7 @@ static int l_lovrWorldGetColliders(lua_State* L) { while (collider) { luax_pushtype(L, Collider, collider); lua_rawseti(L, -2, index++); - collider = collider->next; + collider = lovrColliderGetNext(collider); } return 1; diff --git a/src/modules/physics/physics.c b/src/modules/physics/physics.c index 3a32e959..f5ca1ed5 100644 --- a/src/modules/physics/physics.c +++ b/src/modules/physics/physics.c @@ -3,6 +3,49 @@ #include #include +struct World { + uint32_t ref; + dWorldID id; + dSpaceID space; + dJointGroupID contactGroup; + arr_t(Shape*) overlaps; + char* tags[MAX_TAGS]; + uint16_t masks[MAX_TAGS]; + Collider* head; +}; + +struct Collider { + uint32_t ref; + dBodyID body; + World* world; + Collider* prev; + Collider* next; + void* userdata; + uint32_t tag; + arr_t(Shape*) shapes; + arr_t(Joint*) joints; + float friction; + float restitution; +}; + +struct Shape { + uint32_t ref; + ShapeType type; + dGeomID id; + Collider* collider; + void* vertices; + void* indices; + void* userdata; + bool sensor; +}; + +struct Joint { + uint32_t ref; + JointType type; + dJointID id; + void* userdata; +}; + static void defaultNearCallback(void* data, dGeomID a, dGeomID b) { lovrWorldCollide((World*) data, dGeomGetData(a), dGeomGetData(b), -1, -1); } @@ -391,6 +434,10 @@ World* lovrColliderGetWorld(Collider* collider) { return collider->world; } +Collider* lovrColliderGetNext(Collider* collider) { + return collider->next; +} + void lovrColliderAddShape(Collider* collider, Shape* shape) { lovrRetain(shape); diff --git a/src/modules/physics/physics.h b/src/modules/physics/physics.h index a86fedc8..ad58a43b 100644 --- a/src/modules/physics/physics.h +++ b/src/modules/physics/physics.h @@ -25,59 +25,17 @@ typedef enum { JOINT_SLIDER } JointType; +typedef struct World World; typedef struct Collider Collider; typedef struct Shape Shape; typedef struct Joint Joint; -typedef struct { - uint32_t ref; - dWorldID id; - dSpaceID space; - dJointGroupID contactGroup; - arr_t(Shape*) overlaps; - char* tags[MAX_TAGS]; - uint16_t masks[MAX_TAGS]; - Collider* head; -} World; - -struct Collider { - uint32_t ref; - dBodyID body; - World* world; - Collider* prev; - Collider* next; - void* userdata; - uint32_t tag; - arr_t(Shape*) shapes; - arr_t(Joint*) joints; - float friction; - float restitution; -}; - -struct Shape { - uint32_t ref; - ShapeType type; - dGeomID id; - Collider* collider; - void* vertices; - void* indices; - void* userdata; - bool sensor; -}; - typedef Shape SphereShape; typedef Shape BoxShape; typedef Shape CapsuleShape; typedef Shape CylinderShape; typedef Shape MeshShape; -struct Joint { - uint32_t ref; - JointType type; - dJointID id; - void* userdata; -}; - typedef Joint BallJoint; typedef Joint DistanceJoint; typedef Joint HingeJoint; @@ -125,6 +83,7 @@ void lovrColliderDestroy(void* ref); void lovrColliderDestroyData(Collider* collider); void lovrColliderInitInertia(Collider* collider, Shape* shape); World* lovrColliderGetWorld(Collider* collider); +Collider* lovrColliderGetNext(Collider* collider); void lovrColliderAddShape(Collider* collider, Shape* shape); void lovrColliderRemoveShape(Collider* collider, Shape* shape); Shape** lovrColliderGetShapes(Collider* collider, size_t* count);