From 43f78a6a546e0aa7c9ce063a9e4fcabb60eb1b8c Mon Sep 17 00:00:00 2001 From: Sachith Hasaranga Seneviratne Date: Mon, 2 Jun 2014 13:07:51 +0530 Subject: [PATCH] Added accessor methods for ID, set disabling/enabling/status checking to work for IDs as well --- src/physics/physical_object.cpp | 3 ++- src/physics/physical_object.hpp | 9 +++++++++ src/physics/physics.cpp | 5 +++++ src/scriptengine/script_engine.hpp | 1 + src/scriptengine/script_physics.cpp | 5 +++++ src/scriptengine/script_physics.hpp | 5 +++++ src/tracks/track_object_manager.cpp | 6 +++--- 7 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index f3131558d..1702fc52b 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -56,9 +56,10 @@ PhysicalObject::Settings::Settings(const XMLNode &xml_node) { init(); std::string shape; + xml_node.get("id", &m_id ); xml_node.get("mass", &m_mass ); xml_node.get("radius", &m_radius ); - xml_node.get("shape", &shape ); + xml_node.get("shape", &shape ); xml_node.get("reset", &m_crash_reset ); xml_node.get("explode", &m_knock_kart ); xml_node.get("flatten", &m_flatten_kart); diff --git a/src/physics/physical_object.hpp b/src/physics/physical_object.hpp index 104f5fb81..a8f6cbe8f 100644 --- a/src/physics/physical_object.hpp +++ b/src/physics/physical_object.hpp @@ -47,6 +47,8 @@ public: class Settings { public: + /** ID of the object. */ + std::string m_id; /** Mass of the object. */ float m_mass; /** Radius of the object. */ @@ -91,6 +93,9 @@ private: /** The bullet collision shape. */ btCollisionShape *m_shape; + /** ID of the object. */ + std::string m_id; + /** The corresponding bullet rigid body. */ btRigidBody *m_body; @@ -161,6 +166,10 @@ public: bool isSoccerBall () const; // ------------------------------------------------------------------------ /** Returns the rigid body of this physical object. */ + std::string getID() { return m_id; } + // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + /** Returns the rigid body of this physical object. */ btRigidBody *getBody () { return m_body; } // ------------------------------------------------------------------------ /** Returns true if this object should trigger a rescue in a kart that diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 9d9e98c69..243925d93 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -248,6 +248,11 @@ void Physics::update(float dt) Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); Scripting::Physics::setCollision(0,0); //TODO : support item types etc Scripting::Physics::setCollisionType("Projectile-PhysObj"); + Scripting::Physics::setCollision + ( + p->getUserPointer(1)->getPointerPhysicalObject()->getID, + "item" + ); script_engine->runScript("collisions"); p->getUserPointer(0)->getPointerFlyable() ->hit(NULL, p->getUserPointer(1)->getPointerPhysicalObject()); diff --git a/src/scriptengine/script_engine.hpp b/src/scriptengine/script_engine.hpp index dc18cb1ea..74f8bd7eb 100644 --- a/src/scriptengine/script_engine.hpp +++ b/src/scriptengine/script_engine.hpp @@ -32,6 +32,7 @@ namespace Scripting{ registerScriptCallbacks(asIScriptEngine *engine); void setCollision(int collider1,int collider2); void setCollisionType(std::string collisionType); + void setCollision(std::string collider1, std::string collider2); } namespace Kart{ diff --git a/src/scriptengine/script_physics.cpp b/src/scriptengine/script_physics.cpp index 30791aab7..f0fb4a53f 100644 --- a/src/scriptengine/script_physics.cpp +++ b/src/scriptengine/script_physics.cpp @@ -43,6 +43,11 @@ namespace Scripting{ m_collidingkartid1 = collider1; m_collidingkartid2 = collider2; } + void setCollision(std::string collider1, std::string collider2) + { + m_collider1 = collider1; + m_collider2 = collider2; + } void setCollisionType(std::string collisionType) { m_collisionType = collisionType; diff --git a/src/scriptengine/script_physics.hpp b/src/scriptengine/script_physics.hpp index 8345c7e68..79e687c5b 100644 --- a/src/scriptengine/script_physics.hpp +++ b/src/scriptengine/script_physics.hpp @@ -27,8 +27,13 @@ namespace Scripting{ namespace Physics{ //private: + //IDs of kart collisions int m_collidingkartid1; int m_collidingkartid2; + + //Details of collision + std::string m_collider1; + std::string m_collider2; std::string m_collisionType; //public: diff --git a/src/tracks/track_object_manager.cpp b/src/tracks/track_object_manager.cpp index 65a422cfe..7566cc90c 100644 --- a/src/tracks/track_object_manager.cpp +++ b/src/tracks/track_object_manager.cpp @@ -92,7 +92,7 @@ void TrackObjectManager::disable(std::string name , std::string type){ for_in (curr,m_all_objects){ if (type != curr->getType())continue; - if (curr->getName() == (name)) + if (curr->getName() == (name) || curr->getID() == (name)) { curr->setEnable(false); @@ -109,7 +109,7 @@ void TrackObjectManager::enable(std::string name , std::string type){ if (type != curr->getType())continue; - if (curr->getName() == (name)) + if (curr->getName() == (name) || curr->getID() == (name)) { curr->reset(); @@ -125,7 +125,7 @@ void TrackObjectManager::enable(std::string name , std::string type){ bool TrackObjectManager::getStatus(std::string name){ TrackObject* curr; for_in (curr,m_all_objects){ - if (curr->getName() == (name)) + if (curr->getName() == (name)||curr->getID()==(name)) { return curr->isEnabled();