Add optional category bit mask to World:getFixturesInArea.

This commit is contained in:
Sasha Szpakowski
2023-10-02 12:15:26 -03:00
parent 28a898df1f
commit 6cb0287500
2 changed files with 9 additions and 3 deletions
+7 -2
View File
@@ -174,8 +174,9 @@ bool World::QueryCallback::ReportFixture(b2Fixture *fixture)
return true;
}
World::CollectCallback::CollectCallback(World *world, lua_State *L)
World::CollectCallback::CollectCallback(World *world, uint16 categoryMask, lua_State *L)
: world(world)
, categoryMask(categoryMask)
, L(L)
{
lua_newtable(L);
@@ -187,6 +188,9 @@ World::CollectCallback::~CollectCallback()
bool World::CollectCallback::ReportFixture(b2Fixture *f)
{
if (categoryMask != 0xFFFF && (categoryMask & f->GetFilterData().categoryBits) == 0)
return true;
Fixture *fixture = (Fixture *)(f->GetUserData().pointer);
if (!fixture)
throw love::Exception("A fixture has escaped Memoizer!");
@@ -614,10 +618,11 @@ int World::getFixturesInArea(lua_State *L)
float ly = (float)luaL_checknumber(L, 2);
float ux = (float)luaL_checknumber(L, 3);
float uy = (float)luaL_checknumber(L, 4);
uint16 categoryMaskBits = (uint16)luaL_optinteger(L, 5, 0xFFFF);
b2AABB box;
box.lowerBound = Physics::scaleDown(b2Vec2(lx, ly));
box.upperBound = Physics::scaleDown(b2Vec2(ux, uy));
CollectCallback query(this, L);
CollectCallback query(this, categoryMaskBits, L);
world->QueryAABB(&query, box);
return 1;
}
+2 -1
View File
@@ -106,11 +106,12 @@ public:
class CollectCallback : public b2QueryCallback
{
public:
CollectCallback(World *world, lua_State *L);
CollectCallback(World *world, uint16 categoryMask, lua_State *L);
virtual ~CollectCallback();
bool ReportFixture(b2Fixture *fixture) override;
private:
World *world;
uint16 categoryMask;
lua_State *L;
int i = 1;
};