GRIM: Implemented the collision handler callback function.

This commit is contained in:
Giulio Camuffo 2011-09-04 15:16:07 +02:00
parent 9b8f540ccd
commit 9e260c58a4
4 changed files with 32 additions and 3 deletions

View File

@ -640,7 +640,7 @@ void Actor::moveTo(const Graphics::Vector3d &pos) {
if (_collisionMode != CollisionOff) {
for (GrimEngine::ActorListType::const_iterator i = g_grim->actorsBegin(); i != g_grim->actorsEnd(); ++i) {
Actor *a = i->_value;
if (a != this && a->isInSet(g_grim->getSceneName()) && a->isVisible()) {
if (a != this && a->isInSet(_setName) && a->isVisible()) {
collidesWith(a, &v);
}
}
@ -1487,6 +1487,7 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const {
v *= size1 + size2;
*vec = v + p2 - p1;
collisionHandlerCallback(actor);
return true;
}
} else if (mode1 == CollisionBox && mode2 == CollisionBox) {
@ -1595,6 +1596,7 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const {
float z = vec->z();
*vec = point - circlePos;
vec->z() = z;
collisionHandlerCallback(actor);
return true;
}
}
@ -1630,4 +1632,30 @@ void Actor::costumeMarkerCallback(int marker) {
lua_endblock();
}
void Actor::collisionHandlerCallback(Actor *other) const {
lua_beginblock();
lua_pushobject(lua_getref(refSystemTable));
lua_pushstring("collisionHandler");
lua_Object table = lua_gettable();
if (lua_istable(table)) {
lua_pushobject(table);
lua_pushstring("collisionHandler");
lua_Object func = lua_gettable();
if (lua_isfunction(func)) {
lua_pushobject(func);
lua_pushusertag(getId(), MKTAG('A','C','T','R'));
lua_pushusertag(other->getId(), MKTAG('A','C','T','R'));
lua_callfunction(func);
}
} else if (lua_isfunction(table)) {
lua_pushusertag(getId(), MKTAG('A','C','T','R'));
lua_pushusertag(other->getId(), MKTAG('A','C','T','R'));
lua_callfunction(table);
}
lua_endblock();
}
} // end of namespace Grim

View File

@ -452,6 +452,7 @@ public:
private:
void costumeMarkerCallback(int marker);
void collisionHandlerCallback(Actor *other) const;
void updateWalk();
void addShadowPlane(const char *n, Scene *scene, int shadowId);
bool shouldDrawShadow(int shadowId);

View File

@ -59,7 +59,7 @@ void Object::dereference() {
}
}
int32 Object::getId() {
int32 Object::getId() const {
return _id;
}

View File

@ -46,7 +46,7 @@ public:
void reference();
void dereference();
int32 getId();
int32 getId() const;
private:
void setId(int32 id);