Added accessor methods for ID, set disabling/enabling/status checking to work for IDs as well

This commit is contained in:
Sachith Hasaranga Seneviratne 2014-06-02 13:07:51 +05:30
parent ad71674b2c
commit 43f78a6a54
7 changed files with 30 additions and 4 deletions

View File

@ -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);

View File

@ -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

View File

@ -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());

View File

@ -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{

View File

@ -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;

View File

@ -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:

View File

@ -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();