Rename CompoundShape 'shape' to 'child';

Maybe slightly less ambiguous/confusing?
This commit is contained in:
bjorn 2024-04-07 13:44:24 -07:00
parent 47dec01772
commit 060e72c525
4 changed files with 63 additions and 63 deletions

View File

@ -389,18 +389,18 @@ static int l_lovrCompoundShapeIsFrozen(lua_State* L) {
return 1;
}
static int l_lovrCompoundShapeAddShape(lua_State* L) {
static int l_lovrCompoundShapeAddChild(lua_State* L) {
CompoundShape* shape = luax_checktype(L, 1, CompoundShape);
Shape* child = luax_checkshape(L, 2);
float position[3], orientation[4];
int index = 3;
index = luax_readvec3(L, index, position, NULL);
index = luax_readquat(L, index, orientation, NULL);
lovrCompoundShapeAddShape(shape, child, position, orientation);
lovrCompoundShapeAddChild(shape, child, position, orientation);
return 0;
}
static int l_lovrCompoundShapeReplaceShape(lua_State* L) {
static int l_lovrCompoundShapeReplaceChild(lua_State* L) {
CompoundShape* shape = luax_checktype(L, 1, CompoundShape);
uint32_t index = luax_checku32(L, 2) - 1;
Shape* child = luax_checkshape(L, 3);
@ -408,49 +408,49 @@ static int l_lovrCompoundShapeReplaceShape(lua_State* L) {
int i = 4;
i = luax_readvec3(L, i, position, NULL);
i = luax_readquat(L, i, orientation, NULL);
lovrCompoundShapeReplaceShape(shape, index, child, position, orientation);
lovrCompoundShapeReplaceChild(shape, index, child, position, orientation);
return 0;
}
static int l_lovrCompoundShapeRemoveShape(lua_State* L) {
static int l_lovrCompoundShapeRemoveChild(lua_State* L) {
CompoundShape* shape = luax_checktype(L, 1, CompoundShape);
uint32_t index = luax_checku32(L, 2) - 1;
lovrCompoundShapeRemoveShape(shape, index);
lovrCompoundShapeRemoveChild(shape, index);
return 0;
}
static int l_lovrCompoundShapeGetShape(lua_State* L) {
static int l_lovrCompoundShapeGetChild(lua_State* L) {
CompoundShape* shape = luax_checktype(L, 1, CompoundShape);
uint32_t index = luax_checku32(L, 2) - 1;
Shape* child = lovrCompoundShapeGetShape(shape, index);
Shape* child = lovrCompoundShapeGetChild(shape, index);
luax_pushshape(L, child);
return 1;
}
static int l_lovrCompoundShapeGetShapes(lua_State* L) {
static int l_lovrCompoundShapeGetChildren(lua_State* L) {
CompoundShape* shape = luax_checktype(L, 1, CompoundShape);
int count = (int) lovrCompoundShapeGetShapeCount(shape);
int count = (int) lovrCompoundShapeGetChildCount(shape);
lua_createtable(L, count, 0);
for (int i = 0; i < count; i++) {
Shape* child = lovrCompoundShapeGetShape(shape, (uint32_t) i);
Shape* child = lovrCompoundShapeGetChild(shape, (uint32_t) i);
luax_pushshape(L, child);
lua_rawseti(L, -2, i + 1);
}
return 1;
}
static int l_lovrCompoundShapeGetShapeCount(lua_State* L) {
static int l_lovrCompoundShapeGetChildCount(lua_State* L) {
CompoundShape* shape = luax_checktype(L, 1, CompoundShape);
uint32_t count = lovrCompoundShapeGetShapeCount(shape);
uint32_t count = lovrCompoundShapeGetChildCount(shape);
lua_pushinteger(L, count);
return 1;
}
static int l_lovrCompoundShapeGetShapeOffset(lua_State* L) {
static int l_lovrCompoundShapeGetChildOffset(lua_State* L) {
CompoundShape* shape = luax_checktype(L, 1, CompoundShape);
uint32_t index = luax_checku32(L, 2) - 1;
float position[3], orientation[4], angle, ax, ay, az;
lovrCompoundShapeGetShapeOffset(shape, index, position, orientation);
lovrCompoundShapeGetChildOffset(shape, index, position, orientation);
quat_getAngleAxis(orientation, &angle, &ax, &ay, &az);
lua_pushnumber(L, position[0]);
lua_pushnumber(L, position[1]);
@ -462,28 +462,28 @@ static int l_lovrCompoundShapeGetShapeOffset(lua_State* L) {
return 7;
}
static int l_lovrCompoundShapeSetShapeOffset(lua_State* L) {
static int l_lovrCompoundShapeSetChildOffset(lua_State* L) {
CompoundShape* shape = luax_checktype(L, 1, CompoundShape);
uint32_t index = luax_checku32(L, 2) - 1;
float position[3], orientation[4];
int i = 3;
i = luax_readvec3(L, i, position, NULL);
i = luax_readquat(L, i, orientation, NULL);
lovrCompoundShapeSetShapeOffset(shape, index, position, orientation);
lovrCompoundShapeSetChildOffset(shape, index, position, orientation);
return 0;
}
const luaL_Reg lovrCompoundShape[] = {
lovrShape,
{ "isFrozen", l_lovrCompoundShapeIsFrozen },
{ "addShape", l_lovrCompoundShapeAddShape },
{ "replaceShape", l_lovrCompoundShapeReplaceShape },
{ "removeShape", l_lovrCompoundShapeRemoveShape },
{ "getShape", l_lovrCompoundShapeGetShape },
{ "getShapes", l_lovrCompoundShapeGetShapes },
{ "getShapeCount", l_lovrCompoundShapeGetShapeCount },
{ "getShapeOffset", l_lovrCompoundShapeGetShapeOffset },
{ "setShapeOffset", l_lovrCompoundShapeSetShapeOffset },
{ "__len", l_lovrCompoundShapeGetShapeCount }, // :)
{ "addChild", l_lovrCompoundShapeAddChild },
{ "replaceChild", l_lovrCompoundShapeReplaceChild },
{ "removeChild", l_lovrCompoundShapeRemoveChild },
{ "getChild", l_lovrCompoundShapeGetChild },
{ "getChildren", l_lovrCompoundShapeGetChildren },
{ "getChildCount", l_lovrCompoundShapeGetChildCount },
{ "getChildOffset", l_lovrCompoundShapeGetChildOffset },
{ "setChildOffset", l_lovrCompoundShapeSetChildOffset },
{ "__len", l_lovrCompoundShapeGetChildCount }, // :)
{ NULL, NULL }
};

View File

@ -187,13 +187,13 @@ TerrainShape* lovrTerrainShapeCreate(float* vertices, uint32_t n, float scaleXZ,
CompoundShape* lovrCompoundShapeCreate(Shape** shapes, float* positions, float* orientations, uint32_t count, bool freeze);
bool lovrCompoundShapeIsFrozen(CompoundShape* shape);
void lovrCompoundShapeAddShape(CompoundShape* shape, Shape* child, float* position, float* orientation);
void lovrCompoundShapeReplaceShape(CompoundShape* shape, uint32_t index, Shape* child, float* position, float* orientation);
void lovrCompoundShapeRemoveShape(CompoundShape* shape, uint32_t index);
Shape* lovrCompoundShapeGetShape(CompoundShape* shape, uint32_t index);
uint32_t lovrCompoundShapeGetShapeCount(CompoundShape* shape);
void lovrCompoundShapeGetShapeOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation);
void lovrCompoundShapeSetShapeOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation);
void lovrCompoundShapeAddChild(CompoundShape* shape, Shape* child, float* position, float* orientation);
void lovrCompoundShapeReplaceChild(CompoundShape* shape, uint32_t index, Shape* child, float* position, float* orientation);
void lovrCompoundShapeRemoveChild(CompoundShape* shape, uint32_t index);
Shape* lovrCompoundShapeGetChild(CompoundShape* shape, uint32_t index);
uint32_t lovrCompoundShapeGetChildCount(CompoundShape* shape);
void lovrCompoundShapeGetChildOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation);
void lovrCompoundShapeSetChildOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation);
// These tokens need to exist for Lua bindings
#define lovrSphereShapeDestroy lovrShapeDestroy

View File

@ -430,7 +430,7 @@ Shape* lovrColliderGetShape(Collider* collider, uint32_t child) {
return collider->shape;
}
return lovrCompoundShapeGetShape(collider->shape, child);
return lovrCompoundShapeGetChild(collider->shape, child);
}
void lovrColliderSetShape(Collider* collider, Shape* shape) {
@ -835,9 +835,9 @@ void lovrShapeDestroy(void* ref) {
void lovrShapeDestroyData(Shape* shape) {
if (shape->shape) {
if (shape->type == SHAPE_COMPOUND) {
uint32_t count = lovrCompoundShapeGetShapeCount(shape);
uint32_t count = lovrCompoundShapeGetChildCount(shape);
for (uint32_t i = 0; i < count; i++) {
Shape* child = lovrCompoundShapeGetShape(shape, i);
Shape* child = lovrCompoundShapeGetChild(shape, i);
lovrRelease(child, lovrShapeDestroy);
}
}
@ -994,9 +994,9 @@ TerrainShape* lovrTerrainShapeCreate(float* vertices, uint32_t n, float scaleXZ,
CompoundShape* lovrCompoundShapeCreate(Shape** shapes, vec3 positions, quat orientations, uint32_t count, bool freeze) {
lovrCheck(!freeze || count >= 2, "A frozen CompoundShape must contain at least two shapes");
CompoundShape* parent = lovrCalloc(sizeof(CompoundShape));
parent->ref = 1;
parent->type = SHAPE_COMPOUND;
CompoundShape* shape = lovrCalloc(sizeof(CompoundShape));
shape->ref = 1;
shape->type = SHAPE_COMPOUND;
JPH_CompoundShapeSettings* settings = freeze ?
(JPH_CompoundShapeSettings*) JPH_StaticCompoundShapeSettings_Create() :
@ -1011,20 +1011,20 @@ CompoundShape* lovrCompoundShapeCreate(Shape** shapes, vec3 positions, quat orie
}
if (freeze) {
parent->shape = (JPH_Shape*) JPH_StaticCompoundShape_Create((JPH_StaticCompoundShapeSettings*) settings);
shape->shape = (JPH_Shape*) JPH_StaticCompoundShape_Create((JPH_StaticCompoundShapeSettings*) settings);
} else {
parent->shape = (JPH_Shape*) JPH_MutableCompoundShape_Create((JPH_MutableCompoundShapeSettings*) settings);
shape->shape = (JPH_Shape*) JPH_MutableCompoundShape_Create((JPH_MutableCompoundShapeSettings*) settings);
}
JPH_ShapeSettings_Destroy((JPH_ShapeSettings*) settings);
return parent;
return shape;
}
bool lovrCompoundShapeIsFrozen(CompoundShape* shape) {
return JPH_Shape_GetSubType(shape->shape) == JPH_ShapeSubType_StaticCompound;
}
void lovrCompoundShapeAddShape(CompoundShape* shape, Shape* child, float* position, float* orientation) {
void lovrCompoundShapeAddChild(CompoundShape* shape, Shape* child, float* position, float* orientation) {
lovrCheck(!lovrCompoundShapeIsFrozen(shape), "CompoundShape is frozen and can not be changed");
lovrCheck(child->type != SHAPE_COMPOUND, "Currently, nesting compound shapes is not supported");
JPH_Vec3 pos = { position[0], position[1], position[2] };
@ -1033,27 +1033,27 @@ void lovrCompoundShapeAddShape(CompoundShape* shape, Shape* child, float* positi
lovrRetain(child);
}
void lovrCompoundShapeReplaceShape(CompoundShape* shape, uint32_t index, Shape* child, float* position, float* orientation) {
void lovrCompoundShapeReplaceChild(CompoundShape* shape, uint32_t index, Shape* child, float* position, float* orientation) {
lovrCheck(!lovrCompoundShapeIsFrozen(shape), "CompoundShape is frozen and can not be changed");
lovrCheck(child->type != SHAPE_COMPOUND, "Currently, nesting compound shapes is not supported");
lovrCheck(index < lovrCompoundShapeGetShapeCount(shape), "CompoundShape has no shape at index %d", index + 1);
lovrCheck(index < lovrCompoundShapeGetChildCount(shape), "CompoundShape has no child at index %d", index + 1);
JPH_Vec3 pos = { position[0], position[1], position[2] };
JPH_Quat rot = { orientation[0], orientation[1], orientation[2], orientation[3] };
lovrRelease(lovrCompoundShapeGetShape(shape, index), lovrShapeDestroy);
lovrRelease(lovrCompoundShapeGetChild(shape, index), lovrShapeDestroy);
JPH_MutableCompoundShape_ModifyShape2((JPH_MutableCompoundShape*) shape->shape, index, &pos, &rot, child->shape);
lovrRetain(child);
}
void lovrCompoundShapeRemoveShape(CompoundShape* shape, uint32_t index) {
void lovrCompoundShapeRemoveChild(CompoundShape* shape, uint32_t index) {
lovrCheck(!lovrCompoundShapeIsFrozen(shape), "CompoundShape is frozen and can not be changed");
lovrCheck(index < lovrCompoundShapeGetShapeCount(shape), "CompoundShape has no shape at index %d", index + 1);
Shape* child = lovrCompoundShapeGetShape(shape, index);
lovrCheck(index < lovrCompoundShapeGetChildCount(shape), "CompoundShape has no child at index %d", index + 1);
Shape* child = lovrCompoundShapeGetChild(shape, index);
JPH_MutableCompoundShape_RemoveShape((JPH_MutableCompoundShape*) shape->shape, index);
lovrRelease(child, lovrShapeDestroy);
}
Shape* lovrCompoundShapeGetShape(CompoundShape* shape, uint32_t index) {
if (index < lovrCompoundShapeGetShapeCount(shape)) {
Shape* lovrCompoundShapeGetChild(CompoundShape* shape, uint32_t index) {
if (index < lovrCompoundShapeGetChildCount(shape)) {
const JPH_Shape* child;
JPH_CompoundShape_GetSubShape((JPH_CompoundShape*) shape->shape, index, &child, NULL, NULL, NULL);
return (Shape*) (uintptr_t) JPH_Shape_GetUserData(child);
@ -1062,12 +1062,12 @@ Shape* lovrCompoundShapeGetShape(CompoundShape* shape, uint32_t index) {
}
}
uint32_t lovrCompoundShapeGetShapeCount(CompoundShape* shape) {
uint32_t lovrCompoundShapeGetChildCount(CompoundShape* shape) {
return JPH_CompoundShape_GetNumSubShapes((JPH_CompoundShape*) shape->shape);
}
void lovrCompoundShapeGetShapeOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation) {
lovrCheck(index < lovrCompoundShapeGetShapeCount(shape), "CompoundShape has no shape at index %d", index + 1);
void lovrCompoundShapeGetChildOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation) {
lovrCheck(index < lovrCompoundShapeGetChildCount(shape), "CompoundShape has no child at index %d", index + 1);
const JPH_Shape* child;
JPH_Vec3 pos;
JPH_Quat rot;
@ -1077,9 +1077,9 @@ void lovrCompoundShapeGetShapeOffset(CompoundShape* shape, uint32_t index, float
quat_init(orientation, &rot.x);
}
void lovrCompoundShapeSetShapeOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation) {
void lovrCompoundShapeSetChildOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation) {
lovrCheck(!lovrCompoundShapeIsFrozen(shape), "CompoundShape is frozen and can not be changed");
lovrCheck(index < lovrCompoundShapeGetShapeCount(shape), "CompoundShape has no shape at index %d", index + 1);
lovrCheck(index < lovrCompoundShapeGetChildCount(shape), "CompoundShape has no child at index %d", index + 1);
JPH_Vec3 pos = { position[0], position[1], position[2] };
JPH_Quat rot = { orientation[0], orientation[1], orientation[2], orientation[3] };
JPH_MutableCompoundShape_ModifyShape((JPH_MutableCompoundShape*) shape->shape, index, &pos, &rot);

View File

@ -1119,31 +1119,31 @@ bool lovrCompoundShapeIsFrozen(CompoundShape* shape) {
return false;
}
void lovrCompoundShapeAddShape(CompoundShape* shape, Shape* child, float* position, float* orientation) {
void lovrCompoundShapeAddChild(CompoundShape* shape, Shape* child, float* position, float* orientation) {
//
}
void lovrCompoundShapeReplaceShape(CompoundShape* shape, uint32_t index, Shape* child, float* position, float* orientation) {
void lovrCompoundShapeReplaceChild(CompoundShape* shape, uint32_t index, Shape* child, float* position, float* orientation) {
//
}
void lovrCompoundShapeRemoveShape(CompoundShape* shape, uint32_t index) {
void lovrCompoundShapeRemoveChild(CompoundShape* shape, uint32_t index) {
//
}
Shape* lovrCompoundShapeGetShape(CompoundShape* shape, uint32_t index) {
Shape* lovrCompoundShapeGetChild(CompoundShape* shape, uint32_t index) {
return NULL;
}
uint32_t lovrCompoundShapeGetShapeCount(CompoundShape* shape) {
uint32_t lovrCompoundShapeGetChildCount(CompoundShape* shape) {
return 0;
}
void lovrCompoundShapeGetShapeOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation) {
void lovrCompoundShapeGetChildOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation) {
//
}
void lovrCompoundShapeSetShapeOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation) {
void lovrCompoundShapeSetChildOffset(CompoundShape* shape, uint32_t index, float* position, float* orientation) {
//
}