@@ -325,59 +325,34 @@ bool CRenderWareSA::DoContainTheSameGeometry(RpClump* pClumpA, RpClump* pClumpB,
325325 // Fast check if comparing one atomic
326326 if (pAtomicB)
327327 {
328- RpAtomic* atomicA = pGame->GetRenderWare ()->GetFirstAtomic (pClumpA);
329- if (!atomicA)
330- return false ;
331-
332- return atomicA->geometry == pAtomicB->geometry ;
328+ RpGeometry* pGeometryA = ((RpAtomic*)((pClumpA->atomics .root .next ) - 0x8 ))->geometry ;
329+ RpGeometry* pGeometryB = pAtomicB->geometry ;
330+ return pGeometryA == pGeometryB;
333331 }
334332
335- // Check number of atomics in clumps
336- int numAtomicsA = RpClumpGetNumAtomics (pClumpA);
337- int numAtomicsB = RpClumpGetNumAtomics (pClumpB);
338- if (numAtomicsA != numAtomicsB)
339- return false ;
333+ // Get atomic list from both sides
334+ std::vector<RpAtomic*> atomicListA;
335+ std::vector<RpAtomic*> atomicListB;
336+ GetClumpAtomicList (pClumpA, atomicListA);
337+ if (pClumpB)
338+ GetClumpAtomicList (pClumpB, atomicListB);
339+ if (pAtomicB)
340+ atomicListB.push_back (pAtomicB);
340341
341- std::vector<RpGeometry*> geometryListA;
342- std::vector <RpGeometry*> geometryListB ;
343- geometryListA. reserve (numAtomicsA * sizeof (RpGeometry*));
344- geometryListB. reserve (numAtomicsB * sizeof (RpGeometry*) );
342+ // Count geometries that exist in both sides
343+ std::set <RpGeometry*> geometryListA ;
344+ for (uint i = 0 ; i < atomicListA. size (); i++)
345+ MapInsert (geometryListA, atomicListA[i]-> geometry );
345346
346- // Get geometry from clump A
347- RpClumpForAllAtomics (
348- pClumpA, [](RpAtomic* atomic, void * data) -> bool {
349- auto * geometryList = static_cast <std::vector<RpGeometry*>*>(data);
350- geometryList->push_back (atomic->geometry );
347+ uint uiInBoth = 0 ;
348+ for (uint i = 0 ; i < atomicListB.size (); i++)
349+ if (MapContains (geometryListA, atomicListB[i]->geometry ))
350+ uiInBoth++;
351351
352- return true ;
353- },
354- &geometryListA);
355-
356- // Get geometry from clump B
357- RpClumpForAllAtomics (
358- pClumpB,
359- [](RpAtomic* atomic, void * data) -> bool
360- {
361- auto * geometryList = static_cast <std::vector<RpGeometry*>*>(data);
362- geometryList->push_back (atomic->geometry );
363-
364- return true ;
365- },
366- &geometryListB);
367-
368- if (geometryListA.size () != geometryListB.size ())
352+ // If less than 50% match then assume it is not the same
353+ if (uiInBoth * 2 < atomicListB.size () || atomicListB.size () == 0 )
369354 return false ;
370355
371- std::unordered_set<RpGeometry*> geometrySetB;
372- geometrySetB.reserve (geometryListB.size ());
373- geometrySetB.insert (geometryListB.begin (), geometryListB.end ());
374-
375- for (const auto & geomA : geometryListA)
376- {
377- if (geometrySetB.find (geomA) == geometrySetB.end ())
378- return false ;
379- }
380-
381356 return true ;
382357}
383358
0 commit comments