From fcbf4a1a1902a99dc5219f2c478ec5b61b9628d4 Mon Sep 17 00:00:00 2001 From: bitplane Date: Mon, 4 Jun 2007 02:50:30 +0000 Subject: [PATCH] Removed array::erase from loops in Octtree.h and COctTreeTriangleSelector.cpp, they now generate a lot faster. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@684 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 4 +++- source/Irrlicht/COctTreeTriangleSelector.cpp | 14 ++++++++++++-- source/Irrlicht/OctTree.h | 15 +++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/changes.txt b/changes.txt index a3ec2fd8..efed8157 100644 --- a/changes.txt +++ b/changes.txt @@ -1,6 +1,6 @@ Changes in version 1.3.1 (?? Mar 2007) - - Some fixes in the 3d basic structures: plane3d.classifyPointRelation no + - Some fixes in the 3d basic structures: plane3d.classifyPointRelation now correctly returns the relation, it returned the opposite before. Also renamed existsInterSection to existsIntersection for consistency. triangle3d.isOnSameSide is now private - it's just a helper class not @@ -89,6 +89,8 @@ Changes in version 1.3.1 (?? Mar 2007) - Fixed a crash when using Octtrees caused by unnecessary dropping of meshes when deserializing the scene node. + - Removed an array::erase from Octtrees and Octtree triangle selector. + GUI: - Fixed a messagebox focus bug when no 'okay' button was present diff --git a/source/Irrlicht/COctTreeTriangleSelector.cpp b/source/Irrlicht/COctTreeTriangleSelector.cpp index d9a22c1b..cb7872ed 100644 --- a/source/Irrlicht/COctTreeTriangleSelector.cpp +++ b/source/Irrlicht/COctTreeTriangleSelector.cpp @@ -70,6 +70,7 @@ void COctTreeTriangleSelector::constructOctTree(SOctTreeNode* node) node->Box.getEdges(edges); core::aabbox3d box; + core::array keepTriangles; // calculate children @@ -85,10 +86,19 @@ void COctTreeTriangleSelector::constructOctTree(SOctTreeNode* node) if (node->Triangles[i].isTotalInsideBox(box)) { node->Child[ch]->Triangles.push_back(node->Triangles[i]); - node->Triangles.erase(i); - --i; + //node->Triangles.erase(i); + //--i; + } + else + { + keepTriangles.push_back(node->Triangles[i]); } } + memcpy(node->Triangles.pointer(), keepTriangles.pointer(), + sizeof(core::triangle3df)*keepTriangles.size()); + + node->Triangles.set_used(keepTriangles.size()); + keepTriangles.set_used(0); if (node->Child[ch]->Triangles.empty()) { diff --git a/source/Irrlicht/OctTree.h b/source/Irrlicht/OctTree.h index 69ee6fad..9bf6bbbc 100644 --- a/source/Irrlicht/OctTree.h +++ b/source/Irrlicht/OctTree.h @@ -189,6 +189,7 @@ private: // calculate all children core::aabbox3d box; + core::array keepIndices; if (totalPrimitives > minimalPolysPerNode && !Box.isEmpty()) for (s32 ch=0; ch<8; ++ch) @@ -219,13 +220,19 @@ private: tic.Indices.push_back((*indices)[i].Indices[t+1]); tic.Indices.push_back((*indices)[i].Indices[t+2]); - (*indices)[i].Indices.erase(t, 3); - - t-=3; - added = true; } + else + { + keepIndices.push_back((*indices)[i].Indices[t]); + keepIndices.push_back((*indices)[i].Indices[t+1]); + keepIndices.push_back((*indices)[i].Indices[t+2]); + } } + + memcpy( (*indices)[i].Indices.pointer(), keepIndices.pointer(), keepIndices.size()*sizeof(u16)); + (*indices)[i].Indices.set_used(keepIndices.size()); + keepIndices.set_used(0); } if (added)