Readded get/setCategory and get/setMask

This commit is contained in:
bart@bart
2009-09-05 14:37:44 +02:00
parent 41a7c11f9f
commit 0b38be2b4c
6 changed files with 112 additions and 0 deletions
+61
View File
@@ -159,6 +159,67 @@ namespace box2d
v[1] = (int)f.maskBits;
v[2] = f.groupIndex;
}
int Shape::setCategory(lua_State * L)
{
b2FilterData f = shape->GetFilterData();
f.categoryBits = (uint16)getBits(L);
shape->SetFilterData(f);
shape->GetBody()->GetWorld()->Refilter(shape);
return 0;
}
int Shape::setMask(lua_State * L)
{
b2FilterData f = shape->GetFilterData();
f.maskBits = ~(uint16)getBits(L);
shape->SetFilterData(f);
shape->GetBody()->GetWorld()->Refilter(shape);
return 0;
}
int Shape::getCategory(lua_State * L)
{
return pushBits(L, shape->GetFilterData().categoryBits);
}
int Shape::getMask(lua_State * L)
{
return pushBits(L, ~(shape->GetFilterData().maskBits));
}
uint16 Shape::getBits(lua_State * L)
{
// Get number of args.
int argc = lua_gettop(L);
// The new bitset.
std::bitset<16> b;
for(int i = 1;i<=argc;i++)
{
size_t bpos = (size_t)(lua_tointeger(L, i)-1);
if(bpos < 0 || bpos > 16)
return luaL_error(L, "Values must be in range 1-16.");
b.set(bpos, true);
}
return (uint16)b.to_ulong();
}
int Shape::pushBits(lua_State * L, uint16 bits)
{
// Create a bitset.
std::bitset<16> b((unsigned long)bits);
// Push all set bits.
for(int i = 0;i<16;i++)
if(b.test(i))
lua_pushinteger(L, i+1);
// Count number of set bits.
return (int)b.count();
}
int Shape::setData(lua_State * L)
{
+7
View File
@@ -167,6 +167,13 @@ namespace box2d
* category (16-bits), mask (16-bits) and group (32-bits/int).
**/
void getFilterData(int * v);
int setCategory(lua_State * L);
int setMask(lua_State * L);
int getCategory(lua_State * L);
int getMask(lua_State * L);
uint16 getBits(lua_State * L);
int pushBits(lua_State * L, uint16 bits);
/**
* This function stores an in-C reference to
@@ -54,6 +54,10 @@ namespace box2d
{ "testSegment", w_Shape_testSegment },
{ "setFilterData", w_Shape_setFilterData },
{ "getFilterData", w_Shape_getFilterData },
{ "setCategory", w_Shape_setCategory },
{ "getCategory", w_Shape_getCategory },
{ "setMask", w_Shape_setMask },
{ "getMask", w_Shape_getMask },
{ "setData", w_Shape_setData },
{ "getData", w_Shape_getData },
{ "getBoundingBox", w_Shape_getBoundingBox },
@@ -54,6 +54,10 @@ namespace box2d
{ "testSegment", w_Shape_testSegment },
{ "setFilterData", w_Shape_setFilterData },
{ "getFilterData", w_Shape_getFilterData },
{ "setCategory", w_Shape_setCategory },
{ "getCategory", w_Shape_getCategory },
{ "setMask", w_Shape_setMask },
{ "getMask", w_Shape_getMask },
{ "setData", w_Shape_setData },
{ "getData", w_Shape_getData },
{ "getBoundingBox", w_Shape_getBoundingBox },
+32
View File
@@ -144,6 +144,34 @@ namespace box2d
lua_pushinteger(L, v[2]);
return 3;
}
int w_Shape_setCategory(lua_State * L)
{
Shape * t = luax_checkshape(L, 1);
lua_remove(L, 1);
return t->setCategory(L);
}
int w_Shape_getCategory(lua_State * L)
{
Shape * t = luax_checkshape(L, 1);
lua_remove(L, 1);
return t->getCategory(L);
}
int w_Shape_setMask(lua_State * L)
{
Shape * t = luax_checkshape(L, 1);
lua_remove(L, 1);
return t->setMask(L);
}
int w_Shape_getMask(lua_State * L)
{
Shape * t = luax_checkshape(L, 1);
lua_remove(L, 1);
return t->getMask(L);
}
int w_Shape_setData(lua_State * L)
{
@@ -180,6 +208,10 @@ namespace box2d
{ "testSegment", w_Shape_testSegment },
{ "setFilterData", w_Shape_setFilterData },
{ "getFilterData", w_Shape_getFilterData },
{ "setCategory", w_Shape_setCategory },
{ "getCategory", w_Shape_getCategory },
{ "setMask", w_Shape_setMask },
{ "getMask", w_Shape_getMask },
{ "setData", w_Shape_setData },
{ "getData", w_Shape_getData },
{ "getBoundingBox", w_Shape_getBoundingBox },
+4
View File
@@ -46,6 +46,10 @@ namespace box2d
int w_Shape_testSegment(lua_State * L);
int w_Shape_setFilterData(lua_State * L);
int w_Shape_getFilterData(lua_State * L);
int w_Shape_setCategory(lua_State * L);
int w_Shape_getCategory(lua_State * L);
int w_Shape_setMask(lua_State * L);
int w_Shape_getMask(lua_State * L);
int w_Shape_setData(lua_State * L);
int w_Shape_getData(lua_State * L);
int w_Shape_getBoundingBox(lua_State * L);