diff --git a/src/api/l_physics_world.c b/src/api/l_physics_world.c index 7168f46ba..cf506acad 100644 --- a/src/api/l_physics_world.c +++ b/src/api/l_physics_world.c @@ -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); @@ -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 }, diff --git a/src/modules/physics/physics.c b/src/modules/physics/physics.c index edfb6b80f..0aac970f2 100644 --- a/src/modules/physics/physics.c +++ b/src/modules/physics/physics.c @@ -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); } diff --git a/src/modules/physics/physics.h b/src/modules/physics/physics.h index 3cab6040b..a81967dc8 100644 --- a/src/modules/physics/physics.h +++ b/src/modules/physics/physics.h @@ -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); diff --git a/test/lovr/physics.lua b/test/lovr/physics.lua index e3218dabf..03a4f2707 100644 --- a/test/lovr/physics.lua +++ b/test/lovr/physics.lua @@ -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)