Make physics structs private;

This commit is contained in:
bjorn 2022-03-25 12:40:29 -07:00
parent 018b94a0fb
commit 6c9531564e
5 changed files with 52 additions and 46 deletions

View File

@ -5,7 +5,7 @@
#include <lauxlib.h>
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;

View File

@ -5,7 +5,7 @@
#include <lauxlib.h>
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;

View File

@ -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;

View File

@ -3,6 +3,49 @@
#include <stdlib.h>
#include <stdbool.h>
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);

View File

@ -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);