World:isCollisionEnabledBetween takes nils;

They act like wildcards, just like nil tags do otherwise.
This commit is contained in:
bjorn 2023-08-15 18:24:19 -07:00
parent b1deeda0ce
commit 0d6c9a1def
3 changed files with 16 additions and 13 deletions

View File

@ -392,8 +392,8 @@ static int l_lovrWorldEnableCollisionBetween(lua_State* L) {
static int l_lovrWorldIsCollisionEnabledBetween(lua_State* L) {
World* world = luax_checktype(L, 1, World);
const char* tag1 = luaL_checkstring(L, 2);
const char* tag2 = luaL_checkstring(L, 3);
const char* tag1 = lua_tostring(L, 2);
const char* tag2 = lua_tostring(L, 3);
lua_pushboolean(L, lovrWorldIsCollisionEnabledBetween(world, tag1, tag2));
return 1;
}

View File

@ -401,35 +401,38 @@ const char* lovrWorldGetTagName(World* world, uint32_t tag) {
return (tag == NO_TAG) ? NULL : world->tags[tag];
}
int lovrWorldDisableCollisionBetween(World* world, const char* tag1, const char* tag2) {
void lovrWorldDisableCollisionBetween(World* world, const char* tag1, const char* tag2) {
uint32_t i = findTag(world, tag1);
uint32_t j = findTag(world, tag2);
if (i == NO_TAG || j == NO_TAG) {
return NO_TAG;
return;
}
world->masks[i] &= ~(1 << j);
world->masks[j] &= ~(1 << i);
return 0;
return;
}
int lovrWorldEnableCollisionBetween(World* world, const char* tag1, const char* tag2) {
void lovrWorldEnableCollisionBetween(World* world, const char* tag1, const char* tag2) {
uint32_t i = findTag(world, tag1);
uint32_t j = findTag(world, tag2);
if (i == NO_TAG || j == NO_TAG) {
return NO_TAG;
return;
}
world->masks[i] |= (1 << j);
world->masks[j] |= (1 << i);
return 0;
return;
}
int lovrWorldIsCollisionEnabledBetween(World* world, const char* tag1, const char* tag2) {
bool lovrWorldIsCollisionEnabledBetween(World* world, const char* tag1, const char* tag2) {
uint32_t i = findTag(world, tag1);
uint32_t j = findTag(world, tag2);
if (i == NO_TAG || j == NO_TAG) {
return NO_TAG;
return true;
}
return (world->masks[i] & (1 << j)) && (world->masks[j] & (1 << i));

View File

@ -67,9 +67,9 @@ void lovrWorldSetAngularDamping(World* world, float damping, float threshold);
bool lovrWorldIsSleepingAllowed(World* world);
void lovrWorldSetSleepingAllowed(World* world, bool allowed);
const char* lovrWorldGetTagName(World* world, uint32_t tag);
int lovrWorldDisableCollisionBetween(World* world, const char* tag1, const char* tag2);
int lovrWorldEnableCollisionBetween(World* world, const char* tag1, const char* tag2);
int lovrWorldIsCollisionEnabledBetween(World* world, const char* tag1, const char* tag);
void lovrWorldDisableCollisionBetween(World* world, const char* tag1, const char* tag2);
void lovrWorldEnableCollisionBetween(World* world, const char* tag1, const char* tag2);
bool lovrWorldIsCollisionEnabledBetween(World* world, const char* tag1, const char* tag);
// Collider