
tutniet
By: a guest on
May 7th, 2012 | syntax:
C++ | size: 0.91 KB | hits: 15 | expires: Never
float Beam::getTotalMass(bool withLocked)
{
if (!withLocked) return totalmass; // already computed in calc_masses2
bool found = true;
float mass = 0.0f;
std::map< Beam*, bool> lookup_table;
std::pair<std::map< Beam*, bool>::iterator, bool> ret;
lookup_table.insert(std::pair< Beam*, bool>(this, false));
while (found)
{
found = false;
for (std::map< Beam*, bool>::iterator it_beam=lookup_table.begin(); it_beam != lookup_table.end(); ++it_beam)
{
if (!it_beam->second)
{
for (std::vector<hook_t>::iterator it_hook=it_beam->first->hooks.begin(); it_hook != it_beam->first->hooks.end(); ++it_hook)
{
if (it_hook->lockTruck)
{
ret = lookup_table.insert(std::pair< Beam*, bool>(it_hook->lockTruck, false));
found = found || ret.second;
}
}
mass += it_beam->first->totalmass;
it_beam->second = true;
}
}
}
return mass;
}