Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/api/l_physics_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ static int l_lovrWorldGetTags(lua_State* L) {
return 1;
}

static int l_lovrWorldIsTagStatic(lua_State* L) {
World* world = luax_checkworld(L, 1);
const char* tag = luaL_checkstring(L, 2);
bool isStatic;
luax_assert(L, lovrWorldIsTagStatic(world, tag, &isStatic));
lua_pushboolean(L, isStatic);
return 1;
}

static int l_lovrWorldGetColliderCount(lua_State* L) {
World* world = luax_checkworld(L, 1);
uint32_t count = lovrWorldGetColliderCount(world);
Expand Down Expand Up @@ -608,6 +617,7 @@ const luaL_Reg lovrWorld[] = {
{ "destroy", l_lovrWorldDestroy },
{ "isDestroyed", l_lovrWorldIsDestroyed },
{ "getTags", l_lovrWorldGetTags },
{ "isTagStatic", l_lovrWorldIsTagStatic },
{ "getColliderCount", l_lovrWorldGetColliderCount },
{ "getJointCount", l_lovrWorldGetJointCount },
{ "getColliders", l_lovrWorldGetColliders },
Expand Down
7 changes: 7 additions & 0 deletions src/modules/physics/physics.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ uint32_t lovrWorldGetTagMask(World* world, const char* string, size_t length) {
return (accept ? accept : ~ignore) | 0x80000000;
}

bool lovrWorldIsTagStatic(World* world, const char* tag, bool* isStatic) {
uint8_t index = findTag(world, tag, strlen(tag));
lovrCheck(index != 0xff, "Unknown tag '%s'", tag);
*isStatic = world->staticTagMask & (1 << index);
return true;
}

uint32_t lovrWorldGetColliderCount(World* world) {
return JPH_PhysicsSystem_GetNumBodies(world->system);
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/physics/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void lovrWorldDestruct(World* world);
bool lovrWorldIsDestroyed(World* world);
char** lovrWorldGetTags(World* world, uint32_t* count);
uint32_t lovrWorldGetTagMask(World* world, const char* string, size_t length);
bool lovrWorldIsTagStatic(World* world, const char* tag, bool* isStatic);
uint32_t lovrWorldGetColliderCount(World* world);
uint32_t lovrWorldGetJointCount(World* world);
Collider* lovrWorldGetColliders(World* world, Collider* collider);
Expand Down
12 changes: 12 additions & 0 deletions test/lovr/physics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ group('physics', function()
expect(taggedWorld:getTags()).to.equal({ 'a', 'b' })
end)

test(':isTagStatic', function()
local taggedWorld = lovr.physics.newWorld({
tags = { 'dynamic', 'environment', 'sensor' },
staticTags = { 'environment', 'sensor' }
})

expect(taggedWorld:isTagStatic('dynamic')).to.equal(false)
expect(taggedWorld:isTagStatic('environment')).to.equal(true)
expect(taggedWorld:isTagStatic('sensor')).to.equal(true)
expect(function() taggedWorld:isTagStatic('unknown') end).to.fail()
end)

test('distant colliders', function()
local c1 = world:newBoxCollider(1e8, 0, 0)
local c2 = world:newBoxCollider(1e8, 0, 0)
Expand Down
Loading