Fix table creation for getList() functions, and ignore the ground body

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-09-25 12:18:13 -04:00
parent b6f3d2114f
commit 28c5982d92
2 changed files with 23 additions and 21 deletions
+2 -1
View File
@@ -405,7 +405,8 @@ namespace box2d
Fixture * fixture = (Fixture *)Memoizer::find(f); Fixture * fixture = (Fixture *)Memoizer::find(f);
if (!fixture) throw love::Exception("A fixture has escaped Memoizer!"); if (!fixture) throw love::Exception("A fixture has escaped Memoizer!");
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)fixture); luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)fixture);
lua_rawseti(L, -1, i); lua_rawseti(L, -2, i);
i++;
} while ((f = f->GetNext())); } while ((f = f->GetNext()));
return 1; return 1;
} }
+21 -20
View File
@@ -357,7 +357,7 @@ namespace box2d
int World::getBodyCount() const int World::getBodyCount() const
{ {
return world->GetBodyCount(); return world->GetBodyCount()-1; // ignore the ground body
} }
int World::getJointCount() const int World::getJointCount() const
@@ -374,15 +374,16 @@ namespace box2d
{ {
lua_newtable(L); lua_newtable(L);
b2Body * b = world->GetBodyList(); b2Body * b = world->GetBodyList();
for (int i = 1; i <= world->GetBodyCount(); i++) { int i = 1;
if (!b) return 1; do {
if (!b) break;
if (b == groundBody) continue;
Body * body = (Body *)Memoizer::find(b); Body * body = (Body *)Memoizer::find(b);
if (!body) throw love::Exception("A body has escaped Memoizer!"); if (!body) throw love::Exception("A body has escaped Memoizer!");
body->retain();
luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body); luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
lua_rawseti(L, -1, i); lua_rawseti(L, -2, i);
b = b->GetNext(); i++;
} } while ((b = b->GetNext()));
return 1; return 1;
} }
@@ -390,15 +391,15 @@ namespace box2d
{ {
lua_newtable(L); lua_newtable(L);
b2Joint * j = world->GetJointList(); b2Joint * j = world->GetJointList();
for (int i = 1; i <= world->GetJointCount(); i++) { int i = 1;
if (!j) return 1; do {
if (!j) break;
Joint * joint = (Joint *)Memoizer::find(j); Joint * joint = (Joint *)Memoizer::find(j);
if (!joint) throw love::Exception("A joint has escaped Memoizer!"); if (!joint) throw love::Exception("A joint has escaped Memoizer!");
joint->retain();
luax_newtype(L, "Joint", PHYSICS_JOINT_T, (void*)joint); luax_newtype(L, "Joint", PHYSICS_JOINT_T, (void*)joint);
lua_rawseti(L, -1, i); lua_rawseti(L, -2, i);
j = j->GetNext(); i++;
} } while ((j = j->GetNext()));
return 1; return 1;
} }
@@ -406,15 +407,15 @@ namespace box2d
{ {
lua_newtable(L); lua_newtable(L);
b2Contact * c = world->GetContactList(); b2Contact * c = world->GetContactList();
for (int i = 1; i <= world->GetContactCount(); i++) { int i = 1;
if (!c) return 1; do {
Contact * contact = (Contact *)Memoizer::find(c); if (!c) break;
Contact * contact = (Contact *)Memoizer::find(c);
if (!contact) throw love::Exception("A contact has escaped Memoizer!"); if (!contact) throw love::Exception("A contact has escaped Memoizer!");
contact->retain();
luax_newtype(L, "Contact", PHYSICS_CONTACT_T, (void*)contact); luax_newtype(L, "Contact", PHYSICS_CONTACT_T, (void*)contact);
lua_rawseti(L, -1, i); lua_rawseti(L, -2, i);
c = c->GetNext(); i++;
} } while ((c = c->GetNext()));
return 1; return 1;
} }