Fix Fixture:getShape(), for real this time.

All the Memoizer stuff was pointless: when you create a Fixture, it clones the b2Shape, so there was never going to be a memoized Shape to find. And cloning the Shape is incorrect as well, since you should able to modify the Shape retrieved through getShape and have it affect the Fixture. Everything's much simpler now.
This commit is contained in:
Bill Meltsner
2012-02-05 19:22:33 -05:00
parent 6cde0169b6
commit 20f4e567b3
11 changed files with 23 additions and 39 deletions
+2 -5
View File
@@ -33,16 +33,13 @@ namespace physics
{
namespace box2d
{
ChainShape::ChainShape(b2ChainShape * c, bool loop)
: Shape(c), loop(loop)
ChainShape::ChainShape(b2ChainShape * c, bool loop, bool own)
: Shape(c, own), loop(loop)
{
}
ChainShape::~ChainShape()
{
Memoizer::remove(shape);
delete shape;
shape = NULL;
}
void ChainShape::setNextVertex(float x, float y)
+1 -1
View File
@@ -46,7 +46,7 @@ namespace box2d
* Create a new ChainShape from a Box2D chain shape.
* @param c The chain shape.
**/
ChainShape(b2ChainShape * c, bool loop = false);
ChainShape(b2ChainShape * c, bool loop = false, bool own = true);
virtual ~ChainShape();
+2 -5
View File
@@ -33,16 +33,13 @@ namespace physics
{
namespace box2d
{
CircleShape::CircleShape(b2CircleShape * c)
: Shape(c)
CircleShape::CircleShape(b2CircleShape * c, bool own)
: Shape(c, own)
{
}
CircleShape::~CircleShape()
{
Memoizer::remove(shape);
delete shape;
shape = NULL;
}
float CircleShape::getRadius() const
+1 -1
View File
@@ -49,7 +49,7 @@ namespace box2d
* @param body The parent body.
* @param def The CircleShape definition.
**/
CircleShape(b2CircleShape * c);
CircleShape(b2CircleShape * c, bool own = true);
virtual ~CircleShape();
+2 -5
View File
@@ -33,16 +33,13 @@ namespace physics
{
namespace box2d
{
EdgeShape::EdgeShape(b2EdgeShape * e)
: Shape(e)
EdgeShape::EdgeShape(b2EdgeShape * e, bool own)
: Shape(e, own)
{
}
EdgeShape::~EdgeShape()
{
Memoizer::remove(shape);
delete shape;
shape = NULL;
}
int EdgeShape::getPoints(lua_State * L)
+1 -1
View File
@@ -42,7 +42,7 @@ namespace box2d
* Create a new EdgeShape from a Box2D edge shape.
* @param e The edge shape.
**/
EdgeShape(b2EdgeShape * e);
EdgeShape(b2EdgeShape * e, bool own = true);
virtual ~EdgeShape();
+2 -9
View File
@@ -126,15 +126,8 @@ namespace box2d
{
if (!fixture->GetShape())
return NULL;
Shape * s = (Shape *)Memoizer::find(fixture->GetShape());
if (!s)
{
b2BlockAllocator a;
s = new Shape(fixture->GetShape()->Clone(&a));
}
else
s->retain();
return s;
return new Shape(fixture->GetShape(), false);
}
bool Fixture::isValid() const
+2 -5
View File
@@ -33,16 +33,13 @@ namespace physics
{
namespace box2d
{
PolygonShape::PolygonShape(b2PolygonShape * p)
: Shape(p)
PolygonShape::PolygonShape(b2PolygonShape * p, bool own)
: Shape(p, own)
{
}
PolygonShape::~PolygonShape()
{
Memoizer::remove(shape);
delete shape;
shape = NULL;
}
int PolygonShape::getPoints(lua_State * L)
+1 -1
View File
@@ -47,7 +47,7 @@ namespace box2d
* @param body The parent Body.
* @param def The polygon definition.
**/
PolygonShape(b2PolygonShape * p);
PolygonShape(b2PolygonShape * p, bool own = true);
virtual ~PolygonShape();
+7 -5
View File
@@ -37,18 +37,20 @@ namespace physics
namespace box2d
{
Shape::Shape()
: shape(NULL)
: shape(NULL), own(false)
{
}
Shape::Shape(b2Shape * shape)
: shape(shape)
Shape::Shape(b2Shape * shape, bool own)
: shape(shape), own(own)
{
Memoizer::add(shape, this);
if (own)
Memoizer::add(shape, this);
}
Shape::~Shape()
{
if (shape)
if (shape && own)
{
Memoizer::remove(shape);
delete shape;
+2 -1
View File
@@ -50,6 +50,7 @@ namespace box2d
// The Box2D shape.
b2Shape * shape;
bool own;
public:
@@ -57,7 +58,7 @@ namespace box2d
* Creates a Shape.
**/
Shape();
Shape(b2Shape * shape);
Shape(b2Shape * shape, bool own = true);
virtual ~Shape();