Build type information on first use (load-time), instead of using a hardcoded list

--HG--
branch : dynamiccore2
This commit is contained in:
Bart van Strien
2016-11-13 16:38:57 +01:00
parent 452a8a877e
commit c761202486
192 changed files with 734 additions and 614 deletions
+2 -2
View File
@@ -435,7 +435,7 @@ int Body::getFixtureList(lua_State *L) const
Fixture *fixture = (Fixture *)Memoizer::find(f);
if (!fixture)
throw love::Exception("A fixture has escaped Memoizer!");
luax_pushtype(L, PHYSICS_FIXTURE_ID, fixture);
luax_pushtype(L, Fixture::type, fixture);
lua_rawseti(L, -2, i);
i++;
}
@@ -483,7 +483,7 @@ int Body::getContactList(lua_State *L) const
else
contact->retain();
luax_pushtype(L, PHYSICS_CONTACT_ID, contact);
luax_pushtype(L, Contact::type, contact);
contact->release();
lua_rawseti(L, -2, i);
i++;
+2
View File
@@ -34,6 +34,8 @@ namespace physics
namespace box2d
{
love::Type ChainShape::type(&Shape::type);
ChainShape::ChainShape(b2ChainShape *c, bool loop, bool own)
: Shape(c, own), loop(loop)
{
+2
View File
@@ -39,6 +39,8 @@ class ChainShape : public Shape
{
public:
static love::Type type;
/**
* Create a new ChainShape from a Box2D chain shape.
* @param c The chain shape.
@@ -34,6 +34,8 @@ namespace physics
namespace box2d
{
love::Type CircleShape::type(&Shape::type);
CircleShape::CircleShape(b2CircleShape *c, bool own)
: Shape(c, own)
{
+2
View File
@@ -44,6 +44,8 @@ class CircleShape : public Shape
{
public:
static love::Type type;
/**
* Create a new CircleShape from the a Box2D CircleShape definition.
* @param c The CircleShape definition.
+2
View File
@@ -31,6 +31,8 @@ namespace physics
namespace box2d
{
love::Type Contact::type(&Object::type);
Contact::Contact(b2Contact *contact)
: contact(contact)
{
+2
View File
@@ -49,6 +49,8 @@ public:
friend class World;
friend class World::ContactCallback;
static love::Type type;
/**
* Creates a new Contact by copying a Box2D contact
* point. It does not store the pointer, but copy the
+2
View File
@@ -34,6 +34,8 @@ namespace physics
namespace box2d
{
love::Type EdgeShape::type(&Shape::type);
EdgeShape::EdgeShape(b2EdgeShape *e, bool own)
: Shape(e, own)
{
+2
View File
@@ -39,6 +39,8 @@ class EdgeShape : public Shape
{
public:
static love::Type type;
/**
* Create a new EdgeShape from a Box2D edge shape.
* @param e The edge shape.
+2
View File
@@ -37,6 +37,8 @@ namespace physics
namespace box2d
{
love::Type Fixture::type(&Object::type);
Fixture::Fixture(Body *body, Shape *shape, float density)
: body(body)
, fixture(nullptr)
+2
View File
@@ -61,6 +61,8 @@ class Fixture : public Object
public:
friend class Physics;
static love::Type type;
/**
* Creates a Fixture.
**/
@@ -34,6 +34,8 @@ namespace physics
namespace box2d
{
love::Type FrictionJoint::type(&Joint::type);
FrictionJoint::FrictionJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
: Joint(body1, body2)
, joint(NULL)
@@ -38,6 +38,8 @@ class FrictionJoint : public Joint
{
public:
static love::Type type;
/**
* Creates a new FrictionJoint connecting body1 and body2.
**/
+2
View File
@@ -32,6 +32,8 @@ namespace physics
namespace box2d
{
love::Type GearJoint::type(&Joint::type);
GearJoint::GearJoint(Joint *joint1, Joint *joint2, float ratio, bool collideConnected)
: Joint(joint1->body2, joint2->body2)
, joint(NULL)
+2
View File
@@ -47,6 +47,8 @@ class GearJoint : public Joint
{
public:
static love::Type type;
/**
* Creates a GearJoint connecting joint1 to joint2.
**/
+2
View File
@@ -32,6 +32,8 @@ namespace physics
namespace box2d
{
love::Type MotorJoint::type(&Joint::type);
MotorJoint::MotorJoint(Body *body1, Body *body2)
: Joint(body1, body2)
, joint(NULL)
+2
View File
@@ -40,6 +40,8 @@ class MotorJoint : public Joint
{
public:
static love::Type type;
MotorJoint(Body *body1, Body* body2);
MotorJoint(Body *body1, Body* body2, float correctionFactor, bool collideConnected);
virtual ~MotorJoint();
+2
View File
@@ -32,6 +32,8 @@ namespace physics
namespace box2d
{
love::Type MouseJoint::type(&Joint::type);
MouseJoint::MouseJoint(Body *body1, float x, float y)
: Joint(body1)
, joint(NULL)
+2
View File
@@ -43,6 +43,8 @@ class MouseJoint : public Joint
{
public:
static love::Type type;
/**
* Creates a MouseJoint which connects body1 to the target point.
**/
+4 -4
View File
@@ -146,7 +146,7 @@ int Physics::newPolygonShape(lua_State *L)
}
PolygonShape *p = new PolygonShape(s);
luax_pushtype(L, PHYSICS_POLYGON_SHAPE_ID, p);
luax_pushtype(L, PolygonShape::type, p);
p->release();
return 1;
}
@@ -208,7 +208,7 @@ int Physics::newChainShape(lua_State *L)
delete[] vecs;
ChainShape *c = new ChainShape(s);
luax_pushtype(L, PHYSICS_CHAIN_SHAPE_ID, c);
luax_pushtype(L, ChainShape::type, c);
c->release();
return 1;
}
@@ -296,8 +296,8 @@ Fixture *Physics::newFixture(Body *body, Shape *shape, float density)
int Physics::getDistance(lua_State *L)
{
Fixture *fixtureA = luax_checktype<Fixture>(L, 1, PHYSICS_FIXTURE_ID);
Fixture *fixtureB = luax_checktype<Fixture>(L, 2, PHYSICS_FIXTURE_ID);
Fixture *fixtureA = luax_checktype<Fixture>(L, 1, Fixture::type);
Fixture *fixtureB = luax_checktype<Fixture>(L, 2, Fixture::type);
b2DistanceProxy pA, pB;
b2DistanceInput i;
b2DistanceOutput o;
@@ -34,6 +34,8 @@ namespace physics
namespace box2d
{
love::Type PolygonShape::type(&Shape::type);
PolygonShape::PolygonShape(b2PolygonShape *p, bool own)
: Shape(p, own)
{
+2
View File
@@ -42,6 +42,8 @@ class PolygonShape : public Shape
{
public:
static love::Type type;
/**
* Create a new PolygonShape from a Box2D polygon definition.
* @param p The polygon definition.
@@ -32,6 +32,8 @@ namespace physics
namespace box2d
{
love::Type PrismaticJoint::type(&Joint::type);
PrismaticJoint::PrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
: Joint(body1, body2)
, joint(NULL)
@@ -39,6 +39,8 @@ class PrismaticJoint : public Joint
{
public:
static love::Type type;
/**
* Creates a new PrismaticJoint connecting body1 and body2.
**/
@@ -32,6 +32,8 @@ namespace physics
namespace box2d
{
love::Type PulleyJoint::type(&Joint::type);
PulleyJoint::PulleyJoint(Body *bodyA, Body *bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected)
: Joint(bodyA, bodyB)
, joint(NULL)
+2
View File
@@ -41,6 +41,8 @@ class PulleyJoint : public Joint
{
public:
static love::Type type;
/**
* Creates a PulleyJoint connecting bodyA to bodyB.
**/
@@ -34,6 +34,8 @@ namespace physics
namespace box2d
{
love::Type RevoluteJoint::type(&Joint::type);
RevoluteJoint::RevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
: Joint(body1, body2)
, joint(NULL)
@@ -39,6 +39,8 @@ class RevoluteJoint : public Joint
{
public:
static love::Type type;
/**
* Creates a new RevoluteJoint connecting body1 and body2.
**/
+2
View File
@@ -32,6 +32,8 @@ namespace physics
namespace box2d
{
love::Type RopeJoint::type(&Joint::type);
RopeJoint::RopeJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected)
: Joint(body1, body2)
, joint(NULL)
+2
View File
@@ -39,6 +39,8 @@ class RopeJoint : public Joint
{
public:
static love::Type type;
/**
* Creates a RopeJoint connecting body1 to body2.
**/
+2
View File
@@ -34,6 +34,8 @@ namespace physics
namespace box2d
{
love::Type WeldJoint::type(&Joint::type);
WeldJoint::WeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
: Joint(body1, body2)
, joint(NULL)
+2
View File
@@ -38,6 +38,8 @@ class WeldJoint : public Joint
{
public:
static love::Type type;
/**
* Creates a new WeldJoint connecting body1 and body2.
**/
+2
View File
@@ -32,6 +32,8 @@ namespace physics
namespace box2d
{
love::Type WheelJoint::type(&Joint::type);
WheelJoint::WheelJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
: Joint(body1, body2)
, joint(NULL)
+2
View File
@@ -40,6 +40,8 @@ class WheelJoint : public Joint
{
public:
static love::Type type;
/**
* Creates a new WheelJoint connecting body1 and body2.
**/
+12 -10
View File
@@ -34,6 +34,8 @@ namespace physics
namespace box2d
{
love::Type World::type(&Object::type);
World::ContactCallback::ContactCallback()
: ref(nullptr)
, L(nullptr)
@@ -57,7 +59,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
{
Fixture *a = (Fixture *)Memoizer::find(contact->GetFixtureA());
if (a != nullptr)
luax_pushtype(L, PHYSICS_FIXTURE_ID, a);
luax_pushtype(L, Fixture::type, a);
else
throw love::Exception("A fixture has escaped Memoizer!");
}
@@ -66,7 +68,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
{
Fixture *b = (Fixture *)Memoizer::find(contact->GetFixtureB());
if (b != nullptr)
luax_pushtype(L, PHYSICS_FIXTURE_ID, b);
luax_pushtype(L, Fixture::type, b);
else
throw love::Exception("A fixture has escaped Memoizer!");
}
@@ -77,7 +79,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
else
cobj->retain();
luax_pushtype(L, PHYSICS_CONTACT_ID, cobj);
luax_pushtype(L, Contact::type, cobj);
cobj->release();
int args = 3;
@@ -128,8 +130,8 @@ bool World::ContactFilter::process(Fixture *a, Fixture *b)
if (ref != nullptr && L != nullptr)
{
ref->push(L);
luax_pushtype(L, PHYSICS_FIXTURE_ID, a);
luax_pushtype(L, PHYSICS_FIXTURE_ID, b);
luax_pushtype(L, Fixture::type, a);
luax_pushtype(L, Fixture::type, b);
lua_call(L, 2, 1);
return luax_toboolean(L, -1);
}
@@ -155,7 +157,7 @@ bool World::QueryCallback::ReportFixture(b2Fixture *fixture)
Fixture *f = (Fixture *)Memoizer::find(fixture);
if (!f)
throw love::Exception("A fixture has escaped Memoizer!");
luax_pushtype(L, PHYSICS_FIXTURE_ID, f);
luax_pushtype(L, Fixture::type, f);
lua_call(L, 1, 1);
bool cont = luax_toboolean(L, -1);
lua_pop(L, 1);
@@ -184,7 +186,7 @@ float32 World::RayCastCallback::ReportFixture(b2Fixture *fixture, const b2Vec2 &
Fixture *f = (Fixture *)Memoizer::find(fixture);
if (!f)
throw love::Exception("A fixture has escaped Memoizer!");
luax_pushtype(L, PHYSICS_FIXTURE_ID, f);
luax_pushtype(L, Fixture::type, f);
b2Vec2 scaledPoint = Physics::scaleUp(point);
lua_pushnumber(L, scaledPoint.x);
lua_pushnumber(L, scaledPoint.y);
@@ -473,7 +475,7 @@ int World::getBodyList(lua_State *L) const
Body *body = (Body *)Memoizer::find(b);
if (!body)
throw love::Exception("A body has escaped Memoizer!");
luax_pushtype(L, PHYSICS_BODY_ID, body);
luax_pushtype(L, Body::type, body);
lua_rawseti(L, -2, i);
i++;
}
@@ -491,7 +493,7 @@ int World::getJointList(lua_State *L) const
if (!j) break;
Joint *joint = (Joint *)Memoizer::find(j);
if (!joint) throw love::Exception("A joint has escaped Memoizer!");
luax_pushtype(L, PHYSICS_JOINT_ID, joint);
luax_pushtype(L, Joint::type, joint);
lua_rawseti(L, -2, i);
i++;
}
@@ -512,7 +514,7 @@ int World::getContactList(lua_State *L) const
contact = new Contact(c);
else
contact->retain();
luax_pushtype(L, PHYSICS_CONTACT_ID, contact);
luax_pushtype(L, Contact::type, contact);
contact->release();
lua_rawseti(L, -2, i);
i++;
+2
View File
@@ -66,6 +66,8 @@ public:
friend class Body;
friend class Fixture;
static love::Type type;
class ContactCallback
{
public:
+4 -4
View File
@@ -30,7 +30,7 @@ namespace box2d
Body *luax_checkbody(lua_State *L, int idx)
{
Body *b = luax_checktype<Body>(L, idx, PHYSICS_BODY_ID);
Body *b = luax_checktype<Body>(L, idx, Body::type);
if (b->body == 0)
luaL_error(L, "Attempt to use destroyed body.");
return b;
@@ -526,7 +526,7 @@ int w_Body_getWorld(lua_State *L)
{
Body *t = luax_checkbody(L, 1);
World *world = t->getWorld();
luax_pushtype(L, PHYSICS_WORLD_ID, world);
luax_pushtype(L, World::type, world);
return 1;
}
@@ -566,7 +566,7 @@ int w_Body_destroy(lua_State *L)
int w_Body_isDestroyed(lua_State *L)
{
Body *b = luax_checktype<Body>(L, 1, PHYSICS_BODY_ID);
Body *b = luax_checktype<Body>(L, 1, Body::type);
luax_pushboolean(L, b->body == nullptr);
return 1;
}
@@ -650,7 +650,7 @@ static const luaL_Reg w_Body_functions[] =
extern "C" int luaopen_body(lua_State *L)
{
return luax_register_type(L, PHYSICS_BODY_ID, "Body", w_Body_functions, nullptr);
return luax_register_type(L, Body::type, "Body", w_Body_functions, nullptr);
}
} // box2d
@@ -31,7 +31,7 @@ namespace box2d
ChainShape *luax_checkchainshape(lua_State *L, int idx)
{
return luax_checktype<ChainShape>(L, idx, PHYSICS_CHAIN_SHAPE_ID);
return luax_checktype<ChainShape>(L, idx, ChainShape::type);
}
int w_ChainShape_setNextVertex(lua_State *L)
@@ -68,7 +68,7 @@ int w_ChainShape_getChildEdge(lua_State *L)
int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
EdgeShape *e = 0;
luax_catchexcept(L, [&](){ e = c->getChildEdge(index); });
luax_pushtype(L, PHYSICS_EDGE_SHAPE_ID, e);
luax_pushtype(L, EdgeShape::type, e);
e->release();
return 1;
}
@@ -149,7 +149,7 @@ static const luaL_Reg w_ChainShape_functions[] =
extern "C" int luaopen_chainshape(lua_State *L)
{
return luax_register_type(L, PHYSICS_CHAIN_SHAPE_ID, "ChainShape", w_Shape_functions, w_ChainShape_functions, nullptr);
return luax_register_type(L, ChainShape::type, "ChainShape", w_Shape_functions, w_ChainShape_functions, nullptr);
}
} // box2d
@@ -29,7 +29,7 @@ namespace box2d
CircleShape *luax_checkcircleshape(lua_State *L, int idx)
{
return luax_checktype<CircleShape>(L, idx, PHYSICS_CIRCLE_SHAPE_ID);
return luax_checktype<CircleShape>(L, idx, CircleShape::type);
}
int w_CircleShape_getRadius(lua_State *L)
@@ -75,7 +75,7 @@ static const luaL_Reg w_CircleShape_functions[] =
extern "C" int luaopen_circleshape(lua_State *L)
{
return luax_register_type(L, PHYSICS_CIRCLE_SHAPE_ID, "CircleShape", w_Shape_functions, w_CircleShape_functions, nullptr);
return luax_register_type(L, CircleShape::type, "CircleShape", w_Shape_functions, w_CircleShape_functions, nullptr);
}
} // box2d
+5 -5
View File
@@ -30,7 +30,7 @@ namespace box2d
Contact *luax_checkcontact(lua_State *L, int idx)
{
Contact *c = luax_checktype<Contact>(L, idx, PHYSICS_CONTACT_ID);
Contact *c = luax_checktype<Contact>(L, idx, Contact::type);
if (!c->isValid())
luaL_error(L, "Attempt to use destroyed contact.");
return c;
@@ -146,14 +146,14 @@ int w_Contact_getFixtures(lua_State *L)
Fixture *b = nullptr;
luax_catchexcept(L, [&](){ t->getFixtures(a, b); });
luax_pushtype(L, PHYSICS_FIXTURE_ID, a);
luax_pushtype(L, PHYSICS_FIXTURE_ID, b);
luax_pushtype(L, Fixture::type, a);
luax_pushtype(L, Fixture::type, b);
return 2;
}
int w_Contact_isDestroyed(lua_State *L)
{
Contact *c = luax_checktype<Contact>(L, 1, PHYSICS_CONTACT_ID);
Contact *c = luax_checktype<Contact>(L, 1, Contact::type);
luax_pushboolean(L, !c->isValid());
return 1;
}
@@ -181,7 +181,7 @@ static const luaL_Reg w_Contact_functions[] =
extern "C" int luaopen_contact(lua_State *L)
{
return luax_register_type(L, PHYSICS_CONTACT_ID, "Contact", w_Contact_functions, nullptr);
return luax_register_type(L, Contact::type, "Contact", w_Contact_functions, nullptr);
}
} // box2d
@@ -29,7 +29,7 @@ namespace box2d
DistanceJoint *luax_checkdistancejoint(lua_State *L, int idx)
{
DistanceJoint *j = luax_checktype<DistanceJoint>(L, idx, PHYSICS_DISTANCE_JOINT_ID);
DistanceJoint *j = luax_checktype<DistanceJoint>(L, idx, DistanceJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -93,7 +93,7 @@ static const luaL_Reg w_DistanceJoint_functions[] =
extern "C" int luaopen_distancejoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_DISTANCE_JOINT_ID, "DistanceJoint", w_Joint_functions, w_DistanceJoint_functions, nullptr);
return luax_register_type(L, DistanceJoint::type, "DistanceJoint", w_Joint_functions, w_DistanceJoint_functions, nullptr);
}
} // box2d
+2 -2
View File
@@ -29,7 +29,7 @@ namespace box2d
EdgeShape *luax_checkedgeshape(lua_State *L, int idx)
{
return luax_checktype<EdgeShape>(L, idx, PHYSICS_EDGE_SHAPE_ID);
return luax_checktype<EdgeShape>(L, idx, EdgeShape::type);
}
int w_EdgeShape_setNextVertex(lua_State *L)
@@ -105,7 +105,7 @@ static const luaL_Reg w_EdgeShape_functions[] =
extern "C" int luaopen_edgeshape(lua_State *L)
{
return luax_register_type(L, PHYSICS_EDGE_SHAPE_ID, "EdgeShape", w_Shape_functions, w_EdgeShape_functions, nullptr);
return luax_register_type(L, EdgeShape::type, "EdgeShape", w_Shape_functions, w_EdgeShape_functions, nullptr);
}
} // box2d
+9 -9
View File
@@ -30,7 +30,7 @@ namespace box2d
Fixture *luax_checkfixture(lua_State *L, int idx)
{
Fixture *f = luax_checktype<Fixture>(L, idx, PHYSICS_FIXTURE_ID);
Fixture *f = luax_checktype<Fixture>(L, idx, Fixture::type);
if (!f->isValid())
luaL_error(L, "Attempt to use destroyed fixture.");
return f;
@@ -111,7 +111,7 @@ int w_Fixture_getBody(lua_State *L)
Body *body = t->getBody();
if (body == 0)
return 0;
luax_pushtype(L, PHYSICS_BODY_ID, body);
luax_pushtype(L, Body::type, body);
return 1;
}
@@ -124,19 +124,19 @@ int w_Fixture_getShape(lua_State *L)
switch (shape->getType())
{
case Shape::SHAPE_EDGE:
luax_pushtype(L, PHYSICS_EDGE_SHAPE_ID, shape);
luax_pushtype(L, EdgeShape::type, shape);
break;
case Shape::SHAPE_CHAIN:
luax_pushtype(L, PHYSICS_CHAIN_SHAPE_ID, shape);
luax_pushtype(L, ChainShape::type, shape);
break;
case Shape::SHAPE_CIRCLE:
luax_pushtype(L, PHYSICS_CIRCLE_SHAPE_ID, shape);
luax_pushtype(L, CircleShape::type, shape);
break;
case Shape::SHAPE_POLYGON:
luax_pushtype(L, PHYSICS_POLYGON_SHAPE_ID, shape);
luax_pushtype(L, PolygonShape::type, shape);
break;
default:
luax_pushtype(L, PHYSICS_SHAPE_ID, shape);
luax_pushtype(L, Shape::type, shape);
break;
}
return 1;
@@ -263,7 +263,7 @@ int w_Fixture_destroy(lua_State *L)
int w_Fixture_isDestroyed(lua_State *L)
{
Fixture *f = luax_checktype<Fixture>(L, 1, PHYSICS_FIXTURE_ID);
Fixture *f = luax_checktype<Fixture>(L, 1, Fixture::type);
luax_pushboolean(L, !f->isValid());
return 1;
}
@@ -302,7 +302,7 @@ static const luaL_Reg w_Fixture_functions[] =
extern "C" int luaopen_fixture(lua_State *L)
{
return luax_register_type(L, PHYSICS_FIXTURE_ID, "Fixture", w_Fixture_functions, nullptr);
return luax_register_type(L, Fixture::type, "Fixture", w_Fixture_functions, nullptr);
}
} // box2d
@@ -30,7 +30,7 @@ namespace box2d
FrictionJoint *luax_checkfrictionjoint(lua_State *L, int idx)
{
FrictionJoint *j = luax_checktype<FrictionJoint>(L, idx, PHYSICS_FRICTION_JOINT_ID);
FrictionJoint *j = luax_checktype<FrictionJoint>(L, idx, FrictionJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -77,7 +77,7 @@ static const luaL_Reg w_FrictionJoint_functions[] =
extern "C" int luaopen_frictionjoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_FRICTION_JOINT_ID, "FrictionJoint", w_Joint_functions, w_FrictionJoint_functions, nullptr);
return luax_register_type(L, FrictionJoint::type, "FrictionJoint", w_Joint_functions, w_FrictionJoint_functions, nullptr);
}
} // box2d
+2 -2
View File
@@ -30,7 +30,7 @@ namespace box2d
GearJoint *luax_checkgearjoint(lua_State *L, int idx)
{
GearJoint *j = luax_checktype<GearJoint>(L, idx, PHYSICS_GEAR_JOINT_ID);
GearJoint *j = luax_checktype<GearJoint>(L, idx, GearJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -77,7 +77,7 @@ static const luaL_Reg w_GearJoint_functions[] =
extern "C" int luaopen_gearjoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_GEAR_JOINT_ID, "GearJoint", w_Joint_functions, w_GearJoint_functions, nullptr);
return luax_register_type(L, GearJoint::type, "GearJoint", w_Joint_functions, w_GearJoint_functions, nullptr);
}
} // box2d
+27 -16
View File
@@ -22,6 +22,17 @@
#include "wrap_Joint.h"
#include "common/StringMap.h"
#include "Body.h"
#include "DistanceJoint.h"
#include "RevoluteJoint.h"
#include "PrismaticJoint.h"
#include "MouseJoint.h"
#include "PulleyJoint.h"
#include "GearJoint.h"
#include "FrictionJoint.h"
#include "WeldJoint.h"
#include "WheelJoint.h"
#include "RopeJoint.h"
#include "MotorJoint.h"
namespace love
{
@@ -38,27 +49,27 @@ void luax_pushjoint(lua_State *L, Joint *j)
switch (j->getType())
{
case Joint::JOINT_DISTANCE:
return luax_pushtype(L, PHYSICS_DISTANCE_JOINT_ID, j);
return luax_pushtype(L, DistanceJoint::type, j);
case Joint::JOINT_REVOLUTE:
return luax_pushtype(L, PHYSICS_REVOLUTE_JOINT_ID, j);
return luax_pushtype(L, RevoluteJoint::type, j);
case Joint::JOINT_PRISMATIC:
return luax_pushtype(L, PHYSICS_PRISMATIC_JOINT_ID, j);
return luax_pushtype(L, PrismaticJoint::type, j);
case Joint::JOINT_MOUSE:
return luax_pushtype(L, PHYSICS_MOUSE_JOINT_ID, j);
return luax_pushtype(L, MouseJoint::type, j);
case Joint::JOINT_PULLEY:
return luax_pushtype(L, PHYSICS_PULLEY_JOINT_ID, j);
return luax_pushtype(L, PulleyJoint::type, j);
case Joint::JOINT_GEAR:
return luax_pushtype(L, PHYSICS_GEAR_JOINT_ID, j);
return luax_pushtype(L, GearJoint::type, j);
case Joint::JOINT_FRICTION:
return luax_pushtype(L, PHYSICS_FRICTION_JOINT_ID, j);
return luax_pushtype(L, FrictionJoint::type, j);
case Joint::JOINT_WELD:
return luax_pushtype(L, PHYSICS_WELD_JOINT_ID, j);
return luax_pushtype(L, WeldJoint::type, j);
case Joint::JOINT_WHEEL:
return luax_pushtype(L, PHYSICS_WHEEL_JOINT_ID, j);
return luax_pushtype(L, WheelJoint::type, j);
case Joint::JOINT_ROPE:
return luax_pushtype(L, PHYSICS_ROPE_JOINT_ID, j);
return luax_pushtype(L, RopeJoint::type, j);
case Joint::JOINT_MOTOR:
return luax_pushtype(L, PHYSICS_MOTOR_JOINT_ID, j);
return luax_pushtype(L, MotorJoint::type, j);
default:
return lua_pushnil(L);
}
@@ -66,7 +77,7 @@ void luax_pushjoint(lua_State *L, Joint *j)
Joint *luax_checkjoint(lua_State *L, int idx)
{
Joint *t = luax_checktype<Joint>(L, idx, PHYSICS_JOINT_ID);
Joint *t = luax_checktype<Joint>(L, idx, Joint::type);
if (!t->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return t;
@@ -92,8 +103,8 @@ int w_Joint_getBodies(lua_State *L)
b2 = t->getBodyB();
});
luax_pushtype(L, PHYSICS_BODY_ID, b1);
luax_pushtype(L, PHYSICS_BODY_ID, b2);
luax_pushtype(L, Body::type, b1);
luax_pushtype(L, Body::type, b2);
return 2;
}
@@ -149,7 +160,7 @@ int w_Joint_destroy(lua_State *L)
int w_Joint_isDestroyed(lua_State *L)
{
Joint *t = luax_checktype<Joint>(L, 1, PHYSICS_JOINT_ID);
Joint *t = luax_checktype<Joint>(L, 1, Joint::type);
luax_pushboolean(L, !t->isValid());
return 1;
}
@@ -171,7 +182,7 @@ const luaL_Reg w_Joint_functions[] =
extern "C" int luaopen_joint(lua_State *L)
{
return luax_register_type(L, PHYSICS_JOINT_ID, "Joint", w_Joint_functions, nullptr);
return luax_register_type(L, Joint::type, "Joint", w_Joint_functions, nullptr);
}
} // box2d
@@ -29,7 +29,7 @@ namespace box2d
MotorJoint *luax_checkmotorjoint(lua_State *L, int idx)
{
MotorJoint *j = luax_checktype<MotorJoint>(L, idx, PHYSICS_MOTOR_JOINT_ID);
MotorJoint *j = luax_checktype<MotorJoint>(L, idx, MotorJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -127,7 +127,7 @@ static const luaL_Reg w_MotorJoint_functions[] =
extern "C" int luaopen_motorjoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_MOTOR_JOINT_ID, "MotorJoint", w_Joint_functions, w_MotorJoint_functions, nullptr);
return luax_register_type(L, MotorJoint::type, "MotorJoint", w_Joint_functions, w_MotorJoint_functions, nullptr);
}
@@ -29,7 +29,7 @@ namespace box2d
MouseJoint *luax_checkmousejoint(lua_State *L, int idx)
{
MouseJoint *j = luax_checktype<MouseJoint>(L, idx, PHYSICS_MOUSE_JOINT_ID);
MouseJoint *j = luax_checktype<MouseJoint>(L, idx, MouseJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -111,7 +111,7 @@ static const luaL_Reg w_MouseJoint_functions[] =
extern "C" int luaopen_mousejoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_MOUSE_JOINT_ID, "MouseJoint", w_Joint_functions, w_MouseJoint_functions, nullptr);
return luax_register_type(L, MouseJoint::type, "MouseJoint", w_Joint_functions, w_MouseJoint_functions, nullptr);
}
} // box2d
+20 -20
View File
@@ -59,7 +59,7 @@ int w_newWorld(lua_State *L)
World *w;
luax_catchexcept(L, [&](){ w = instance()->newWorld(gx, gy, sleep); });
luax_pushtype(L, PHYSICS_WORLD_ID, w);
luax_pushtype(L, World::type, w);
w->release();
return 1;
@@ -78,7 +78,7 @@ int w_newBody(lua_State *L)
Body *body;
luax_catchexcept(L, [&](){ body = instance()->newBody(world, x, y, btype); });
luax_pushtype(L, PHYSICS_BODY_ID, body);
luax_pushtype(L, Body::type, body);
body->release();
return 1;
}
@@ -90,7 +90,7 @@ int w_newFixture(lua_State *L)
float density = (float)luaL_optnumber(L, 3, 1.0f);
Fixture *fixture;
luax_catchexcept(L, [&](){ fixture = instance()->newFixture(body, shape, density); });
luax_pushtype(L, PHYSICS_FIXTURE_ID, fixture);
luax_pushtype(L, Fixture::type, fixture);
fixture->release();
return 1;
}
@@ -104,7 +104,7 @@ int w_newCircleShape(lua_State *L)
float radius = (float)luaL_checknumber(L, 1);
CircleShape *shape;
luax_catchexcept(L, [&](){ shape = instance()->newCircleShape(radius); });
luax_pushtype(L, PHYSICS_CIRCLE_SHAPE_ID, shape);
luax_pushtype(L, CircleShape::type, shape);
shape->release();
return 1;
}
@@ -115,7 +115,7 @@ int w_newCircleShape(lua_State *L)
float radius = (float)luaL_checknumber(L, 3);
CircleShape *shape;
luax_catchexcept(L, [&](){ shape = instance()->newCircleShape(x, y, radius); });
luax_pushtype(L, PHYSICS_CIRCLE_SHAPE_ID, shape);
luax_pushtype(L, CircleShape::type, shape);
shape->release();
return 1;
}
@@ -133,7 +133,7 @@ int w_newRectangleShape(lua_State *L)
float h = (float)luaL_checknumber(L, 2);
PolygonShape *shape;
luax_catchexcept(L, [&](){ shape = instance()->newRectangleShape(w, h); });
luax_pushtype(L, PHYSICS_POLYGON_SHAPE_ID, shape);
luax_pushtype(L, PolygonShape::type, shape);
shape->release();
return 1;
}
@@ -146,7 +146,7 @@ int w_newRectangleShape(lua_State *L)
float angle = (float)luaL_optnumber(L, 5, 0);
PolygonShape *shape;
luax_catchexcept(L, [&](){ shape = instance()->newRectangleShape(x, y, w, h, angle); });
luax_pushtype(L, PHYSICS_POLYGON_SHAPE_ID, shape);
luax_pushtype(L, PolygonShape::type, shape);
shape->release();
return 1;
}
@@ -162,7 +162,7 @@ int w_newEdgeShape(lua_State *L)
float y2 = (float)luaL_checknumber(L, 4);
EdgeShape *shape;
luax_catchexcept(L, [&](){ shape = instance()->newEdgeShape(x1, y1, x2, y2); });
luax_pushtype(L, PHYSICS_EDGE_SHAPE_ID, shape);
luax_pushtype(L, EdgeShape::type, shape);
shape->release();
return 1;
}
@@ -194,7 +194,7 @@ int w_newDistanceJoint(lua_State *L)
luax_catchexcept(L, [&]() {
j = instance()->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);
});
luax_pushtype(L, PHYSICS_DISTANCE_JOINT_ID, j);
luax_pushtype(L, DistanceJoint::type, j);
j->release();
return 1;
}
@@ -206,7 +206,7 @@ int w_newMouseJoint(lua_State *L)
float y = (float)luaL_checknumber(L, 3);
MouseJoint *j;
luax_catchexcept(L, [&](){ j = instance()->newMouseJoint(body, x, y); });
luax_pushtype(L, PHYSICS_MOUSE_JOINT_ID, j);
luax_pushtype(L, MouseJoint::type, j);
j->release();
return 1;
}
@@ -237,7 +237,7 @@ int w_newRevoluteJoint(lua_State *L)
luax_catchexcept(L, [&]() {
j = instance()->newRevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected, referenceAngle);
});
luax_pushtype(L, PHYSICS_REVOLUTE_JOINT_ID, j);
luax_pushtype(L, RevoluteJoint::type, j);
j->release();
return 1;
}
@@ -272,7 +272,7 @@ int w_newPrismaticJoint(lua_State *L)
luax_catchexcept(L, [&]() {
j = instance()->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected, referenceAngle);
});
luax_pushtype(L, PHYSICS_PRISMATIC_JOINT_ID, j);
luax_pushtype(L, PrismaticJoint::type, j);
j->release();
return 1;
}
@@ -296,7 +296,7 @@ int w_newPulleyJoint(lua_State *L)
luax_catchexcept(L, [&]() {
j = instance()->newPulleyJoint(body1, body2, b2Vec2(gx1,gy1), b2Vec2(gx2,gy2), b2Vec2(x1,y1), b2Vec2(x2,y2), ratio, collideConnected);
});
luax_pushtype(L, PHYSICS_PULLEY_JOINT_ID, j);
luax_pushtype(L, PulleyJoint::type, j);
j->release();
return 1;
}
@@ -312,7 +312,7 @@ int w_newGearJoint(lua_State *L)
luax_catchexcept(L, [&]() {
j = instance()->newGearJoint(joint1, joint2, ratio, collideConnected);
});
luax_pushtype(L, PHYSICS_GEAR_JOINT_ID, j);
luax_pushtype(L, GearJoint::type, j);
j->release();
return 1;
}
@@ -341,7 +341,7 @@ int w_newFrictionJoint(lua_State *L)
luax_catchexcept(L, [&]() {
j = instance()->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);
});
luax_pushtype(L, PHYSICS_FRICTION_JOINT_ID, j);
luax_pushtype(L, FrictionJoint::type, j);
j->release();
return 1;
}
@@ -372,7 +372,7 @@ int w_newWeldJoint(lua_State *L)
luax_catchexcept(L, [&]() {
j = instance()->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected, referenceAngle);
});
luax_pushtype(L, PHYSICS_WELD_JOINT_ID, j);
luax_pushtype(L, WeldJoint::type, j);
j->release();
return 1;
}
@@ -406,7 +406,7 @@ int w_newWheelJoint(lua_State *L)
luax_catchexcept(L, [&]() {
j = instance()->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
});
luax_pushtype(L, PHYSICS_WHEEL_JOINT_ID, j);
luax_pushtype(L, WheelJoint::type, j);
j->release();
return 1;
}
@@ -425,7 +425,7 @@ int w_newRopeJoint(lua_State *L)
luax_catchexcept(L, [&]() {
j = instance()->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
});
luax_pushtype(L, PHYSICS_ROPE_JOINT_ID, j);
luax_pushtype(L, RopeJoint::type, j);
j->release();
return 1;
}
@@ -447,7 +447,7 @@ int w_newMotorJoint(lua_State *L)
{
luax_catchexcept(L, [&](){ j = instance()->newMotorJoint(body1, body2); });
}
luax_pushtype(L, PHYSICS_MOTOR_JOINT_ID, j);
luax_pushtype(L, MotorJoint::type, j);
j->release();
return 1;
}
@@ -537,7 +537,7 @@ extern "C" int luaopen_love_physics(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "physics";
w.type = MODULE_ID;
w.type = &Module::type;
w.functions = functions;
w.types = types;
@@ -29,7 +29,7 @@ namespace box2d
PolygonShape *luax_checkpolygonshape(lua_State *L, int idx)
{
return luax_checktype<PolygonShape>(L, idx, PHYSICS_POLYGON_SHAPE_ID);
return luax_checktype<PolygonShape>(L, idx, PolygonShape::type);
}
int w_PolygonShape_getPoints(lua_State *L)
@@ -55,7 +55,7 @@ static const luaL_Reg w_PolygonShape_functions[] =
extern "C" int luaopen_polygonshape(lua_State *L)
{
return luax_register_type(L, PHYSICS_POLYGON_SHAPE_ID, "PolygonShape", w_Shape_functions, w_PolygonShape_functions, nullptr);
return luax_register_type(L, PolygonShape::type, "PolygonShape", w_Shape_functions, w_PolygonShape_functions, nullptr);
}
} // box2d
@@ -30,7 +30,7 @@ namespace box2d
PrismaticJoint *luax_checkprismaticjoint(lua_State *L, int idx)
{
PrismaticJoint *j = luax_checktype<PrismaticJoint>(L, idx, PHYSICS_PRISMATIC_JOINT_ID);
PrismaticJoint *j = luax_checktype<PrismaticJoint>(L, idx, PrismaticJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -204,7 +204,7 @@ static const luaL_Reg w_PrismaticJoint_functions[] =
extern "C" int luaopen_prismaticjoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_PRISMATIC_JOINT_ID, "PrismaticJoint", w_Joint_functions, w_PrismaticJoint_functions, nullptr);
return luax_register_type(L, PrismaticJoint::type, "PrismaticJoint", w_Joint_functions, w_PrismaticJoint_functions, nullptr);
}
} // box2d
@@ -29,7 +29,7 @@ namespace box2d
PulleyJoint *luax_checkpulleyjoint(lua_State *L, int idx)
{
PulleyJoint *j = luax_checktype<PulleyJoint>(L, idx, PHYSICS_PULLEY_JOINT_ID);
PulleyJoint *j = luax_checktype<PulleyJoint>(L, idx, PulleyJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -74,7 +74,7 @@ static const luaL_Reg w_PulleyJoint_functions[] =
extern "C" int luaopen_pulleyjoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_PULLEY_JOINT_ID, "PulleyJoint", w_Joint_functions, w_PulleyJoint_functions, nullptr);
return luax_register_type(L, PulleyJoint::type, "PulleyJoint", w_Joint_functions, w_PulleyJoint_functions, nullptr);
}
} // box2d
@@ -30,7 +30,7 @@ namespace box2d
RevoluteJoint *luax_checkrevolutejoint(lua_State *L, int idx)
{
RevoluteJoint *j = luax_checktype<RevoluteJoint>(L, idx, PHYSICS_REVOLUTE_JOINT_ID);
RevoluteJoint *j = luax_checktype<RevoluteJoint>(L, idx, RevoluteJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -196,7 +196,7 @@ static const luaL_Reg w_RevoluteJoint_functions[] =
extern "C" int luaopen_revolutejoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_REVOLUTE_JOINT_ID, "RevoluteJoint", w_Joint_functions, w_RevoluteJoint_functions, nullptr);
return luax_register_type(L, RevoluteJoint::type, "RevoluteJoint", w_Joint_functions, w_RevoluteJoint_functions, nullptr);
}
} // box2d
+2 -2
View File
@@ -29,7 +29,7 @@ namespace box2d
RopeJoint *luax_checkropejoint(lua_State *L, int idx)
{
RopeJoint *j = luax_checktype<RopeJoint>(L, idx, PHYSICS_ROPE_JOINT_ID);
RopeJoint *j = luax_checktype<RopeJoint>(L, idx, RopeJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -50,7 +50,7 @@ static const luaL_Reg w_RopeJoint_functions[] =
extern "C" int luaopen_ropejoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_ROPE_JOINT_ID, "RopeJoint", w_Joint_functions, w_RopeJoint_functions, nullptr);
return luax_register_type(L, RopeJoint::type, "RopeJoint", w_Joint_functions, w_RopeJoint_functions, nullptr);
}
} // box2d
+2 -2
View File
@@ -30,7 +30,7 @@ namespace box2d
Shape *luax_checkshape(lua_State *L, int idx)
{
return luax_checktype<Shape>(L, idx, PHYSICS_SHAPE_ID);
return luax_checktype<Shape>(L, idx, Shape::type);
}
int w_Shape_getType(lua_State *L)
@@ -108,7 +108,7 @@ const luaL_Reg w_Shape_functions[] =
extern "C" int luaopen_shape(lua_State *L)
{
return luax_register_type(L, PHYSICS_SHAPE_ID, "Shape", w_Shape_functions, nullptr);
return luax_register_type(L, Shape::type, "Shape", w_Shape_functions, nullptr);
}
} // box2d
+2 -2
View File
@@ -29,7 +29,7 @@ namespace box2d
WeldJoint *luax_checkweldjoint(lua_State *L, int idx)
{
WeldJoint *j = luax_checktype<WeldJoint>(L, idx, PHYSICS_WELD_JOINT_ID);
WeldJoint *j = luax_checktype<WeldJoint>(L, idx, WeldJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -84,7 +84,7 @@ static const luaL_Reg w_WeldJoint_functions[] =
extern "C" int luaopen_weldjoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_WELD_JOINT_ID, "WeldJoint", w_Joint_functions, w_WeldJoint_functions, nullptr);
return luax_register_type(L, WeldJoint::type, "WeldJoint", w_Joint_functions, w_WeldJoint_functions, nullptr);
}
} // box2d
@@ -29,7 +29,7 @@ namespace box2d
WheelJoint *luax_checkwheeljoint(lua_State *L, int idx)
{
WheelJoint *j = luax_checktype<WheelJoint>(L, idx, PHYSICS_WHEEL_JOINT_ID);
WheelJoint *j = luax_checktype<WheelJoint>(L, idx, WheelJoint::type);
if (!j->isValid())
luaL_error(L, "Attempt to use destroyed joint.");
return j;
@@ -160,7 +160,7 @@ static const luaL_Reg w_WheelJoint_functions[] =
extern "C" int luaopen_wheeljoint(lua_State *L)
{
return luax_register_type(L, PHYSICS_WHEEL_JOINT_ID, "WheelJoint", w_Joint_functions, w_WheelJoint_functions, nullptr);
return luax_register_type(L, WheelJoint::type, "WheelJoint", w_Joint_functions, w_WheelJoint_functions, nullptr);
}
} // box2d
+3 -3
View File
@@ -29,7 +29,7 @@ namespace box2d
World *luax_checkworld(lua_State *L, int idx)
{
World *w = luax_checktype<World>(L, idx, PHYSICS_WORLD_ID);
World *w = luax_checktype<World>(L, idx, World::type);
if (!w->isValid())
luaL_error(L, "Attempt to use destroyed world.");
return w;
@@ -203,7 +203,7 @@ int w_World_destroy(lua_State *L)
int w_World_isDestroyed(lua_State *L)
{
World *w = luax_checktype<World>(L, 1, PHYSICS_WORLD_ID);
World *w = luax_checktype<World>(L, 1, World::type);
luax_pushboolean(L, !w->isValid());
return 1;
}
@@ -237,7 +237,7 @@ static const luaL_Reg w_World_functions[] =
extern "C" int luaopen_world(lua_State *L)
{
return luax_register_type(L, PHYSICS_WORLD_ID, "World", w_World_functions, nullptr);
return luax_register_type(L, World::type, "World", w_World_functions, nullptr);
}
} // box2d