Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setCollisionMask and getCollisionMask to Shape's API #2090

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions src/modules/physics/box2d/Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/modules/physics/box2d/Shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ class Shape : public love::physics::Shape

int setCategory(lua_State *L);
int setMask(lua_State *L);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear to me if we want to maintain this API, or prefer to deprecate.

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);

Expand Down
20 changes: 20 additions & 0 deletions src/modules/physics/box2d/wrap_Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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 },
Expand Down