diff --git a/src/modules/physics/box2d/Shape.cpp b/src/modules/physics/box2d/Shape.cpp index cec11f5c3..c73b01b29 100644 --- a/src/modules/physics/box2d/Shape.cpp +++ b/src/modules/physics/box2d/Shape.cpp @@ -283,6 +283,15 @@ int Shape::setMask(lua_State *L) return 0; } +int Shape::setCollisionMask(lua_State *L) +{ + throwIfFixtureNotValid(); + b2Filter f = fixture->GetFilterData(); + f.maskBits = (uint16)getBits(L); + fixture->SetFilterData(f); + return 0; +} + void Shape::setGroupIndex(int index) { throwIfFixtureNotValid(); @@ -310,6 +319,12 @@ int Shape::getMask(lua_State *L) return pushBits(L, ~(fixture->GetFilterData().maskBits)); } +int Shape::getCollisionMask(lua_State *L) +{ + throwIfFixtureNotValid(); + return pushBits(L, fixture->GetFilterData().maskBits); +} + uint16 Shape::getBits(lua_State *L) { // Get number of args. diff --git a/src/modules/physics/box2d/Shape.h b/src/modules/physics/box2d/Shape.h index 43f754598..26ea87e6d 100644 --- a/src/modules/physics/box2d/Shape.h +++ b/src/modules/physics/box2d/Shape.h @@ -161,8 +161,10 @@ class Shape : public love::physics::Shape int setCategory(lua_State *L); int setMask(lua_State *L); + int setCollisionMask(lua_State *L); int getCategory(lua_State *L); int getMask(lua_State *L); + int getCollisionMask(lua_State *L); uint16 getBits(lua_State *L); int pushBits(lua_State *L, uint16 bits); diff --git a/src/modules/physics/box2d/wrap_Shape.cpp b/src/modules/physics/box2d/wrap_Shape.cpp index 50ca1c8dc..a279bb702 100644 --- a/src/modules/physics/box2d/wrap_Shape.cpp +++ b/src/modules/physics/box2d/wrap_Shape.cpp @@ -272,6 +272,15 @@ int w_Shape_setMask(lua_State *L) return ret; } +int w_Shape_setCollisionMask(lua_State *L) +{ + Shape *t = luax_checkshape(L, 1); + lua_remove(L, 1); + int ret = 0; + luax_catchexcept(L, [&]() { ret = t->setCollisionMask(L); }); + return ret; +} + int w_Shape_getMask(lua_State *L) { Shape *t = luax_checkshape(L, 1); @@ -281,6 +290,15 @@ int w_Shape_getMask(lua_State *L) return ret; } +int w_Shape_getCollisionMask(lua_State *L) +{ + Shape *t = luax_checkshape(L, 1); + lua_remove(L, 1); + int ret = 0; + luax_catchexcept(L, [&]() { ret = t->getCollisionMask(L); }); + return ret; +} + int w_Shape_setUserData(lua_State *L) { Shape *t = luax_checkshape(L, 1); @@ -372,7 +390,9 @@ const luaL_Reg w_Shape_functions[] = { "setCategory", w_Shape_setCategory }, { "getCategory", w_Shape_getCategory }, { "setMask", w_Shape_setMask }, + { "setCollisionMask", w_Shape_setCollisionMask }, { "getMask", w_Shape_getMask }, + { "getCollisionMask", w_Shape_getCollisionMask }, { "setUserData", w_Shape_setUserData }, { "getUserData", w_Shape_getUserData }, { "getBoundingBox", w_Shape_getBoundingBox },