mirror of
https://github.com/love2d/love-android.git
synced 2026-08-20 04:31:26 +02:00
updated to latest mobile-common (0cf55b7da58e), removed libtiff, libpng, libmng, devil, jasper, jpeg-8d, added libturbo-jpeg
This commit is contained in:
@@ -41,7 +41,6 @@ Body::Body(World *world, b2Vec2 p, Body::Type type)
|
||||
{
|
||||
udata = new bodyudata();
|
||||
udata->ref = nullptr;
|
||||
world->retain();
|
||||
b2BodyDef def;
|
||||
def.position = Physics::scaleDown(p);
|
||||
def.userData = (void *) udata;
|
||||
@@ -57,8 +56,7 @@ Body::Body(b2Body *b)
|
||||
, udata(nullptr)
|
||||
{
|
||||
udata = (bodyudata *) b->GetUserData();
|
||||
world = (World *)Memoizer::find(b->GetWorld());
|
||||
world->retain();
|
||||
world.set((World *) Memoizer::find(b->GetWorld()));
|
||||
// Box2D body holds a reference to the love Body.
|
||||
this->retain();
|
||||
Memoizer::add(body, this);
|
||||
@@ -69,7 +67,6 @@ Body::~Body()
|
||||
if (udata != nullptr)
|
||||
delete udata->ref;
|
||||
delete udata;
|
||||
world->release();
|
||||
}
|
||||
|
||||
float Body::getX()
|
||||
@@ -420,7 +417,7 @@ bool Body::isFixedRotation() const
|
||||
|
||||
World *Body::getWorld() const
|
||||
{
|
||||
return world;
|
||||
return world.get();
|
||||
}
|
||||
|
||||
int Body::getFixtureList(lua_State *L) const
|
||||
@@ -435,7 +432,6 @@ int Body::getFixtureList(lua_State *L) const
|
||||
Fixture *fixture = (Fixture *)Memoizer::find(f);
|
||||
if (!fixture)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
fixture->retain();
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, fixture);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
@@ -444,6 +440,31 @@ int Body::getFixtureList(lua_State *L) const
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Body::getContactList(lua_State *L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
const b2ContactEdge *ce = body->GetContactList();
|
||||
int i = 1;
|
||||
do
|
||||
{
|
||||
if (!ce)
|
||||
break;
|
||||
|
||||
Contact *contact = (Contact *) Memoizer::find(ce->contact);
|
||||
if (!contact)
|
||||
contact = new Contact(ce->contact);
|
||||
else
|
||||
contact->retain();
|
||||
|
||||
luax_pushtype(L, "Contact", PHYSICS_CONTACT_T, contact);
|
||||
contact->release();
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
while ((ce = ce->next));
|
||||
return 1;
|
||||
}
|
||||
|
||||
b2Vec2 Body::getVector(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 2, 2);
|
||||
|
||||
@@ -393,6 +393,13 @@ public:
|
||||
**/
|
||||
int getFixtureList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all active Contacts attached to this Body.
|
||||
* This list changes during World:update and you may miss some collisions
|
||||
* if you don't use the collision callbacks.
|
||||
**/
|
||||
int getContactList(lua_State *L) const;
|
||||
|
||||
/**
|
||||
* Destroy this body.
|
||||
**/
|
||||
@@ -429,7 +436,7 @@ private:
|
||||
//
|
||||
// This ensures that a World only can be destroyed
|
||||
// once all bodies have been destroyed too.
|
||||
World *world;
|
||||
Object::StrongRef<World> world;
|
||||
|
||||
bodyudata *udata;
|
||||
|
||||
|
||||
@@ -142,6 +142,15 @@ void Contact::getChildren(int &childA, int &childB)
|
||||
childB = contact->GetChildIndexB();
|
||||
}
|
||||
|
||||
void Contact::getFixtures(Fixture *&fixtureA, Fixture *&fixtureB)
|
||||
{
|
||||
fixtureA = (Fixture *) Memoizer::find(contact->GetFixtureA());
|
||||
fixtureB = (Fixture *) Memoizer::find(contact->GetFixtureB());
|
||||
|
||||
if (!fixtureA || !fixtureB)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -148,6 +148,11 @@ public:
|
||||
|
||||
void getChildren(int &childA, int &childB);
|
||||
|
||||
/**
|
||||
* Gets the Fixtures associated with this Contact.
|
||||
**/
|
||||
void getFixtures(Fixture *&fixtureA, Fixture *&fixtureB);
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D contact.
|
||||
|
||||
@@ -40,21 +40,30 @@ namespace box2d
|
||||
{
|
||||
|
||||
Joint::Joint(Body *body1)
|
||||
: world(body1->world)
|
||||
: world(body1->world.get())
|
||||
, udata(nullptr)
|
||||
, body1(body1)
|
||||
, body2(0)
|
||||
, body2(nullptr)
|
||||
{
|
||||
udata = new jointudata();
|
||||
udata->ref = nullptr;
|
||||
}
|
||||
|
||||
Joint::Joint(Body *body1, Body *body2)
|
||||
: world(body1->world)
|
||||
: world(body1->world.get())
|
||||
, udata(nullptr)
|
||||
, body1(body1)
|
||||
, body2(body2)
|
||||
{
|
||||
udata = new jointudata();
|
||||
udata->ref = nullptr;
|
||||
}
|
||||
|
||||
Joint::~Joint()
|
||||
{
|
||||
if (udata != nullptr)
|
||||
delete udata->ref;
|
||||
delete udata;
|
||||
}
|
||||
|
||||
Joint::Type Joint::getType() const
|
||||
@@ -116,6 +125,7 @@ float Joint::getReactionTorque(float dt)
|
||||
|
||||
b2Joint *Joint::createJoint(b2JointDef *def)
|
||||
{
|
||||
def->userData = udata;
|
||||
joint = world->world->CreateJoint(def);
|
||||
Memoizer::add(joint, this);
|
||||
// Box2D joint has a reference to this love Joint.
|
||||
@@ -151,6 +161,34 @@ bool Joint::getCollideConnected() const
|
||||
return joint->GetCollideConnected();
|
||||
}
|
||||
|
||||
int Joint::setUserData(lua_State *L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
|
||||
if (udata->ref != nullptr)
|
||||
{
|
||||
// We set the Reference's lua_State to this one before deleting it, so
|
||||
// it unrefs using the current lua_State's stack. This is necessary
|
||||
// if setUserData is called in a coroutine.
|
||||
udata->ref->setL(L);
|
||||
delete udata->ref;
|
||||
}
|
||||
|
||||
udata->ref = new Reference(L);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Joint::getUserData(lua_State *L)
|
||||
{
|
||||
if (udata != nullptr && udata->ref != nullptr)
|
||||
udata->ref->push(L);
|
||||
else
|
||||
lua_pushnil(L);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -39,6 +39,16 @@ namespace box2d
|
||||
class Body;
|
||||
class World;
|
||||
|
||||
/**
|
||||
* This struct is stored in a void pointer in the Box2D Joint class. For now, all
|
||||
* we need is a Lua reference to arbitrary data, but we might need more later.
|
||||
**/
|
||||
struct jointudata
|
||||
{
|
||||
// Reference to arbitrary data.
|
||||
Reference *ref;
|
||||
};
|
||||
|
||||
/**
|
||||
* A Joint acts as positioning constraints on Bodies.
|
||||
* A Joint can be used to prevent Bodies from going to
|
||||
@@ -95,6 +105,17 @@ public:
|
||||
|
||||
bool getCollideConnected() const;
|
||||
|
||||
/**
|
||||
* This function stores an in-C reference to arbitrary Lua data in the Box2D
|
||||
* Joint object.
|
||||
**/
|
||||
int setUserData(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the data set with setUserData. If no data is set, nil is returned.
|
||||
**/
|
||||
int getUserData(lua_State *L);
|
||||
|
||||
/**
|
||||
* Joints require pointers to a Box2D joint objects at
|
||||
* different polymorphic levels, which is why these function
|
||||
@@ -117,6 +138,8 @@ protected:
|
||||
|
||||
World *world;
|
||||
|
||||
jointudata *udata;
|
||||
|
||||
private:
|
||||
|
||||
// A Joint must be destroyed *before* the bodies it acts upon,
|
||||
|
||||
@@ -125,8 +125,8 @@ int Physics::newPolygonShape(lua_State *L)
|
||||
}
|
||||
|
||||
PolygonShape *p = new PolygonShape(s);
|
||||
|
||||
luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, p);
|
||||
p->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -167,6 +167,7 @@ int Physics::newChainShape(lua_State *L)
|
||||
|
||||
ChainShape *c = new ChainShape(s);
|
||||
luax_pushtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, c);
|
||||
c->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -246,7 +247,7 @@ int Physics::getDistance(lua_State *L)
|
||||
b2SimplexCache c;
|
||||
c.count = 0;
|
||||
|
||||
EXCEPT_GUARD(
|
||||
luax_catchexcept(L, [&]() {
|
||||
pA.Set(fixtureA->fixture->GetShape(), 0);
|
||||
pB.Set(fixtureB->fixture->GetShape(), 0);
|
||||
i.proxyA = pA;
|
||||
@@ -255,7 +256,7 @@ int Physics::getDistance(lua_State *L)
|
||||
i.transformB = fixtureB->fixture->GetBody()->GetTransform();
|
||||
i.useRadii = true;
|
||||
b2Distance(&o, &c, &i);
|
||||
)
|
||||
});
|
||||
|
||||
lua_pushnumber(L, Physics::scaleUp(o.distance));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
|
||||
// Implements Module.
|
||||
const char *getName() const;
|
||||
virtual ModuleType getModuleType() const { return M_PHYSICS; }
|
||||
|
||||
/**
|
||||
* Creates a new World.
|
||||
|
||||
@@ -57,10 +57,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
|
||||
{
|
||||
Fixture *a = (Fixture *)Memoizer::find(contact->GetFixtureA());
|
||||
if (a != 0)
|
||||
{
|
||||
a->retain();
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, a);
|
||||
}
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
@@ -69,10 +66,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
|
||||
{
|
||||
Fixture *b = (Fixture *)Memoizer::find(contact->GetFixtureB());
|
||||
if (b != 0)
|
||||
{
|
||||
b->retain();
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, b);
|
||||
}
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
@@ -84,6 +78,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
|
||||
cobj->retain();
|
||||
|
||||
luax_pushtype(L, "Contact", (PHYSICS_CONTACT_T), cobj);
|
||||
cobj->release();
|
||||
|
||||
int args = 3;
|
||||
if (impulse)
|
||||
@@ -161,7 +156,6 @@ bool World::QueryCallback::ReportFixture(b2Fixture *fixture)
|
||||
Fixture *f = (Fixture *)Memoizer::find(fixture);
|
||||
if (!f)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
f->retain();
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, f);
|
||||
lua_call(L, 1, 1);
|
||||
return luax_toboolean(L, -1);
|
||||
@@ -189,7 +183,6 @@ float32 World::RayCastCallback::ReportFixture(b2Fixture *fixture, const b2Vec2 &
|
||||
Fixture *f = (Fixture *)Memoizer::find(fixture);
|
||||
if (!f)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
f->retain();
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, f);
|
||||
b2Vec2 scaledPoint = Physics::scaleUp(point);
|
||||
lua_pushnumber(L, scaledPoint.x);
|
||||
@@ -257,23 +250,20 @@ void World::update(float dt)
|
||||
world->Step(dt, 8, 6);
|
||||
|
||||
// Destroy all objects marked during the time step.
|
||||
for (auto i = destructBodies.begin(); i < destructBodies.end(); i++)
|
||||
for (Body *b : destructBodies)
|
||||
{
|
||||
Body *b = *i;
|
||||
if (b->body != 0) b->destroy();
|
||||
// Release for reference in vector.
|
||||
b->release();
|
||||
}
|
||||
for (auto i = destructFixtures.begin(); i < destructFixtures.end(); i++)
|
||||
for (Fixture *f : destructFixtures)
|
||||
{
|
||||
Fixture *f = *i;
|
||||
if (f->isValid()) f->destroy();
|
||||
// Release for reference in vector.
|
||||
f->release();
|
||||
}
|
||||
for (auto i = destructJoints.begin(); i < destructJoints.end(); i++)
|
||||
for (Joint *j : destructJoints)
|
||||
{
|
||||
Joint *j = *i;
|
||||
if (j->isValid()) j->destroyJoint();
|
||||
// Release for reference in vector.
|
||||
j->release();
|
||||
@@ -316,13 +306,9 @@ bool World::ShouldCollide(b2Fixture *fixtureA, b2Fixture *fixtureB)
|
||||
{
|
||||
// Fixtures should be memoized, if we created them
|
||||
Fixture *a = (Fixture *)Memoizer::find(fixtureA);
|
||||
if (!a)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
a->retain();
|
||||
Fixture *b = (Fixture *)Memoizer::find(fixtureB);
|
||||
if (!b)
|
||||
if (!a || !b)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
b->retain();
|
||||
return filter.process(a, b);
|
||||
}
|
||||
|
||||
@@ -445,7 +431,6 @@ int World::getBodyList(lua_State *L) const
|
||||
Body *body = (Body *)Memoizer::find(b);
|
||||
if (!body)
|
||||
throw love::Exception("A body has escaped Memoizer!");
|
||||
body->retain();
|
||||
luax_pushtype(L, "Body", PHYSICS_BODY_T, body);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
@@ -464,7 +449,6 @@ 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!");
|
||||
joint->retain();
|
||||
luax_pushtype(L, "Joint", PHYSICS_JOINT_T, joint);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
@@ -487,6 +471,7 @@ int World::getContactList(lua_State *L) const
|
||||
else
|
||||
contact->retain();
|
||||
luax_pushtype(L, "Contact", PHYSICS_CONTACT_T, contact);
|
||||
contact->release();
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ int w_Body_setX(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setX(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setX(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ int w_Body_setY(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setY(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setY(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ int w_Body_setAngle(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setAngle(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setAngle(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -283,14 +283,14 @@ int w_Body_setPosition(lua_State *L)
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
EXCEPT_GUARD(t->setPosition(arg1, arg2);)
|
||||
luax_catchexcept(L, [&](){ t->setPosition(arg1, arg2); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Body_resetMassData(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
EXCEPT_GUARD(t->resetMassData();)
|
||||
luax_catchexcept(L, [&](){ t->resetMassData(); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ int w_Body_setMassData(lua_State *L)
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float m = (float)luaL_checknumber(L, 4);
|
||||
float i = (float)luaL_checknumber(L, 5);
|
||||
EXCEPT_GUARD(t->setMassData(x, y, m, i);)
|
||||
luax_catchexcept(L, [&](){ t->setMassData(x, y, m, i); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ int w_Body_setMass(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
float m = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setMass(m);)
|
||||
luax_catchexcept(L, [&](){ t->setMass(m); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ int w_Body_setInertia(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
float i = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setInertia(i);)
|
||||
luax_catchexcept(L, [&](){ t->setInertia(i); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ int w_Body_setType(lua_State *L)
|
||||
const char *typeStr = luaL_checkstring(L, 2);
|
||||
Body::Type type;
|
||||
Body::getConstant(typeStr, type);
|
||||
EXCEPT_GUARD(t->setType(type);)
|
||||
luax_catchexcept(L, [&](){ t->setType(type); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ int w_Body_setActive(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
bool b = luax_toboolean(L, 2);
|
||||
EXCEPT_GUARD(t->setActive(b);)
|
||||
luax_catchexcept(L, [&](){ t->setActive(b); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -510,7 +510,7 @@ int w_Body_setFixedRotation(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
bool b = luax_toboolean(L, 2);
|
||||
EXCEPT_GUARD(t->setFixedRotation(b);)
|
||||
luax_catchexcept(L, [&](){ t->setFixedRotation(b); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -522,19 +522,36 @@ int w_Body_isFixedRotation(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Body_getWorld(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
World *world = t->getWorld();
|
||||
luax_pushtype(L, "World", PHYSICS_WORLD_T, world);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Body_getFixtureList(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
lua_remove(L, 1);
|
||||
int n = 0;
|
||||
EXCEPT_GUARD(n = t->getFixtureList(L);)
|
||||
luax_catchexcept(L, [&](){ n = t->getFixtureList(L); });
|
||||
return n;
|
||||
}
|
||||
|
||||
int w_Body_getContactList(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
lua_remove(L, 1);
|
||||
int n = 0;
|
||||
luax_catchexcept(L, [&](){ n = t->getContactList(L); });
|
||||
return n;
|
||||
}
|
||||
|
||||
int w_Body_destroy(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
EXCEPT_GUARD(t->destroy();)
|
||||
luax_catchexcept(L, [&](){ t->destroy(); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -604,7 +621,9 @@ static const luaL_Reg functions[] =
|
||||
{ "setAwake", w_Body_setAwake },
|
||||
{ "setFixedRotation", w_Body_setFixedRotation },
|
||||
{ "isFixedRotation", w_Body_isFixedRotation },
|
||||
{ "getWorld", w_Body_getWorld },
|
||||
{ "getFixtureList", w_Body_getFixtureList },
|
||||
{ "getContactList", w_Body_getContactList },
|
||||
{ "destroy", w_Body_destroy },
|
||||
{ "setUserData", w_Body_setUserData },
|
||||
{ "getUserData", w_Body_getUserData },
|
||||
|
||||
@@ -83,7 +83,9 @@ int w_Body_setActive(lua_State *L);
|
||||
int w_Body_setAwake(lua_State *L);
|
||||
int w_Body_setFixedRotation(lua_State *L);
|
||||
int w_Body_isFixedRotation(lua_State *L);
|
||||
int w_Body_getWorld(lua_State *L);
|
||||
int w_Body_getFixtureList(lua_State *L);
|
||||
int w_Body_getContactList(lua_State *L);
|
||||
int w_Body_destroy(lua_State *L);
|
||||
int w_Body_setUserData(lua_State *L);
|
||||
int w_Body_getUserData(lua_State *L);
|
||||
|
||||
@@ -39,7 +39,7 @@ int w_ChainShape_setNextVertex(lua_State *L)
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
EXCEPT_GUARD(c->setNextVertex(x, y);)
|
||||
luax_catchexcept(L, [&](){ c->setNextVertex(x, y); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ int w_ChainShape_setPreviousVertex(lua_State *L)
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
EXCEPT_GUARD(c->setPreviousVertex(x, y);)
|
||||
luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -64,8 +64,9 @@ int w_ChainShape_getChildEdge(lua_State *L)
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
|
||||
EdgeShape *e = 0;
|
||||
EXCEPT_GUARD(e = c->getChildEdge(index);)
|
||||
luax_catchexcept(L, [&](){ e = c->getChildEdge(index); });
|
||||
luax_pushtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
|
||||
e->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ int w_ChainShape_getPoint(lua_State *L)
|
||||
ChainShape *c = luax_checkchainshape(L, 1);
|
||||
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
|
||||
b2Vec2 v;
|
||||
EXCEPT_GUARD(v = c->getPoint(index);)
|
||||
luax_catchexcept(L, [&](){ v = c->getPoint(index); });
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
**/
|
||||
|
||||
#include "wrap_Contact.h"
|
||||
#include "Fixture.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -138,6 +139,18 @@ int w_Contact_getChildren(lua_State *L)
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Contact_getFixtures(lua_State *L)
|
||||
{
|
||||
Contact *t = luax_checkcontact(L, 1);
|
||||
Fixture *a = nullptr;
|
||||
Fixture *b = nullptr;
|
||||
luax_catchexcept(L, [&](){ t->getFixtures(a, b); });
|
||||
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, a);
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, b);
|
||||
return 2;
|
||||
}
|
||||
|
||||
extern "C" int luaopen_contact(lua_State *L)
|
||||
{
|
||||
static const luaL_Reg functions[] =
|
||||
@@ -156,6 +169,7 @@ extern "C" int luaopen_contact(lua_State *L)
|
||||
{ "setTangentSpeed", w_Contact_setTangentSpeed },
|
||||
{ "getTangentSpeed", w_Contact_getTangentSpeed },
|
||||
{ "getChildren", w_Contact_getChildren },
|
||||
{ "getFixtures", w_Contact_getFixtures },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ int w_Contact_resetRestitution(lua_State *L);
|
||||
int w_Contact_setTangentSpeed(lua_State *L);
|
||||
int w_Contact_getTangentSpeed(lua_State *L);
|
||||
int w_Contact_getChildren(lua_State *L);
|
||||
int w_Contact_getFixtures(lua_State *L);
|
||||
extern "C" int luaopen_contact(lua_State *L);
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -94,6 +94,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -65,7 +65,7 @@ int w_Fixture_setDensity(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setDensity(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setDensity(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,6 @@ int w_Fixture_getBody(lua_State *L)
|
||||
Body *body = t->getBody();
|
||||
if (body == 0)
|
||||
return 0;
|
||||
body->retain();
|
||||
luax_pushtype(L, "Body", PHYSICS_BODY_T, body);
|
||||
return 1;
|
||||
}
|
||||
@@ -140,6 +139,7 @@ int w_Fixture_getShape(lua_State *L)
|
||||
luax_pushtype(L, "Shape", PHYSICS_SHAPE_T, shape);
|
||||
break;
|
||||
}
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ int w_Fixture_rayCast(lua_State *L)
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
lua_remove(L, 1);
|
||||
int ret = 0;
|
||||
EXCEPT_GUARD(ret = t->rayCast(L);)
|
||||
luax_catchexcept(L, [&](){ ret = t->rayCast(L); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ int w_Fixture_setGroupIndex(lua_State *L)
|
||||
int w_Fixture_destroy(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
EXCEPT_GUARD(t->destroy();)
|
||||
luax_catchexcept(L, [&](){ t->destroy(); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ int w_FrictionJoint_setMaxForce(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setMaxForce(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setMaxForce(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ int w_FrictionJoint_setMaxTorque(lua_State *L)
|
||||
{
|
||||
FrictionJoint *t = luax_checkfrictionjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setMaxTorque(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setMaxTorque(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ int w_GearJoint_setRatio(lua_State *L)
|
||||
{
|
||||
GearJoint *t = luax_checkgearjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setRatio(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setRatio(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -75,10 +75,24 @@ int w_Joint_getCollideConnected(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_setUserData(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setUserData(L);
|
||||
}
|
||||
|
||||
int w_Joint_getUserData(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getUserData(L);
|
||||
}
|
||||
|
||||
int w_Joint_destroy(lua_State *L)
|
||||
{
|
||||
Joint *t = luax_checkjoint(L, 1);
|
||||
EXCEPT_GUARD(t->destroyJoint();)
|
||||
luax_catchexcept(L, [&](){ t->destroyJoint(); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -89,6 +103,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -38,6 +38,8 @@ int w_Joint_getAnchors(lua_State *L);
|
||||
int w_Joint_getReactionForce(lua_State *L);
|
||||
int w_Joint_getReactionTorque(lua_State *L);
|
||||
int w_Joint_getCollideConnected(lua_State *L);
|
||||
int w_Joint_setUserData(lua_State *L);
|
||||
int w_Joint_getUserData(lua_State *L);
|
||||
int w_Joint_destroy(lua_State *L);
|
||||
extern "C" int luaopen_joint(lua_State *L);
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ int w_MotorJoint_setMaxForce(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
float arg1 = (float) luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setMaxForce(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setMaxForce(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ int w_MotorJoint_setMaxTorque(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
float arg1 = (float) luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setMaxTorque(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setMaxTorque(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ int w_MotorJoint_setCorrectionFactor(lua_State *L)
|
||||
{
|
||||
MotorJoint *t = luax_checkmotorjoint(L, 1);
|
||||
float arg1 = (float) luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setCorrectionFactor(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setCorrectionFactor(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -128,6 +128,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -112,6 +112,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
static Physics *instance = 0;
|
||||
#define instance() (Module::getInstance<Physics>(Module::M_PHYSICS))
|
||||
|
||||
int w_newWorld(lua_State *L)
|
||||
{
|
||||
@@ -58,8 +58,9 @@ int w_newWorld(lua_State *L)
|
||||
bool sleep = luax_optboolean(L, 3, true);
|
||||
|
||||
World *w;
|
||||
EXCEPT_GUARD(w = instance->newWorld(gx, gy, sleep);)
|
||||
luax_catchexcept(L, [&](){ w = instance()->newWorld(gx, gy, sleep); });
|
||||
luax_pushtype(L, "World", PHYSICS_WORLD_T, w);
|
||||
w->release();
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -76,8 +77,9 @@ int w_newBody(lua_State *L)
|
||||
return luaL_error(L, "Invalid Body type: %s", typestr);
|
||||
|
||||
Body *body;
|
||||
EXCEPT_GUARD(body = instance->newBody(world, x, y, btype);)
|
||||
luax_catchexcept(L, [&](){ body = instance()->newBody(world, x, y, btype); });
|
||||
luax_pushtype(L, "Body", PHYSICS_BODY_T, body);
|
||||
body->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -87,8 +89,9 @@ int w_newFixture(lua_State *L)
|
||||
Shape *shape = luax_checkshape(L, 2);
|
||||
float density = (float)luaL_optnumber(L, 3, 1.0f);
|
||||
Fixture *fixture;
|
||||
EXCEPT_GUARD(fixture = instance->newFixture(body, shape, density);)
|
||||
luax_catchexcept(L, [&](){ fixture = instance()->newFixture(body, shape, density); });
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, fixture);
|
||||
fixture->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -100,8 +103,9 @@ int w_newCircleShape(lua_State *L)
|
||||
{
|
||||
float radius = (float)luaL_checknumber(L, 1);
|
||||
CircleShape *shape;
|
||||
EXCEPT_GUARD(shape = instance->newCircleShape(radius);)
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newCircleShape(radius); });
|
||||
luax_pushtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
else if (top == 3)
|
||||
@@ -110,8 +114,9 @@ int w_newCircleShape(lua_State *L)
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
float radius = (float)luaL_checknumber(L, 3);
|
||||
CircleShape *shape;
|
||||
EXCEPT_GUARD(shape = instance->newCircleShape(x, y, radius);)
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newCircleShape(x, y, radius); });
|
||||
luax_pushtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -127,8 +132,9 @@ int w_newRectangleShape(lua_State *L)
|
||||
float w = (float)luaL_checknumber(L, 1);
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
PolygonShape *shape;
|
||||
EXCEPT_GUARD(shape = instance->newRectangleShape(w, h);)
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newRectangleShape(w, h); });
|
||||
luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
else if (top == 4 || top == 5)
|
||||
@@ -139,8 +145,9 @@ int w_newRectangleShape(lua_State *L)
|
||||
float h = (float)luaL_checknumber(L, 4);
|
||||
float angle = (float)luaL_optnumber(L, 5, 0);
|
||||
PolygonShape *shape;
|
||||
EXCEPT_GUARD(shape = instance->newRectangleShape(x, y, w, h, angle);)
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newRectangleShape(x, y, w, h, angle); });
|
||||
luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -154,22 +161,23 @@ int w_newEdgeShape(lua_State *L)
|
||||
float x2 = (float)luaL_checknumber(L, 3);
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
EdgeShape *shape;
|
||||
EXCEPT_GUARD(shape = instance->newEdgeShape(x1, y1, x2, y2);)
|
||||
luax_catchexcept(L, [&](){ shape = instance()->newEdgeShape(x1, y1, x2, y2); });
|
||||
luax_pushtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, shape);
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newPolygonShape(lua_State *L)
|
||||
{
|
||||
int ret = 0;
|
||||
EXCEPT_GUARD(ret = instance->newPolygonShape(L);)
|
||||
luax_catchexcept(L, [&](){ ret = instance()->newPolygonShape(L); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
int w_newChainShape(lua_State *L)
|
||||
{
|
||||
int ret = 0;
|
||||
EXCEPT_GUARD(ret = instance->newChainShape(L);)
|
||||
luax_catchexcept(L, [&](){ ret = instance()->newChainShape(L); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -183,8 +191,11 @@ int w_newDistanceJoint(lua_State *L)
|
||||
float y2 = (float)luaL_checknumber(L, 6);
|
||||
bool collideConnected = luax_optboolean(L, 7, false);
|
||||
DistanceJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -194,8 +205,9 @@ int w_newMouseJoint(lua_State *L)
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
MouseJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newMouseJoint(body, x, y);)
|
||||
luax_catchexcept(L, [&](){ j = instance()->newMouseJoint(body, x, y); });
|
||||
luax_pushtype(L, "MouseJoint", PHYSICS_MOUSE_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -207,8 +219,11 @@ int w_newRevoluteJoint(lua_State *L)
|
||||
float y = (float)luaL_checknumber(L, 4);
|
||||
bool collideConnected = luax_optboolean(L, 5, false);
|
||||
RevoluteJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newRevoluteJoint(body1, body2, x, y, collideConnected);)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newRevoluteJoint(body1, body2, x, y, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -237,8 +252,11 @@ int w_newPrismaticJoint(lua_State *L)
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
PrismaticJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -258,8 +276,11 @@ int w_newPulleyJoint(lua_State *L)
|
||||
bool collideConnected = luax_optboolean(L, 12, true); // PulleyJoints default to colliding connected bodies, see b2PulleyJoint.h
|
||||
|
||||
PulleyJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newPulleyJoint(body1, body2, b2Vec2(gx1,gy1), b2Vec2(gx2,gy2), b2Vec2(x1,y1), b2Vec2(x2,y2), ratio, collideConnected);)
|
||||
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, "PulleyJoint", PHYSICS_PULLEY_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -271,8 +292,11 @@ int w_newGearJoint(lua_State *L)
|
||||
bool collideConnected = luax_optboolean(L, 4, false);
|
||||
|
||||
GearJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newGearJoint(joint1, joint2, ratio, collideConnected);)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newGearJoint(joint1, joint2, ratio, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -297,8 +321,11 @@ int w_newFrictionJoint(lua_State *L)
|
||||
collideConnected = luax_optboolean(L, 5, false);
|
||||
}
|
||||
FrictionJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -323,8 +350,11 @@ int w_newWeldJoint(lua_State *L)
|
||||
collideConnected = luax_optboolean(L, 5, false);
|
||||
}
|
||||
WeldJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -354,8 +384,11 @@ int w_newWheelJoint(lua_State *L)
|
||||
}
|
||||
|
||||
WheelJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -370,8 +403,11 @@ int w_newRopeJoint(lua_State *L)
|
||||
float maxLength = (float)luaL_checknumber(L, 7);
|
||||
bool collideConnected = luax_optboolean(L, 8, false);
|
||||
RopeJoint *j;
|
||||
EXCEPT_GUARD(j = instance->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -383,25 +419,28 @@ int w_newMotorJoint(lua_State *L)
|
||||
if (!lua_isnoneornil(L, 3))
|
||||
{
|
||||
float correctionFactor = (float)luaL_checknumber(L, 3);
|
||||
EXCEPT_GUARD(j = instance->newMotorJoint(body1, body2, correctionFactor);)
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newMotorJoint(body1, body2, correctionFactor);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
EXCEPT_GUARD(j = instance->newMotorJoint(body1, body2);)
|
||||
luax_catchexcept(L, [&](){ j = instance()->newMotorJoint(body1, body2); });
|
||||
}
|
||||
luax_pushtype(L, "MotorJoint", PHYSICS_MOTOR_JOINT_T, j);
|
||||
j->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getDistance(lua_State *L)
|
||||
{
|
||||
return instance->getDistance(L);
|
||||
return instance()->getDistance(L);
|
||||
}
|
||||
|
||||
int w_setMeter(lua_State *L)
|
||||
{
|
||||
int arg1 = luaL_checkint(L, 1);
|
||||
EXCEPT_GUARD(Physics::setMeter(arg1);)
|
||||
luax_catchexcept(L, [&](){ Physics::setMeter(arg1); });
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -467,9 +506,10 @@ static const lua_CFunction types[] =
|
||||
|
||||
extern "C" int luaopen_love_physics(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
Physics *instance = instance();
|
||||
if (instance == nullptr)
|
||||
{
|
||||
EXCEPT_GUARD(instance = new Physics();)
|
||||
luax_catchexcept(L, [&](){ instance = new Physics(); });
|
||||
}
|
||||
else
|
||||
instance->retain();
|
||||
|
||||
@@ -122,7 +122,7 @@ int w_PrismaticJoint_setUpperLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setUpperLimit(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setUpperLimit(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ int w_PrismaticJoint_setLowerLimit(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setLowerLimit(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setLowerLimit(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ int w_PrismaticJoint_setLimits(lua_State *L)
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
EXCEPT_GUARD(t->setLimits(arg1, arg2);)
|
||||
luax_catchexcept(L, [&](){ t->setLimits(arg1, arg2); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -189,6 +189,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -75,6 +75,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -122,7 +122,7 @@ int w_RevoluteJoint_setUpperLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setUpperLimit(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setUpperLimit(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ int w_RevoluteJoint_setLowerLimit(lua_State *L)
|
||||
{
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->setLowerLimit(arg1);)
|
||||
luax_catchexcept(L, [&](){ t->setLowerLimit(arg1); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ int w_RevoluteJoint_setLimits(lua_State *L)
|
||||
RevoluteJoint *t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
EXCEPT_GUARD(t->setLimits(arg1, arg2);)
|
||||
luax_catchexcept(L, [&](){ t->setLimits(arg1, arg2); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -189,6 +189,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -51,6 +51,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -76,7 +76,7 @@ int w_Shape_rayCast(lua_State *L)
|
||||
Shape *t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
int ret = 0;
|
||||
EXCEPT_GUARD(ret = t->rayCast(L);)
|
||||
luax_catchexcept(L, [&](){ ret = t->rayCast(L); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -153,6 +153,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "setUserData", w_Joint_setUserData },
|
||||
{ "getUserData", w_Joint_getUserData },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -39,7 +39,7 @@ int w_World_update(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
EXCEPT_GUARD(t->update(dt);)
|
||||
luax_catchexcept(L, [&](){ t->update(dt); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ int w_World_translateOrigin(lua_State *L)
|
||||
World *t = luax_checkworld(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
EXCEPT_GUARD(t->translateOrigin(arg1, arg2);)
|
||||
luax_catchexcept(L, [&](){ t->translateOrigin(arg1, arg2); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ int w_World_getBodyList(lua_State *L)
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
int ret = 0;
|
||||
EXCEPT_GUARD(ret = t->getBodyList(L);)
|
||||
luax_catchexcept(L, [&](){ ret = t->getBodyList(L); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ int w_World_getJointList(lua_State *L)
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
int ret = 0;
|
||||
EXCEPT_GUARD(ret = t->getJointList(L);)
|
||||
luax_catchexcept(L, [&](){ ret = t->getJointList(L); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ int w_World_getContactList(lua_State *L)
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
int ret = 0;
|
||||
EXCEPT_GUARD(ret = t->getContactList(L);)
|
||||
luax_catchexcept(L, [&](){ ret = t->getContactList(L); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -178,14 +178,14 @@ int w_World_rayCast(lua_State *L)
|
||||
World *t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
int ret = 0;
|
||||
EXCEPT_GUARD(ret = t->rayCast(L);)
|
||||
luax_catchexcept(L, [&](){ ret = t->rayCast(L); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
int w_World_destroy(lua_State *L)
|
||||
{
|
||||
World *t = luax_checkworld(L, 1);
|
||||
EXCEPT_GUARD(t->destroy();)
|
||||
luax_catchexcept(L, [&](){ t->destroy(); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user