From b350eb5f4d44e8448115796144375d79438d74ae Mon Sep 17 00:00:00 2001 From: Marijn Tamis Date: Fri, 28 Apr 2017 14:19:07 +0200 Subject: NvCloth 1.1.0 Release. (22041545) --- NvCloth/src/SwSolver.cpp | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'NvCloth/src/SwSolver.cpp') diff --git a/NvCloth/src/SwSolver.cpp b/NvCloth/src/SwSolver.cpp index c83eed8..c7437e1 100644 --- a/NvCloth/src/SwSolver.cpp +++ b/NvCloth/src/SwSolver.cpp @@ -93,29 +93,57 @@ void sortTasks(shdfnd::Array& tasks) void cloth::SwSolver::addCloth(Cloth* cloth) { - SwCloth& swCloth = static_cast(*cloth).mCloth; + SwCloth& swCloth = *static_cast(cloth); mSimulatedCloths.pushBack(SimulatedCloth(swCloth, this)); sortTasks(mSimulatedCloths); + + mCloths.pushBack(&swCloth); } void cloth::SwSolver::removeCloth(Cloth* cloth) { - SwCloth& swCloth = static_cast(*cloth).mCloth; + SwCloth& swCloth = *static_cast(cloth); - Vector::Type::Iterator tIt = mSimulatedCloths.begin(); - Vector::Type::Iterator tEnd = mSimulatedCloths.end(); - while (tIt != tEnd && tIt->mCloth != &swCloth) - ++tIt; + //Remove from mSimulatedCloths + { + Vector::Type::Iterator tIt = mSimulatedCloths.begin(); + Vector::Type::Iterator tEnd = mSimulatedCloths.end(); + while(tIt != tEnd && tIt->mCloth != &swCloth) + ++tIt; + + if(tIt != tEnd) + { + NV_CLOTH_FREE(tIt->mScratchMemory); + mSimulatedCloths.replaceWithLast(tIt); + sortTasks(mSimulatedCloths); + } + } - if (tIt != tEnd) + //Remove from mCloths { - NV_CLOTH_FREE(tIt->mScratchMemory); - mSimulatedCloths.replaceWithLast(tIt); - sortTasks(mSimulatedCloths); + ClothVector::Iterator tEnd = mCloths.end(); + ClothVector::Iterator it = mCloths.find(&swCloth); + + if(it != tEnd) + { + mCloths.replaceWithLast(it); + } } } +int cloth::SwSolver::getNumCloths() const +{ + return mCloths.size(); +} +cloth::Cloth * const * cloth::SwSolver::getClothList() const +{ + if(getNumCloths()) + return reinterpret_cast(&mCloths[0]); + else + return nullptr; +} + bool cloth::SwSolver::beginSimulation(float dt) { if (mSimulatedCloths.empty()) -- cgit v1.2.3