mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Add optional category bit mask to World:getFixturesInArea.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user