Skip to content

Commit

Permalink
s/collideShape/overlapShape;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed May 21, 2024
1 parent 679c5be commit 0031d3f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
22 changes: 11 additions & 11 deletions src/api/l_physics_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static int luax_pushcastresult(lua_State* L, CastResult* hit) {
return 9;
}

static int luax_pushcollideresult(lua_State* L, CollideResult* hit) {
static int luax_pushoverlapresult(lua_State* L, OverlapResult* hit) {
luax_pushtype(L, Collider, hit->collider);
luax_pushshape(L, hit->shape);
lua_pushnumber(L, hit->position[0]);
Expand All @@ -46,18 +46,18 @@ static float castClosestCallback(void* userdata, CastResult* hit) {
return hit->fraction;
}

static float collideCallback(void* userdata, CollideResult* hit) {
static float overlapCallback(void* userdata, OverlapResult* hit) {
lua_State* L = userdata;
lua_pushvalue(L, -1);
int n = luax_pushcollideresult(L, hit);
int n = luax_pushoverlapresult(L, hit);
lua_call(L, n, 1);
bool stop = lua_type(L, -1) == LUA_TBOOLEAN && lua_toboolean(L, -1);
lua_pop(L, 1);
return stop ? -FLT_MAX : FLT_MAX;
}

static float collideFirstCallback(void* userdata, CollideResult* hit) {
*((CollideResult*) userdata) = *hit;
static float overlapFirstCallback(void* userdata, OverlapResult* hit) {
*((OverlapResult*) userdata) = *hit;
return -FLT_MAX;
}

Expand Down Expand Up @@ -353,7 +353,7 @@ static int l_lovrWorldShapecast(lua_State* L) {
return 0;
}

static int l_lovrWorldCollideShape(lua_State* L) {
static int l_lovrWorldOverlapShape(lua_State* L) {
World* world = luax_checktype(L, 1, World);
int index;
float pose[7];
Expand All @@ -362,14 +362,14 @@ static int l_lovrWorldCollideShape(lua_State* L) {
index = luax_readquat(L, index, pose + 3, NULL);
uint32_t filter = luax_checktagmask(L, index++, world);
if (lua_isnoneornil(L, index)) {
CollideResult hit;
if (lovrWorldCollideShape(world, shape, pose, filter, collideFirstCallback, &hit)) {
return luax_pushcollideresult(L, &hit);
OverlapResult hit;
if (lovrWorldOverlapShape(world, shape, pose, filter, overlapFirstCallback, &hit)) {
return luax_pushoverlapresult(L, &hit);
}
} else {
luaL_checktype(L, index, LUA_TFUNCTION);
lua_settop(L, index);
lovrWorldCollideShape(world, shape, pose, filter, collideCallback, L);
lovrWorldOverlapShape(world, shape, pose, filter, overlapCallback, L);
}
return 0;
}
Expand Down Expand Up @@ -633,7 +633,7 @@ const luaL_Reg lovrWorld[] = {
{ "update", l_lovrWorldUpdate },
{ "raycast", l_lovrWorldRaycast },
{ "shapecast", l_lovrWorldShapecast },
{ "collideShape", l_lovrWorldCollideShape },
{ "overlapShape", l_lovrWorldOverlapShape },
{ "queryBox", l_lovrWorldQueryBox },
{ "querySphere", l_lovrWorldQuerySphere },
{ "getGravity", l_lovrWorldGetGravity },
Expand Down
16 changes: 8 additions & 8 deletions src/modules/physics/physics.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,13 @@ bool lovrWorldShapecast(World* world, Shape* shape, float pose[7], float end[3],

typedef struct {
World* world;
CollideCallback* callback;
OverlapCallback* callback;
void* userdata;
} CollideContext;
} OverlapContext;

static float collideCallback(void* arg, JPH_CollideShapeResult* result) {
CastResult hit;
CollideContext* ctx = arg;
static float overlapCallback(void* arg, JPH_CollideShapeResult* result) {
OverlapResult hit;
OverlapContext* ctx = arg;
hit.collider = (Collider*) (uintptr_t) JPH_BodyInterface_GetUserData(ctx->world->bodies, result->bodyID2);
hit.shape = subshapeToShape(hit.collider, result->subShapeID2);
vec3_fromJolt(hit.position, &result->contactPointOn2);
Expand All @@ -559,7 +559,7 @@ static float collideCallback(void* arg, JPH_CollideShapeResult* result) {
return ctx->callback(ctx->userdata, &hit);
}

bool lovrWorldCollideShape(World* world, Shape* shape, float pose[7], uint32_t filter, CollideCallback* callback, void* userdata) {
bool lovrWorldOverlapShape(World* world, Shape* shape, float pose[7], uint32_t filter, OverlapCallback* callback, void* userdata) {
const JPH_NarrowPhaseQuery* query = JPH_PhysicsSystem_GetNarrowPhaseQueryNoLock(world->system);

JPH_Vec3 centerOfMass;
Expand All @@ -572,7 +572,7 @@ bool lovrWorldCollideShape(World* world, Shape* shape, float pose[7], uint32_t f
JPH_Vec3 scale = { 1.f, 1.f, 1.f };
JPH_RVec3 offset = { 0.f, 0.f, 0.f };

CollideContext context = {
OverlapContext context = {
.world = world,
.callback = callback,
.userdata = userdata
Expand All @@ -581,7 +581,7 @@ bool lovrWorldCollideShape(World* world, Shape* shape, float pose[7], uint32_t f
JPH_BroadPhaseLayerFilter* layerFilter = getBroadPhaseLayerFilter(world, filter);
JPH_ObjectLayerFilter* tagFilter = getObjectLayerFilter(world, filter);

return JPH_NarrowPhaseQuery_CollideShape(query, shape->handle, &scale, &transform, &offset, collideCallback, &context, layerFilter, tagFilter, NULL);
return JPH_NarrowPhaseQuery_CollideShape(query, shape->handle, &scale, &transform, &offset, overlapCallback, &context, layerFilter, tagFilter, NULL);
}

typedef struct {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/physics/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ typedef struct {
float fraction;
} CastResult;

typedef CastResult CollideResult;
typedef CastResult OverlapResult;

typedef float CastCallback(void* userdata, CastResult* hit);
typedef float CollideCallback(void* userdata, CollideResult* hit);
typedef float OverlapCallback(void* userdata, OverlapResult* hit);
typedef void QueryCallback(void* userdata, Collider* collider);

World* lovrWorldCreate(WorldInfo* info);
Expand All @@ -84,7 +84,7 @@ void lovrWorldSetGravity(World* world, float gravity[3]);
void lovrWorldUpdate(World* world, float dt);
bool lovrWorldRaycast(World* world, float start[3], float end[3], uint32_t filter, CastCallback* callback, void* userdata);
bool lovrWorldShapecast(World* world, Shape* shape, float pose[7], float end[3], uint32_t filter, CastCallback* callback, void* userdata);
bool lovrWorldCollideShape(World* world, Shape* shape, float pose[7], uint32_t filter, CollideCallback* callback, void* userdata);
bool lovrWorldOverlapShape(World* world, Shape* shape, float pose[7], uint32_t filter, OverlapCallback* callback, void* userdata);
bool lovrWorldQueryBox(World* world, float position[3], float size[3], uint32_t filter, QueryCallback* callback, void* userdata);
bool lovrWorldQuerySphere(World* world, float position[3], float radius, uint32_t filter, QueryCallback* callback, void* userdata);
void lovrWorldDisableCollisionBetween(World* world, const char* tag1, const char* tag2);
Expand Down

0 comments on commit 0031d3f

Please sign in to comment.