From 9e260c58a437e4843638e5eee5694992b8aaa06e Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Sun, 4 Sep 2011 15:16:07 +0200 Subject: [PATCH] GRIM: Implemented the collision handler callback function. --- engines/grim/actor.cpp | 30 +++++++++++++++++++++++++++++- engines/grim/actor.h | 1 + engines/grim/object.cpp | 2 +- engines/grim/object.h | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp index 57a3bb92e10..08946459504 100644 --- a/engines/grim/actor.cpp +++ b/engines/grim/actor.cpp @@ -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 diff --git a/engines/grim/actor.h b/engines/grim/actor.h index e7a5ae6ca11..c03bf8c65dc 100644 --- a/engines/grim/actor.h +++ b/engines/grim/actor.h @@ -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); diff --git a/engines/grim/object.cpp b/engines/grim/object.cpp index 7ae505b5f0a..ed839965936 100644 --- a/engines/grim/object.cpp +++ b/engines/grim/object.cpp @@ -59,7 +59,7 @@ void Object::dereference() { } } -int32 Object::getId() { +int32 Object::getId() const { return _id; } diff --git a/engines/grim/object.h b/engines/grim/object.h index 7b079ed4ab1..fbc0f7e9e0b 100644 --- a/engines/grim/object.h +++ b/engines/grim/object.h @@ -46,7 +46,7 @@ public: void reference(); void dereference(); - int32 getId(); + int32 getId() const; private: void setId(int32 id);