From 80fb261b5ace1e2286ac8a374823435f373cfbf1 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sun, 25 Sep 2011 22:29:30 -0400 Subject: [PATCH] Better ChainShape API consistency --HG-- branch : box2d-update --- src/modules/physics/box2d/ChainShape.cpp | 11 ++++++++--- src/modules/physics/box2d/ChainShape.h | 4 ++-- src/modules/physics/box2d/wrap_ChainShape.cpp | 17 +++++++---------- src/modules/physics/box2d/wrap_ChainShape.h | 4 ++-- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/modules/physics/box2d/ChainShape.cpp b/src/modules/physics/box2d/ChainShape.cpp index 2f3a3a1ec..2839118c2 100644 --- a/src/modules/physics/box2d/ChainShape.cpp +++ b/src/modules/physics/box2d/ChainShape.cpp @@ -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; diff --git a/src/modules/physics/box2d/ChainShape.h b/src/modules/physics/box2d/ChainShape.h index ccabc2e08..6668de47b 100644 --- a/src/modules/physics/box2d/ChainShape.h +++ b/src/modules/physics/box2d/ChainShape.h @@ -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; }; diff --git a/src/modules/physics/box2d/wrap_ChainShape.cpp b/src/modules/physics/box2d/wrap_ChainShape.cpp index ef5195cfe..22114ee54 100644 --- a/src/modules/physics/box2d/wrap_ChainShape.cpp +++ b/src/modules/physics/box2d/wrap_ChainShape.cpp @@ -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 }, diff --git a/src/modules/physics/box2d/wrap_ChainShape.h b/src/modules/physics/box2d/wrap_ChainShape.h index ae81e4ba8..4e29e0b0b 100644 --- a/src/modules/physics/box2d/wrap_ChainShape.h +++ b/src/modules/physics/box2d/wrap_ChainShape.h @@ -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);