1 /* 2 OpenLieroX 3 4 physic simulation interface 5 6 code under LGPL 7 created on 9/2/2008 8 */ 9 10 #include "Physics.h" 11 #include "PhysicsLX56.h" 12 #include "Debug.h" 13 #include "LieroX.h" 14 #include "CWorm.h" 15 #include "CClient.h" 16 #include "CProjectile.h" 17 #include "CBonus.h" 18 19 20 static PhysicsEngine* engine = NULL; Get()21PhysicsEngine* PhysicsEngine::Get() { return engine; } Set(PhysicsEngine * e)22void PhysicsEngine::Set(PhysicsEngine* e) { engine = e; } 23 Init()24void PhysicsEngine::Init() { 25 engine = CreatePhysicsEngineLX56(); 26 27 notes << "PhysicsEngine " << engine->name() << " loaded" << endl; 28 } 29 UnInit()30void PhysicsEngine::UnInit() { 31 if(engine) { 32 notes << "unloading PhysicsEngine " << engine->name() << " .." << endl; 33 delete engine; 34 engine = NULL; 35 } 36 else 37 errors << "PhysicsEngine::UnInit: physics engine not loaded" << endl; 38 } 39 GetPhysicsTime()40AbsTime GetPhysicsTime() { 41 return tLX->currentTime; 42 } 43 44 45 skipWorm(CWorm * worm)46void PhysicsEngine::skipWorm(CWorm* worm) { 47 worm->fLastSimulationTime += tLX->fRealDeltaTime; 48 } 49 skipProjectiles(Iterator<CProjectile * >::Ref projs)50void PhysicsEngine::skipProjectiles(Iterator<CProjectile*>::Ref projs) { 51 cClient->fLastSimulationTime += tLX->fRealDeltaTime; 52 53 for(Iterator<CProjectile*>::Ref i = projs; i->isValid(); i->next()) { 54 CProjectile* p = i->get(); 55 p->fLastSimulationTime += tLX->fRealDeltaTime; 56 } 57 } 58 skipBonuses(CBonus * bonuses,size_t count)59void PhysicsEngine::skipBonuses(CBonus* bonuses, size_t count) { 60 if(!cClient->getGameLobby()->bBonusesOn) return; 61 CBonus *b = bonuses; 62 for(size_t i=0; i < count; i++,b++) { 63 if(!b->getUsed()) continue; 64 b->fLastSimulationTime += tLX->fRealDeltaTime; 65 } 66 } 67