Revision: 2759 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2759&view=rev Author: ulteq Date: 2012-05-30 17:58:43 +0000 (Wed, 30 May 2012) Log Message: ----------- improved getAllLinkedBeams() method
Modified Paths: -------------- trunk/source/main/physics/Beam.cpp trunk/source/main/physics/Beam.h Modified: trunk/source/main/physics/Beam.cpp =================================================================== --- trunk/source/main/physics/Beam.cpp 2012-05-30 17:51:05 UTC (rev 2758) +++ trunk/source/main/physics/Beam.cpp 2012-05-30 17:58:43 UTC (rev 2759) @@ -1353,17 +1353,17 @@ float mass = totalmass; - std::list<Beam*> linkedBeams = getAllLinkedBeams(); - for (std::list<Beam*>::iterator it = linkedBeams.begin(); it != linkedBeams.end(); ++it) + { mass += (*it)->totalmass; + } return mass; } -std::list<Beam*> Beam::getAllLinkedBeams() +void Beam::determineLinkedBeams() { - std::list<Beam*> result; + linkedBeams.clear(); bool found = true; std::map< Beam*, bool> lookup_table; @@ -1386,7 +1386,7 @@ ret = lookup_table.insert(std::pair< Beam*, bool>(it_hook->lockTruck, false)); if (ret.second) { - result.push_back(it_hook->lockTruck); + linkedBeams.push_back(it_hook->lockTruck); found = true; } } @@ -1395,8 +1395,6 @@ } } } - - return result; } int Beam::getWheelNodeCount() @@ -1939,6 +1937,15 @@ //this is a hook assistance beam and needs to be disabled after reset for (std::vector <hook_t>::iterator it = hooks.begin(); it!=hooks.end(); it++) { + if (it->lockTruck) + { + it->lockTruck->determineLinkedBeams(); + + for (std::list<Beam*>::iterator it_truck = it->lockTruck->linkedBeams.begin(); it_truck != it->lockTruck->linkedBeams.end(); ++it) + { + (*it_truck)->determineLinkedBeams(); + } + } it->beam->mSceneNode->detachAllObjects(); it->beam->disabled = true; it->locked = UNLOCKED; @@ -4360,10 +4367,10 @@ if (linked) { // apply to the locked truck - std::list<Beam*> linkedBeams = getAllLinkedBeams(); - for (std::list<Beam*>::iterator it = linkedBeams.begin(); it != linkedBeams.end(); ++it) + { (*it)->showSkeleton(meshes, newMode, false); + } } lockSkeletonchange=false; @@ -4449,10 +4456,10 @@ if (linked) { // apply to the locked truck - std::list<Beam*> linkedBeams = getAllLinkedBeams(); - for (std::list<Beam*>::iterator it = linkedBeams.begin(); it != linkedBeams.end(); ++it) + { (*it)->hideSkeleton(newMode, false); + } } lockSkeletonchange=false; @@ -4551,10 +4558,10 @@ if (linked) { // apply to the locked truck - std::list<Beam*> linkedBeams = getAllLinkedBeams(); - for (std::list<Beam*>::iterator it = linkedBeams.begin(); it != linkedBeams.end(); ++it) + { (*it)->setBeamVisibility(visible, false); + } } } @@ -4594,10 +4601,10 @@ if (linked) { // apply to the locked truck - std::list<Beam*> linkedBeams = getAllLinkedBeams(); - for (std::list<Beam*>::iterator it = linkedBeams.begin(); it != linkedBeams.end(); ++it) + { (*it)->setMeshVisibility(visible, false); + } } } @@ -4864,6 +4871,8 @@ continue; } + Beam* lastLockTruck = it->lockTruck; // memorize current value + //this is a locked or prelocked hook and its not a locking attempt if ((it->locked == LOCKED || it->locked == PRELOCK) && mode != HOOK_LOCK) { @@ -4978,6 +4987,22 @@ //break; } } + + if (it->lockTruck != lastLockTruck) + { + std::list<Beam*> linkedBeams (linkedBeams); + + linkedBeams.push_back(this); + linkedBeams.push_back(std::max(lastLockTruck, it->lockTruck)); + linkedBeams.splice(linkedBeams.end(), linkedBeams.front()->linkedBeams); + linkedBeams.sort(); + linkedBeams.unique(); + + for (std::list<Beam*>::iterator it = linkedBeams.begin(); it != linkedBeams.end(); ++it) + { + (*it)->determineLinkedBeams(); + } + } } } Modified: trunk/source/main/physics/Beam.h =================================================================== --- trunk/source/main/physics/Beam.h 2012-05-30 17:51:05 UTC (rev 2758) +++ trunk/source/main/physics/Beam.h 2012-05-30 17:58:43 UTC (rev 2759) @@ -280,7 +280,9 @@ /* *@return Returns a list of all connected (hooked) beams */ - std::list<Beam*> getAllLinkedBeams(); + std::list<Beam*> getAllLinkedBeams() { return linkedBeams; }; + std::list<Beam*> linkedBeams; + void determineLinkedBeams(); // this must be in the header as the network stuff is using it... bool getBrakeLightVisible(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel