diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 0ad5d29e3..5481f763e 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -171,9 +171,11 @@ void Physics::update(float dt) Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); int kartid1 = p->getUserPointer(0)->getPointerKart()->getWorldKartId(); int kartid2 = p->getUserPointer(1)->getPointerKart()->getWorldKartId(); - // TODO: do not use globals this way, pass directly as function paramters - Scripting::Physics::setCollision(kartid1,kartid2); - script_engine->runScript("void onKartKartCollision()"); + script_engine->runScript("void onKartKartCollision(int, int)", + [=](asIScriptContext* ctx) { + ctx->SetArgDWord(0, kartid1); + ctx->SetArgDWord(1, kartid2); + }); continue; } // if kart-kart collision @@ -182,28 +184,27 @@ void Physics::update(float dt) // Kart hits physical object // ------------------------- Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); - Scripting::Physics::setCollision(0, 0); - //Scripting::Physics::setCollisionType("KartObject"); //object as in physical object - Scripting::Physics::setCollision( - p->getUserPointer(0)->getPointerPhysicalObject()->getID(), - "kart" - ); - script_engine->runScript("void onKartObjectCollision()"); + AbstractKart *kart = p->getUserPointer(1)->getPointerKart(); + int kartId = kart->getWorldKartId(); + std::string obj_id = p->getUserPointer(0)->getPointerPhysicalObject()->getID(); + + // TODO: pass obj_id as arguent + script_engine->runScript("void onKartObjectCollision(int)", + [=](asIScriptContext* ctx) { + ctx->SetArgDWord(0, kartId); + }); PhysicalObject *obj = p->getUserPointer(0) ->getPointerPhysicalObject(); if (obj->isCrashReset()) { - AbstractKart *kart = p->getUserPointer(1)->getPointerKart(); new RescueAnimation(kart); } else if (obj->isExplodeKartObject()) { - AbstractKart *kart = p->getUserPointer(1)->getPointerKart(); ExplosionAnimation::create(kart); } else if (obj->isFlattenKartObject()) { - AbstractKart *kart = p->getUserPointer(1)->getPointerKart(); const KartProperties* kp = kart->getKartProperties(); kart->setSquash(kp->getSquashDuration() * kart->getPlayerDifficulty()->getSquashDuration(), kp->getSquashSlowdown() * kart->getPlayerDifficulty()->getSquashSlowdown()); @@ -211,7 +212,6 @@ void Physics::update(float dt) else if(obj->isSoccerBall() && race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER) { - int kartId = p->getUserPointer(1)->getPointerKart()->getWorldKartId(); SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld(); soccerWorld->setLastKartTohitBall(kartId); } @@ -255,12 +255,11 @@ void Physics::update(float dt) // Projectile hits physical object // ------------------------------- Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); - Scripting::Physics::setCollision(0,0); //TODO : support item types etc - //Scripting::Physics::setCollisionType("ItemObject"); - Scripting::Physics::setCollision( - p->getUserPointer(1)->getPointerPhysicalObject()->getID(), - "item" - ); + // TODO: pass arguments + //Scripting::Physics::setColl0ision( + // p->getUserPointer(1)->getPointerPhysicalObject()->getID(), + // "item" + //); script_engine->runScript("void onItemObjectCollision()"); 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 41c2c65cd..e1c596454 100644 --- a/src/scriptengine/script_engine.hpp +++ b/src/scriptengine/script_engine.hpp @@ -31,8 +31,6 @@ namespace Scripting namespace Physics { void registerScriptFunctions(asIScriptEngine *engine); - void setCollision(int collider1,int collider2); - 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 893f32624..60fc0ce68 100644 --- a/src/scriptengine/script_physics.cpp +++ b/src/scriptengine/script_physics.cpp @@ -36,40 +36,10 @@ namespace Scripting HitEffect *he = new Explosion(*explosion_loc, "explosion", "explosion_bomb.xml"); projectile_manager->addHitEffect(he); } - //Bind getters for colliding karts - void getCollidingKart1(asIScriptGeneric *gen) - { - gen->SetReturnDWord(m_collidingkartid1); - } - void getCollidingKart2(asIScriptGeneric *gen) - { - gen->SetReturnDWord(m_collidingkartid2); - } - //Bind getter for colliding objects - void getCollidingID(asIScriptGeneric *gen) - { - void *pointer = &m_collider1; - gen->SetReturnObject(pointer); - } - - //Callbacks from Physics Engine, for collisions - void setCollision(int collider1,int collider2) - { - m_collidingkartid1 = collider1; - m_collidingkartid2 = collider2; - } - void setCollision(std::string collider1, std::string collider2) - { - m_collider1 = collider1; - m_collider2 = collider2; - } void registerScriptFunctions(asIScriptEngine *engine) { int r; engine->SetDefaultNamespace("Physics"); - r = engine->RegisterGlobalFunction("uint getCollidingKart1()", asFUNCTION(getCollidingKart1), asCALL_GENERIC); assert( r >= 0 ); - r = engine->RegisterGlobalFunction("uint getCollidingKart2()", asFUNCTION(getCollidingKart2), asCALL_GENERIC); assert( r >= 0 ); - r = engine->RegisterGlobalFunction("string getCollidingID()", asFUNCTION(getCollidingID), asCALL_GENERIC); assert(r >= 0); r = engine->RegisterGlobalFunction("string createExplosion(Vec3 &in)", asFUNCTION(createExplosion), asCALL_GENERIC); assert(r >= 0); } } diff --git a/src/scriptengine/script_physics.hpp b/src/scriptengine/script_physics.hpp index d6f47534d..51fbaa9c7 100644 --- a/src/scriptengine/script_physics.hpp +++ b/src/scriptengine/script_physics.hpp @@ -27,34 +27,11 @@ namespace Scripting namespace Physics { - - //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; - + //script engine functions void registerScriptFunctions(asIScriptEngine *engine); asIScriptFunction* registerScriptCallbacks(asIScriptEngine *engine); - - - //game engine functions - void setCollision(int collider1, int collider2); - void setCollisionType(std::string); - - - - //script-bound functions - void getCollidingKart1(asIScriptGeneric *gen); - void getCollidingKart2(asIScriptGeneric *gen); - void getCollsionType(asIScriptGeneric *gen); - void getCollidingID(asIScriptGeneric *gen); - }