Better ChainShape API consistency

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-09-25 22:29:30 -04:00
parent de908f3354
commit 80fb261b5a
4 changed files with 19 additions and 17 deletions
+8 -3
View File
@@ -72,7 +72,12 @@ namespace box2d
b2ChainShape * c = (b2ChainShape *)shape;
b2EdgeShape e;
c->GetChildEdge(&e, index);
return new EdgeShape(&e);
EdgeShape * edge = (EdgeShape *)Memoizer::find(&e);
if (!edge) return new EdgeShape(&e);
else {
edge->retain();
return edge;
}
}
int ChainShape::getChildCount() const
@@ -87,14 +92,14 @@ namespace box2d
return c->m_count;
}
b2Vec2 ChainShape::getVertex(int index) const
b2Vec2 ChainShape::getPoint(int index) const
{
b2ChainShape * c = (b2ChainShape *)shape;
const b2Vec2 & v = c->m_vertices[index];
return Physics::scaleUp(v);
}
const b2Vec2 * ChainShape::getVertices() const
const b2Vec2 * ChainShape::getPoints() const
{
b2ChainShape * c = (b2ChainShape *)shape;
return c->m_vertices;
+2 -2
View File
@@ -89,13 +89,13 @@ namespace box2d
* @param index The index of the vertex.
* @returns The specified vertex.
**/
b2Vec2 getVertex(int index) const;
b2Vec2 getPoint(int index) const;
/**
* Returns all of the vertices.
* @returns The vertices the shape comprises.
**/
const b2Vec2 * getVertices() const;
const b2Vec2 * getPoints() const;
};
+7 -10
View File
@@ -74,30 +74,27 @@ namespace box2d
return 1;
}
int w_ChainShape_getVertex(lua_State * L)
int w_ChainShape_getPoint(lua_State * L)
{
ChainShape * c = luax_checkchainshape(L, 1);
int index = luaL_checkint(L, 2);
b2Vec2 v = c->getVertex(index);
b2Vec2 v = c->getPoint(index);
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
return 2;
}
int w_ChainShape_getVertices(lua_State * L)
int w_ChainShape_getPoints(lua_State * L)
{
ChainShape * c = luax_checkchainshape(L, 1);
const b2Vec2 * verts = c->getVertices();
const b2Vec2 * verts = c->getPoints();
int count = c->getVertexCount();
lua_createtable(L, count*2, 0);
for (int i = 0; i < count; i++) {
b2Vec2 v = Physics::scaleUp(verts[i]);
lua_pushnumber(L, v.x);
lua_rawseti(L, -2, i*2+1);
lua_pushnumber(L, v.y);
lua_rawseti(L, -2, i*2+2);
}
return 1;
return count*2;
}
static const luaL_Reg functions[] = {
@@ -106,8 +103,8 @@ namespace box2d
{ "getChildCount", w_ChainShape_getChildCount },
{ "getChildEdge", w_ChainShape_getChildEdge },
{ "getVertexCount", w_ChainShape_getVertexCount },
{ "getVertex", w_ChainShape_getVertex },
{ "getVertices", w_ChainShape_getVertices },
{ "getPoint", w_ChainShape_getPoint },
{ "getPoints", w_ChainShape_getPoints },
// From Shape.
{ "getType", w_Shape_getType },
{ "getRadius", w_Shape_getRadius },
+2 -2
View File
@@ -39,8 +39,8 @@ namespace box2d
int w_ChainShape_getChildCount(lua_State * L);
int w_ChainShape_getChildEdge(lua_State * L);
int w_ChainShape_getVertexCount(lua_State * L);
int w_ChainShape_getVertex(lua_State * L);
int w_ChainShape_getVertices(lua_State * L);
int w_ChainShape_getPoint(lua_State * L);
int w_ChainShape_getPoints(lua_State * L);
int luaopen_chainshape(lua_State * L);